- Timer Stop Input (Mode 9) [U3 Datasheet] | LabJack
« Close

Datasheets and User Guides

App Notes

Software & Driver - Timer Stop Input (Mode 9) [U3 Datasheet]

This mode should only be assigned to Timer1.  On every rising edge seen by the external pin, this mode increments a 16-bit register.  When that register matches the specified timer value (stop count value), Timer0 is stopped.  The range for the stop count value is 1-65535.  Generally, the signal applied to Timer1 is from Timer0, which is configured in some output timer mode.  One place where this might be useful is for stepper motors, allowing control over a certain number of steps.

Note that the timer is counting from the external pin like other input timer modes, so you must connect something to the stop timer input pin.  For example, if you are using Timer1 to stop Timer0 which is outputting pulses, you must connect a jumper from Timer0 to Timer1.

Once this timer reaches the specified stop count value, and stops the adjacent timer, the timers must be reconfigured to restart the output.

When Timer0 is stopped, it is still enabled but just not outputting anything.  Thus rather than returning to whatever previous digital I/O state was on that terminal, it goes to the state "digital-input" (which has a 100 kΩ pull-up to 3.3 volts).  That means the best results are generally obtained if the terminal used by Timer0 was initially configured as digital input (factory default), rather than output-high or output-low.  This will result in negative going pulses, so if you need positive going pulses consider using a simple inverter IC such as the CD74ACT540E from TI.

The MSW of the read from this timer mode returns the number of edges counted, but does not increment past the stop count value.  The LSW of the read returns edges waiting for.


Edge Rate Limits

This edge-detecting timer mode requires processing resources as an interrupt is required to handle each edge.  See more about edge rate limits in Section 2.9.2.



This description seems to be conflicted because is says that Timer0 should be configured as output but also says that for "best results" Timer0 should be configured as input.

The terminal that Timer0 appears on should have been configured as a digital input before the timer was put on it.  I added some text above.

Tyfon's picture


Why can't I see the timmer stop alternativ in the U3 test panel -> Configure Timers and Counters?

labjack support's picture

We don't list the Timer Stop mode in the LJTCP Test panel because the way it operates just does not fit with a simple polled program like the Test panel.  You really need to experiment with this mode in some sort of programming language where you can reconfigure it automatically as needed.

Tyfon's picture

Thank you for your answer. My purpose is to use the U3 for controlling a stepper. I’ve managed to control the stepper by updating the code “ljud_ePut(ljHandle,LJ_ioPUT_DIGITAL_BIT…” in Matlab. But us you understand this method is very slow. As I understand from the datasheet the timer stop function might be useful here. Unfortunately I haven’t been able to see any example code or pseudo code concerning the “timer stop” in this site, or have I missed it?

The notion of being able to specify a specific number of fast pulses would be of great importance to my project.

labjack support's picture

There isn't a specific timer stop example for MATLAB. You'll want to start with the timer and counter example as these show what calls are needed to enable and configure timers in general. You can base your code off this example and modify it for 2 timers and for your timer modes and values. These pages document the timer modes you can configure.

As for configuration, enable 2 timers and configure the timer clock. Timer 0 will be your pulses. A PWM or frequency out mode will do. Timer 1 will be the timer stop mode which controls when timer 0 stops (the pulsing). Here's an old forum topic with some MATLAB code (it needs a GoOne call) configuring the timer stop mode and a PWM8 for the pulse:


Tyfon's picture

Thank you! I'll do some experimenting with the code and will hopefully share some working example here. I guess there's more people out there wanting to control steppers with U3 and Matlab.