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/TMS570LC4357: Is there a way to generate a PWM with a specific frequency and duty cycle based off a variable determined in CCS?

Part Number: TMS570LC4357
Other Parts Discussed in Thread: HALCOGEN

Tool/software: Code Composer Studio

I'm aware that it is very easy to generate a PWM signal in HALCoGen, but the issue with that is that HALCoGen has to be opened and modified each time I want to change the signal.

Say  I have a variable "x" that, if the value is 6, the duty cycle is 50%, and if the value is 2.345, the duty cycle is 60%.

Is there an easy way to do this? Generating a PWM in CCS using delays and switching a pin on and off tends to fall error to delays in running the code, and is very difficult to calibrate it so that it is outputting the frequency that I want.

  • Hello Nikola,

    The function of pwmSetDuty() can be used to change the duty cycle of the PWM signal.

    pwmSetDuty(hetRAMBASE_t * hetRAM, uint32 pwm, uint32 pwmDuty) is generated through HALCoGen.

    pwmStop() and pwmStop() can be sued to start or stop a PWM defined in HALCoGen.

    Those function updates the parameters of MOV64 instruction which modify the data field of the PWCNT and DJZ instructions. All the changes take effect in the next loop resolution clock period.