PWM duty cycle Calibration

Thread Starter

safiqul_03

Joined Apr 5, 2013
4
Hi,
I need to calibrate PWM duty cycle. The output PWM signal (from my circuit) has approximately 27.5us delay [On state: 6.5us delay and in OFF state: 34us delay] compare to the CPU generated PWM signal. How can I calibrate the duty cycle? The delays are constant according to the frequency and duty cycle percentage. I have added the signal diagram!
 

Attachments

Thread Starter

safiqul_03

Joined Apr 5, 2013
4
I mean (Pulse with modulation) pulse duty cycle calibration! I have generated a 200hz PWM signal with 50% duty cycle (see previously attached picture). But after my circuit on/off delay, it introduces 27.5us (34-6.5) difference of the pulse width of 50% of 200hz. How do I compensate (calibrate with 50% duty cycle) this delay by software?
 

MrChips

Joined Oct 2, 2009
30,824
You are asking how to correct the waveform to produce 50% duty cycle.
Generate the signal at twice the frequency and feed it to a T-type flip-flop.
 

Ron H

Joined Apr 14, 2005
7,063
I mean (Pulse with modulation) pulse duty cycle calibration! I have generated a 200hz PWM signal with 50% duty cycle (see previously attached picture). But after my circuit on/off delay, it introduces 27.5us (34-6.5) difference of the pulse width of 50% of 200hz. How do I compensate (calibrate with 50% duty cycle) this delay by software?
Why are your delays so large?
 

Ron H

Joined Apr 14, 2005
7,063
A flip flop only changes state (high to low/ or low to high) on a rising edge. Therefore, half the input frequency but duty cycle is exactly half of the input.
I believe his delays are between the PWM output and wherever he is applying the signal, like in a MOSFET or IGBT driver, maybe.
 

THE_RB

Joined Feb 11, 2008
5,438
If the on and off delays and known and constant, and you know the PWM period, you can just do some simple math to work it out.

Is this a homework question?
 

Thread Starter

safiqul_03

Joined Apr 5, 2013
4
If the on and off delays and known and constant, and you know the PWM period, you can just do some simple math to work it out.

Is this a homework question?
Hello,
This is not a home work. I am trying to learn about PWM and how to correct it's duty cycle and frequency. I am using CPU speed 20Mhz. Like, if my desired frequency is 200hz. so, frequency_value = 20Mhz/(prescaler (32) * 200hz) -1 = 3124. dutycycle_value = frequency_value/2 (if 50%)=1562. my output duty cycle error (off/on) 27.5us (34us(off) - 6.5us(on)) which represents the value 16 (clock_speed / prescaler * frequency). So, do I need to subtract (1562 -16) the duty error value from frequency and then generate the duty cycle from the frequncy? Please give me some feedback! Thank you!
 

Thread Starter

safiqul_03

Joined Apr 5, 2013
4
You are asking how to correct the waveform to produce 50% duty cycle.
Generate the signal at twice the frequency and feed it to a T-type flip-flop.
Hello,
I am trying to correct the waveform by software, using some mathematical calculation. I am using CPU speed 20Mhz. Like, if my desired frequency is 200hz. so, frequency_value = 20Mhz/(prescaler (32) * 200hz) -1 = 3124. dutycycle_value = frequency_value/2 (if 50%)=1562. my output duty cycle error (off/on) 27.5us (34us(off) - 6.5us(on)) which represents the value 16 (clock_speed / prescaler * frequency). So, do I need to subtract (1562 -16) the duty error value from frequency and then generate the duty cycle from the frequncy? Please give me some feedback! Thank you!
 

THE_RB

Joined Feb 11, 2008
5,438
You set the PWM frequency by setting the total period, in most micros this is done by setting a register for the desired PWM total period.

Then you set the PWM ON period by setting another value in another register. This is usually called the PWM value.

If you have a known ON / edge delay, then you need to make the PWM On period longer by the same amount, to compensate that / edge delay.

If you have a known \ edge delay, you need to make the PWM period shorter by that same amount, to compensate it.

So there are 4 easy factors that you need to be aware of, all clearly explained above. :)
 
Top