Do I Have to Change Internal Interrupt Setups when I Change Clock Speed? The reason I ask is because I am trying to modify this code:
https://github.com/DccPlusPlus/BaseStation/blob/master/DCCpp_Uno/DCCpp_Uno.ino (Beginning at Line 289)
so that if will work on an ATmega328P-derivative board running at 3.3V and 8 MHz. I need the waveforms to be generated at the same speed, so is there anything I have to change? The original code is written for a 16 MHz uno or mega.
-
1Yes, you will have to recalculate all the timer compare values (halve them for half the clock speed?)Majenko– Majenko2017年04月11日 21:07:27 +00:00Commented Apr 11, 2017 at 21:07
-
1Halve the values and round down: 3199 → 1599, etc.Edgar Bonet– Edgar Bonet2017年04月12日 07:43:04 +00:00Commented Apr 12, 2017 at 7:43
1 Answer 1
The equation for timer period is given by the following formula, where N
is the value of the prescaler, TOP
is the value given by either MAX
(i.e. 0xFF
, 0xFFFF
) or the value in register OCRnx
, and f
is the frequency of the I/O clock.
If you're using phase-correct or phase- and frequency-correct mode, the factor (TOP
+1) in the formula above should be replaced by 2 ×ばつ TOP
.
-
1It's not
TOP
. It's either 2 ×TOP
(in the phase-correct and phase-and-frequency-correct PWM modes) orTOP
+ 1 (in any other mode).Edgar Bonet– Edgar Bonet2017年11月02日 15:00:28 +00:00Commented Nov 2, 2017 at 15:00
Explore related questions
See similar questions with these tags.