Forum > General

What happens when the TTimer interval is < than it takes to run its own code?

(1/3) > >>

Alzibiff:
I am returning to visual Pascal some 20 years since I used it last so things are a wee bit rusty...
I am writing a program to control a solenoid - when the solenoid is ON, it allows water to flow. When the solenoid is OFF, the water stops flowing. Why? I want to set up a sort of dripping tap and control the ON and OFF times of the solenoid to vary the size and frequency of the drips.

I have sorted out the code to switch the solenoid on and off from my RPi using one of its GPIO pins so I am making progress but the rest is making my brain hurt. (I have three solenoids to control and make three dripping taps).

I have a button which will toggle the dripping on and off and was thinking that a TTimer object would do the job with the OnTimer code going something like this ...

Switch solenoid ON
delay to generate a drip
turn solenoid OFF
delay to generate an interval between drips (end of OnTimer code, back to the start)

That way I get a drip every time that the timer ticks ... yes?

I want to vary both delay periods by taking values from a couple of edit boxes - that is, the time that it takes the TTimer to tick is going to change. What value do I set for the TTimer.interval?

Can I simply have a value less than the total of the combined delays - say 1ms -  so that I get a basic repeat..until false loop for my ONTimer code? In short, what I want to do is enable a timer so that it tick tick ticks away continuously repeating code till I tell it to stop by clicking a button which will disable it.


All assistance gratefully received,

Alan

derek.john.evans:
TTimer is somewhat inaccurate and the call back uses the main thread. TFPTimer also synchronizes with the main thread.

What about running time critical threads?

derek.john.evans:

--- Quote ---What happens when the TTimer interval is less time than it takes to run its own
--- End quote ---

I just had a look. From what I can tell, a timer with interval 500ms, will still tick away at 500ms even if the timer event takes 400ms.  If the event takes 1000ms, then the timer will slow to 1000ms.
ie: No timer events will "build up", and no-multiple timer calls will happen, since they are sent in the main thread.

So, yes, you can have a short timer, and then check LclIntf.GetTickCount64 to get the actual time. Which is what a lot of games do.

I guess, the issue is, TTimer runs in the main thread, which is effected by all GUI processing. So, how critical are these events?

Alzibiff:
link=topic=29504.msg186515#msg186515 date=1440942709]

--- Quote ---I guess, the issue is, TTimer runs in the main thread, which is effected by all GUI processing. So, how critical are these events?

--- End quote ---

That is good news (for me).
The accuracy of the timer is not so critical in my application but it needs to be as repeatable as possible from one call to the next.

I understand the point which you are making about the rest of the GUI processing affecting timer accuracy and although this seems that it COULD be a problem, my program will be doing the same tasks from call to call. That is, the GUI processing time should be more or less constant throughout the run of my program.

Of course, to confirm the above, I will just have to  suck it and see I guess! I'm grateful for your response though as I can continue to develop my application with a wee bit more confidence before the rest of my electronic components arrive and I get a chance to try things out experimentally.

One last question - what is "LclIntf.GetTickCount64" exactly and how do I check it?

Thank you,

ALan



derek.john.evans:
The function GetTickCount64 is in the unit LclIntf.

Basically it maps to the Win32 GetTickCount function:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms724408%28v=vs.85%29.aspx

It returns milliseconds and is 10-16ms accurate. (according to Microsoft).

It just means, you use a timer to monitor your taps, but you should use GetTickCount to determine if they should switch on/off since it is the real time. TTimer is an event interval which it tries to make good on.

Navigation

[0] Message Index

[#] Next page

Go to full version