Difference between revisions of "Category:Timer"

From DSignT Support Database
Jump to: navigation, search
(Created page with "== trigger external events and generate interrupts == {{table |reporter=John Madsen, Utiliscope |hardware=D.Module2.TS203 |software= |description=how to use one of the TS203's t...")
 
(Replaced content with "Category:D.Module")
 
Line 1: Line 1:
== trigger external events and generate interrupts ==
+
[[Category:D.Module]]
 
 
{{table
 
|reporter=John Madsen, Utiliscope
 
|hardware=D.Module2.TS203
 
|software=
 
|description=how to use one of the TS203's timers to trigger an external event
 
|status={{yes|closed}}
 
|solution=see below
 
}}
 
 
 
[[Category:D.Module2.TS203]]
 
[[Category:Timer]]
 
 
 
 
 
'''Q:'''
 
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
 
 
 
 
 
'''A:'''
 
you can use the TS203 timer TMR0 to generate pulses every 100ns or 1ms. 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.
 
This configuration is deterministic: the DSP timer output is independent of any other processes running on the DSP.
 
 
 
<syntaxhighlight lang="c">
 
DM2_gpioMap (DM2_GPIO_TIMERPULSE, 3);  // TMR0E -> GPIO3
 
DM2_gpioMap (DM2_GPIO_TIMERCLK, 3);    // TMR0E -> toggle-ff -> GPIO3
 
</syntaxhighlight>
 
 
 
 
 
The timer input clock is SYSCLK. To initialize and start the timer use:
 
<syntaxhighlight lang="c">
 
  DM2_timerStart (0, DM2_dspGetClock()/output_frequency_in_hz);
 
</syntaxhighlight>
 
 
 
 
 
If the toggle-flipflop output is used:
 
<syntaxhighlight lang="c">
 
  DM2_timerStart (0, DM2_dspGetClock()/(2*output_frequency_in_hz));
 
</syntaxhighlight>
 
 
 
 
 
A timer interrupt is installed with
 
<syntaxhighlight lang="c">
 
  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);
 
</syntaxhighlight>
 
 
 
 
 
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.
 

Latest revision as of 12:13, 10 February 2011

Pages in category "Timer"

This category contains only the following page.



Contact Post.png Support Tool.png