Other Parts Discussed in Thread: TM4C1294NCPDT, ENERGIA
Hello,
I'm trying to use a TM4C1294NCPDT to generate very precise interrupt-driven pulses using the hardware timers, and I'm not having much luck. I have the following code in an Energia sketch to (I hope) set up Timer 0A in 16-bit mode driven by the PIOSC clock at 16 MHz (?) with a prescale to get 1 microsecond ticks, and the timer configured for one-shot operation with a load of 10000 to get a 10 ms pulse. One external interrupt turns output on starts the timer and the timer's interrupt stops the timer and turns the output off.
The code I have is not working as I intended, and I'm not smart enough to understand the TM4C1294NCPDT's datasheet for the timers. A few pointers on what I'm doing wrong would be greatly appreciated.
#include "Energia.h"
#include <driverlib/timer.h>
#include <driverlib/sysctl.h>
void setup()
{
Serial.begin(19200);
pinMode(PB_3, INPUT_PULLDOWN);
pinMode(PD_3, OUTPUT);
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
while (!SysCtlPeripheralReady(SYSCTL_PERIPH_TIMER0));
TimerConfigure(TIMER0_BASE, TIMER_CFG_A_ONE_SHOT);
TimerClockSourceSet(TIMER0_BASE, TIMER_CLOCK_PIOSC);
TimerPrescaleSet(TIMER0_BASE, TIMER_A, 16);
TimerIntRegister(TIMER0_BASE, TIMER_A, lightOff);
//TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
TimerLoadSet(TIMER0_BASE, TIMER_A, 10000);
attachInterrupt(PB_3, lightOn, RISING);
}
void loop()
{
}
void lightOff()
{
digitalWrite(PD_3, LOW);
TimerDisable(TIMER0_BASE, TIMER_A);
TimerIntDisable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
}
void lightOn()
{
digitalWrite(PD_3, HIGH);
TimerEnable(TIMER0_BASE, TIMER_A);
TimerIntEnable(TIMER0_BASE, TIMER_A);
}