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.

Timer Capture Mode for pulse capture

i am writing a code for pulse capture using the timer CCp of lm4f120h5qr launchpad board and it shows some arbitary vaue; What is wrong with the code??
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/sysctl.h"
#include "driverlib/interrupt.h"
#include "driverlib/gpio.h"
#include "driverlib/timer.h"
#include "driverlib/rom.h"
#include "utils/ustdlib.h"
#include "utils/ustdlib.c"
#include "driverlib/uart.h"

#define GPIO_PA0_U0RX 0x00000001
#define GPIO_PA1_U0TX 0x00000401

void main(void)
{
//unsigned long ulPeriod;

//sysytem clock set
SysCtlClockSet(SYSCTL_SYSDIV_1|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);

//SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
//GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);

//SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
//GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_6);

SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);
TimerControlEvent(TIMER0_BASE, TIMER_A,TIMER_EVENT_BOTH_EDGES);

//ulPeriod = (SysCtlClockGet() / 10000) / 2;
//TimerLoadSet(TIMER0_BASE, TIMER_A, ulPeriod -1);

//IntEnable(INT_TIMER0A);
//TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
//IntMasterEnable();


//enable timer start
TimerEnable(TIMER0_BASE, TIMER_A);
unsigned long a = TimerValueGet(TIMER0_BASE, TIMER_A);

//UART PART TRANSMISSION

char schar;
char b;
// int i;
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

GPIOPinConfigure(GPIO_PA0_U0RX);
GPIOPinConfigure(GPIO_PA1_U0TX);

GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE));
UARTCharPut(UART0_BASE, '!');


do
{ //UARTCharPut(UART0_BASE, c);
//for(i=1;i<8;i++)
{
//b= am[i];

schar= UARTCharGet(UART0_BASE);
schar = 'a';
//c='X';
// UARTCharPut(UART0_BASE, am[0]);
UARTCharPut(UART0_BASE, am[1]);
UARTCharPut(UART0_BASE, am[2]);
UARTCharPut(UART0_BASE, am[3]);
UARTCharPut(UART0_BASE, am[4]);
UARTCharPut(UART0_BASE, am[5]);
UARTCharPut(UART0_BASE, am[6]);
UARTCharPut(UART0_BASE, am[7]);
UARTCharPut(UART0_BASE, schar);


// UARTCharPut(UART0_BASE, c);

}
} while((b != '\n') && (b != '\r'));


UARTCharPut(UART0_BASE, '@');




}

  • Hi,

    You should't be surprised if the code "does not work" - the pulse capture means you have to introduce something from outside world into micro - but all your pins are configured as output and none of them as input, and more precisely, as capture pin. You did not specify what is your choice about that. Take care not all pins are the same, read the manual. Second, you configure the timer as periodic, not for capture - the macro for that is TIMER_CFG_A_CAP_TIME (if you really need to measure the pulse, but is not the right choice if you need to count edges. What do you need?).

    However, the easy way to do what you want is to download the PinMux utility and use it to generate the configuration code for you. Keep in mind that for measurement you need to consider also the time-out.

    Petrei 

  • You've taken pains to clearly/promptly define the MCU pins required by less important Uart - have not carried through with the Timer Pin assisnment.  (I use an older, more advanced M4 MCU - and there are 2 MCU pins available for potential config. as, "T0CCP0.) 

    In addition - while you, " SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); " do you do the same for the Port upon which Timer0 is tied?  (unless that's Port_A or Port_F - I see no other Ports being so enabled.  We remote diagnosticians benefit from such clarity.

    Do you really want to, " SysCtlClockSet(SYSCTL_SYSDIV_1|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN); ?"  Might your use of the PLL - and then SYSDIV_1 - produce, "out of MCU spec" results?  You should read/understand how fast the PLL is running prior to entering a SYSDIV value...

    The many "commented out" lines serve to confound and camouflage potential errors - at minimum they "interrupt" our ability to fully/properly grasp the intent of your code...

  • I figger the comments should tell us what code is supposed to do...

    Then there is what we actually write. ...and sometimes never the twain shall meet -- which is why the comments are required...

    Of course on this forum the comments are usually missing as the code is all self documenting -- right?