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 Interrupt not working

Other Parts Discussed in Thread: TM4C123GH6PM

Hi, I`m using the tm4c123gh6pm and i try to create a a interruption to count the number o cycles of my PWM, I look in the internet but I not find a answer.

I add a external void in the startup and change the handle PWM1-0

My code is:

#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
#include "driverlib/debug.h"
#include "driverlib/pwm.h"
#include "driverlib/pin_map.h"
#include "inc/hw_gpio.h"
#include "driverlib/rom.h"
#include "driverlib/interrupt.h"
#include "inc/tm4c123gh6pm.h"
//Definicoes

#define PWM_FREQUENCY 10000

//////////////////////////////////////////////////////

unsigned int counter=0;


int main(void){

volatile uint32_t PERIODO;
volatile uint32_t PWMClock;

SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ); // Setar clock principal

SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1); //ativa PWM 1
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); //habilita modulo PD


GPIOPinTypePWM(GPIO_PORTD_BASE, GPIO_PIN_0); //seta Pino 0 porta D como PWM
GPIOPinConfigure(GPIO_PD0_M1PWM0); //seta PD0 como modulo 1 do PWM0

//ui32PWMClock = SysCtlClockGet() / 64; //pelo clock divisor
PWMClock = SysCtlClockGet(); //pega o clock
PERIODO = (PWMClock / PWM_FREQUENCY) - 1; //calcula periodo em ciclos de clock
PWMGenConfigure(PWM1_BASE, PWM_GEN_0, PWM_GEN_MODE_DOWN); //Usa o gerador de PWM0
PWMGenPeriodSet(PWM1_BASE, PWM_GEN_0, PERIODO); //define periodo

PWMPulseWidthSet(PWM1_BASE, PWM_OUT_0, PERIODO / 2);
PWMOutputState(PWM1_BASE, PWM_OUT_0_BIT, true);
PWMGenEnable(PWM1_BASE, PWM_GEN_0);

PWMGenIntTrigEnable(PWM1_BASE, PWM_GEN_0, PWM_INT_CNT_LOAD);
PWMIntEnable (PWM1_BASE, PWM_GEN_0);///
IntEnable(INT_PWM1_0);
IntMasterEnable();

while(1)
{

}
}

void PWM1_0IntHandler(void)
{
PWMGenIntClear(PWM1_BASE, PWM_GEN_0, PWM_INT_CNT_ZERO);
counter++;
}