I'm trying to do a simple test program to count positive edges using edge capture mode on the TM4C123 LaunchPad. The code is based on edge_count.c in the TivaWare examples - changed to be compatible with TM4C123 instead of LM4F232.
When I read the timer value, it never changes. I've tried various frequency input signals on the PB4 pin.
Thanks,
//*****************************************************************************
#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/sysctl.h"
#include "driverlib/timer.h"
#include "driverlib/uart.h"
#include "utils/uartstdio.h"
//*****************************************************************************
//! UART0, connected to the Virtual Serial Port and running at 115,200, 8-N-1,
//! is used to display messages from this application.
//
//*****************************************************************************
//*****************************************************************************
//
// The error routine that is called if the driver library encounters an error.
//
//*****************************************************************************
#ifdef DEBUG
void
__error__(char *pcFilename, uint32_t ui32Line)
{
}
#endif
//*****************************************************************************
//
// Configure the UART and its pins. This must be called before UARTprintf().
//
//*****************************************************************************
void
ConfigureUART(void)
{
//
// Enable the GPIO Peripheral used by the UART.
//
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
//
// Enable UART0
//
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
//
// Configure GPIO Pins for UART mode.
//
ROM_GPIOPinConfigure(GPIO_PA0_U0RX);
ROM_GPIOPinConfigure(GPIO_PA1_U0TX);
ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
//
// Use the internal 16MHz oscillator as the UART clock source.
//
UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);
//
// Initialize the UART for console I/O.
//
UARTStdioConfig(0, 115200, 16000000);
}
//*****************************************************************************
//
//*****************************************************************************
int
main(void)
{
uint32_t ui32Count, ui32LastCount;
//
// 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();
//
ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
SYSCTL_XTAL_16MHZ);
//
// Initialize the UART and write status.
//
ConfigureUART();
UARTprintf("\033[2JEdge count example\n");
//
// Enable the GPIO port that is used for the on-board LED.
//
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
//
// Enable the GPIO pins for the LED (PF2 & PF1).
//
ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2 | GPIO_PIN_1);
//
// Enable the peripherals used by this example.
//
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
GPIOPinConfigure(GPIO_PB4_T1CCP0);
ROM_GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_4);
// GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_4,
// GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
ROM_TimerConfigure(TIMER1_BASE, (TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_CAP_COUNT_UP));
ROM_TimerControlEvent(TIMER1_BASE, TIMER_A, TIMER_EVENT_POS_EDGE);
ROM_TimerLoadSet(TIMER1_BASE, TIMER_A, 0);
ROM_TimerMatchSet(TIMER1_BASE, TIMER_A, 0xFFFF);
ROM_TimerPrescaleSet(TIMER1_BASE, TIMER_A, 0);
ROM_TimerPrescaleMatchSet(TIMER1_BASE, TIMER_A, 0xFF);
ROM_TimerEnable(TIMER1_BASE, TIMER_A);
ui32LastCount = 0;
while(1)
{
// Get the current timer count.
ui32Count = TimerValueGet(TIMER1_BASE, TIMER_A);
//
// Has it changed?
//
if(ui32Count != ui32LastCount)
{
UARTprintf("%x ", ui32Count);
ui32LastCount = ui32Count;
SysCtlDelay(SysCtlClockGet()/30);
}
}
}