Timeline for Arduino Mega TIMER1 one second interval
Current License: CC BY-SA 4.0
7 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Aug 7, 2019 at 18:04 | comment | added | Sim Son | @EdgarBonet so practically resetting TCNT is one tick? | |
Aug 7, 2019 at 17:56 | comment | added | Edgar Bonet |
@Adam: Avoid writing code in comments: it's not very readable. Post a link instead. @SimSon: 1. Adam copy-pasted from this answer. 2. The timer counts from 0 to OCR1A inclusive. If you want a period of 62500, then OCR1A should be set to 62500−1=62499.
|
|
Aug 7, 2019 at 16:32 | comment | added | Sim Son | Allright! I suggest you try this standalone by blinking an led, just to see. If it doesn't work, feel free to ask! | |
Aug 7, 2019 at 16:30 | comment | added | Adam | It is only comment. | |
Aug 7, 2019 at 16:27 | comment | added | Sim Son |
I can't guarantee because I don't have an atmega2560 available right now, so there might be little things to fix. What is TOP=OCR1A supposed to do? I don't think that's neccessary. Also I think, OCR1A=62500 is theoretically correct (there is no "tick" at 0), but probably you won't recognize any difference...
|
|
Aug 7, 2019 at 16:09 | comment | added | Adam | Thanks, do you mean something like this: TCCR1A = 0; // undo the Arduino's timer configuration TCCR1B = 0; // ditto TCNT1 = 0; // reset timer OCR1A = 62500 - 1; // period = 62500 clock tics TCCR1B = _BV(WGM12) // CTC mode, TOP = OCR1A | _BV(CS12); // clock at F_CPU/256 TIMSK1 = _BV(OCIE1A); // interrupt on output compare A | |
Aug 7, 2019 at 14:58 | history | answered | Sim Son | CC BY-SA 4.0 |