PWM duty cycle Calibration

Discussion in 'General Electronics Chat' started by safiqul_03, Apr 5, 2013.

  1. safiqul_03

    Thread Starter New Member

    Apr 5, 2013
    4
    0
    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!
     
  2. MrChips

    Moderator

    Oct 2, 2009
    12,432
    3,360
    What do you mean by calibrate PWM duty cycle?
     
  3. safiqul_03

    Thread Starter New Member

    Apr 5, 2013
    4
    0
    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?
     
  4. MrChips

    Moderator

    Oct 2, 2009
    12,432
    3,360
    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.
     
    GopherT likes this.
  5. Ron H

    AAC Fanatic!

    Apr 14, 2005
    7,050
    657
    That won't remove the unequal delays in rise and fall times.
     
  6. Ron H

    AAC Fanatic!

    Apr 14, 2005
    7,050
    657
    Why are your delays so large?
     
  7. GopherT

    AAC Fanatic!

    Nov 23, 2012
    6,006
    3,763
    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.
     
  8. Ron H

    AAC Fanatic!

    Apr 14, 2005
    7,050
    657
    I believe his delays are between the PWM output and wherever he is applying the signal, like in a MOSFET or IGBT driver, maybe.
     
  9. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    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?
     
  10. safiqul_03

    Thread Starter New Member

    Apr 5, 2013
    4
    0
    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!
     
  11. safiqul_03

    Thread Starter New Member

    Apr 5, 2013
    4
    0
    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!
     
  12. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    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. :)
     
Loading...