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.

PWM comparators

Greetings, i'm trying to use PWM module from TM4C123GH6PMI launchpad. I have been loking the datasheet and found that there is a comparator in Count/Down mode with saw teeth to compare and generate a PWM exist, but from the ROM datasheet i can't find a way to use it.

Is it supose to use an internal signal to compare with a external signal like from ADC or other way.

I need to generate a PWM exit with a value given by my system function that comes from a PI or PID controller.

What commands should i use if possible? Is there any example i could guide on? Also want to achieve a 10kHz pwm frequency.

  • Hello Victor,

    The API

        PWMGenConfigure(PWM0_BASE, PWM_GEN_0,
                        PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);

    in the code at the following TIVAWare example

    C:\ti\TivaWare_C_Series-2.1.0.12573\examples\peripherals\pwm\reload_interrupt.c

    can be modified for UP-DOWN counter instead of DOWN Counter.

    The PWM Generator compares the up-down count value with the comparator value in the PWMCMPA or PWMCMPB based on which pin will be used to generate the final output.

    Regards

    Amit

  • And what is the variable that is used to compare in that example?

    All i see in these examples are interruptions and updates of fixed numbers.

    The number in with i can set the PID value to change the duty cycle.

  • Hello Victor,

    I don't get the question here.

    The functions PWMPulseWidthSet is used to set the comparator to get the Duty Cycle.

    If you would post a pseudo code, it would be helpful.

    Regards

    Amit

  • Amit, this is my problem:

    Wref-Wreal=error;

    Erro -> PI/PID -> Iref

    Iref-Ireal=error2

    by histeresis, its easy and done.

    But to use PWM i need a new PI/PID, so i get:

    error2 -> PI/PID -> Vref

    I suppose this Vref is my PWMPulseWidthSet, but in that comand you know the maximum frequência you want to use, and Vref you dont know what are the values. How to i know that my Vref is going to change between the range i have choosen for the PWMPulseWidthSet?

     

    I hope i made my point this time. The compare function of PWM, how it works and how its implemented for this case.

  • Hello Victor,

    Yes, I do understand it better now. One way is to calibrate the error with a schmoo of duty cycle so that a reference table can be built before the application is run, which will help gauge the new duty cycle based on how much error is there

    Regards

    Amit