[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  Measure times ON-OFF Bit

Measure times ON-OFF Bit

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Dandrade   (5 posts)  [Biography] bio
Date Wed 08 Nov 2006 08:43 PM (UTC)
Message

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.
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Wed 08 Nov 2006 10:13 PM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


7,973 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]