Updating PWM duty cycle while using Streaming mode | LabJack
 

Updating PWM duty cycle while using Streaming mode

4 posts / 0 new
Last post
Josef Biberstein
iamxanadu's picture
Updating PWM duty cycle while using Streaming mode

I'm have an application where I need to log readings from several load cells at about 100 scans/sec and then trigger a set of four servo motors to follow a predetermined schedule with duty cycle updates every 10ms or so when a given reading from one of the load cells exceeds a threshold. I have a T7 and have managed to get streaming mode and the PWM DIO_EF to work seperately pretty easily using Python. However, just naively trying to update the servos' duty cycles using        

ljm.eWriteName(handle, f"DIO{pwmNum}_EF_CONFIG_A", command*pwmClockRoll)

while the stream is running causes huge delays which overflow the stream buffer. Upon further reading of the DIO EF page, it does say that there can be complications when streaming and using EF that require a system timer, and to contact support if you need to do both. Is it possible to update PWM duty cycles while streaming is running without causing large delays? I have other options I can pursue for running the servos on a different microcontroller, but it would be cleaner to do everything on the T7 if possible.

LabJack Support
labjack support's picture
One potential way to reduce

One potential way to reduce the PWM update time is to update all of your PWM duty cycles in one command using eWriteNames or eNames. If you only have an issue with the buffer overflow, one potential solution is to run the DIO_EF updates in a separate thread from the stream acquisition:

https://labjack.com/support/software/api/ljm/streaming-lots-of-9999-values

Depending on all of your requirements, running the control in an embedded lua script may be a suitable alternative to streaming. The major limitations to that are command response AIN sample rates, and logging data to a computer is more difficult since you would need to transfer data out of Lua using USER_RAM registers. Please see Table A.1.4 in our data rates page and our USER_RAM documentation:

https://labjack.com/support/datasheets/t-series/appendix-a-1#adc-convers...

https://labjack.com/support/datasheets/t-series/lua-scripting#user-ram

Josef Biberstein
iamxanadu's picture
Thanks for your answer. In

Thanks for your answer. In lieu of jumping straight to a Lua implementation, I've tried to take your advice on both using eWriteNames and on running the DIO_EF updates in another thread. This does seem to fix the stream overflowing, but I'm now getting the following error

Address 44304, LJM library error code 2565 EF_VALUE_GREATER_THAN_PERIOD

when I try to set the duty cycle to follow my predetermined schedule. This seems strange since I am able to set the duty cycle to, for instance, 50% for all four PWMs before I start the stream with no issue. However, even if I hard code the worker thread to always set a 50% duty cycle (same number as before) once the stream is running, I get the above error. Any insight you could offer here would be much appreciated. I'm attaching my code and the servo schedule file in case that helps.

File Attachment: 
LabJack Support
labjack support's picture
That error indicates DIO#_EF

That error indicates DIO#_EF_CONFIG_A is higher than DIO_EF_CLOCK0_ROLL_VALUE for one or more of your PWM. Please note that the clock roll value is an integer and should be rounded as such. The same goes for the DIO#_EF_CONFIG_A registers.