Pages: [1]   Go Down
Author Topic: Equivalent CTC ICR1 value to sync with phase correct PWM - SOLVED  (Read 278 times)
0 Members and 1 Guest are viewing this topic.
Sheffield, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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??


« Last Edit: February 26, 2014, 09:40:24 am by rdorling » Logged

Sheffield, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: [1]   Go Up
Jump to: