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.

TM4C1231H6PGE: Interrupt synchronous to PWM frequency

Part Number: TM4C1231H6PGE
Other Parts Discussed in Thread: TM4C123GH6PM,

Hello,

In my Launchpad code I use one of the PWM peripherals to control a servo motor.

The PWM frequency is 400Hz.

Is it possible to make the PWM peripheral generate an interrupt synchronous to the PWM frequency ?

  • The part you selected when making this post does not contain the motion control PWM peripheral. I assume you mean to use a general purpose timer to generate a PWM. Yes, you can generate an interrupt from the general purpose timer at the PWM frequency while it generates the PWM signal.
  • Sorry,

    I meant the TM4C123GH6PM not TM4C1231H6PGE.

    This is the code I use for generating the PWM.

    int main(void)
    {
    // Configure the clock to 80 MHz
    SysCtlClockSet(SYSCTL_SYSDIV_2_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
    
    // PWM Initialization
    SysCtlPWMClockSet ( SYSCTL_PWMDIV_64 ) ;
    SysCtlPeripheralEnable ( SYSCTL_PERIPH_PWM1 ) ;
    SysCtlPeripheralEnable ( SYSCTL_PERIPH_GPIOD ) ;
    
    GPIOPinTypePWM ( GPIO_PORTD_BASE , GPIO_PIN_1 ) ;
    GPIOPinConfigure ( GPIO_PD1_M1PWM1 ) ;
    
    volatile uint32_t ui32PWMClock = SysCtlClockGet ( ) / 64 ;
    
    volatile uint32_t ui32Load = ( ui32PWMClock / PWM_FREQUENCY ) - 1 ;
    
    PWMGenConfigure ( PWM1_BASE , PWM_GEN_0 , PWM_GEN_MODE_DOWN ) ;
    PWMGenPeriodSet ( PWM1_BASE , PWM_GEN_0 , ui32Load ) ;
    
    PWMPulseWidthSet ( PWM1_BASE , PWM_OUT_1 , some_value) ;
    PWMOutputState ( PWM1_BASE , PWM_OUT_1_BIT , true ) ;
    
    PWMGenEnable ( PWM1_BASE , PWM_GEN_0 ) ;
    
    while(1)
    {
    PWMPulseWidthSet ( PWM1_BASE , PWM_OUT_1 , some_other_value ) ;
    }
    }

    Can you please post an example of how to make this peripheral generate an interrupt ?

  • That device does have the PWM module. It took can generate interrupts. I do not have that specific example. You enable the PWM interrupts with the TivaWare function "PWMGenIntTrigEnable()".

  • Let me explain what I want to do:
    I'm designing a control system that involves an I2C sensor and a motor controller.
    The motor controller "speaks" PWM and is able to receive commands at a rate up to 400 Hz.

    So 400 Hz is the rate I want to time my control loop to - I.E:
    Take a reading from the sensor, make all the required calculations and send a one time update to the speed controller.

    For this, I want to have the PWM peripheral generate the interrupt.
    What do you think ?
    Is this the best approach ?
  • Hi,

    In addition to Bob's fine answers,

    You configure PWM0 to generate interrupt on re-load count cycles. What you do in the much faster PWM interrupt handler to update i2C @400Hz is a software loop control issue, right? In such a configuration would faster PWM interrupt be asynchronous 400Hz update (2.5ms) speed controller?
  • I don't really understand your question...

    This is what I want to do:

    The speed controller expects to get PWM commands at 400 Hz.

    So this is the PWM frequency I want the Tiva's module to generate - and I want all the software processes to be timed to it. I.E: reading I2C angle information, some minor filtering and calculating the required output.

    To achieve that - my idea is to generate a 400 Hz interrupt from the PWM module, and have all the process marked in red execute under this interrupt's ISR.

    I haven't done this yet...so my question to Bob was if such an approach is a good idea or not ? Or perhaps there's a better / simpler way...