Measure times ON-OFF Bit

Posted by Dandrade on Wed 08 Nov 2006 08:43 PM — 2 posts, 11,269 views.

#0

Make to builder one function for measure times duration, period for each signal identific positive and negative.

Objetive function "create" variables for each signal and return values about times and signal positive/negative.

My function,memory before/after time to read bit, and return the values times.Have error about nil function and the variables, dont know automatic create variables.

Have this moment it function:

t=os.date('*t') --get hardware clock time

function duty_cly(sensor)

local pol="negativo"
local duracao

--input.sinal[sensor]= get_bit(sensor) after is add

if(input.sinal[sensor] == true)then
pol="positivo"
if(input.t2b[sensor] == true) then
input.t2a[sensor]=t
input.t2b[sensor]=t
input.t1b[sensor]=nil

else
input.t2a[sensor]=t
end
duracao=os.difftime (input.t2b[sensor], input.t2a[sensor])
else -- se sinal for negativo
if(input.t1b[sensor] == true) then
input.t1a[sensor]=t
input.t1b[sensor]=t
input.t2b[sensor]=nil

else
input.t1a[sensor]=t
end
duracao=os.difftime (input.t1b[sensor], input.t1a[sensor])
end
contador(sensor) --call counter pulses
if not(input.t1a[sensor] == input.t2a[sensor]) then --processa somente quando existe tempo > 0seg
--Ignore if time equal segund

if(pol == "positivo")then
return pol ,os.difftime (input.t1b[sensor], input.t2a[sensor],duracao)
else
return pol ,os.difftime (input.t2b[sensor], input.t1a[sensor],duracao)
end
end

end


PS: Like to measure milisegund or 0.1 segundes, the instrutions os.date get only secundes.
Australia Forum Administrator #1
I don't see what this has to do with MUSHclient, but I think you will find that the standard Lua functions won't return more resolution than 1 second, because that is all the underlying operating system calls do.

You may need to write your own function in C that returns higher resolution, and call that from Lua.

For things that are merely Lua questions, and not at all related to the other content of this site, I suggest using the Lua mailing list, they are quite helpful.