Why can't I use the delay on AVR studio 6 ?

Go To Last Post
50 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Friends,

I tried to put a delay
#define F_CPU 80000000

and
_delay_ms(1000);

on AVR Studio 6, but it doesn't work exactly 1 second??

I tested it on AVR Studio 4, it's working fine,

Is there any missing configuration on AVR Studio 6??

I'm using ATMEGA128.

Thanks

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Are you using the same ATMEGA128 chip for both tests? When you say

Quote:
on AVR Studio 6, but it doesn't work exactly 1 second
how much does it differ by?

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

bianchi77 wrote:
#define F_CPU 80000000
Where did you get an 80 MHz ATmega 128? I could use a few...

JJ

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I hope that that is a typo error here on the forom.

btw if he has some... I'm also very interested.....

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

js wrote:
Are you using the same ATMEGA128 chip for both tests? When you say
Quote:
on AVR Studio 6, but it doesn't work exactly 1 second
how much does it differ by?

yes I'm using the same ATMEGA128,

I don't understand why it has a different result by the time I compile it...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

joeymorin wrote:
bianchi77 wrote:
#define F_CPU 80000000
Where did you get an 80 MHz ATmega 128? I could use a few...

JJ


Sorry, it's a typo,
suppose to be 8Mhz...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
yes I'm using the same ATMEGA128,
So
Quote:
how much does it differ by?
1ms, 100ms more??

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Show the commands that built the code. I'm guessing you have AS6 set to -O0.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
Show the commands that built the code. I'm guessing you have AS6 set to -O0.

Where can I see that ?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you have not re-arranged your windows and panes in AS6, then take a look at the bottom left. There should be a pane/tab called "Output", very close to the "Error list" tab. Do a "Rebuild" of your project, then go to that Output pane, mark everything, copy it, and paste it in a post here.

(You are far from alone, but it always mamzes me with people using a tool without having clicked around in it, figuring out what the different parts cater for. Take the tme to do that, it will likely be rewarding..)

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

To Johan, thanks for the clue,

Here's the output :

------ Build started: Project: LCDv1.0, Configuration: Debug AVR ------
Build started.
Project "LCDv1.0.cproj" (default targets):
Target "PreBuildEvent" skipped, due to false condition; ('$(PreBuildEvent)'!='') was evaluated as (''!='').
Target "CoreBuild" in file "C:\Program Files (x86)\Atmel\Atmel Studio 6.1\Vs\Compiler.targets" from project "C:\Users\Antonius\Documents\Atmel Studio\6.1\LCDv1.0\LCDv1.0\LCDv1.0.cproj" (target "Build" depends on it):
	Using "RunCompilerTask" task from assembly "C:\Program Files (x86)\Atmel\Atmel Studio 6.1\Extensions\Application\AvrGCC.dll".
	Task "RunCompilerTask"
		C:\Program Files (x86)\Atmel\Atmel Studio 6.1\shellUtils\make.exe all 
		make: Nothing to be done for `all'.
	Done executing task "RunCompilerTask".
	Using "RunOutputFileVerifyTask" task from assembly "C:\Program Files (x86)\Atmel\Atmel Studio 6.1\Extensions\Application\AvrGCC.dll".
	Task "RunOutputFileVerifyTask"
				Program Memory Usage 	:	818 bytes   0.6 % Full
				Data Memory Usage 		:	82 bytes   2.0 % Full
	Done executing task "RunOutputFileVerifyTask".
Done building target "CoreBuild" in project "LCDv1.0.cproj".
Target "PostBuildEvent" skipped, due to false condition; ('$(PostBuildEvent)' != '') was evaluated as ('' != '').
Target "Build" in file "C:\Program Files (x86)\Atmel\Atmel Studio 6.1\Vs\Avr.common.targets" from project "C:\Users\Antonius\Documents\Atmel Studio\6.1\LCDv1.0\LCDv1.0\LCDv1.0.cproj" (entry point):
Done building target "Build" in project "LCDv1.0.cproj".
Done building project "LCDv1.0.cproj".

Build succeeded.
========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It seems you did a "Build" and the project was already up-to-date, so no compialtion command were issued.

I said do a "Rebuild" (which is a different thing, actually doing a "clean" and then a "build" so that everything actually gets rebuilt, and we can see the commands).

Next time I'll mark the word "Rebuild" even better, e.g. do a Rebuild, or perhaps even Rebuild.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Rebuild :)

------ Rebuild All started: Project: LCDv1.0, Configuration: Debug AVR ------
Build started.
Project "LCDv1.0.cproj" (ReBuild target(s)):
Target "PreBuildEvent" skipped, due to false condition; ('$(PreBuildEvent)'!='') was evaluated as (''!='').
Target "CoreRebuild" in file "C:\Program Files (x86)\Atmel\Atmel Studio 6.1\Vs\Compiler.targets" from project "C:\Users\Antonius\Documents\Atmel Studio\6.1\LCDv1.0\LCDv1.0\LCDv1.0.cproj" (target "ReBuild" depends on it):
	Task "RunCompilerTask"
		C:\Program Files (x86)\Atmel\Atmel Studio 6.1\shellUtils\make.exe clean all 
		rm -rf  LCDv1.0.o   
		rm -rf  LCDv1.0.d   
		rm -rf "LCDv1.0.elf" "LCDv1.0.a" "LCDv1.0.hex" "LCDv1.0.lss" "LCDv1.0.eep" "LCDv1.0.map" "LCDv1.0.srec"
		Building file: .././LCDv1.0.c
		Invoking: AVR/GNU C Compiler : 3.4.2
		"C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.2.939\avr8-gnu-toolchain\bin\avr-gcc.exe"  -funsigned-char -funsigned-bitfields -DDEBUG  -O1 -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -mrelax -g2 -Wall -mmcu=atmega128a -c -std=gnu99 -MD -MP -MF "LCDv1.0.d" -MT"LCDv1.0.d" -MT"LCDv1.0.o"   -o "LCDv1.0.o" ".././LCDv1.0.c"
		.././LCDv1.0.c: In function 'main':
C:\Users\Antonius\Documents\Atmel Studio\6.1\LCDv1.0\LCDv1.0\LCDv1.0.c(118,3): pointer targets in passing argument 1 of 'lcd_string' differ in signedness [-Wpointer-sign]
C:\Users\Antonius\Documents\Atmel Studio\6.1\LCDv1.0\LCDv1.0\LCDv1.0.c(87,6): expected 'unsigned char *' but argument is of type 'char *'
C:\Users\Antonius\Documents\Atmel Studio\6.1\LCDv1.0\LCDv1.0\LCDv1.0.c(120,3): pointer targets in passing argument 1 of 'lcd_string' differ in signedness [-Wpointer-sign]
C:\Users\Antonius\Documents\Atmel Studio\6.1\LCDv1.0\LCDv1.0\LCDv1.0.c(87,6): expected 'unsigned char *' but argument is of type 'char *'
C:\Users\Antonius\Documents\Atmel Studio\6.1\LCDv1.0\LCDv1.0\LCDv1.0.c(127,3): pointer targets in passing argument 1 of 'lcd_string' differ in signedness [-Wpointer-sign]
C:\Users\Antonius\Documents\Atmel Studio\6.1\LCDv1.0\LCDv1.0\LCDv1.0.c(87,6): expected 'unsigned char *' but argument is of type 'char *'
C:\Users\Antonius\Documents\Atmel Studio\6.1\LCDv1.0\LCDv1.0\LCDv1.0.c(129,3): pointer targets in passing argument 1 of 'lcd_string' differ in signedness [-Wpointer-sign]
C:\Users\Antonius\Documents\Atmel Studio\6.1\LCDv1.0\LCDv1.0\LCDv1.0.c(87,6): expected 'unsigned char *' but argument is of type 'char *'
C:\Users\Antonius\Documents\Atmel Studio\6.1\LCDv1.0\LCDv1.0\LCDv1.0.c(136,3): pointer targets in passing argument 1 of 'lcd_string' differ in signedness [-Wpointer-sign]
C:\Users\Antonius\Documents\Atmel Studio\6.1\LCDv1.0\LCDv1.0\LCDv1.0.c(87,6): expected 'unsigned char *' but argument is of type 'char *'
C:\Users\Antonius\Documents\Atmel Studio\6.1\LCDv1.0\LCDv1.0\LCDv1.0.c(138,3): pointer targets in passing argument 1 of 'lcd_string' differ in signedness [-Wpointer-sign]
C:\Users\Antonius\Documents\Atmel Studio\6.1\LCDv1.0\LCDv1.0\LCDv1.0.c(87,6): expected 'unsigned char *' but argument is of type 'char *'
C:\Users\Antonius\Documents\Atmel Studio\6.1\LCDv1.0\LCDv1.0\LCDv1.0.c(145,3): pointer targets in passing argument 1 of 'lcd_string' differ in signedness [-Wpointer-sign]
C:\Users\Antonius\Documents\Atmel Studio\6.1\LCDv1.0\LCDv1.0\LCDv1.0.c(87,6): expected 'unsigned char *' but argument is of type 'char *'
C:\Users\Antonius\Documents\Atmel Studio\6.1\LCDv1.0\LCDv1.0\LCDv1.0.c(147,3): pointer targets in passing argument 1 of 'lcd_string' differ in signedness [-Wpointer-sign]
C:\Users\Antonius\Documents\Atmel Studio\6.1\LCDv1.0\LCDv1.0\LCDv1.0.c(87,6): expected 'unsigned char *' but argument is of type 'char *'
		Finished building: .././LCDv1.0.c
		Building target: LCDv1.0.elf
		Invoking: AVR/GNU Linker : 3.4.2
		"C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.2.939\avr8-gnu-toolchain\bin\avr-gcc.exe" -o LCDv1.0.elf  LCDv1.0.o   -Wl,-Map="LCDv1.0.map" -Wl,--start-group -Wl,-lm  -Wl,--end-group -Wl,--gc-sections -mrelax -mmcu=atmega128a 
		Finished building target: LCDv1.0.elf
		"C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.2.939\avr8-gnu-toolchain\bin\avr-objcopy.exe" -O ihex -R .eeprom -R .fuse -R .lock -R .signature  "LCDv1.0.elf" "LCDv1.0.hex"
		"C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.2.939\avr8-gnu-toolchain\bin\avr-objcopy.exe" -j .eeprom  --set-section-flags=.eeprom=alloc,load --change-section-lma .eeprom=0  --no-change-warnings -O ihex "LCDv1.0.elf" "LCDv1.0.eep" || exit 0
		"C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.2.939\avr8-gnu-toolchain\bin\avr-objdump.exe" -h -S "LCDv1.0.elf" > "LCDv1.0.lss"
		"C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.2.939\avr8-gnu-toolchain\bin\avr-objcopy.exe" -O srec -R .eeprom -R .fuse -R .lock -R .signature  "LCDv1.0.elf" "LCDv1.0.srec"
		"C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.2.939\avr8-gnu-toolchain\bin\avr-size.exe" "LCDv1.0.elf"
		   text	   data	    bss	    dec	    hex	filename
		    736	     82	      0	    818	    332	LCDv1.0.elf
	Done executing task "RunCompilerTask".
	Task "RunOutputFileVerifyTask"
				Program Memory Usage 	:	818 bytes   0.6 % Full
				Data Memory Usage 		:	82 bytes   2.0 % Full
	Done executing task "RunOutputFileVerifyTask".
Done building target "CoreRebuild" in project "LCDv1.0.cproj".
Target "PostBuildEvent" skipped, due to false condition; ('$(PostBuildEvent)' != '') was evaluated as ('' != '').
Target "ReBuild" in file "C:\Program Files (x86)\Atmel\Atmel Studio 6.1\Vs\Avr.common.targets" from project "C:\Users\Antonius\Documents\Atmel Studio\6.1\LCDv1.0\LCDv1.0\LCDv1.0.cproj" (entry point):
Done building target "ReBuild" in project "LCDv1.0.cproj".
Done building project "LCDv1.0.cproj".

Build succeeded.
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Dont we need to include to use delays?

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well, you're compiling with the optimizer activated ("-O1"), so it's not that.

It is now time for you to

1) Show a minimal but complete program that demonstrates the problem. (Do not type this program into the forum. We want an exact copy of what you're compiling and running - so do a copy/paste from your editor to the forum here.)

2) Double-check that the AVR is actually running at 8 MHz. We do not accept "I know it is running at 8 MHz!". We need a description of the proof you have for this or we simply will doubt that the AVR is running at 8 MHz.

3) Answer the question asked earlier: How much does the delay time differ from the expected? So far it's been all "doesn't work exactly 1 second" and "a different result by the time I compile it". Those are totally meaningless statements. Is it of by 0.1 percent or by half an hour?

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

Last Edited: Wed. May 22, 2013 - 03:04 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Dont we need to include to use delays?

Yes Bob, but the OP has not shown any complete code. Just snippets - and probably typed in rather than copied and pasted. As such they are not to be trusted, and are worth zero.

As you can see above I have asked the OP to post a complete but minimal program that displays the problem.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It would not hurt to define F_CPU as unsigned long, to rule out some problem with 16 bit overflow.

See
https://www.avrfreaks.net/index.p...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

JohanEkdahl wrote:
Well, you're compiling with the optimizer activated ("-O1"), so it's not that.

It is now time for you to

1) Show a minimal but complete program that demonstrates the problem. (Do not type this program into the forum. We want an exact copy of what you're compiling and running - so do a copy/paste from your editor to the forum here.)

2) Double-check that the AVR is actually running at 8 MHz. We do not accept "I know it is running at 8 MHz!". We need a description of the proof you have for this or we simply will doubt that the AVR is running at 8 MHz.

3) Answer the question asked earlier: How much does the delay time differ from the expected? So far it's been all "doesn't work exactly 1 second" and "a different result by the time I compile it". Those are totally meaningless statements. Is it of by 0.1 percent or by half an hour?


Ok, I'll answer your question,

No 1.
Here's the code :

#include 
#include 
#include 
#include 


// structure to allow bit field operations, name conversions: PORTA.0 -> PORT_A.b0  PORTB.7 -> PORT_B.b7
typedef struct{ uint8_t b0:1;
                uint8_t b1:1;
                uint8_t b2:1;
                uint8_t b3:1;
                uint8_t b4:1;
                uint8_t b5:1;
                uint8_t b6:1;
                uint8_t b7:1; } bits;
 
// define all the ports of your microcontroller, add more ports depending on the available mcu ports
#define PORT_D (* (volatile bits *) &PORTD)
#define PIN_D (* (volatile bits *) &PIND)
#define DDR_D (* (volatile bits *) &DDRD)
 
#define PORT_G (* (volatile bits *) &PORTG)
#define PIN_G (* (volatile bits *) &PING)
#define DDR_G (* (volatile bits *) &DDRG)
 
//Mention Clock frequency here
#define _XTAL_FREQ 8000000 
#define F_CPU 8000000UL  // 8 MHz

// Define baud rate
#define USART_BAUDRATE 9600   
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1)
 
#define lcd_data_pin PORTA

#define en PORT_D.b0
#define rs PORT_D.b1
#define rw PORT_D.b2
 

void lcd_init();
void lcd_data(unsigned char data1);
void lcd_cmd(unsigned char cmd);
void lcd_control(unsigned char cmdordata);
void lcd_string(unsigned char *str);
void usart_init(unsigned int ubrr);
void usart_transmit( unsigned char data );
unsigned char usart_receive( void );
void usart_pstr(char *s);

void usart_init( unsigned int ubrr )
{
/* Set baud rate */

	UBRR0H = (unsigned char)(ubrr>>8);
	UBRR0L = (unsigned char)ubrr;
	/* Enable receiver and transmitter */
	UCSR0B = (1<<RXEN)|(1<<TXEN);
	/* Set frame format: 8data, 2stop bit */
	UCSR0C = (1<<USBS)|(3<<UCSZ0);
}

void usart_transmit( unsigned char data )
{
/* Wait for empty transmit buffer */
while ( !( UCSR0A & (1<<UDRE)) )
;
/* Put data into buffer, sends the data */
UDR0 = data;
}



void usart_pstr(char *s) {

    // loop through entire string

    while (*s) {
        usart_transmit(*s);
        s++;
    }
}


unsigned char usart_receive( void )
{
/* Wait for data to be received */
while ( !(UCSR0A & (1<<RXC)) )
;
/* Get and return received data from buffer */
return UDR0;
}

 

void lcd_init(){
    
    lcd_cmd(0x30);
	_delay_ms(10);      
    lcd_cmd(0x38);
	_delay_ms(10);      
    lcd_cmd(0x0F);
	_delay_ms(10);
   	lcd_cmd(0x80);
	_delay_ms(10);

}
 
void lcd_data(unsigned char data1)
{
     
    
    lcd_data_pin = data1;// & 0x0F;
     	en=1;
        rs=1;
        rw=0;
        _delay_ms(10);
        en=0;
        
}
 
void lcd_cmd(unsigned char cmd){
    lcd_data_pin = cmd ;
	    
		en=1;
        rs=0;
        rw=0;
        _delay_ms(10);       
        en=0;
        
}
	

 
void lcd_string(unsigned char *str){
 
    while(*str){
        lcd_data(*str++);       
    }
 
}


 
 
 
 
int main(){
 
    DDR_D.b0 = 1;
	DDR_D.b1 = 1;
	DDR_D.b2 = 1;
    DDRA = 0xFF;
 
    lcd_init();
	usart_init ( BAUD_PRESCALE );
    
    
    while(1){
	
	  usart_pstr("HALLO FROM ATMEGA128\n");
	
	  

 	  _delay_ms (10);
		lcd_cmd(0x80);//put the cursor into the first row
        _delay_ms (10);
        lcd_cmd(0x01);//Clear display
	    _delay_ms (10);
        lcd_cmd(0xC0);//goto second row
        _delay_ms (10); 
       lcd_cmd(0x01); //Clear display

	   lcd_cmd(0x80);//put the cursor into the first row
        _delay_ms (10);
        lcd_cmd(0x01);//Clear display
	    _delay_ms (10);
       lcd_string("Message");
	   lcd_cmd(0xC0);//goto second row
       lcd_string("Flasher");
	   _delay_ms(1000);
	    //next screen
       
	   lcd_cmd(0x80);//put the cursor into the first row
        _delay_ms (10);
        lcd_cmd(0x01);//Clear display
	    _delay_ms (10);
	   lcd_string("With ATMEGA128");
	   lcd_cmd(0xC0);//goto second row
       lcd_string("By arick");
	   _delay_ms(1000);
	   //next screen
	   
	   lcd_cmd(0x80);//put the cursor into the first row
        _delay_ms (10);
        lcd_cmd(0x01);//Clear display
	    _delay_ms (10);
       lcd_string("Published on");
	   lcd_cmd(0xC0);//goto second row
       lcd_string("Instructable.com");
	   _delay_ms(1000);
	   //next screen
	   lcd_cmd(0x80);//put the cursor into the first row
        _delay_ms (10);
        lcd_cmd(0x01);//Clear display
	    _delay_ms (10);
       lcd_string("Made in");
	   lcd_cmd(0xC0);//goto second row
       lcd_string("AUSTRALIA");
	   _delay_ms(1000);


      
    }
    
    return (0);
}

No 2. yes it's 8Mhz,
I put a jumper 8Mhz Crystal and pull it out to see it's stopped running without crystal.

No 3.
How much does the delay time differ from the expected?

If I compiled with AVR studio 4, it's normal 1 second delay, I can compare with my clock ticking on the wall...but with AVR studio 6, it's very fast, I don't know exactly but it's not 1000ms....that's it...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

bianchi77 wrote:
it's very fast, I don't know exactly but it's not 1000ms....that's it...
You'll have to do better than that. Is it 500 mS? 100 mS? Without a more accurate measure, the best we can say is the problem lies somewhere between lines 1 and 217 in your code.

In your code I see several calls to _delay_ms(), with a number of them having 1000 as an argument. This is the code that exhibits faster-than-expected _delay_ms() behaviour? You're saying that serial comms at 9600 is working as expected, but calls to _delay_ms() are too fast? Are you in fact seeing output from:

usart_pstr("HALLO FROM ATMEGA128\n");

... ?

JJ

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

joeymorin wrote:
bianchi77 wrote:
it's very fast, I don't know exactly but it's not 1000ms....that's it...
You'll have to do better than that. Is it 500 mS? 100 mS? Without a more accurate measure, the best we can say is the problem lies somewhere between lines 1 and 217 in your code.

In your code I see several calls to _delay_ms(), with a number of them having 1000 as an argument. This is the code that exhibits faster-than-expected _delay_ms() behaviour? You're saying that serial comms at 9600 is working as expected, but calls to _delay_ms() are too fast? Are you in fact seeing output from:

usart_pstr("HALLO FROM ATMEGA128\n");

... ?

JJ


Yes I'm seeing the output on my terminal...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

joeymorin wrote:
Is it 500 mS? 100 mS? Without a more accurate measure, the best we can say is the problem lies somewhere between lines 1 and 217 in your code.

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Here's the code

I see no #define for F_CPU in there. If it is missing then the delay routines will think the AVR is running at 1 MHz, and if it is actually running at 8 MHz then the delays will be 1/8 of the expected. I.e. actually 125 ms for _delay_ms(1000).

If F_CPU is defined through the project settings dialogue for defined symbols, then double-check that it is correct.

If there actually is a #define in the code and you have not shown it then you have not followed ny advice #1 a few post earlier. This a) stops us from helping you, and b) effectively wastes our time and makes us frustrated to the point where you might be abandoned.

Be meticulous about the facts and questions you post, and there is a much better chance of you getting help.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

I see no #define for F_CPU in there. If it is missing then the delay routines will think the AVR is running at 1 MHz, and if it is actually running at 8 MHz then the delays will be 1/8 of the expected.

I thought that too but if that had occurred the build output would have shown:

# warning "F_CPU not defined for "

I don't see that warning in the build output.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
I don't see that warning in the build output.

I do not trust that the build output is for the source that was posted 12 hours later.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

JohanEkdahl wrote:
I see no #define for F_CPU in there. If it is missing then the delay routines will think the AVR is running at 1 MHz, and if it is actually running at 8 MHz then the delays will be 1/8 of the expected. I.e. actually 125 ms for _delay_ms(1000).
clawson wrote:
I thought that too but if that had occurred the build output would have shown:
# warning "F_CPU not defined for "

I don't see that warning in the build output.

Hmmm... it is actually in his posted code... about 20 lines after the #include:
#include 
#include 
#include 
#include 

...

//Mention Clock frequency here
#define _XTAL_FREQ 8000000 
#define F_CPU 8000000UL  // 8 MHz

If the build output is indeed genuine, then the observed behaviour might be explained if F_CPU is also defined through the project settings dialogue for defined symbols, but differently. My money is with Johan's on 1 MHz.

bianchi77 wrote:
If I compiled with AVR studio 4, it's normal 1 second delay, I can compare with my clock ticking on the wall...but with AVR studio 6, it's very fast, I don't know exactly but it's not 1000ms....that's it...
I don't use Studio. Is there a difference between 4 and 6 w.r.t the default value for F_CPU via project settings dialogue for defined symbols?

JJ

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Hmmm... it is actually in his posted code...

Well, since it needs to be done before the #include I only bothered to read the first few lines.

This is turning out to be a real mess. And possibly the un-necessary waste of time that I feared.

If people drove cars the way questions are posed here at 'freaks then 98 percent of the population would be dead by now, due to wreckless, hip-hap and totally confused driving.. :roll:

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

JohanEkdahl wrote:
If people drove cars the way questions are posed here at 'freaks then 98 percent of the population would be dead by now, due to wreckless, hip-hap and totally confused driving.. :roll:
Perhaps the driving is different where you live, but these questions don't surprise me at all ;) ... They are, however, just as frustrating as the drivers...

JJ

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ok to make it clear I rebuild from this code now...
The code :

/*
 * LCDv1.c
 *
 * Created: 22/05/2013 10:52:57 AM
 *  Author: Antonius
 */ 

#define F_CPU 80000000UL    // AVR clock frequency in Hz, used by util/delay.h
#include 
#include 

// structure to allow bit field operations, name conversions: PORTA.0 -> PORT_A.b0  PORTB.7 -> PORT_B.b7
typedef struct{ uint8_t b0:1;
	uint8_t b1:1;
	uint8_t b2:1;
	uint8_t b3:1;
	uint8_t b4:1;
	uint8_t b5:1;
	uint8_t b6:1;
uint8_t b7:1; } bits;

// define all the ports of your microcontroller, add more ports depending on the available mcu ports
#define PORT_D (* (volatile bits *) &PORTD)
#define PIN_D (* (volatile bits *) &PIND)
#define DDR_D (* (volatile bits *) &DDRD)

#define PORT_G (* (volatile bits *) &PORTG)
#define PIN_G (* (volatile bits *) &PING)
#define DDR_G (* (volatile bits *) &DDRG)

//Mention Clock frequency here
//#define _XTAL_FREQ 8000000

#define lcd_data_pin PORTA

#define en PORT_D.b0
#define rs PORT_D.b1
#define rw PORT_D.b2


void lcd_init();
void lcd_data(unsigned char data1);
void lcd_cmd(unsigned char cmd);
void lcd_control(unsigned char cmdordata);
void lcd_string(unsigned char *str);


void lcd_init(){
	
	lcd_cmd(0x30);
	_delay_ms(10);
	lcd_cmd(0x38);
	_delay_ms(10);
	lcd_cmd(0x0F);
	_delay_ms(10);
	lcd_cmd(0x80);
	_delay_ms(10);

}

void lcd_data(unsigned char data1)
{
	
	
	lcd_data_pin = data1;// & 0x0F;
	en=1;
	rs=1;
	rw=0;
	_delay_ms(10);
	en=0;
	
}

void lcd_cmd(unsigned char cmd){
	lcd_data_pin = cmd ;
	
	en=1;
	rs=0;
	rw=0;
	_delay_ms(10);
	en=0;
	
}



void lcd_string(unsigned char *str){
	
	while(*str){
		lcd_data(*str++);
	}
	
}




int main(){
	
	DDR_D.b0 = 1;
	DDR_D.b1 = 1;
	DDR_D.b2 = 1;
	DDRA = 0xFF;
	
	lcd_init();
	
	
	while(1){
		_delay_ms (10);
		lcd_cmd(0x80);//put the cursor into the first row
		_delay_ms (10);
		lcd_cmd(0x01);//Clear display
		_delay_ms (10);
		lcd_cmd(0xC0);//goto second row
		_delay_ms (10);
		lcd_cmd(0x01); //Clear display
		
		lcd_string("HELLO ATMEGA128");
		lcd_cmd(0xC0);//goto second row
		lcd_string("By bianchi");
		_delay_ms(1000);
		//next screen
		lcd_cmd(0x80);//put the cursor into the first row
		_delay_ms (10);
		lcd_cmd(0x01);//Clear display
		_delay_ms (10);
		lcd_string("Home");
		lcd_cmd(0xC0);//goto second row
		lcd_string("WA");
		_delay_ms(1000);
		//next screen
		lcd_cmd(0x80);//put the cursor into the first row
		_delay_ms (10);
		lcd_cmd(0x01);//Clear display
		_delay_ms (10);
		lcd_string("LCD");
		lcd_cmd(0xC0);//goto second row
		lcd_string("with Qtouch");
		_delay_ms(1000);
		//next screen
		lcd_cmd(0x80);//put the cursor into the first row
		_delay_ms (10);
		lcd_cmd(0x01);//Clear display
		_delay_ms (10);
		lcd_string("Made in");
		lcd_cmd(0xC0);//goto second row
		lcd_string("AUSTRALIA");
		_delay_ms(1000);


		
	}
	
	return (0);
}

The output :

------ Rebuild All started: Project: LCDv1.0, Configuration: Debug AVR ------
Build started.
Project "LCDv1.0.cproj" (ReBuild target(s)):
Target "PreBuildEvent" skipped, due to false condition; ('$(PreBuildEvent)'!='') was evaluated as (''!='').
Target "CoreRebuild" in file "C:\Program Files (x86)\Atmel\Atmel Studio 6.1\Vs\Compiler.targets" from project "C:\Users\Antonius\Documents\Atmel Studio\6.1\LCDv1.0\LCDv1.0\LCDv1.0.cproj" (target "ReBuild" depends on it):
	Using "RunCompilerTask" task from assembly "C:\Program Files (x86)\Atmel\Atmel Studio 6.1\Extensions\Application\AvrGCC.dll".
	Task "RunCompilerTask"
		C:\Program Files (x86)\Atmel\Atmel Studio 6.1\shellUtils\make.exe clean all 
		rm -rf  LCDv1.0.o   
		rm -rf  LCDv1.0.d   
		rm -rf "LCDv1.0.elf" "LCDv1.0.a" "LCDv1.0.hex" "LCDv1.0.lss" "LCDv1.0.eep" "LCDv1.0.map" "LCDv1.0.srec"
		Building file: .././LCDv1.0.c
		Invoking: AVR/GNU C Compiler : 3.4.2
		"C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.2.939\avr8-gnu-toolchain\bin\avr-gcc.exe"  -funsigned-char -funsigned-bitfields -DDEBUG  -O1 -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -mrelax -g2 -Wall -mmcu=atmega128a -c -std=gnu99 -MD -MP -MF "LCDv1.0.d" -MT"LCDv1.0.d" -MT"LCDv1.0.o"   -o "LCDv1.0.o" ".././LCDv1.0.c"
		.././LCDv1.0.c: In function 'main':
C:\Users\Antonius\Documents\Atmel Studio\6.1\LCDv1.0\LCDv1.0\LCDv1.0.c(118,3): pointer targets in passing argument 1 of 'lcd_string' differ in signedness [-Wpointer-sign]
C:\Users\Antonius\Documents\Atmel Studio\6.1\LCDv1.0\LCDv1.0\LCDv1.0.c(87,6): expected 'unsigned char *' but argument is of type 'char *'
C:\Users\Antonius\Documents\Atmel Studio\6.1\LCDv1.0\LCDv1.0\LCDv1.0.c(120,3): pointer targets in passing argument 1 of 'lcd_string' differ in signedness [-Wpointer-sign]
C:\Users\Antonius\Documents\Atmel Studio\6.1\LCDv1.0\LCDv1.0\LCDv1.0.c(87,6): expected 'unsigned char *' but argument is of type 'char *'
C:\Users\Antonius\Documents\Atmel Studio\6.1\LCDv1.0\LCDv1.0\LCDv1.0.c(127,3): pointer targets in passing argument 1 of 'lcd_string' differ in signedness [-Wpointer-sign]
C:\Users\Antonius\Documents\Atmel Studio\6.1\LCDv1.0\LCDv1.0\LCDv1.0.c(87,6): expected 'unsigned char *' but argument is of type 'char *'
C:\Users\Antonius\Documents\Atmel Studio\6.1\LCDv1.0\LCDv1.0\LCDv1.0.c(129,3): pointer targets in passing argument 1 of 'lcd_string' differ in signedness [-Wpointer-sign]
C:\Users\Antonius\Documents\Atmel Studio\6.1\LCDv1.0\LCDv1.0\LCDv1.0.c(87,6): expected 'unsigned char *' but argument is of type 'char *'
C:\Users\Antonius\Documents\Atmel Studio\6.1\LCDv1.0\LCDv1.0\LCDv1.0.c(136,3): pointer targets in passing argument 1 of 'lcd_string' differ in signedness [-Wpointer-sign]
C:\Users\Antonius\Documents\Atmel Studio\6.1\LCDv1.0\LCDv1.0\LCDv1.0.c(87,6): expected 'unsigned char *' but argument is of type 'char *'
C:\Users\Antonius\Documents\Atmel Studio\6.1\LCDv1.0\LCDv1.0\LCDv1.0.c(138,3): pointer targets in passing argument 1 of 'lcd_string' differ in signedness [-Wpointer-sign]
C:\Users\Antonius\Documents\Atmel Studio\6.1\LCDv1.0\LCDv1.0\LCDv1.0.c(87,6): expected 'unsigned char *' but argument is of type 'char *'
C:\Users\Antonius\Documents\Atmel Studio\6.1\LCDv1.0\LCDv1.0\LCDv1.0.c(145,3): pointer targets in passing argument 1 of 'lcd_string' differ in signedness [-Wpointer-sign]
C:\Users\Antonius\Documents\Atmel Studio\6.1\LCDv1.0\LCDv1.0\LCDv1.0.c(87,6): expected 'unsigned char *' but argument is of type 'char *'
C:\Users\Antonius\Documents\Atmel Studio\6.1\LCDv1.0\LCDv1.0\LCDv1.0.c(147,3): pointer targets in passing argument 1 of 'lcd_string' differ in signedness [-Wpointer-sign]
C:\Users\Antonius\Documents\Atmel Studio\6.1\LCDv1.0\LCDv1.0\LCDv1.0.c(87,6): expected 'unsigned char *' but argument is of type 'char *'
		Finished building: .././LCDv1.0.c
		Building target: LCDv1.0.elf
		Invoking: AVR/GNU Linker : 3.4.2
		"C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.2.939\avr8-gnu-toolchain\bin\avr-gcc.exe" -o LCDv1.0.elf  LCDv1.0.o   -Wl,-Map="LCDv1.0.map" -Wl,--start-group -Wl,-lm  -Wl,--end-group -Wl,--gc-sections -mrelax -mmcu=atmega128a 
		Finished building target: LCDv1.0.elf
		"C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.2.939\avr8-gnu-toolchain\bin\avr-objcopy.exe" -O ihex -R .eeprom -R .fuse -R .lock -R .signature  "LCDv1.0.elf" "LCDv1.0.hex"
		"C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.2.939\avr8-gnu-toolchain\bin\avr-objcopy.exe" -j .eeprom  --set-section-flags=.eeprom=alloc,load --change-section-lma .eeprom=0  --no-change-warnings -O ihex "LCDv1.0.elf" "LCDv1.0.eep" || exit 0
		"C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.2.939\avr8-gnu-toolchain\bin\avr-objdump.exe" -h -S "LCDv1.0.elf" > "LCDv1.0.lss"
		"C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.2.939\avr8-gnu-toolchain\bin\avr-objcopy.exe" -O srec -R .eeprom -R .fuse -R .lock -R .signature  "LCDv1.0.elf" "LCDv1.0.srec"
		"C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.2.939\avr8-gnu-toolchain\bin\avr-size.exe" "LCDv1.0.elf"
		   text	   data	    bss	    dec	    hex	filename
		    736	     82	      0	    818	    332	LCDv1.0.elf
	Done executing task "RunCompilerTask".
	Using "RunOutputFileVerifyTask" task from assembly "C:\Program Files (x86)\Atmel\Atmel Studio 6.1\Extensions\Application\AvrGCC.dll".
	Task "RunOutputFileVerifyTask"
				Program Memory Usage 	:	818 bytes   0.6 % Full
				Data Memory Usage 		:	82 bytes   2.0 % Full
	Done executing task "RunOutputFileVerifyTask".
Done building target "CoreRebuild" in project "LCDv1.0.cproj".
Target "PostBuildEvent" skipped, due to false condition; ('$(PostBuildEvent)' != '') was evaluated as ('' != '').
Target "ReBuild" in file "C:\Program Files (x86)\Atmel\Atmel Studio 6.1\Vs\Avr.common.targets" from project "C:\Users\Antonius\Documents\Atmel Studio\6.1\LCDv1.0\LCDv1.0\LCDv1.0.cproj" (entry point):
Done building target "ReBuild" in project "LCDv1.0.cproj".
Done building project "LCDv1.0.cproj".

Build succeeded.
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========

Learner driver sometimes needs to ask to the experience ones, right....hehehe
Thank you...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
#define F_CPU 80000000UL    // AVR clock frequency in Hz, used by util/delay.h

*sigh* ... A fresh batch of 80 MHz AVR just arrived? Let me guess... You have finally done what we've all been asking you to do, and you've measured how long the 1000 mS delays are... but you're just keeping us in suspense...? Are they [edit]10000[/edit] mS?

Or are you going to tell us that you have once again posted code that was not copy-pasted from Studio?

It is also time that you post the disassembled output of your build.

JJ

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

Last Edited: Fri. May 24, 2013 - 02:44 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You guys can see on the video,
now the delay is more than 1 second,
crystal = 8 Mhz, I plug it out to test and when I plug it out it's stop running...
so I'm sure it's 8Mhz

the video...with the code above
http://youtu.be/a_5X5Q-DF8k

Thank you

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

as you guys see on the video it's more than 1000ms...?

//next screen
		lcd_cmd(0x80);//put the cursor into the first row
		_delay_ms (10);
		lcd_cmd(0x01);//Clear display
		_delay_ms (10);
		lcd_string("Home");
		lcd_cmd(0xC0);//goto second row
		lcd_string("WA");
		_delay_ms(1000);
		//next screen
		lcd_cmd(0x80);//put the cursor into the first row
		_delay_ms (10);
		lcd_cmd(0x01);//Clear display
		_delay_ms (10);
		lcd_string("LCD");
		lcd_cmd(0xC0);//goto second row
		lcd_string("with Qtouch");
		_delay_ms(1000);
		//next screen
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

bianchi77 wrote:
as you guys see on the video it's more than 1000ms...?
Yeah. It's 10,000 mS. Ten times too much. Like your definition of F_CPU.

JJ

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
so I'm sure it's 8Mhz
Like Joe keeps on pointing out you have 80 MHz and NOT 8 MHz in the definition.
Quote:
#define F_CPU 80000000UL // AVR clock frequency in Hz, used by util/delay.h
One zero TOO MANY!

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Might I suggest

#define F_CPU (8UL*1000*1000)

?

Iluvatar is the better part of Valar.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

my mistake guys,
#define F_CPU 8000000UL // AVR clock frequency in Hz, used by util/delay.h

Now it has 6 zeros isn't it ??
It's time to test,

thanks a lot..

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

All good.....
1s delay accomplished.....
Thank you very very ( 6 times ) much....(80 Mhz bug)
hiiiihihihii

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

js wrote:
Quote:
so I'm sure it's 8Mhz
Like Joe keeps on pointing out you have 80 MHz and NOT 8 MHz in the definition.
Quote:
#define F_CPU 80000000UL // AVR clock frequency in Hz, used by util/delay.h
One zero TOO MANY!

Got it mate, thanks....

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

joeymorin wrote:
bianchi77 wrote:
as you guys see on the video it's more than 1000ms...?
Yeah. It's 10,000 mS. Ten times too much. Like your definition of F_CPU.

JJ

yup it's my mistake, sorry, I put too many zeros on the def....

Another lesson to learn...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

bianchi77 wrote:
All good.....
1s delay accomplished.....
Thank you very very ( 6 times ) much....(80 Mhz bug)
hiiiihihihii
Glad to hear it.

I assume you realize that the problem was never with Studio 6. The fact that it worked as expected in Studio 4, but not in Studio 6, is likely due to the project settings dialogue for defined symbols having different default values for F_CPU. You never reported what that value was. Had you done so, this might have been solved much sooner.

Lessons you should have learned here:

    - F_CPU must be defined before including libraries that depend upon it. - redefining F_CPU (or any other symbol) in your code overrides the value of that symbol as defined in the project settings dialogue for defined symbols, but only for code that appears after the redefinition.
    - you should try to answer all questions raised by those who respond to your topic here on avrfreaks.net
Have fun with your project.

JJ

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

skeeve wrote:
Might I suggest
#define F_CPU (8UL*1000*1000)

?

Not a bad idea! ;)

If I'm not mistaken, however, C does not guarantee the order of evaluation absent parenthesis or obvious operator precedence. Is it not possible, then, that 1000*1000 would be evaluated as 16-bit signed first, leading to overflow?

Would this be better:

#define F_CPU ((8UL*1000)*1000)

... ?

JJ

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If only my bank manager would add a simple zero (or 3) to my account balance...

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So now we spent two pages of attempting to help on something that was pointed out to the problem owner in the second reply? What a total waste of time. :(

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Not a bad idea!

#define F_CPU 8E6

perhaps? ;-)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

#define F_CPU 8E6

perhaps? ;-)

Or:
#define F_CPU ((1<<3)*(1E6))

...? [edit];)[/edit]

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

Last Edited: Fri. May 24, 2013 - 03:53 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You really should have a smilie on that, Joey, to indicate that it was ironic or a joke..

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I had a smiley but actually it wasn't a joke - how confusing!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

joeymorin wrote:
skeeve wrote:
Might I suggest
#define F_CPU (8UL*1000*1000)

?

Not a bad idea! ;)

If I'm not mistaken, however, C does not guarantee the order of evaluation absent parenthesis or obvious operator precedence. Is it not possible, then, that 1000*1000 would be evaluated as 16-bit signed first, leading to overflow?

My expression works because C guarantees the associativity of operators,
e.g. strings of multiplications, divisions and moduli are performed left to right. In
fred(&x) * greg(&x) / hank(&x) % ivan(&x) * jane(&x)

the indicated arithmetic would be effectively performed in the order indicated,
but the functions could be called in any order.

Quote:
Would this be better:
#define F_CPU ((8UL*1000)*1000)

... ?

It works, but it will have some people matching parentheses.
Other suggestions in this topic make F_CPU into a floating point number.
That could be fixed by a cast.
That might also have some people matching parentheses.

Iluvatar is the better part of Valar.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
If only my bank manager would add a simple zero (or 3) to my account balance...

I bet you have no debts....

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

skeeve wrote:
My expression works because C guarantees the associativity of operators,
e.g. strings of multiplications, divisions and moduli are performed left to right.
Learn somethin' new every day...

JJ

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
I bet you have no debts....
You lost the bet, send the $80,000,000.00 wager now so that I can pay my debts. :-)

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly