Please enable JavaScript to view this site.

DAQFactory User's Guide

Navigation: 17 Devices > 17.7 LabJack UE9 / U6 / U3 > 17.7.6 Counters and Timers > 17.7.6.5 Setting up Specific Timer Modes

17.7.6.5.8 Timer Stop

Scroll Prev Top Next More

Timer stop allows you to stop a particular (even numbered) timer after a certain number of pulses is received on the odd numbered timer stop timer pin.  This is especially useful when used with frequency or PWM out to drive a stepper motor a certain number of pulses.  For example, to generate exactly 1000 pulses on Timer 0, we'd setup timer 0 as frequency out, and timer 1 in timer stop mode and tie the two output pins together.  You'll recognize the first part from the frequency out section:

 

//Set the timer/counter pin offset to 4, which will put the first timer/counter on FIO4.
AddRequest (ID,  LJ_ioPUT_CONFIG, LJ_chTIMER_COUNTER_PIN_OFFSET, 4, 0, 0)
 
// use system clock so works on U3 and UE9:

AddRequest(ID, LJ_ioPUT_CONFIG, LJ_chTIMER_CLOCK_BASE, LJ_tcSYS, 0, 0)
 
//Set the divisor to 48.
AddRequest(ID, LJ_ioPUT_CONFIG, LJ_chTIMER_CLOCK_DIVISOR, 48, 0, 0)
 
//Enable 1 timer.  It will use FIO4.
AddRequest(ID, LJ_ioPUT_CONFIG, LJ_chNUMBER_TIMERS_ENABLED, 2, 0, 0)
 
//Configure Timer0 as Frequency out.  
AddRequest(ID, LJ_ioPUT_TIMER_MODE, 0, LJ_tmFREQOUT, 0, 0)
 
//Set the second divisor to 10
AddRequest(ID, LJ_ioPUT_TIMER_VALUE, 0, 10, 0, 0)
 
// now timer stop:
AddRequest(ID, LJ_ioPUT_TIMER_MODE, 1, LJ_tmTIMERSTOP, 0, 0)
 
// set number of pulses:
AddRequest(ID, LJ_ioPUT_TIMER_VALUE, 1, 1000, 0, 0)
 
//Execute the requests.
GoOne(0)

Once the 1000 pulse are complete, Timer 0 will stop.  To restart it, you'll need to reconfigure the timers by simply rerunning the above script.

Add a digital line to control the direction and you have a very easy stepper controller.  But if you want it even easier, you can use a Channel event to allow a channel to trigger the pulses.  To do this:

1) Create a sequence called PulseOut with the above script, replacing the 1000 in the last AddRequest with NumPulses[0]:

 

....

AddRequest(ID, LJ_ioPUT_TIMER_MODE, 1, LJ_tmTIMERSTOP, 0, 0)
 
// set number of pulses:
AddRequest(ID, LJ_ioPUT_TIMER_VALUE, 1, NumPulses[0], 0, 0)

....

2) Create a new channel, call it NumPulses. Device Type = Test, D# = 0, I/O Type = D to A, Chan # = a unique number (if you are using more than 1 Test D/A channel).  Click Apply.

3) Click on the + next to CHANNELS: in the Workspace if not already expanded and click on the NumPulses channel.

4) Click on the Event tab, and put this script in:

 

Sequence.PulseOut.begin()

Now, you can use the various DAQFactory components to simply set the NumPulses channel and the desired length pulse train will be outputted.   Just remember that sliders and knobs will continuously update this channel and so are not good for changing NumPulses since the pulse train will likely take longer than the update speed.  You can also change NumPulses in script:

 

NumPulses = 500

Just remember that as soon as NumPulses is set, the pulse train will start.