That's why I've urged you several times to read AN-216. It gives a detailed description of the process including why/how a prescaler must be selected.sturgessb wrote:how is Register.ICR1 calculated? [I'm] confused.
Also, I gave the formula for the Phase/Frequency Correct mode in a previous post, reproduced below.
Code: Select all
icr = F_cpu / (2 * prescaler * F_pwm)
A prescaler value of at 6 or more must be used in order to reduce the ICR value to less than 65536. However, 6 is not one of the available choices which are (from the datasheet) 1, 8, 64, 256 and 1024. Choosing the smallest prescaler value that will work yields the maximum resolution (as explained in the application note), so a prescaler of 8 would be the best choice for 50Hz. Plugging that value in the equation above gives a result of 18,432 for ICR. That the ICR value is the same is not suprising because 50Hz is 1/8 of 400Hz and the timer is being clocked at 1/8 the rate in that case due to the use of 8 for the prescaler.
In any event, the duty cycle of the resulting waveform depends only on the ratio of OCR to ICR - the prescaler value is immaterial.