Hello!
I'm working on a T-7 PRO and i want to have a sinwave output at a DAC by using lua. For that i'm using the tutorial in the kipling named "output sin wave" wich looks like the script in this website: https://labjack.com/support/software/examples/lua-scripting/analog-outpu...
But the problem is the frequency when i use an oscilloscope to visualise the signal i have a signal with a frequency which is not the same that the one used in the lua script.
Can i have any explication about that point please?
Thank you
The timer period calculation is incorrect, it is missing pi in the denominator. I updated the script to fix the bug:
https://labjack.com/support/software/examples/lua-scripting/analog-outpu...
Thank you for bringing this to our attention.
Thank you,
I'm trying with this script to use in the same time FIO3 by toggling it from high to low and vis versa exactly in the peaks of the sine wave. Here is a script that i did but the moment when the FIO3 is toggled is not very accurate. There is a way more precise to do that?
Thank's a lot
print("Output sine wave. Analog output is DAC0.")
local vout = 0
local amplitude = 2
local offset = 2.5
local frequency = 1
local radstep = .1
local interval = 1000 / (2 * math.pi * (frequency / radstep))
local rads = 0
LJ.IntervalConfig(0, interval)
while true do
if LJ.CheckInterval(0) then
if rads >= 2 then
radstep = radstep * -1
end
vout = ( (math.sin(rads) ) * amplitude) + offset
rads = rads + radstep
if vout>= 4.2 then
MB.writeName("FIO3",1)
print("High")
elseif vout <=0.50 then
MB.writeName("FIO3",0)
print("Low")
end
MB.writeName("DAC0", vout)
MB.writeName("USER_RAM0_F32", vout)
print(vout)
end
end
Rather than set the FIO based on the current voltage you could add in another timer. We know that you should hit the maximum/minimum at period/4 and (3/4)*period. You could do something like:
LJ.IntervalConfig(1,1000/(frequency*4))
local counter = 0
while true do
if LJ.CheckInterval(1) then
counter = counter + 1
if counter==1 then
MB.writeName("FIO3",1)
print("High")
elseif counter==3 then
MB.writeName("FIO3",0)
print("Low")
counter = -1
end
end
if LJ.CheckInterval(0) then
if rads >= 2 then
radstep = radstep * -1
end
MB.writeName("DAC0", vout)
MB.writeName("USER_RAM0_F32", vout)
print(vout)
end
end
I tried to use the example " Output sine wave " but it can't provide a sine wave with high frequency 100 Hz. It seems that the frequency is limited to 60Hz. Is that normal, and their is any solution to that?
Thank you!