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

Gammon Software Solutions forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

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

Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Measure times ON-OFF Bit

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page


Posted by Dandrade   (5 posts)  [Biography] bio
Date Wed 08 Nov 2006 08:43 PM (UTC)  quote  ]
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  (18,769 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Wed 08 Nov 2006 10:13 PM (UTC)  quote  ]
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.


1,054 views.

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

[Home]

Written by Nick Gammon - 5K

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

[Best viewed with any browser - 2K]    [Internet Contents Rating Association (ICRA) - 2K]    [Web site powered by FutureQuest.Net]