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.

TMS570LC4357: Using ePWM or N2HET to hold a specific duty cycle for a specific time

Part Number: TMS570LC4357

Tool/software:

I have a LTC2644 DAC connected to shared ePWM/N2HET pin.  I'd like to generate a low-frequency PWM output (50Hz) on that output with a duty cycle that can vary between 1-2ms for servo control.  I'd like to avoid any HW changes (say, removing the LTC2644) on the board.  The idea is that since the output frequency is low, we can achieve this with the LTC2644 remaining in place.

The LTC2644 is controlled via PWM, and produces a voltage level depending on the duty cycle of the input signal.  With an external voltage reference of 5V, a 1% input duty cycle produces 0.05V, and with 99% it would jump to 4.95V.  Settling time is 8us in either direction.

To produce a 50Hz PWM output with (say) 1ms duty cycle, I'd have to iterate the following:

- Provide input PWM signal to LTC2644 with a duty cycle of 99% for 1ms

- After 1ms, provide an input PWM signal with a duty cycle of 1%, and hold that for the remainder of the 20ms period -- 19ms.

The servo control will expect stable 1-2ms duty cycles and adjust orientation accordingly.

Since I have a choice to use either ePWM or NHET -- is one better suited over the other to run a program like the above with tight timing requirements in the 1-2ms range?

Would you be able to share example code that could achieve this?

Thanks!

  • I was wondering if you had a pointer?

    Can the ePWM module be used to achieve the following:
    - We have to be able to set a specific time T_high in the interval 1-2ms "from the outside". This is the one parameter that will be updated from time to time in the main program, and consumed by the ePWM module.
    - The ePWM will do the following: it will alternate 99% and 1% duty cycles, and hold the 99% duty cycle precisely for the T_high specified above. Then for (20 ms - T_high) it will hold the 1% duty cycle.
    - The same pattern is repeated until T_high is changed to another value.
    - the frequency of the PWM signal is fixed, say 10 kHz.

    I am a little lost in the TRM how this could be implemented. Is this entirely possible in hardware by using the AQ module and/or shadow registers for swapping 99% and 1% duty cycles, or will this require interrupts to the CPU?

  • Hi ,

    My sincere apologies for the delayed response, i was off for some days so didn't get any time to work on this issue.

    Since I have a choice to use either ePWM or NHET -- is one better suited over the other to run a program like the above with tight timing requirements in the 1-2ms range?

    Would you be able to share example code that could achieve this?

    These requirements can be achieved with either ePWM or NHET. Both of them can support this, however ePWM is more easy way of implementing PWM's as compared with NHET which involves another dedicated timer core to achieve this.

    You can access Hercules Demo's from below link:

    (+) [FAQ] TMS570LC4357: Examples and Demos available for Hercules Controllers (E.g. TMS570x, RM57x and RM46x etc) - Arm-based microcontrollers forum - Arm-based microcontrollers - TI E2E support forums

    The below highlighted example is based on ePWM:

    In this example we are generating PWM with 6.25us period, you can take it as reference and change the parameters according to your requirements.

    --
    Thanks & regards,
    Jagadish.

  • Thanks,.  Per our requirement, the period is constant, but we need to apply 99% duty cycle for a specific precise time (say 1ms), and then apply 1% duty cycle immediately after that (say, for 19ms).  That pattern repeats after.  The time (1ms) can be adjusted by a program during its runtime.  Would you have any advice how best to implement this?  I'm thinking that interrupts may not be precise enough to implement this.    

  • but we need to apply 99% duty cycle for a specific precise time (say 1ms), and then apply 1% duty cycle immediately after that (say, for 19ms).

    Immediately after means you want to do it with in next cycle only.

    I mean in the first cycle you want TON=19ms and TOFF=1ms, on second cycle you want TON=1ms and TOFF=19ms and you want to continue this pattern. Is it your requirement?

  • Oh sorry, here's the more precise requirement:

    - The PWM period is always the same (let's say 50 Hz)

    - Let's call TON the time during which 99% duty cycle is active. Let's call TOFF the time during which 1% duty cycle is active.  TOFF is always (20 ms - TON).  

    - Let's call 20 ms a "cycle"

    - Start the "cycle" with 99% duty cycle for a time duration of TON.  After that, switch over to 1% duty cycle for a time duration of TOFF.

    Thanks for your help.

  • Hi ,

    I'm thinking that interrupts may not be precise enough to implement this.    

    In ePWM the period and duty cycle will be decided by values of TBPRD and CMPA registers.

    For example, here is the values for 50% duty cyle:

    So, what you can do here is that you can create a small API to update the dutycyle based on the inputs.

    For example,

    void etpwmSetDutyCycle(etpwmBASE_t *etpwm, uint8 dutycycle)
    
    {
    	uint16_t dutycycle_value;
    	if(dutycycle > 100)
    	{
    		return; /*Duty cylce should be between 0 to 100*/
    	}
    	dutycycle_value = ((etpwm->TBPRD * dutycycle) / 100);
    	etpwm->CMPA  = dutycycle_value;
    }

    So, you can call above API, whenever you need to update the duty cycle of the signal with required percentage.

    --
    Thanks & regards,
    Jagadish.

  • Thanks .  I'm thinking interrupts would not be precise enough:  e.g., have a timer expire (after TON = 1ms), fire an interrupt, update the PWM settings, and continue for TOFF = 19ms, interrupt, and change settings, and repeat.  Is there a way to do this in hardware?  Presumably N2HET has that functionality, but ePWM not?

  • I'm thinking interrupts would not be precise enough:  e.g., have a timer expire (after TON = 1ms), fire an interrupt, update the PWM settings, and continue for TOFF = 19ms, interrupt, and change settings, and repeat.  Is there a way to do this in hardware?  Presumably N2HET has that functionality, but ePWM not?

    I think you can give a try with interrupts as well, because here we are operating interns of ms right, interrupts are fast enough to perform with int this duration.

  • Thanks, . Do you have any advice how accurate interrupts would be?  TON will vary between 1ms and 2ms for servo control.  That range between 1-2ms would be mapped to (at least) 100 steps, so the resolution and accuracy would be 10 microseconds.

  • Hi 

    Apologies for the delayed response.

    In below thread i mentioned the interrupt latency in these devices.

    (19) TMS570LC4357: portYIELD_WITHIN_API behavior - Arm-based microcontrollers forum - Arm-based microcontrollers - TI E2E support forums

    If your GCLK is 300Mhz then interrupt latency will be <=(47/300M).

    which is <=156nS.

    --

    Thanks & regards,
    Jagadish.