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.

TIVA "Input Edge Timing Mode" KO....! (MEASURE OF LINE FREQUENCY 50 HzHi)

Other Parts Discussed in Thread: TM4C129XNCZAD

Hi,

My problem : Can't get interrupt on edge front of square wave of 50 Hz injected in PL4 pin...

My target :   TM4C129X Dev Kit

My code :

//*****************************************************************************

//

// Copyright (c) 2013-2014 Texas Instruments Incorporated. All rights reserved.

// Software License Agreement

//

// This is part of revision 2.1.0.12573 of the DK-TM4C129X Firmware Package.

//

// TITLE : LINE_FREQUENCY_METER_00

// TARGET : TM4C129X Dev Kit

// SCOPE : To measure continuosly the frequency of a square wave (50 [Hz]) injected to PL4 pin.

// using the timer capture ....

// FILE : main.c

// DATE : 05/03/2015 (DD/MM/YEAR)

//*****************************************************************************

 

// startup_ccs.c

// IntDefaultHandler, // ADC Sequence 3

// IntDefaultHandler, // Watchdog timer

// Timer0AIntHandler, // Timer 0 subtimer A <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

// IntDefaultHandler, // Timer 0 subtimer B

// IntDefaultHandler, // Timer 1 subtimer A

//

//******************************************************************

//

//Tiva™ TM4C129XNCZAD Microcontroller

//

//Table 16-1. Available CCP Pins

//

//Timer Up/Down Counter Even CCP Pin Odd CCP Pin

//

// Timer A T0CCP0 -

//16/32-Bit Timer 0

// Timer B - T0CCP1

//

//

// Timer A T1CCP0 -

//16/32-Bit Timer 1

// Timer B - T1CCP1

//

//

// Timer A T2CCP0 -

//16/32-Bit Timer 2

// Timer B - T2CCP1

//

//

// Timer A T3CCP0 -

//16/32-Bit Timer 3

// Timer B - T3CCP1

//

//

// Timer A T4CCP0 -

//16/32-Bit Timer 4

// Timer B - T4CCP1

//

//

// Timer A T5CCP0 -

//16/32-Bit Timer 5

// Timer B - T5CCP1

//

// Timer A T6CCP0 -

//16/32-Bit Timer 6

// Timer B - T6CCP1

//

// Timer A T7CCP0 -

//16/32-Bit Timer 7

// Timer B - T7CCP1

//******************************************************************

 

//Table 16-2. General-Purpose Timers Signals (212BGA)

//

//Pin Name Pin Number Pin Mux / Assignment Pin Type Buffer Type Description

//

// T0CCP0 V3 PA0 (3) I/O TTL 16/32-Bit Timer 0 Capture/Compare/PWM 0.

// C2 PD0 (3)

// H18 PL4 (3)

// P3 PR4 (3)

//

//T0CCP1 W3 PA1 (3) I/O TTL 16/32-Bit Timer 0 Capture/Compare/PWM 1.

// C1 PD1 (3)

// G19 PL5 (3)

// P2 PR5 (3)

//

//T1CCP0 T6 PA2 (3) I/O TTL 16/32-Bit Timer 1 Capture/Compare/PWM 0.

// D2 PD2 (3)

// C18 PL6 (3)

// W9 PR6 (3)

//

//

//T1CCP1 U5 PA3 (3) I/O TTL 16/32-Bit Timer 1 Capture/Compare/PWM 1.

// D1 PD3 (3)

// B18 PL7 (3)

// R10 PR7 (3)

//

//T2CCP0 V4 PA4 (3) I/O TTL 16/32-Bit Timer 2 Capture/Compare/PWM 0.

// K18 PM0 (3)

// D12 PS0 (3)

//

//T2CCP1 W4 PA5 (3) I/O TTL 16/32-Bit Timer 2 Capture/Compare/PWM 1.

// K19 PM1 (3)

// D13 PS1 (3)

//

//Pin Name Pin Number Pin Mux / Assignment Pin Type Buffer Type Description

//

//T3CCP0 V5 PA6 (3) I/O TTL 16/32-Bit Timer 3 Capture/Compare/PWM 0.

// A4 PD4 (3)

// L18 PM2 (3)

// B14 PS2 (3)

//

//T3CCP1 R7 PA7 (3) I/O TTL 16/32-Bit Timer 3 Capture/Compare/PWM 1.

// B4 PD5 (3)

// L19 PM3 (3)

// A14 PS3 (3)

//

//T4CCP0 A16 PB0 (3) I/O TTL 16/32-Bit Timer 4 Capture/Compare/PWM 0.

// B3 PD6 (3)

// M18 PM4 (3)

// V9 PS4 (3)

//

//T4CCP1 B16 PB1 (3) I/O TTL 16/32-Bit Timer 4 Capture/Compare/PWM 1.

// B2 PD7 (3)

// G15 PM5 (3)

// T13 PS5 (3)

//

//T5CCP0 A17 PB2 (3) I/O TTL 16/32-Bit Timer 5 Capture/Compare/PWM 0.

// N19 PM6 (3)

// U10 PS6 (3)

//

//

//T5CCP1 B17 PB3 (3) I/O TTL 16/32-Bit Timer 5 Capture/Compare/PWM 1.

// N18 PM7 (3)

// R13 PS7 (3)

//

//T6CCP0 F2 PB6 (3) I/O TTL 16/32-Bit Timer 6 Capture/Compare/PWM 0.

// D6 PP0 (5)

// E3 PQ0 (3)

// W10 PT0 (3)

//

//

//Pin Name Pin Number Pin Mux / Assignment Pin Type Buffer Type Description

//

//T6CCP1 F1 PB7 (3) I/O TTL 16/32-Bit Timer 6 Capture/Compare/PWM 1.

// D7 PP1 (5)

// E2 PQ1 (3)

// V10 PT1 (3)

//

//

//T7CCP0 M2 PC4 (3) I/O TTL 16/32-Bit Timer 7 Capture/Compare/PWM 0.

// H4 PQ2 (3)

// E18 PT2 (3)

//

//

//T7CCP1 M1 PC5 (3) I/O TTL 16/32-Bit Timer 7 Capture/Compare/PWM 1.

// M4 PQ3 (3)

// F17 PT3 (3)

//

#include <stdint.h>

#include <stdbool.h>

#include "inc/hw_ints.h"

#include "inc/hw_memmap.h"

#include "inc/hw_types.h"

#include "driverlib/debug.h"

#include "driverlib/fpu.h"

#include "driverlib/gpio.h"

#include "driverlib/interrupt.h"

#include "driverlib/pin_map.h"

#include "driverlib/rom.h"

#include "driverlib/rom_map.h"

#include "driverlib/sysctl.h"

#include "driverlib/timer.h"

#include "driverlib/uart.h"

#include "utils/uartstdio.h"

//****************************************************************************

// System clock rate in Hz.

//****************************************************************************

uint32_t g_ui32SysClock;

 

//*****************************************************************************

//

//*****************************************************************************

uint32_t timer_value_actual;

uint32_t timer_value_old;

uint32_t timer_value_delta;

float frequency_result ;

bool g_bIntFlag = false;

 

//*****************************************************************************

// Function prototypes

//*****************************************************************************

float calc_freq(uint32_t timer_value_delta);

 

//*****************************************************************************

//

// The error routine that is called if the driver library encounters an error.

//

//*****************************************************************************

#ifdef DEBUG

void

__error__(char *pcFilename, unsigned long ulLine)

{

}

#endif

//*****************************************************************************

//

// The interrupt handler for the timer interrupt.

//

//*****************************************************************************

void Timer0A_IntHandler(void)

{

// Clear the timer interrupt.

TimerIntClear(TIMER0_BASE, TIMER_CAPA_EVENT);

// Get the counter value

timer_value_actual = TimerValueGet(TIMER0_BASE,TIMER_A);

timer_value_delta = timer_value_actual - timer_value_old ;

timer_value_old = timer_value_actual ;

g_bIntFlag = true; // interrupt done...

}

//*****************************************************************************

// main

//*****************************************************************************

int main(void)

{

uint32_t ui32SysClock;

// Run from the PLL at 120 MHz.

ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |

SYSCTL_OSC_MAIN | SYSCTL_USE_PLL |

SYSCTL_CFG_VCO_480), 120000000);

ui32SysClock = ui32SysClock ; // ANTI WARNING....

// Enable lazy stacking for interrupt handlers. This allows floating-point

// instructions to be used within interrupt handlers, but at the expense of

// extra stack usage.

ROM_FPULazyStackingEnable();

// Configure the device pins.

// PinoutSet();

 

 

// Enable the peripherals used by this example.

// PL4 T0CCP0

// The Timer0 peripheral must be enabled for use.

ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);

SysCtlDelay(30);

// For this example CCP0 is used with port L pin 4.

// GPIO port L needs to be enabled so these pins can be used.

ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOL);

SysCtlDelay(30);

 

 

// Configure PL4 as the CCP0 pin for timer 0.

// This is set up to use GPIO PL4 which can be configured

// as the CCP0 pin for Timer0

ROM_GPIOPinTypeTimer(GPIO_PORTL_BASE, GPIO_PIN_4); //capture

ROM_GPIOPinConfigure(GPIO_PL4_T0CCP0); //capture

 

 

// Set the pin to use the internal pull-up.

// If your board has an external

// pull-up or pull-down, this will not be required.

// MAP_GPIOPadConfigSet(GPIO_PORTM_BASE, GPIO_PIN_0,

// GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU)

MAP_GPIOPadConfigSet(GPIO_PORTL_BASE, GPIO_PIN_4,

GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);

// GPIOPadConfigSet(GPIO_PORTL_BASE, GPIO_PIN_4, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);

//******

// Loop forever while the Timer0A runs.

ROM_IntMasterEnable();

//******

 

//*********************************************************************************

//! - TIMER_CAPB_EVENT - Capture B event interrupt

//! - TIMER_CAPB_MATCH - Capture B match interrupt

//! - TIMER_TIMB_TIMEOUT - Timer B timeout interrupt

//! - TIMER_RTC_MATCH - RTC interrupt mask

//! - TIMER_CAPA_EVENT - Capture A event interrupt

//! - TIMER_CAPA_MATCH - Capture A match interrupt

//! - TIMER_TIMA_TIMEOUT - Timer A timeout interrupt

//*********************************************************************************

// Configure Timer0A as a .....

ROM_TimerConfigure(TIMER0_BASE, TIMER_CAPA_EVENT); // A:capture event mode

// ROM_TimerConfigure(TIMER0_BASE, (TIMER_CFG_SPLIT_PAIR |

// TIMER_CAPA_EVENT));

 

// TimerControlEvent(TIMER0_BASE,TIMER_A,TIMER_EVENT_NEG_EDGE);

// ROM_TimerControlEvent(TIMER0_BASE,TIMER_A,TIMER_EVENT_BOTH_EDGES);

// ROM_TimerControlEvent(TIMER0_BASE,TIMER_A,TIMER_EVENT_NEG_EDGE);

ROM_TimerControlEvent(TIMER0_BASE,TIMER_A,TIMER_EVENT_POS_EDGE);

//******

// Enable the Timer0A interrupt on the processor (NVIC).

ROM_IntEnable(INT_TIMER0A);

//******

 

//******

// enable the Timer0A interrupt

ROM_TimerIntEnable(TIMER0_BASE, TIMER_CAPA_EVENT);

//******

//******

// Enable Timer0A.

ROM_TimerEnable(TIMER0_BASE, TIMER_A);

//******

 

// debug ...

// g_bIntFlag = true;

// timer_value_delta = 20000000;

// debug ...

 

while(1)

{

if(g_bIntFlag == true)

{

g_bIntFlag = false;

frequency_result = calc_freq(timer_value_delta);

// Display frequency_result ....

SysCtlDelay(1);

}

}

}

 

//*****************************************************************************

// calc_freq()

//

// Case --> 50 [Hz]

// 50 [Hz] --> 20 [ms]

// System Clock = 120 000 000 [Hz]

// 1/ 120 000 000 [Hz] = 8.33... e-9 [s] = 8.33 [ns]

// 20 000 000 [ns] / 8.33 [ns] = 2,400,960 clocks counts

// 2,400,960 clocks * 8.33 [ns] = 20,007,923 [ns] --> ca. 20 000 000 [ns]

// 1/20 000 000 [ns] = 50 [Hz]

//

// if timer_value_delta = 20 000 000 [ns] --> frequency = 1 / 20 000 000 [ns] = 0.00000005

// As I want a format XX.XX [Hz] , then it is neccessary to multiply by "1 000 000 000"

//

// 0.00000005 * 1 000 000 000 = 50.00 [Hz]

//

//*****************************************************************************

float calc_freq(uint32_t timer_value_delta)

{

float frequency ;

// frequency = 1 / timer_value_delta * 1000000000 ; // frequency = 50.00

frequency = 1000000000 / timer_value_delta ; // frequency = 50.00

SysCtlDelay(1);

return frequency ;

}

 

Thank you in advance