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.

CCS/TMS320F28027: Difference in cmpa

Part Number: TMS320F28027


Tool/software: Code Composer Studio

hello ,

I am a new bie in microcontrollers.

can anyone please tell me the difference between these two lines and how to use them?

Epwm1Regs.CMPA=600;

Epwm1Regs.half.CMPA=600;

THANK U

  • Hello, Madhuri

    At first, I think you meant

    Epwm1Regs.CMPA.all = 600;
    Epwm1Regs.CMPA.half.CMPA = 600;

    There is a difference. CMPA is divided into two parts: CMPA for regular ePWM counter-compare and CMPAHR( where HR means High Resolution) for High-Resolution compare. There is an ability to divide each TBCLK into more clocks (up to 255, i guess), so you can achieve incredible accuracy in PWM signal generation. You can refer to documentation on ePWM and HRPWM modules.

    So if you have PRD = 10000, and want to genereate 50% duty cycle, you must write 

    Epwm1Regs.CMPA.half.CMPA = 5000;

    If you want to achieve something like 50.00054% duty cycle, you will have to write into CMPA.half.CMPAHR register. Of course, you need to set up HR submodule in first place.

    I also think, that the first way won't even build. 

    Epwm1Regs.CMPA = 600;
  • hello Disona,

    Thank you for detailed explanation.

    one more doubt, if I have dutycycle more than 50%. then I have to use

    Epwm1Regs.CMPA

    and for fine dutycycle operation like 50.003%, I must include HRPWM right??

    what if I want high resolution PWM less than 50%
  • You can write any value to EPwmXRegs.CMPA.half.CMPA. But this value must not be larger, than your period.

    Just to make sure:

    Let's assume we have TBPRD = 200 and counter is counting in UP-COUNT mode. In this case, what is the accuracy of your PWM? It's (1/200)*100% = 0.5%

    That means, that you can set CORRECTLY any duty cycle with step 0.5%: you can set 0.0% (CMPA = 0), 10.0% (CMPA = 20), 13.5%(CMPA = 27), 30.0% (CMPA = 60)... 99.5%(CMPA = 199) 100.0% (CMPA = 200).

    All of this CMPA must be written in EPwmXRegs.CMPA.half.CMPA register.

    But if you want to set more accurate duty cycle, for example 10.2% - you are not able to do it. Because in this case you need CMPA = (10.2 / 100%) * TBPRD = 0.102*200 = 20.4. But CMPA can only be integer value, so you can set only CMPA = 20 or CMPA = 21 (10.0% and 10.5% respectively). 

    So in this case High Resolution Module can help: you can set CMPA = 20 (10.0%) and than set CMPAHR to add this missing 0.2% percent.

  • thank you Disona :)