EmbeddedRelated.com
Forums

Atmel AVR, too slow encoder tics counting

Started by Umpa May 6, 2004
In article <c7fg8j$a1c$1@nemesis.news.tpi.pl>, Umpa 
<?@umpaumpalala.com.invalid> writes
>> How fast are you running the clock on your CPU? >> What is your clock src? >> >I have ATmega16 -- 16 MHz. >Clock source is internal I think, I didn`t connect any quartz. > >Did I do something wrong? >
An ATMega16 on internal oscillator runs by default at 1MHz not 16MHz. So that will make quite a difference. 16Mhz is the max frequency it will go at when using a crystal. -- Tim Mitchell
> What to do to improve frequency ?
Re-write the interrupt code in assembler. Make sure that your LCD output function does not disable interrupts. How fast do you want to go?
> long int licz = 0;
That needs a "volatile".
Umpa schrieb:
>> How fast are you running the clock on your CPU? >> What is your clock src? >> > I have ATmega16 -- 16 MHz. > Clock source is internal I think, I didn`t connect any quartz. > > Did I do something wrong? >
Have you checked the correct setup for the internal oscillator? The ATmegas are shipped with internal RC @ 1MHz... Alexander
> 16Mhz is the max frequency it will go at when using a crystal. > --
Hurrayy !!! Maybe it is a cause !! Tell me please, what cristal shall I attach, where, and what to set up in my program ? Or provide me with any document. Umpa.
> How fast do you want to go?
10 kHz would be enough. But, above two people have said that my ATmega16 works with 1MHz frequency, and I need to attach cristal. I think, it solves my problem. Umpa.
In article <c7fobq$os$1@atlantis.news.tpi.pl>, Umpa 
<?@umpaumpalala.com.invalid> writes
> >> 16Mhz is the max frequency it will go at when using a crystal. >> -- >Hurrayy !!! >Maybe it is a cause !! >Tell me please, what cristal shall I attach, where, and what >to set up in my program ? >Or provide me with any document. >
If you don't have the Mega16 data sheet you can download it from www.atmel.com, it contains all the information you need to either attach a crystal or change the internal RC oscillator speed. -- Tim Mitchell
One more thing.
I need to use UART transmision.
I bought 11,059 MHz cristal.
If I attach this cristal, will processor
run with 11,059 MHz frequency ?

Umpa.


Umpa schrieb:
>> How fast do you want to go? > > 10 kHz would be enough. > But, above two people have said that > my ATmega16 works with 1MHz > frequency, and I need to attach > cristal. I think, it solves my problem.
You can set up your internal RC to 8 or 16MHz by progamming the corrseponding fuses. Look at the datasheet! Alexander
> The second thing is, when I change type of "licz" to > int (not long int), it can count ticks faster.
Well, you also have to protect the reading of "licz" by a pair of CLI/SEI (in the main code). Don't protect the whole LCD call, but rather copy it to a local autovar in protected fashion, and then use the copy in the printf/LCD calls.