Output Square Wave at arbitrary frequency and duty cycle | LabJack
 

Output Square Wave at arbitrary frequency and duty cycle

4 posts / 0 new
Last post
Yannick
yannokolo's picture
Output Square Wave at arbitrary frequency and duty cycle

Hey, I want my LabJack U3 to output a square wave at relatively low frequency (~1Hz) and a low duty cycle such that the pulse is only a couple milliseconds long. I have been doing that programatically ia python: Turn on, wait until the millisecond has passed, turn off. However this gives quite a substantial jitter in pulse length, so this is not the true solution. How can I do this with my U3? Timers do not seem to have a mode that fits my needs, I think.

Thanks for your help!
-Yannokolo

LabJack Support
LabJack Support's picture
Our 16-bit PWM output feature

Our 16-bit PWM output feature is one potential solution:

https://labjack.com/support/datasheets/u3/hardware-description/timers-co...

You could also get better pulse duration when doing command-response communications by using the wait technique described on the following page:

https://labjack.com/support/app-notes/waveform-generation

gl
gl's picture
I have similar problem, Based

I have similar problem, Based on the value of a specific AIN (capture using the stream mode) I want to send HIGH (5V) and LOW (0V) values to DAC0 in a very time-controlled way. Ideally I would like to have microsecond resolution

So far, (using the Python library on my U3-HW), every time the AIN has the desired value, I call the callback function which does something like:

def fnc_callback(ain_zero_value):
    # turn on
    voltage_to_write = 5
    dac0_bits = d.voltageToDACBits(voltage_to_write, dacNumber = 0, is16Bits = False)
    d.getFeedback(u3.DAC0_8(dac0_bits))
    # wait
    time.sleep(0.01)
    # turn off
    voltage_to_write = 0
    dac0_bits = d.voltageToDACBits(voltage_to_write, dacNumber = 0, is16Bits = False)
    d.getFeedback(u3.DAC0_8(dac0_bits))

 

it works but unfortunately I see a lot of jitter. Can someone help is getting it better

Thanks a lot

LabJack Support
LabJack Support's picture
Since you are using stream

Since you are using stream mode, I do not think there is any way to get higher resolution delay functionality than the system time functions. If you did not use stream mode, the waitshort command between DAC updates could give you better resolution: https://github.com/labjack/LabJackPython/blob/master/src/u3.py#L2063

For higher resolution while streaming I would recommend switching to a T-series device like the T4. It has a wait function with 1 microsecond resolution. The T4 also supports stream out mode, which could likely be set up to control the DAC outputs how you want instead of using a callback:

https://labjack.com/products/t4