This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320F28069: PWM duty cycle confusion

Part Number: TMS320F28069


It is well said in TRM that TBPRD register must be one less that PWM period. So if I want to make 40kHz PWM (assuming 90MHz operation) I would set TBPRD as 2250 - 1 = 2249 and if I would like to make 400kHz PWM I would set the TBPRD to 225-1 = 224

Also if I would want to make 400kHz PWM with 50% DC I would need to set CMPA as 225 / 2 = 112.5, So therefore I set CMPA as (225/2) - 1 = 111 and CMPAHR as 0.5 * 65536=32768 and would get nice PWM.

However I noticed that when I want to make 40kHz PWM with 50% DC I would need to put 2250/2 = 1125 into CMPB not 1124.

So this is now confusing. When do I need to consider proper period for duty cycle and when I need to subtract 1 for duty cycle?

  • Rein,

    You only subtract 1 because the timer counts from zero, yes you should take this into account, but there error will be minimal. So, I would answer your question by saying that the world isn't perfect, and neither will be your dutycycle.

    At 400KHz you will see an error of + or - 0.222% depending of if you choose 113 or 112. Depending on your system you will need to choose one of these values. Some customers choose to dither the PWM signal and switch between 112 and 113 each cycle, averaging out it will be 50%. On your slower signal you will see even less of a percentage error.

    You could use HRPWM, but I suspect in this is not needed.

    Regards,
    Cody 

  • Hi,

    Unfortunately for my solution the precision is important and even that 0.222% is an error too large. For that reason I will be switching from 400kHz (225 SYSCLKs period) to 401.786kHz to be able to use 50.0% duty cycle (exactly 112 SYSCLKs). So I was wandering that what are the exact rules when I need to take that 1 SYSCLK into account and when not? I assumed that I always need to consider this but then the 40kHz PWM showed otherwise that in that cas I do not need to use it. Is it something about HRPWM configuration flags?
  • The issue has been resolved as the root cause was incorrec duty cycle starting point that required 1 SYSCLK removal from the comparator. Once I started all the duty cycles at ZERO event then I didn't have to subtract 1 from the comparator value and for 50% duty cycle the comparator should always be half of the actual period not the TBPRD (which is period - 1)