I intend to capture 4 pulse inputs that come form the receiver of my RC remote. I am using timers in capture mode. Following is the code that I am using. I am expecting UART Output on my terminal window. But it seems like nothing is getting executed as not even a single character is getting printed.
/*
* Pulse_cap_4_channels.c
*
* Created on: Jan 17, 2014
* Author: Piyush
*/
#define PART_LM4F120H5QR
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/debug.h"
#include "driverlib/fpu.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/pin_map.h"
#include "driverlib/rom.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"
#include "driverlib/timer.h"
#include "driverlib/pwm.h"
#include "utils/uartstdio.h"
//#include "ST7735.h"
//#include "PLL.h"
//#include "SysTick.h"
//#include<string.h>
unsigned long a=0;
unsigned long t1A_1=0,t1A_2=0,t1B_1=0,t1B_2=0,t2A_1=0,t2A_2=0,t2B_1=0,t2B_2=0;
unsigned long c1A_1=0,c1A_2=0,c1B_1=0,c1B_2=0,c2A_1=0,c2A_2=0,c2B_1=0,c2B_2=0;
void InitConsole(void)
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
GPIOPinConfigure(GPIO_PA0_U0RX);
GPIOPinConfigure(GPIO_PA1_U0TX);
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
UARTStdioInit(0);
}
void InitTimers(void)
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER2);
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
GPIOPinConfigure(GPIO_PB1_T2CCP1);
GPIOPinConfigure(GPIO_PB0_T2CCP0);
GPIOPinConfigure(GPIO_PB5_T1CCP1);
GPIOPinConfigure(GPIO_PB4_T1CCP0);
GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_0);
GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_1);
GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_4);
GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_5);
TimerConfigure(TIMER2_BASE, TIMER_CFG_16_BIT_PAIR |TIMER_CFG_B_CAP_TIME|TIMER_CFG_A_CAP_TIME);
TimerConfigure(TIMER1_BASE, TIMER_CFG_16_BIT_PAIR |TIMER_CFG_B_CAP_TIME|TIMER_CFG_A_CAP_TIME);
TimerControlEvent(TIMER2_BASE, TIMER_B,TIMER_EVENT_BOTH_EDGES);
TimerControlEvent(TIMER2_BASE, TIMER_A,TIMER_EVENT_BOTH_EDGES);
TimerControlEvent(TIMER1_BASE, TIMER_B,TIMER_EVENT_BOTH_EDGES);
TimerControlEvent(TIMER1_BASE, TIMER_A,TIMER_EVENT_BOTH_EDGES);
IntEnable(INT_TIMER2B);
IntEnable(INT_TIMER2A);
IntEnable(INT_TIMER1A);
IntEnable(INT_TIMER1B);
TimerIntEnable(TIMER2_BASE, TIMER_CAPB_EVENT);
TimerIntEnable(TIMER2_BASE, TIMER_CAPA_EVENT);
TimerIntEnable(TIMER1_BASE, TIMER_CAPB_EVENT);
TimerIntEnable(TIMER1_BASE, TIMER_CAPA_EVENT);
IntMasterEnable();
TimerEnable(TIMER2_BASE, TIMER_B);
TimerEnable(TIMER1_BASE, TIMER_A);
TimerEnable(TIMER2_BASE, TIMER_A);
TimerEnable(TIMER1_BASE, TIMER_B);
}
int main(void)
{
InitConsole();
SysCtlClockSet(SYSCTL_SYSDIV_64 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
InitTimers();
while(1)
{
UARTprintf("$ %d %d %d %d\n\r",c1A_2,c1B_2,c2A_1,c2B_2);
}
}
void Timer2BIntHandler(void)
{
TimerIntClear(TIMER2_BASE, TIMER_CAPB_EVENT);
t2B_2=TimerValueGet(TIMER2_BASE, TIMER_B);
if(t2B_2>t2B_1)
{
c2B_2=t2B_2-t2B_1;
}
else
{
c2B_2=65535-t2B_1+t2B_2;
}
if(c2B_2>10000)
{
c2B_2=c2B_1;
}
t2B_1=t2B_2;
c2B_1=c2B_2;
}
void Timer2AIntHandler(void)
{
TimerIntClear(TIMER2_BASE, TIMER_CAPA_EVENT);
t2A_2=TimerValueGet(TIMER2_BASE, TIMER_A);
if(t2A_2>t2B_1)
{
c2A_2=t2A_2-t2B_1;
}
else
{
c2A_2=65535-t2B_1+t2A_2;
}
if(c2A_2>10000)
{
c2A_2=c2A_1;
}
t2B_1=t2A_2;
c2A_1=c2A_2;
}
void Timer1AIntHandler(void)
{
TimerIntClear(TIMER1_BASE, TIMER_CAPA_EVENT);
t1A_2=TimerValueGet(TIMER1_BASE, TIMER_A);
if(t1A_2 > t1A_1)
{
c1A_2=t1A_2-t1A_1;
}
else
{
c1A_2=65535-t1A_1+t1A_2;
}
if(c1A_2>10000)
{
c1A_2=c1A_1;
}
t1A_1=t1A_2;
c1A_1=c1A_2;
}
void Timer1BIntHandler(void)
{
TimerIntClear(TIMER1_BASE, TIMER_CAPB_EVENT);
t1B_2=TimerValueGet(TIMER1_BASE, TIMER_B);
if(t1B_2>t1B_1)
{
c1B_2=t1B_2-t1B_1;
}
else
{
c1B_2=65535-t1B_1+t1B_2;
}
if(c1B_2>10000)
{
c1B_2=c1B_1;
}
t1B_1=t1B_2;
c1B_1=c1B_2;
}
Please take a look and see what is wrong with it.
My Thanks