AVR-timer1-simple

Jul 05, 2003 5 Replies

I am not able to understand why on the AVR3.55 simulator below mentioned code gives app. 50sec ticks instead of 1sec



#define CLK 4000000



outp(5,TCCR1B);//prescale CK to CK/1024 outw(63000,TCNT1);//I want 1 sec interval



signal(SIG_OVERFLOW1){ outw(61635,TCNT1); //0xFFFF - CLK/1024 to get 1sec ticks if(bit_is_set(1,PORTB)) cbi(1,PORTB); else sbi(1,PORTB); //toggle output pin }


well, first off, i would have to question how you are making assembly instruction calls without the "asm" directive? you got the magic compiler or something?

Looks like it's the AVR GCC compiler. Some folks think it's magic. ;-)

Possibly an early release since I think they've deprecated the "asm-like" function calls. I use ICCAVR so I'm not 100% sure...

Rich Webb Norfolk, VA

yeah, back in my AVR days, i used ICC also (you go Richard)...

don't know much about GCC........

compiler

There isn't a single assembly instruction in his code example. The cbi() and sbi() are GCC AVR "pseudo" functions or macros, which are translated bij the compiler into asm cbi and sbi instructions.

Meindert

Meantime I found an answer. The reason is with ATMEL Avr 3.55 simulator. When I verified the pin output toggle with scope it works as should be.

snipped-for-privacy@wp.pl wrote:

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required