T7/LUA PWM Library Example Problems | LabJack
 

T7/LUA PWM Library Example Problems

4 posts / 0 new
Last post
hackish
hackish's picture
T7/LUA PWM Library Example Problems

I've been trying to get the PWM thing to work. The shipped PWM LUA code is pretty buggy, so I thought I'd point out some of the challenges. Maybe the example needs to be updated?

First, it took quite a while to discover that the example doesn't work properly unless you manually edit some user defined variables. It would be really nice if the documentation said how to set the duty cycle and frequency.

function PWM.init (self, ichan, ifreq, iduty, iclk, idivisor)--duty should be in %, not decimal

Does not work unless you specify counter 0. Any other counters give back     Modbus Error: 2555

The example itself shows the initialization:
myPWM.init(myPWM, 0, 50, 5, 0, 1)--init on outPin with 50Hz (20ms) and 50% duty cycle

I think this is actually a 5% duty cycle, not 50% as the comment says.
 

LabJack Support
labjack support's picture
Hello, I'm not sure what

Hello, I'm not sure what example you are specifically referring to but I made the changes you suggested to the Digital IO EF, PWM Library & Example.  The example does indeed configure FIO0 to output a 5% duty cycle signal and not 50%.  It also immediately sets the duty cycle back to 0% after initializing.  I also added more comments about where to find more information about the T-Series PWM feature to hopefully assist you and other customers with using DIO channels other than FIO0 and enabling PWM Output using clock sources using clock sources 1 and 2.

The new example code is available on our website and will be made available to everyone after the next release of Kipling:
LabJack website: https://labjack.com/support/software/examples/lua-scripting/digital-io-ef/pwm-library-and-example

vijay
vijay's picture
I need help on 4ch pwm with

I need help on 4ch pwm with phase delay using lua code. kindly help me if you have sample code.

LabJack Support
labjack support's picture
We always suggest that you

We always suggest that you first try it using the Register Matrix in Kipling.  Once you get it working there, you can then modify one of our Lua examples to do the same register writes.

https://labjack.com/support/datasheets/t-series/digital-io/extended-feat...