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.

CCS/TM4C123GH6PM: Pulse Duration Capture Using Timer.

Part Number: TM4C123GH6PM
Other Parts Discussed in Thread: TM4C1294NCPDT

Tool/software: Code Composer Studio

I have written code for capturing  50 HZ pulse using TIMER. But, the code is not going to Interrupt handler function. Also, I have done changes accordingly in startup.css for the same.

Please, look into it as soon as possible.


#define PART_TMC123GH6PM

#include <stdint.h> // Variable definitions for the C99 standard.
#include <stdio.h> // Input and output facilities for the C99 standard.
#include <stdbool.h> // Boolean definitions for the C99 standard.
//#include "inc/hw_ints.h"
#include "inc/hw_types.h"
#include "driverlib/debug.h"
#include "driverlib/rom.h"
#include "driverlib/sysctl.h"
#include "driverlib/pwm.h"
#include "driverlib/sysctl.h" // Definitions and macros for System Control API of DriverLib.
#include "driverlib/interrupt.h" // Defines and macros for NVIC Controller API of DriverLib.
#include "driverlib/gpio.h" // Definitions and macros for GPIO API of DriverLib.
#include "driverlib/timer.h" // Defines and macros for Timer API of DriverLib.
#include "driverlib/pin_map.h" //Mapping of peripherals to pins for all parts.
#include "driverlib/adc.h" // Definitions for ADC API of DriverLib.
#include "driverlib/fpu.h" // Prototypes for the FPU manipulation routines.
#include "inc/tm4c123gh6pm.h" // Definitions for the interrupt and register assignments.
#include "inc/hw_memmap.h" // Memory map definitions of the Tiva C Series device.
#include "inc/hw_types.h" // Definitions of common types and macros.

uint32_t g_ui32SysClock;

int pulse_time_1=0;
int a = 0, b = 0, c = 0;

void TIMER_Initialize(void)
{
// Enables timer 1
    SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);

    while(!SysCtlPeripheralReady(SYSCTL_PERIPH_TIMER0))
    {

    }
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOL);
    while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOL))
    {

    }
// Timer type set
    GPIOPinTypeTimer(GPIO_PORTL_BASE, GPIO_PIN_4);
// PB5 pin configured with timer 1
    GPIOPinConfigure(GPIO_PL4_T0CCP0);

// Configure timer to edge time capture
    TimerConfigure(TIMER0_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_B_CAP_TIME);
// Event set to both pulse edges
    TimerControlEvent(TIMER0_BASE, TIMER_B, TIMER_EVENT_BOTH_EDGES);
// Enables the timers
    TimerEnable(TIMER0_BASE, TIMER_B);
// Configure timer 1b interrupts
    IntEnable(INT_TIMER0B);
// Enable timer interrupts
    TimerIntEnable(TIMER0_BASE, TIMER_CAPB_EVENT);
// Enables processor interrupts
    IntMasterEnable();
}

int main(void)
{
//    SysCtlClockSet(SYSCTL_SYSDIV_64 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
    g_ui32SysClock = SysCtlClockFreqSet((  SYSCTL_XTAL_25MHZ   |
                               SYSCTL_OSC_MAIN   |
                               SYSCTL_USE_PLL    |
                               SYSCTL_CFG_VCO_480), 120000000);

    TIMER_Initialize();

    while (1)
    {
//        pulse_time_1 = TimerLoadGet(TIMER0_BASE, TIMER_B);
//        TimerEnable(TIMER0_BASE, TIMER_B);

    }
}

void Timer3IntHandler(void)
{
    TimerIntClear(TIMER0_BASE, TIMER_CAPB_EVENT);
    b = TimerValueGet(TIMER0_BASE, TIMER_B);
    if (b < a)
        c = 65535 + a - b;
    else
        c = a - b;
    pulse_time_1 = c / 3125;
    a = TimerValueGet(TIMER0_BASE, TIMER_B);

}

Thanks & Regards

Vinayak


  • The TM4C123GH6PM does not have a GPIOL. It looks like you started with a TM4C129 example. You should have gotten an error when you compiled. On the TM4C123GH6PM, T0CCP0 is on pin PB6 or PF0.

  • Mr. Bob

    Sorry. I have mentioned TM4C123GH6PM in the thread but I have used TM4C129NCPDT controller for my project. My problem remains the same and please help me to  resolve it as soon as possible.

    I had used example code for TM4C123GH6PM but I need to capture five  pulses in total and send it over ethernet, hence I am using TM4C129NCPDT.

    The configuration in my code is as follows:

    T0CCP0-  PORT L PIN 4

    T2CCP0- PORT A PIN 4

    T3CCP0- PORT A PIN 6

    T4CCP0-PORT B PIN 0

    T5CCP0-PORT B PIN 2

    The code is not working even on TM4C123GH6PM

    T1CCP1- PORT B PIN5

  • Mr.Bob

    Please give me acknowledgement about the status of this thread. Also, I would like to receive the solution as soon as possible.

    I am working on live project and this problem is taking way more than allotted  time.

  • First, you need to remove:

    #define PART_TMC123GH6PM

    and 

    #include "inc/tm4c123gh6pm.h" // Definitions for the interrupt and register assignments.

    from your code if you are using the TM4C1294NCPDT. You should use a project that has the proper part number defined. I always start projects by importing the "project0" from the TivaWare example of the family I want to use.

    Finally, you need to either register your interrupt routine (ex: IntRegister(INT_TIMER0B, Timer0IntHandler);) or edit the vector table in startup_ccs.c.

  • Mr. Bob

    I have registered interrupt routine in vector table and also have removed #define part 123 from my code.

    I have defined pins for 129 and coding for the same.

    My custom board is ready with 129 in it.

    Please look into my problem.

  • Sorry, it took me some time to see this. You are trying to use T0CCP0 with Timer0_B. T0CCP1 goes with the Timer B side and T0CCP0 goes with the Timer A side.

  •  Mr bob.

    Thank you, I noticed it now.