ac monophase motor control, timer1 pwm phase correct isues

hi!

i have to control a igbt bridge with 6 pwm for a monophase AC motor, for do that i want to program the tree timers in phase correct mode, have done with timer2 is workin now from 0Hz-0V -->88Hz full voltage and 180º phase angle from pwm on pin3 to pwm on pin11 but when i try to do the same with timer1 the output is only to 1,7Hz! the code is attached
BTW the isr for timer 0 is on control by wiring.c, any way to avoid this without modify the wiring.c? (more elegant way :))
thanks

motor_control.txt.txt (10.3 KB)

Timer1 is 16bit, but it can be configured as 8bit to match the other two timers - sounds like you need to do this.

Beware that all 3 timers are different and be careful to set each up correctly.

hi!
tnx for answer, i think about the 16bit thing, but the part:
sbi (TCCR1A, WGM10); // Mode 1 / Phase Correct PWM 8 bits
cbi (TCCR1A, WGM11);
cbi (TCCR1B, WGM12);
cbi (TCCR1B, WGM13);
should select the timer in 8 bits mode, after i try to make the high part of the registers equal to 0 or ff (without slashes):
// OCR1AH=0x00;
// OCR1BH=0x00;
// TCNT1H=0xFF;
with the same result, after all i move to the timer0 (previous disable in wiring.c of millis, delays, etc.) and i noted when i use timer0 the pwms of timer1 don’t works and vice-versa, and the speed is a lot slow (while the pwms of the timer2 is about 88Hz, sine wave in the pwms of timer1 or 0 is 1,5hz), i attached the new code

codigo.pde (11 KB)

You mustn't write the 16 bit timer1 register halves individually unless you know exactly how too, use the 16bit name for them:

  // TCNT1H = 0x00 ; // wrong, access to the both half registers must be done in correct sequence (in which case the update is atomic)
  TCNT1 = 0x0000 ; // correct - the compiler does the right thing for you.

Also I'd just overwrite TCCR1A and TCCR1B registers - you don't want to be affected by previous state. Here's how
I setup timer1 for a slightly different use:

  OCR1A = 0x0000 ;
  OCR1B = 0x0000 ;
  TCCR1A = 0xB1 ;  // 10 11 00 01   // A=non-inv, B=inv, WGM = 0001 8-bit phase-correct PWM, 255*2
  TCCR1B = 0x01 ;  // 0 0 0 00 001  // clock 16MHz
  TCNT1 = 0x0000 ;

Thanks for reply, i will check it ASAP :slight_smile:

hi!

it works!
i changed the others inicialization procedures to the same structure, the only remarks is the timers don’t want to wokr independently and not more speed than prescaler 8 (16khz), i mean if i try to set one of them in prescaler 1 the others make very slow pwm
for my application is enough 16khz anyway, but i wish to know why i can’t reach more speed with the tree timers
now i have 7 pwms, 6 on hardware 1 on soft, controlled by pots, the code is attached for reference for anybody who wants it.
Thanks for the help!

codigo_0_2.pde (10.1 KB)