Go Down

Topic: Equivalent CTC ICR1 value to sync with phase correct PWM - SOLVED (Read 298 times) previous topic - next topic

rdorling

Feb 26, 2014, 01:22 am Last Edit: Feb 26, 2014, 03:40 pm by rdorling Reason: 1
hi,

i'm using timer1 in ctc mode (mode 12) to generate an interrupt, in which i set OCR2 (pulse width) on timer2.

timer2 is using phase/freq correct mode, top=255, no clock prescalar (giving 32Khz-ish)

i need timer1 to interrupt exactly TWICE the frequency of timer2 pwm (as I'm alternating between outputting audio samples to OCR2 and doing other stuff). if i assume phase/freq correct frequency is half ctc frequency (as it counts down as well as up) then i calculate i need to set ICR1 to 255. but i read somewhere that phase/freq correct frequency isn't exactly half, as it doesn't use exactly 2x the clock cycles but more like 2x-1 clock cycles ??? can anyone verify? i suppose i could also set timer1 to phase/freq correct mode if it made things easier, but then do i set ICR1 to 127 or 128 to double the freq??



rdorling

it's ok i ran some tests. timer2 pwm freq was 31.373Khz. setting timer1 ICR1 to 254 in ctc mode 12 gets me the 62.746Khz i need.

Go Up