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.

LM4F120h5qr capture mode

//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 66%.
// Configure Timer2B as a capture mode, capture the negative edges of the pwm
// which creates by the Timer1B .
//*****************************************************************************

int i=0;

void Timer_2B_interrupt() //question:cannot get into the interupt function
{
   i++;
   if(i>=100)
   {
      i=0;
   }
}

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,timer2 peripheral must be enabled for use.
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1); //for pwm
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER2); //for capture
//
// For this example T1CCP1 (pwm)is used with port B pin 5.
// T2CCP0 (capture)is used with port B pin 0.
// 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.
//
GPIOPinConfigure(GPIO_PB5_T1CCP1);
GPIOPinConfigure(GPIO_PB0_T2CCP0);
//
//
GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_5);
GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_0);

//
// Configure Timer1B as a 16-bit periodic timer.
//
TimerConfigure(TIMER1_BASE, TIMER_CFG_16_BIT_PAIR |
TIMER_CFG_B_PWM);
TimerConfigure(TIMER2_BASE, TIMER_CFG_16_BIT_PAIR |
TIMER_CFG_B_CAP_COUNT);

//
// Set the Timer1B load value to 40000. 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);
TimerLoadSet(TIMER2_BASE, TIMER_B, 40000);
//
// Set the Timer1B match value to load value / 3.
//
TimerMatchSet(TIMER1_BASE, TIMER_B, TimerLoadGet(TIMER1_BASE, TIMER_B) / 2);
TimerMatchSet(TIMER2_BASE, TIMER_B, 1);
//
TimerControlEvent(TIMER2_BASE,TIMER_B,TIMER_EVENT_NEG_EDGE);


// Enable Timer1B.
// Enable Timer2B.
TimerEnable(TIMER1_BASE, TIMER_B);

TimerIntEnable(TIMER2_BASE,TIMER_CAPB_EVENT);
TimerIntRegister(TIMER2_BASE,TIMER_B,Timer_2B_interrupt);
TimerEnable(TIMER2_BASE, TIMER_B);

//
// Loop forever while the Timer1B PWM runs.
//
  while(1)
 {
      ;
 }
}

  • Hi,

    Not verified the whole code, but some problems:

    • See Table 11-1. Available CCP Pins - in data sheet - the capture pin for Timer2B is T2CCP1, not T2CCP0 as in your code;
    • The interrupt for Timer T2: you do not clear the interrupt flag. Seems your intent is just numbering the interrupts (edges) and nothing else. If your intent is to measure the generated pwm, this routine must be re-written.
    • Why do you not use the PinMux utility to correctly initialize these pins?

    Petrei

  • Thanks a lot for your reply.

     I am a new learner of  this ARM core MCU.  Now, this codes above is just for tests so the interrupt function will be re-written later.

    I curious about  how to  use the PinMux utility to correctly initialize these pins. If you can provide more details or some reference documents, I will really appreciate you!

                                                                                                                                                                                                                                                       wilson