Timer Questions

ravoll

Well-known member
Joined
Aug 26, 2010
Messages
50
Programming Experience
Beginner
Hi all,
How can I get a timer to run one interval,one interval only, and stop? Until now I have only used timers to keep running until I say to stop.

Also I need a timerthat will start at the beginning of, and run until any given process is completed.Upon completion it should shut off and tell me how long the process took.
Kinda like a stop watch with a Stop / Start "Trigger".
 
Seriously, what you're saying doesn't make sense. You may think it does, but it doesn't. You seem to be missing something fundamental about how a Timer works.

Forget about code for the moment. Explain precisely how you want your app to behave, step by step, and then we can look at writing code to implement that behaviour because the code you have at the moment is just wrong. We're going round in circles because you're trying top explain what you need in terms of code, but code is the implementation of the solution, not the solution itself.
 
Seriously, what you're saying doesn't make sense. You may think it does, but it doesn't. You seem to be missing something fundamental about how a Timer works.

Forget about code for the moment. Explain precisely how you want your app to behave, step by step, and then we can look at writing code to implement that behaviour because the code you have at the moment is just wrong. We're going round in circles because you're trying top explain what you need in terms of code, but code is the implementation of the solution, not the solution itself.

What's not to understand about a Timer? For my app I set it for 1 second:=1sec on 1sec off,1sec on,1sec off and so on.Or not? Tired of arguing with you about it myself.

So,I'll try to explain as best I can,about what I want. I already have working code for what I need so far,but if you'd like to re-invent "My" wheel, then feel free.Would be easier for us all to get timer1 to stop after the first interval though.

The 1st problem you will have is ,you will need to simulate the signals cause you don't have my dyno.

Here goes.

So basicly I need code to do the following.

The pickup senses signals from the roller ,sent to the PC over any available comport.

(I use the RS232 comport1 connection on my PC.Serialport1 on my form is set to baud rate 115200,so the second problem is this.If we use a USB comport.I will need a serial to usb adapter ,and the most only accept 9600 baud as far as I know).

The program converts the signals into RPM readings from the formula. (the actual
calculations should be in radians. RPM is shown here for easy understanding.
1 RPM = 6.28 Radians).
RPM = (Number of signals per sample / Sampling time) * 60 seconds

Note: The signals from the dyno are generated from a disk, with 6 holes, spinning through an IR device.This means 6 signals per revolution.If your sampling time is 1 sec., then you are measuring frequency (Hz).To get the RPM you must do the math.
Hz. / 6= revolutions per sec.
revs per sec.*60 = RPM
The same as (Hz./6)*60= RPM ,or just Hz*10=RPM.

The program converts the reading into angular acceleration (RPM acceleration)

Angular acceleration = ((Current RPM - Previous RPM) / Sampling Time) * 1 seconds

The program calculates the roller torque based on known roller inertia .

Torque = Rotational Inertia * Angular Acceleration

Then the program calculates the roller power based on calculated torque and roller RPM (angular velocity in radians per second) from the formula

Power = Roller Torque * Angular Velocity

Then the data should be plotted in understandable graphs with the user selected axis. Usually TQ/RPM or HP/RPM or TQ/Time or HP/Time or TQ/Distance or HP/Distance etc.

Programm should start when the first signal from the dyno is present and stop when the signals no longer change ( Top Speed).

Whatever code you write, if any, needs to be something I can edit myself.I have 4 different sizes of rollers for different vehicle types (ie. 2Wd/4Wd,electric/gas powered ect.) each with different inertial properties and need to be able to change parameters in the code as need be.Basicly,each dyno will have it's own software that will only funtion properly with said dyno.



Here some good reading to understand what I'm doing. Technical Article: How our Inertial Dynamometer Works
 
Oh my Gosh... if you think for a moment, we started with just a led indicator lights. Today we are discussing about how Timer works lol

I know.It's crazy,but someone say's my code makes no sense to them.I may just have to go back to the indicator LED version.I didn't want to cause it looks cheesy.I'll wait and see if someone writes a month of coding that makes sense to them before I change my code,
when all I wanted is for timer1 to stop after the 1st interval.
 
What's not to understand about a Timer? For my app I set it for 1 second:=1sec on 1sec off,1sec on,1sec off and so on.Or not?
Um, not. If you set the Interval of a Timer to 1000 then it will raise a Tick event every 1 second. If you set its Enabled property to True or call its Start property, the Timer will raise Tick events, once every second. If you set Enabled to False or call Stop then it won't raise Tick events. That's it. It's not like setting the Interval to 1000 means that the Timer does something for a second and then doesn't do something for a second. It does something ever every second, i.e. raises a Tick event.

You say that you want to stop the Timer after the first "interval". Do you mean the Interval property of the Timer? If so then I told you how to do that in the very first reply: call Stop in the Tick event handler. In that case, you set the Interval to 1000 and then call Start. Nothing will happen for 1 second and then, at the end of that 1 second, the Timer raises a Tick event. In the Tick event handler you call Stop, so the Timer stops and raises no more events.

To coin a phrase, what's not to understand?
 
Hey don't give up. You are in good hands with John.

Oh I haven't given up.I've found another alternative.
I can type Timer2.stop(), or serialport1.close() in the timer1 event,and "they" stop.
I can type them both to the timer1 event and things are fine.My measurement runs for the 1 second timer1 interval and stops just fine.Works great.
But for the life of me I cannot get it accept timer1.stop().

Have looked all over my code.Thought maybe timer1 was closing but some other code caused it to re-open right away.

No matter ,it works fine as is now.Timer2 takes samples every 20 millisec,for 1 second and stops.Thats all I want.
 
Back
Top