Hi all,
I wrote some software which would count rising edges of a signal coming in from an encoder, I had initially done this using the simple GPIO interrupts.
I wanted to step it up a bit, and measure the frequency of the signal by counting the rising edges of a signal coming from a function generator within a certain timespan, thus calculating the frequency.
I started it off by simply trying to count the edges in a similar fashion to what I did before (with the GPIO interrupts) but this time using the timer as a means of counting the rising edges.
After some snooping in the TivaWare directory, I found the edge_count example, and began basing my code off of that. However, when I try to run what I've eventually wrote, absolutely nothing happens. I'm positive it has something to do with either my initialisation of the timer or the calling of the interrupt routine.
I figured this out by not calling my function where I initialise the timer, but _keeping_ the calling of the interrupt routine (TimerValueGet). In this case, I managed to see the output in the UART ("Hello, world!") but it didn't go past the TimerValueGet statement.
In the case where I don't call the function where I intialise the timer and I also remove the line where I call the interrupt routine (TimerValueGet) I do manage to get past this and see data coming into the UART, but it's ofcourse 0 because it isn't counting something.
At first I thought it might be a hardware fault (using the LaunchPad so maybe I just misconfigured a pin) but then I'd at least thought I would get to the "Hello, world!" part of my software, which it doesn't.
Any help would be much appreciated, so can I start to figure out how to measure the frequency.
Regards,
James
EDIT:
Ignore all of the above, I had simply been mixing timers up, that's what you get when you attempt to do this when you're nackered.
I now have the problem that I'm simply not detecting any edges, as my edge counter is remaining at 0. I have attached my updated code this post.
#include <stdint.h> #include <stdbool.h> #include "inc/hw_memmap.h" #include "inc/hw_types.h" #include "inc/hw_timer.h" #include "inc/hw_ints.h" #include "driverlib/gpio.h" #include "drivers/pinout.h" #include "driverlib/pin_map.h" #include "driverlib/timer.h" #include "driverlib/rom.h" #include "driverlib/rom_map.h" #include "driverlib/sysctl.h" #include "driverlib/uart.h" #include "driverlib/interrupt.h" #include "utils/uartstdio.h" #include "inc/tm4c1294ncpdt.h" //***************************************************************************** // // System clock rate in Hz. // //***************************************************************************** uint32_t g_ui32SysClock; uint32_t count, count2; //***************************************************************************** // // 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 InitUART(void) { // // Configure GPIO Pins for UART mode. // GPIOPinConfigure(GPIO_PA0_U0RX); GPIOPinConfigure(GPIO_PA1_U0TX); GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); // // Initialize the UART for console I/O. // UARTStdioConfig(0, 115200, g_ui32SysClock); } void InitSys(void) { /* Init stuff for UART.*/ SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); /* Init stuff for timer.*/ SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); /* Turn on interrupts.*/ IntMasterEnable(); } void InitTimer2(void) { GPIOPinTypeTimer(GPIO_PORTD_BASE, GPIO_PIN_0); GPIOPinConfigure(GPIO_PD0_T0CCP0); TimerConfigure(TIMER0_BASE, (TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_CAP_COUNT)); TimerControlEvent(TIMER0_BASE, TIMER_A, TIMER_EVENT_POS_EDGE); TimerLoadSet(TIMER0_BASE, TIMER_A, 9); TimerMatchSet(TIMER0_BASE, TIMER_A, 0); IntEnable(INT_TIMER0A); TimerIntEnable(TIMER0_BASE, TIMER_CAPA_MATCH); TimerEnable(TIMER0_BASE, TIMER_A); } void Timer0IntHandler(void) { TimerIntClear(TIMER0_BASE, TIMER_CAPA_MATCH); count++; TimerEnable(TIMER0_BASE, TIMER_A); } //***************************************************************************** // // Print "Hello World!" to the UART on the Intelligent UART Module. // //***************************************************************************** int main(void) { // // Run from the PLL at 120 MHz. // g_ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); // // Configure the device pins. // PinoutSet(false, false); InitSys(); InitUART(); InitTimer2(); // // Hello! // UARTprintf("Hello, world!\n"); // // We are finished. Hang around flashing D1. // while(1) { count2 = TimerValueGet(TIMER0_BASE, TIMER_A); UARTprintf("%i; %i\n", count, count2); } }