Category:Timer

From DSignT Support Database
Revision as of 12:12, 10 February 2011 by Adolf (talk | contribs) (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...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

trigger external events and generate interrupts

reported by John Madsen, Utiliscope
hardware D.Module2.TS203
software
problem how to use one of the TS203's timers to trigger an external event
status closed
solution see below


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.

 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.

Pages in category "Timer"

This category contains only the following page.



Contact Post.png Support Tool.png