Hi,
I am programming a U6 using python and I need to generate two sqaure waves that are 90 degrees out of phase from each other. From my research it seems the U6 timers are unable to perform this task due to them all being tied to the same master clock internally. Other then bit-banging very manually, is there a more eloquent way to do this? Can I somehow add a delay to one of the waves in order to offset it? Can I start the second PWM after a certain amount of high ticks the first timer reads? It seems perhaps the PWM may be too restrictive for this task. Any ideas?
The U6 hardware does not have the ability to generate waveforms which are out of phase. The best things we can do is bit-bang as you suggested. T-Series devices use different hardware which can control the phase between PWM outputs: https://labjack.com/support/datasheets/t-series/digital-io/extended-feat...
Ok that is what I thought. So my thoughts now are to create one square wave, read in its high value, and turn on/off another GPIO accordingly. I am able to read in the high and low bits during duty cycle input mode (mode=4), however this same code is not working in PWM output mode (mode = 1). Any ideas as to why it doesn't this in mode 1? Below is my code.
# Outputs pwm signal on Timer 0, value is amount of low bits, TimerMode 1 = 8 bit, 0 is 16 bit
lb.getFeedback(u6.Timer0Config(TimerMode=1, Value=30000))
# Read the current count
val = lb.getFeedback(u6.Timer0())
valInt = int("".join(map(str, val)))
lsBits = valInt % (256)
msBits = valInt / (256)
Timers set to PWM outputs read the timer_clock count, not the duty cycle setting. It sounds like you just need to read an IO (not a timer) and set another IO based on the state of the first.
I have tried to implement the method of toggling two GPIOs basically using a while loop and if statements. This approach does not appear to be reliable as the labjack is not outputting a consistent square wave. The period of my signal is not consistent and there is enough random jitter even running at only 15Hz. I feel that the best approach would be to output one pwm wave using a timer, then toggle a GPIO accordingly to that. However I would need to have visiblity into the bits each time the clock pulse is high and low (I did this with lb.getFeedback(u6.Timer0()) in duty cycle read mode to read the high and low bits) however it does not work in PWM output mode. Any advice or can you direct me to the functions I would need to do this?
While performing C-R (command-response) operations the communication time of about 1 ms and the inconsistent timing of operating systems will cause some error. So at 15 Hz we need to expect ~1.5% error form the communication and some from the OS. Normally I see ~ 1ms of error from the OS, but that can change with system loading.
The plan to change an output when the PWM is at a certain point is prone to the same errors. This can be done by reading the clockBase count (PWM state will change when the count rolls from max to zero and when the count reaches the value set to control the duty cycle.) The other option is to connect the PWM signal to another digital IO to read the state.
Getting your desired phase relationship without the errors inherent to the C-R system will require a T-Series LabJack device or some hardware to create a delay. Both the T7 and the T4 can output PWM while controlling the relative phase. T-Series devices can also implement more complex control systems via the onboard Lua scripting. The hardware delay will take a little design. Something like an R-C filter and a comparator op-amp circuit could be used to output a square wave who's edges are delayed from the input signal.