Hi all,
Please refer the below code. i dont know how to get 50% duty cycle using the below code.
By changing the values of OCR1A & OCR1B.
EXAMPLE:
OCR1A = 21
OCR1B = 19 , i get 120nsec dead time between two PWM signals and but the duty cycle is not 50% (Pls refer the attached snap for Ton and Toff)
by changing the values of OCR1A & OCR1B i can get the difference in Dead time but i dont know how to make it as 50% duty cycle.
pls guide me what to be done to get 50% Duty cycle
Thanks in Advance and looking for your valuable reply.
Regards,
Veeramanikandan
//Timer1 Mode 10 PWM to ICR1
//Dual pin 200KHz PWM generator
//47.5% duty cycle 125ns dead band between pulses
void setup() {
pinMode(11, OUTPUT); //output A (this was 9 changed it for mega)
pinMode(12, OUTPUT); //output B (this was 10 changed it for mega)
TCCR1A = 0; //clear timer registers
TCCR1B = 0;
TCNT1 = 0;
//ICR1 and Prescaler sets frequency
//no prescaler .0625 us per count @ 16Mh
//80 counts x .0625 = 5 us = 200Khz
//for 50KHz it is 20uS and 320 counts
TCCR1B |= _BV(CS10); //no prescaler
ICR1 = 160;// 40 PWM mode counts up and back down for 80 counts
// need to changed to 320 counts / 2 = 160 counts for 50KHz
OCR1A = 21;
//output A set rising/clear falling
//Rise at TCNT 21 upslope, High 38 counts, Fall at TCNT 21 downslope
//47,5% Duty Cycle Pulse centered on TCNT 40. High 38 Low 42
TCCR1A |= _BV(COM1A1) | _BV(COM1A0); //output A set rising/clear falling
OCR1B = 19; //Pin 10 match UNO, for mega its 12
//output B clear rising/set falling
//Fall at TCNT 19 upslope, Low 42, Rise at TCNT 19 downslope
//47.5% Duty Cycle Pulse centered on TCNT 0. High 38 Low 42
TCCR1A |= _BV(COM1B1); //output B clear rising/set falling
TCCR1B |= _BV(WGM13); //PWM mode with ICR1 Mode 10
TCCR1A |= _BV(WGM11); //WGM13:WGM10 set 1010
}
void loop() {}