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...
Help to set up a 1ms time base interrupt Mega2560
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Help to set up a 1ms time base interrupt Mega2560
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?
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?
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: Help to set up a 1ms time base interrupt Mega2560
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!
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!
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Help to set up a 1ms time base interrupt Mega2560
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.
Based on this calculator.
https://eleccelerator.com/avr-timer-calculator/
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;
https://eleccelerator.com/avr-timer-calculator/
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel