Hello,
I am trying to measure the pulse width of a PWM signal. This is the code I am using, I keep getting sent into the IntDefaultHandler. The signal I am trying to capture is a 333hz PPM signal from an RC receiver. Any help would be greatly appreciated. Thank you.
#define PART_TMC123GH6PM
#include <stdint.h> // Variable definitions for the C99 standard.
#include <stdio.h> // Input and output facilities for the C99 standard.
#include <stdbool.h> // Boolean definitions for the C99 standard.
#include "inc/hw_ints.h"
#include "inc/hw_types.h"
#include "driverlib/debug.h"
#include "driverlib/rom.h"
#include "driverlib/sysctl.h"
#include "driverlib/pwm.h"
#include "driverlib/sysctl.h" // Definitions and macros for System Control API of DriverLib.
#include "driverlib/interrupt.h" // Defines and macros for NVIC Controller API of DriverLib.
#include "driverlib/gpio.h" // Definitions and macros for GPIO API of DriverLib.
#include "driverlib/timer.h" // Defines and macros for Timer API of DriverLib.
#include "driverlib/pin_map.h" //Mapping of peripherals to pins for all parts.
#include "driverlib/adc.h" // Definitions for ADC API of DriverLib.
#include "driverlib/fpu.h" // Prototypes for the FPU manipulation routines.
#include "inc/tm4c123gh6pm.h" // Definitions for the interrupt and register assignments.
#include "inc/hw_memmap.h" // Memory map definitions of the Tiva C Series device.
#include "inc/hw_types.h" // Definitions of common types and macros.
int pulse_time_1=0;
int a = 0, b = 0, c = 0;
void TIMER_Initialize(void)
{
// Enables timer 1
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
// PB5 pin configured with timer 1
GPIOPinConfigure(GPIO_PB5_T1CCP1);
// Timer type set
GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_5);
// Configure timer to edge time capture
TimerConfigure(TIMER1_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_B_CAP_TIME);
// Event set to both pulse edges
TimerControlEvent(TIMER1_BASE, TIMER_B, TIMER_EVENT_BOTH_EDGES);
// Configure timer 1b interrupts
IntEnable(INT_TIMER1B);
// Enable timer interrupts
TimerIntEnable(TIMER1_BASE, TIMER_CAPB_EVENT);
// Enables processor interrupts
IntMasterEnable();
// Enables the timers
TimerEnable(TIMER1_BASE, TIMER_B);
}
int main(void)
{
SysCtlClockSet(
SYSCTL_SYSDIV_64 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN
| SYSCTL_XTAL_16MHZ);
TIMER_Initialize();
while (1)
{
pulse_time_1 = TimerLoadGet(TIMER1_BASE, TIMER_B);
TimerEnable(TIMER1_BASE, TIMER_B);
}
}
void Timer1IntHandler(void)
{
TimerIntClear(TIMER1_BASE, TIMER_CAPB_EVENT);
b = TimerValueGet(TIMER1_BASE, TIMER_B);
if (b < a)
c = 65535 + a - b;
else
c = a - b;
pulse_time_1 = c / 3125;
a = TimerValueGet(TIMER1_BASE, TIMER_B);
}