Hi everybody,
I'm trying to port an LM3S9B96 application to a TM4C1294KCPD and I have some issues with the timers. I'm working with Timer 0 split into two 16 bit timers this way:
- System clock i 120MHz with oscillator
- A is configured to timeout each 20ms with interrupt enabled, using a prescaler of 240
- B is configured to detect input line changes on both edges with a prescaler of 120. I would like to measure pulse width of 256 and 512 µs with a 96µs tolerance
My setup is as follow:
// // Enable peripherals // SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0); static const uint32_t RFID_TIMER_PRESCALER = 240; // // Calculate switch time each 20ms // uint16_t SwitchDelayTicks = (g_ui32SysClock / (50 * RFID_TIMER_PRESCALER)) - 1; // // TIMER0 configured to handle input capture and free running 16 bit counter // TimerConfigure(TIMER0_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PERIODIC | TIMER_CFG_B_CAP_TIME); TimerPrescaleSet(TIMER0_BASE, TIMER_A, RFID_TIMER_PRESCALER - 1); TimerLoadSet(TIMER0_BASE, TIMER_A, SwitchDelayTicks); TimerPrescaleSet(TIMER0_BASE, TIMER_B, 120 - 1); TimerLoadSet(TIMER0_BASE, TIMER_B, 0xFFFF); TimerControlEvent(TIMER0_BASE, TIMER_B, TIMER_EVENT_BOTH_EDGES); GPIOPinConfigure(GPIO_PL5_T0CCP1); GPIOPinTypeTimer(GPIO_PORTL_BASE, GPIO_PIN_5);
While A timer is correctly working (I had to make it count down instead of up to use prescaler as I was really supposing to use it...), I have strange issues with timer B. My interrupt routine is like this:
static uint16_t CaptureData[512]; static uint16_t CaptureCount = 0; static uint16_t LastReceivedBitTicks = 0; void Timer0B_IntHandler() { uint32_t ulStatus = TimerIntStatus(TIMER0_BASE, true); if (ulStatus & TIMER_CAPB_EVENT) { uint16_t Delta, CurrentBitTicks; TimerIntClear(TIMER0_BASE, TIMER_CAPB_EVENT); CurrentBitTicks = HWREG(TIMER0_BASE + TIMER_O_TBR); Delta = LastReceivedBitTicks - CurrentBitTicks; CaptureData[CaptureCount] = Delta; CaptureCount = (CaptureCount + 1) & 511; .... } }
I'm supposing to find in CaptureCount vector the time difference between two captures, so numbers like 512 and 256, but I only found numbers around 29500-31200. What am I missing?
Another consideration on TIVA manual. On page 959 there are count ranges when using prescaler. For LM3S9B96 data is correct: when running at X [Hz] core clock, a 16 bit timer would count till (65536 * 1000) / X [ms]. At each prescaler value, this is multiplied by the prescaler factor. This is not valid for TIVA. Is this a manual issue or there is something different to consider?
Thanks in advance and regards,
Stefano