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.

use of capture count timer

Hi,,i want to use a capture count timer to count the no of negative edges...and display it on my screen using uart.For this i have configured timer0 as count timer and timer1 as in pwm mode...BUT the problem is nothing is being displayed on screen.

my code is :::::::::::::::


#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"

unsigned long int count=0,state=0;

void
InitConsole(void)
{

    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);


    /* Make the UART pins be peripheral controlled. */
    GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    //
    // Initialize the UART for console I/O.
    //
    UARTStdioInit(0);
}


void timer_int(void)
{
    TimerIntClear(TIMER0_BASE,TIMER_CAPB_EVENT);
 count=TimerValueGet(TIMER0_BASE,TIMER_B);
 UARTprintf("count elapsed : %d \n",count);
 if(state)
 {GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1,0);
  state=0;
 }
 else {GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1,GPIO_PIN_1);
           state=1;
      }
}







int main(void)
{
    SysCtlClockSet(SYSCTL_SYSDIV_1| SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);//16 mhz
    InitConsole();
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);

    GPIOPinConfigure(GPIO_PB4_T1CCP0);
    GPIOPinConfigure(GPIO_PF1_T0CCP1);

    GPIOPinTypeTimer(GPIO_PORTB_BASE,GPIO_PIN_4);
        GPIOPinTypeTimer(GPIO_PORTF_BASE,GPIO_PIN_1);


    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);

    TimerConfigure(TIMER1_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_B_PWM);
    TimerConfigure(TIMER0_BASE, TIMER_CFG_16_BIT_PAIR |TIMER_CFG_B_CAP_COUNT);

    TimerLoadSet(TIMER1_BASE, TIMER_B, 40000);
    TimerLoadSet(TIMER0_BASE, TIMER_B, 40000);

    TimerMatchSet(TIMER1_BASE, TIMER_B, TimerLoadGet(TIMER1_BASE, TIMER_B) / 2);
    TimerMatchSet(TIMER0_BASE, TIMER_B, 1);

    TimerControlEvent(TIMER0_BASE,TIMER_B,TIMER_EVENT_NEG_EDGE);

    TimerEnable(TIMER1_BASE, TIMER_B);

    TimerIntEnable(TIMER0_BASE,TIMER_CAPB_EVENT);
    TimerIntRegister(TIMER0_BASE,TIMER_B,timer_int);
    TimerEnable(TIMER0_BASE, TIMER_B);


    IntMasterEnable();
    /* UART config */
    InitConsole();

    while(1)
    {


    }
}

  • Hello Mahavir,

    For Timer-1 using B-Timer the PWM output is on PB5 and not on PB4.

    Regards

    Amit

  •  Sir,,but even after making these changes i am not getting the output..

  • Hello mahavir

        GPIOPinConfigure(GPIO_PB5_T1CCP1);

        GPIOPinTypeTimer(GPIO_PORTB_BASE,GPIO_PIN_5);

    Did you check on the scope that PB5 is toggling?

    Regards

    Amit

  • Sir,how to check the scope that PB5 is toggling or not?

  • mahavir dwivedi said:
    nothing is being displayed on screen.

    Might it prove wise to initially create a series of dummy writes to your screen - to prove that such communication is - in fact - possible?  As it stands now - all of your effort is held hostage by the "correctness" of your UART set-up, connecting cable and mated PC.

    Might it be that a, "hard connection" between your MCU's PWM output and your 2nd Timer's MCU input is needed?  None is described.

    Review of the PWM Output (alleged output) as well as the receiving Timer's data input register would provide further operational feedback...

    [edit] "Sir,how to check the scope that PB5 is toggling or not?"  cb1 raises pistol (again) to head. Thinly disguised, "do my homework" ploy has entrapped 2 fresh victims...  cb1 (w/fresh head wound/graze) slowly, bloodily departs...

  • Hello Mahavir,

    OK, may be I misunderstood.

    1. Are you using PWM output to capture the count on the other timer?

    2. Is the UART working on the console.Simply put UARTprintf("Test Begins\n" after the UARTStdioInit(0) function

    3. Alternatively, if you put a breakpoint on the timer interrupt function, does it every come to the timer interrupt function?

    And must be that I may have missed the most obvious. The following is missing in the UART Console Configuration function...

        GPIOPinConfigure(GPIO_PA0_U0RX);
        GPIOPinConfigure(GPIO_PA1_U0TX);

    Regards

    Amit