//Tools: ccs5.4 Stellaris LM4F120 LaunchPad evaluation board(LM4F120H5QR)
//Description: There is no errors or warnings when the compile complete.I have
// already configured the start_ccs.c file. write the Timer2B interupt
function into the start_ccs.c file.
//Question: The pwm function is working properly.But something wrong with
the capture mode.Through watch the value of variable 'i' and set
the breakpoint in the interupt function, I found that it could not
get into the interupt function. where is the wrong?
// Sorry for my poor English and expressions Here is the codes.
//If possible, you can share some codes about the capture mode with me.
//Thanks a lot.
#ifndef PART_LM4F120H5QR
#define PART_LM4F120H5QR
#endif
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_timer.h"
#include "inc/hw_ints.h"
#include "inc/hw_gpio.h"
#include "driverlib/timer.h"
#include "driverlib/interrupt.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
#include "utils/uartstdio.h"
#include "driverlib/pin_map.h"
//*****************************************************************************
//
// Configure Timer1B as a 16-bit PWM with a duty cycle of 50%.
//Configure TIMER1A as capture mode
//*****************************************************************************
int i=0;
void Timer1AIntHandler(void);
int main(void)
{
//
// Set the clocking to run directly from the external crystal/oscillator.
//
SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
SYSCTL_XTAL_16MHZ);
//
// The Timer1 peripheral must be enabled for use.
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);
//SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER2);
//
// For this example CCP1 is used with port B pin 5.
// The actual port and pins used may be different on your part, consult
// the data sheet for more information.
// GPIO port B needs to be enabled so these pins can be used.
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
//
// Configure the GPIO pin muxing for the Timer/CCP function.
// This is only necessary if your part supports GPIO pin function muxing.
// Study the data sheet to see which functions are allocated per pin.
//
GPIOPinConfigure(GPIO_PB5_T1CCP1); //pwm
GPIOPinConfigure(GPIO_PB4_T1CCP0); //capture
//
// Set up the serial console to use for displaying messages. This is
// just for this example program and is not needed for Timer/PWM operation.
//
GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_5); //pwm
GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_4); //capture
//GPIODirModeSet(GPIO_PORTB_BASE,GPIO_PIN_4,GPIO_DIR_MODE_IN);
//GPIOPadConfigSet(GPIO_PORTB_BASE,GPIO_PIN_4,GPIO_STRENGTH_4MA,GPIO_PIN_TYPE_STD_WPU);
// Configure Timer1B as a 16-bit periodic timer.
//
TimerConfigure(TIMER1_BASE, TIMER_CFG_16_BIT_PAIR |
TIMER_CFG_B_PWM); //pwm
TimerConfigure(TIMER1_BASE, TIMER_CFG_16_BIT_PAIR |
TIMER_CFG_A_CAP_COUNT); //capture
//
// Set the Timer1B load value to 50000. For this example a 66% duty
// cycle PWM signal will be generated. From the load value (i.e. 50000)
// down to match value (set below) the signal will be high. From the
// match value to 0 the timer will be low.
//
TimerLoadSet(TIMER1_BASE, TIMER_B, 40000); //pwm
TimerControlEvent(TIMER1_BASE,TIMER_A,TIMER_EVENT_NEG_EDGE);
TimerControlStall(TIMER1_BASE,TIMER_A,true); //capture
TimerLoadSet(TIMER1_BASE, TIMER_A, 6003);
// Set the Timer1B match value to load value / 3.
//
TimerMatchSet(TIMER1_BASE, TIMER_B, TimerLoadGet(TIMER1_BASE, TIMER_B) / 2);
TimerMatchSet(TIMER1_BASE, TIMER_A, 1);
//
// Enable Timer1B.
//
TimerIntRegister(TIMER1_BASE, TIMER_A,Timer1AIntHandler);
TimerEnable(TIMER1_BASE, TIMER_B);
TimerIntEnable(TIMER1_BASE, TIMER_CAPA_EVENT);
IntEnable(INT_TIMER1A);
TimerEnable(TIMER1_BASE, TIMER_A);
IntPrioritySet(INT_TIMER1A,0x20);
//
// Loop forever while the Timer1B PWM runs.
//
IntMasterEnable();
while(1)
{
;
}
}
void Timer1AIntHandler(void)
{
TimerIntClear(TIMER1_BASE, TIMER_A);
i++;
if(i==10000)
{
i=0;
}
}