Hi all,
Below is the snippet of code causing me grief:
void Timer3IntHandler(void)
{
// If timer rollover occurs when sampling is true, increment rollover counter.
if (MAP_TimerIntStatus(TIMER3_BASE, TIMER_TIMA_TIMEOUT) == TIMER_TIMA_TIMEOUT)
{
// Ensures that the program is currently sampling before counting rollovers.
if (captureFlag == 1)
{
rollOverCount ++;
}
}
if (MAP_TimerIntStatus(TIMER3_BASE, TIMER_CAPA_EVENT) == TIMER_CAPA_EVENT)
{
currentSampleCount = MAP_TimerValueGet(TIMER3_BASE, TIMER_A);
samplePeriod = (currentSampleCount + (65535 * rollOverCount)) - lastSampleCount;
lastSampleCount = currentSampleCount;
captureFlag ^= 1;
rollOverCount = 0;
}
MAP_TimerIntClear(TIMER3_BASE, (TIMER_CAPA_EVENT | TIMER_TIMA_TIMEOUT));
}
What I believe the ISR I have written does is take the period of every other square wave signal period. What I mean is, it counts the time from one rising edge to another, then ignores a full wave, then proceeds with the cycle of sampling one period, ignoring one and so on. However, the program is doing something completely different which I just can't figure out.
My test is a 100 Hz square with a duty cycle of 50% into PM4. I can't say for sure what period the program is calculating due to the fact that the values vary greatly from one another. I was curious to know if anyone here could lend me a hand with my
Below is the configuration code:
void edge_timer_init(void)
{
// Enable port peripherals (pins used for timer for my purpose)
MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOM);
// Assign Port M Pin 2 as timer pin for Timer 3.
MAP_GPIOPinTypeTimer(GPIO_PORTM_BASE, GPIO_PIN_2);
MAP_GPIOPinConfigure(GPIO_PM2_T3CCP0);
// Enable pullup on port pins for additional proteciton and accuracy in input.
MAP_GPIOPadConfigSet(GPIO_PORTM_BASE, GPIO_PIN_2, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
// Enable Timer 3 peripheral - used for the edge timer mode.
MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER3);
// Enable processor to call interrupts when interrupts specified in vector file are called.
MAP_IntMasterEnable();
// Configure timer 3 for edge-time capture on rising edges
MAP_TimerConfigure(TIMER3_BASE, (TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_CAP_TIME_UP));
MAP_TimerControlEvent(TIMER3_BASE, TIMER_A, TIMER_EVENT_POS_EDGE);
MAP_IntEnable(INT_TIMER3A);
MAP_TimerIntEnable(TIMER3_BASE, (TIMER_CAPA_EVENT | TIMER_TIMA_TIMEOUT));
MAP_TimerEnable(TIMER3_BASE, TIMER_A);
}
I believe my problem lies in the logic I'm using. Is there a better way of going about this problem?
I have considered using two timers - one for the edge-time mode and one for counting roll overs, but isn't this possible with two half-width timers?
I am trying to achieve this all on an EK-TM4C1294XL development board if that helps.