I want to trigger an event (data acquisition), using one of the I/O coming from the TS203, at as precise a time interval (maybe 100nS or 1mS) as possible
Use the TS203 timer TMR0 to generate periodic pulses or clocks. The timer.c program from the support software can be used as a basis.
The DSP timer output can be routed to one of the GPIO[3:0] pins on the BUS-1 and BUS-2 connectors. The DSP generates only a narrow pulse each time the timer expires. You can select either the direct TMR0E output (pulse), or the output of a toggle-flipflop driven by TMR0E (clock). The toggle-flipflop will divide the timer output by 2 and provide 50% duty cycle.
DM2_gpioMap (DM2_GPIO_TIMERPULSE, 3); // TMR0E -> GPIO3 DM2_gpioMap (DM2_GPIO_TIMERCLK, 3); // TMR0E -> toggle-ff -> GPIO3
The timer input clock is SYSCLK. To initialize and start the timer use:
DM2_timerStart (0, DM2_dspGetClock()/output_frequency_in_hz);
If the toggle-flipflop output is used:
DM2_timerStart (0, DM2_dspGetClock()/(2*output_frequency_in_hz));
A timer interrupt is installed with
int temp; interruptf(SIGTIMER0LP, timer_int); temp = __builtin_sysreg_read(__IMASKL); temp = temp | INT_TIMER0L; __builtin_sysreg_write(__IMASKL, temp); temp = __builtin_sysreg_read(__SQCTL); temp = temp | SQCTL_GIE; __builtin_sysreg_write(__SQCTL, temp);
The interrupt function will be called periodically, but with some jitter: the interrupt code execution is delayed until the current instruction has completed. If this instruction accesses external memory, or if a DRAM refresh cycle is in progress, the interrupt will be delayed. Therefore we do not recommend to toggle an output "manually" in the interrupt service function. For lowest jitter always use the timer output directly.