LUA / counters to form a custom digital waveform? | LabJack
 

LUA / counters to form a custom digital waveform?

8 posts / 0 new
Last post
hackish
hackish's picture
LUA / counters to form a custom digital waveform?

I am trying to generate a time-sensitive custom waveform - cam/crank signal simulating the rpm of an engine.

Is there any facility to have a LUA function called once a timer reached a certain count?

My thought for implementing a feature was to calculate the next transition time based on the 32 bit timer and have an interrupt allow a routine to make the output change, then calculate the counter value for the next transition.

 

Is this sort of thing possible on the T7?

LabJack Support
labjack support's picture
Lua does have timing

Lua does have timing functions. The jitter or which tends to be ±10 us, depending on the tasks the T7 is performing. It sounds like the PWM with phase control feature may be a good option for you: https://labjack.com/support/datasheets/t-series/digital-io/extended-feat...

hackish
hackish's picture
The PWM feature could work,

The PWM feature could work, but I could not find a way to trigger some LUA code to run based on the counter. This would be necessary to update the PWM settings for the next change in the signal. In other words, call my update code when DIO#_EF_CONFIG_A is reached so I can update the next DIO#_EF_CONFIG_A value and perhaps the roll as well.

LabJack Support
labjack support's picture
Does that mean that you need

Does that mean that you need a specific number of pulses?

The pulse out feature also has phase support: https://labjack.com/support/datasheets/t-series/digital-io/extended-feat...

hackish
hackish's picture
These are all pieces of the

These are all pieces of the puzzle, but to give an example, high for 15ms, low for 5ms, high for 30ms, low for 5 ms, high for 5ms, low for 5ms, high for 5ms, low for 15ms. 

Ultimately, what is needed is the ability to run a LUA routine based on a timer being equal to some number. This way, you could update any number of these settings reliably to form the pattern you want - as long as your routine can update the next transition count before it occurs.

Another way this could be implemented is to simply provide a list of transition counts for the timer and have the firmware iterate through them as needed. In my case, I really need to run 2 signals with the 720 degree phase of the engine. Suppose my period was 7200 counts, I could give a list of 30,40,100,110,120,130 etc with a rollover of 7200. If the fake motor needs to go 2x as fast, i'd hand it 15,20,50,55,60,65... and a rollover of 3600.

LabJack Support
labjack support's picture
I see. A lua script can run

I see. A lua script can run at 10 kHz. That would give you an update rate of 100 us, meaning that the smallest change in high or low time would be 100 us.

A second option is Stream-Out. Stream out can run up to 100 kHz and can output a sequence of values: https://labjack.com/support/datasheets/t-series/communication/stream-mod...

hackish
hackish's picture
I think I may have mis

I think I may have mis-understood what stream out was. My experience has been that the hardware was limited when it came to changing multiple items at once, so I thought that stream out was streaming data from the PC to the labjack. Are there any LUA examples available for streaming output?

LabJack Support
labjack support's picture
You're right. Running stream

You're right. Running stream and Lua will push the T7's processor. Using stream-out may work well if you care more about one level of the pulse than the other. For example we could generate a high pulse for a specified period of time then have some extra error in the low time while we load new data into stream-out.

 

Is the 100 us resolution of the discrete bit operation method insufficient?