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.

Read the external pulses using tm4c123h5qc

Other Parts Discussed in Thread: TM4C123GH6PZ

Hi..i suppose to read the  pulses using tm4c123h5qc..i don't known from where i need to start...till now i never used timer in tm4c123h5qc.i need to finish it up with in two days..please tell me driver library is sufficient to do this ??because of time less i can't go through in death of timers in tm4c123h5qc...give some working sample..

Thanks in advance

  • Hello Raaki,

    In TivaWare 2.1.0 there is a examples/peripheral folder when you can fin edge time example for a timer. I hope that meets your requirement.

    Regards

    Amit

  • K Thank you..rite now i'll use this example code..and also i need to known in depth of timers using  interrupt in lm4f123h5qc...any suggestion from where i need to start ??i meant to say datasheet or driver library??

  • Hello Raaki

    You need to be more specific in explaining what you plan to do. Information changes based on the requirements

    Regards

    Amit

  • Hi Thank you for your reply....i have generated  2.5 Hz using ad9833 with silabs controller.n we have some hardware circuit to generate sine wave into pulses..i can able to see the pulses in oscilloscope.now  i need to count that pulses using TM4C123H5QC n display on 20x4 lcd..

    Now i'm planning to use TIMER4 n i'm giving that  pulses to PG0..Is it correct??because i need to make sure that weather i'm giving to correct pin.Please help..

  • Hello Raaki

    Are you sure about the part number TM4C123H5QC as there is no part number like this.

    Regards

    Amit

  • oh sorry..i have TM4C123GH6PZ..

  • Hello Raaki

    Yes, for this part PG0 is OK for Timer-4 Subtimer-A

    Regards

    Amit

  • k what exactly  mean of Subtimer and full timer..now i'm using the example code to count the pulses..Let me to check with PG0 gpio pin.

  • Hello Raaki,

    The normal timer on TM4C devices are 32-bit timers. However they can be made to work independently as 2 16-bit timers as well.

    When used in 16-bit mode, Subtimer-A is mentioned then it is corresponding to CCP0 pin and when Subtimer-B is mentioned it corresponds to CCP1 pin (Please see signal description section of the data sheet)

    When used in 32-bit mode the entire timer is connected to CCP0 pin and CCP1 pin is not required.

    Regards

    Amit

  • Hi...

    i'm configuring the timer like this..Is it correct??

    /*timer*/
    SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER4);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);

    GPIOPinTypeTimer(GPIO_PORTG_BASE, GPIO_PIN_0);
    GPIOPinConfigure(GPIO_PG0_T4CCP0);

    GPIOPadConfigSet(GPIO_PORTG_BASE, GPIO_PIN_0,
    GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);



    IntMasterEnable();

    TimerConfigure(TIMER4_BASE, (TIMER_CFG_SPLIT_PAIR |TIMER_CFG_A_CAP_COUNT));
    TimerControlEvent(TIMER4_BASE, TIMER_A, TIMER_EVENT_POS_EDGE);
    TimerLoadSet(TIMER4_BASE, TIMER_A, 9);
    TimerMatchSet(TIMER4_BASE, TIMER_A, 0);

    IntEnable(INT_TIMER4A);
    TimerIntEnable(TIMER4_BASE, TIMER_CAPA_MATCH);
    TimerEnable(TIMER4_BASE, TIMER_A);

  • Hi Raaki,

    Yes it is correct. In that setup there will be a interrupt generated after 9 positive edgess.

    You still need the interrupt handler and inside of it it needs to be always TimerIntClear();, This is to clear the interrupt flag wich in this case is only TIMER_CAPA_MATCH so you should only need to do TimerIntClear(TIMER4_BASE, TIMER_CAPA_MATCH); 

    I think there is a predefined fuction name for the interrupt handler but i always use TimerIntRegister(); to set the interrupt handler to any name i want. 

  • k thank you..now i'll send the full code..i need to display the 2500 HZ after reading the pulses.but i'm getting some other value.First i'm using  with timer in TM4c123gh6pz..For time being i have used the example code of tivaware.

    #include "inc/lm4f232h5qc.h"
    #include "inc/hw_memmap.h"
    #include "inc/hw_types.h"
    #include "driverlib/qei.h"
    #include "driverlib/gpio.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/systick.h"
    #include <stdint.h>
    #include <stdio.h>
    #include <string.h>
    #include <stdbool.h>
    #include "driverlib/pin_map.h"
    #include "driverlib/uart.h"
    #include "utils/uartstdio.h"
    #include "inc/hw_ints.h"

    #include "driverlib/timer.h"
    #include "driverlib/interrupt.h"

    #define GPIO_PE0_U7RX 0x00040001

    #define GPIO_PE1_U7TX 0x00040401
    #define GPIO_PG0_T4CCP0 0x00060007

    void MainLoopRun(void);

    volatile uint32_t g_ui32IntCount;
    uint32_t g_ui32Flags;

    void
    UARTSend(const unsigned char *pucBuffer, unsigned long ulCount)
    {
    //
    // Loop while there are more characters to send.
    //
    while(ulCount--)
    {
    //
    // Write the next character to the UART.
    //
    UARTCharPutNonBlocking(UART7_BASE, *pucBuffer++);
    }
    }

    void
    ProcessInterrupt(void)
    {
    //
    // Update our interrupt counter.
    //
    g_ui32IntCount++;

    //
    // Toggle the interrupt flag telling the main loop to update the display.
    //
    HWREGBITW(&g_ui32Flags, 0) ^= 1;
    }


    char Buffer1[30];
    void
    Timer4IntHandler(void)
    {
    //
    // Clear the timer interrupt.
    //
    // TODO: Rework this for the timer you are using in your application.
    //
    TimerIntClear(TIMER4_BASE, TIMER_CAPA_MATCH);

    //
    // TODO: Do whatever your application needs to do when the relevant
    // number of edges have been counted.
    //
    ProcessInterrupt();

    //
    // The timer is automatically stopped when it reaches the match value
    // so re-enable it here.
    //
    // TODO: Whether you reenable the timer here or elsewhere will be up to
    // your particular application.
    //
    TimerEnable(TIMER4_BASE, TIMER_A);
    }

    int main(void)

    {

    SysCtlClockSet(SYSCTL_SYSDIV_1|SYSCTL_USE_OSC|SYSCTL_OSC_MAIN|SYSCTL_XTAL_8MHZ); //8Mhz
    //--------------
    // UART
    //--------------



    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART7);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    GPIOPinConfigure(GPIO_PE0_U7RX);
    GPIOPinConfigure(GPIO_PE1_U7TX);
    GPIOPinTypeUART(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    UARTConfigSetExpClk(UART7_BASE, SysCtlClockGet(),9600,(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
    UARTEnable(UART7_BASE);
    sprintf((char *)Buffer1, "Freq Read\n");
    UARTSend((unsigned char *)Buffer1, 20);

    /*timer*/
    SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER4);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);

    GPIOPinTypeTimer(GPIO_PORTG_BASE, GPIO_PIN_0);
    GPIOPinConfigure(GPIO_PG0_T4CCP0);

    GPIOPadConfigSet(GPIO_PORTG_BASE, GPIO_PIN_0,
    GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);



    IntMasterEnable();

    TimerConfigure(TIMER4_BASE, (TIMER_CFG_SPLIT_PAIR |TIMER_CFG_A_CAP_COUNT));
    TimerControlEvent(TIMER4_BASE, TIMER_A, TIMER_EVENT_POS_EDGE);
    TimerLoadSet(TIMER4_BASE, TIMER_A, 9);
    TimerMatchSet(TIMER4_BASE, TIMER_A, 0);

    IntEnable(INT_TIMER4A);
    TimerIntEnable(TIMER4_BASE, TIMER_CAPA_MATCH);
    TimerEnable(TIMER4_BASE, TIMER_A);
    MainLoopRun();

    }


    void
    MainLoopRun(void)
    {
    uint32_t ui32Count, ui32LastCount;

    //
    // Set up for the main loop.
    //
    ui32LastCount = 10;

    //
    // Loop forever while the timer runs.
    //
    while(1)
    {
    //
    // Get the current timer count.
    //
    ui32Count = TimerValueGet(TIMER4_BASE, TIMER_A);

    //
    // Has it changed?
    //
    if(ui32Count != ui32LastCount)
    {
    //
    // Yes - update the display.
    //

    // sprintf((char *)Buffer1, "%d\n",ui32Count);
    // UARTSend((unsigned char *)Buffer1, 20);


    //
    // Remember the new count value.
    //
    ui32LastCount = ui32Count;
    }

    //
    // Has there been an interrupt since last we checked?
    //
    if(HWREGBITW(&g_ui32Flags, 0))
    {
    //
    // Clear the bit.
    //
    HWREGBITW(&g_ui32Flags, 0) = 0;

    //
    // Update the interrupt count.
    //

    sprintf((char *)Buffer1, "%d\n",g_ui32IntCount);
    UARTSend((unsigned char *)Buffer1, 20);

    }
    }
    }

    Thank in advance

  • Hello Raaki,

    Is that you want to capture the pulse width/frequency? In that case you need to use TIMER_CFG_A_CAP_TIME and not TIMER_CFG_A_CAP_COUNT mode of the timer.

    Regards

    Amit

  • HI ..i need to capture frequency..k i'll modify n i'll check that program..k Is their any thing modification need to do in start up cod??because i'm using interrupt..

  • Hello Raaki,

    Please read the Timer Edge Time Mode which explains what to expect from the timer when counting signal edge time and how the snapshot register needs to be accessed in Timer Interrupt Handler.

    Regards

    Amit

  • Hi  Amit..Now some value contineously is display on hyper terminal ..now how can i count to display as 2500Hz..please help me

  • Hello Raaki,

    In this mode the timer will be in free running counter mode and will capture the value of the internal counter when the edge occurs. So to get the correct frequency you would need capture two edges, subtract the same to get the time difference between the edges and then display the difference value to get the frequency (the difference value is the number of clock edges between the two captures)

    Please updated-test-attach your code (attach and not post) for review if the above info did not help.

    Regards

    Amit

  • 0763.FREREADARM.rar

    k..then i need to one more timer rite for capture two edges??

  • Hello Raaki,

    Yes. Also another important thing that was highlighted in this mode is that the Timeout does not occur. So you may want to take care that when the counter rolls over it may have captured values which may seem wrong. As an example when counting up, first edge occurs at 0x1000 and second edge occur at 0x2000. So it is fine that the difference works out to be 0x2000-0x1000. However close the timeout of the counter edge-1 occurs at 0xF000 and edge-2 occurs at 0x0001 then the difference would not be 0x1-0xF000 but (0xFFFF-0xF000)+0x1.

    This of course depends on what the load value of the counter is. So please do take this into account when doing the maths. I would wait for the updated code after all such changes are made.

    Regards

    Amit

  • HI...without knowing in details about driver function it is difficulty for me to write the program..so 1st i'll try to understand the driver function of timer n NVIC ..i'm  finding somewhat tough to use timer with arm controller..k i'll go through the in deapth of timer now..

  • Hi Amith..i have add the Timer0IntHandler in startup code..when i'm building  it is showing error like this.

    Startup.s(119): error: A1516E: Bad symbol 'Timer0IntHandler', not defined or external

    even after add  void  Timer0IntHandler(void) in startup code,same error i'm getting...what is the solution for this??

  • Hello Raaki,

    It has to be declared as extern in the startup file.

    Regards

    Amit

  • In start up file,where i need to add this function..i have defined on the top of this file like 

    extern void Timer0IntHandler(void);

    but still showing error like Startup.s(30): error: A1163E: Unknown opcode void , expecting opcode or Macro

  • Hello Raaki

    If you are using Timer4IntHandler in the code then why are putting Timer0IntHandler in the startup.s file?

    Regards

    Amit

  • Hi Amith..i'm referred  this link..

    http://www.ti.com/TM4C123G-Launchpad-Workshop

    i'm trying to execute sample program given in timer using interrupt..so what ever they are saying in that document i'm following so i'm adding in startup file.

  • Hello Raaki

    I would suggest porting one of the existing examples. It would be fast and less error prone

    Regards

    Amit