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.

EHRPWM variable frequency

Hello,

I have the module configured on C6748 to generate PWM with variable frequency and duty cycle, from 10Hz to 1MHz, however changing frequencies we noticed some glitches on the scope, like for a short time it jumps to an intermediary frequency and then to the requested frequency. TBCTL has been configured to use shadow mode and I am writing into TBPRD and CMPA registers of EHRPWM_0 to update the new frequency and duty cycle and then reconfigure TBCTL with new CLKDIV and HSPCLKDIV, however I don't think TBCTL changing is shadowed, am I correct?

What would be the procedure to adjust any frequency for PWM on the fly, are there any examples available?

Best regards,

David.

  • Hi David,

    Please configure the PWM in Free Run mode. That would solve the glitch issue while changing the duty cycle.

    Please refer below thread for more detail.

    http://e2e.ti.com/support/dsp/omap_applications_processors/f/42/t/278316.aspx

    Thanks.

  • Hi Rajasekaran,

    Thank you for the link, however I'm not changing duty cycle, which was set once to 50%, the TBCTL register was already set to free run using value 3. I'm trying to increase the frequency and I can see on the scope that I have 154.2Hz, 156.6Hz, 145.3Hz, 154.7Hz, 155.6Hz, 166.1Hz. As you can see, the frequency although is increased every 20ms with constant level in software, on the scope appears something else and most of the frequencies are increasing constantly until TBCTL receives different clock divisor settings which I couldn't find any reference of being shadowed.

    What happens when CLKDIV and HSPCLKDIV are being changed by software while counter didn't reached TBPRD value?

    Best regards,

    David.

  • David Luca,

    You are using C6748 device.
    Are you using your own custom or TI board.
    The EHRPWM sample application files are available in the StarterWare package.
    It can generate different waveforms for use of a EHRPWM.
    C6748_StarterWare_x_xx_xx_xx\examples\lcdkC6748\ehrpwm\ehrpwmWaveForm.c
    C6748_StarterWare_x_xx_xx_xx\build\c674x\cgt_ccs\c6748\lcdkC6748\ehrpwm

    Driver code is available in the StarterWare package.
    C6748_StarterWare_x_xx_xx_xx\platform\lcdkC6748\ehrpwm.c

  • Hi Pubesh,

    I used a similar code as the examples to initialize our custom board, I can generate all the frequencies I need, however the glitches appear when changing between frequencies that we see intermediary frequencies. Maybe I didn't explained my problem correctly, my question is what happens with generated waveform when changing TBCTL divisor values while PWM is still counting and loading values from shadow registers? 

    Best regards,

    David.

  • Hi David,

    Thanks for the post.

    From my understanding, you may not change CLKDIV & HSPCLKDIV at run time because TBCTL is register is not shadowed. Please fix your CLKDIV values for the range of frequency required.

    Only TBPRD, CMPA & CMPB registers are shadowed.

    Please adjust the TBPRD value to change the PWM output frequency. Please adjust the CMP value to change the PWM duty cycle.

    Could you able to adjust the output frequency by changing the TBPRD? (without glitches)

  • Hi Rajasekaran,

    I can change the frequency using only TBPRD without glitches but also need to support a large set of frequencies, any suggestions for changing CLKDIV and HSPCLKDIV without the glitches? I'm thinking about an interrupt triggered at CNT==TBRD to reload these values, what would be your approach? This interrupt would be enabled only when frequency needs to increase, every 20ms.

    Best regards,

    David.

  • Hi David,

    The PWM peripheral must be able to generate complex pulse width waveforms with minimal CPU overhead. 

    DAVID: said:

    I can change the frequency using only TBPRD without glitches but also need to support a large set of frequencies, any suggestions for changing CLKDIV and HSPCLKDIV without the glitches?

    From my understanding, changing the values of CLKDIV & HPSCLKDIV would definitely cause the glitches in the PWM output . 

    DAVID: said:

    I'm thinking about an interrupt triggered at CNT==TBPRD to reload these values, what would be your approach? This interrupt would be enabled only when frequency needs to increase, every 20ms.

    Since the PWM is configured in Free Run mode, the counter re-loads the values(TBPRD) for the next output cycle.

    How will you sync the 20ms event with CNT=TBPRD interrupt event?

  • Hi Rajasekaran,

    PWM interrupt will be enabled every 20ms only and they will be synchronized when it occurs when CNT=TBPRD, in the interrupt handler it will be disabled. I will try this and get back to you.

    Best regards,

    David.

  • Hi David,

    Please keep us posted. We will also check and let you know.

    Thank you.

  • Hi David,

    Could you able to sync the 20ms event with CND=TBPRD interrupt event? Any update?

    Thanks.

  • Hi Rajasekaran,

    My software doesn't require synchronization, but every 20ms I enable the interrupt and the prescaler is reloaded in interrupt. Haven't seen any glitches so far but still running tests. I have to use prescaler control without interrupt though for anything less than 50Hz. 

    Best regards,

    David.