W przykładzie zastosowałem dodatkowe ustawienie Wait-for-Trigger mode Timera0_B.
Jest to opcja polegająca na starcie n+1 Timera po zakończeniu zliczania Timera n, czyli Timera wcześniejszego w procesorze. Funkcja Wait-for-Trigger w daisy chaining nie działa dla Timera 0-A lub timera0-A 32bit gdyż nie ma przed nimi wcześniejszego timera wyzwalającego.
Dodatkowo w przykładzie został ustawiony preskaler dla Timera0-A aby przy częstotliwości CPU 3,125Mhz uzyskać wywoływanie one szhot Timera0-B co 1s. W przeciwieństwie do preskalera przy PWM mode, preskaler Timera działającego w periodic mode lub one-shot mode z liczeniem w dół jest uruchomiany inaczej. Jest on mnożnikiem liczby przekazanej w TimerLoadSet().
#include "inc/hw_ints.h" #include "inc/hw_types.h" #include "inc/hw_memmap.h" #include "driverlib/sysctl.h" #include "driverlib/gpio.h" #include "driverlib/timer.h" #include "driverlib/pin_map.h" #include "driverlib/interrupt.h" int main(void) { //clock: SysCtlClockSet(SYSCTL_USE_PLL|SYSCTL_SYSDIV_64|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN); // OSC MAIN and PLL DIV 64 = 3,125-MHz frequency SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_3); // Enable Peripheral Timer0 SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); TimerConfigure(TIMER0_BASE, TIMER_CFG_SPLIT_PAIR|TIMER_CFG_A_PERIODIC|TIMER_CFG_B_ONE_SHOT); TimerControlWaitOnTrigger(TIMER0_BASE, TIMER_B,1); // after the Timer0 A is 0 Timer0 B is start TimerLoadSet(TIMER0_BASE, TIMER_B, 65535); // 6536 Tc = 0,0209s and one shot -> go to Timer0IntHandlerB TimerLoadSet(TIMER0_BASE, TIMER_A,31250); TimerPrescaleSet(TIMER0_BASE, TIMER_A, 100); // one second period 100*31250Tc IntEnable(INT_TIMER0B); // enable interrupt Timer0 B TimerIntEnable(TIMER0_BASE, TIMER_TIMB_TIMEOUT); // interrupt on TIMEOUT IntMasterEnable(); TimerEnable(TIMER0_BASE, TIMER_BOTH); // enable Timer0 A and B while(1) { } } void Timer0IntHandlerB(void){ TimerIntClear(TIMER0_BASE, TIMER_TIMB_TIMEOUT); // clear interrupt register TimerEnable(TIMER0_BASE, TIMER_B); // one shot mode must be enabled after every use GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3, 8); // blink green led SysCtlDelay(50000); // in real project never use SysCtlDelay in interrupt GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3, 0); }