Page 1 of 1

Help to set up a 1ms time base interrupt Mega2560

Posted: Mon Apr 15, 2019 11:00 am
by pirvcb
Hello to everyone!
The platform is an Arduino Mega. But i program it directly by ICSP external programmer. So, no bootloader reserved memory etc.
I need to set up a 1ms time base interrupt in an AVR ATMEGA 2560 at 16MHz. Does someone can help me in doing this? For PIC, i seen, the problem inside Flowcode is not real because prescaler, postscaler and rollover are all presents. But for AVR side i'm stuck to combact with internal register and, because i'm a beginner, this is a little over my skills. Thanks in advance to anyone...

Re: Help to set up a 1ms time base interrupt Mega2560

Posted: Mon Apr 15, 2019 5:35 pm
by Benj
Hello,

Is the 1:64 prescaler an option for you, this generates 976.563 Hz which is fairly close to 1000Hz.

Are you trying to achieve very precise timings?

Re: Help to set up a 1ms time base interrupt Mega2560

Posted: Mon Apr 15, 2019 7:05 pm
by pirvcb
Yes, i would like have exact timing of 1ms to simplify wheel rpm calculation. Was only a facility, i can go over wuthout it.
The other and bigger problem is that putting in sleep mode the micro ATMEGA2560, without any other absobtion than itself, i can't obtain current under 8ma that's quite high for my objective. Maybe i have to try with PIC, more efficient in sleep state.
Thanks for you fast reply, anyway!

Re: Help to set up a 1ms time base interrupt Mega2560

Posted: Tue Apr 16, 2019 11:27 am
by Benj
Hello,

Inside your timer service macro add this code into a C icon and it should give you pretty much bang on 1000hz interrupt assuming your using timer 0 with a 1:64 prescaler.

Code: Select all

TCNT0 += 6;
Based on this calculator.
https://eleccelerator.com/avr-timer-calculator/