Results 1 to 10 of 10

Thread: Timer

  1. #1
    Low Bitrate
    Join Date
    Dec 2007
    Posts
    105

    Timer

    Exactly what can I use the timers for? As in. Can I use them to time an event. Like how long it takes a voltage to go from 1 to 2 volts. Or use them to set a start and stop time and then find out the voltage change on an input. I have an idea for calculating MPG but I need a timer. What I really need a timer that can be started and then when there is a certain voltage change the timer is stopped and the time used in a calculation. But I don't believe that this can be done.

  2. #2
    FLAC
    Join Date
    Oct 2006
    Location
    Las Vegas
    Posts
    1,286
    The timers are always running.

    http://www.mp3car.com/vbulletin/fusi...ml#post1206317

    I have similar needs, I did try to explain this before and I hadn't really recieved a response. That was a while ago.

    It's more like there is a missing building block, something more like a programming language structure: a counter for events.

    since the timer is always running, it would be nice to have a block in a function that says counts the timer to X and then Fire. Maybe flexible enough so that it can be enabled by a boolean variable and configurable as 'always repeat' or fire once. The output or value of the variable could be as simple as boolean, allowing any other function to use it.


    Something like that?

  3. #3
    Fusion Brain Creator 2k1Toaster's Avatar
    Join Date
    Mar 2006
    Location
    Colorado, but Canadian!
    Posts
    10,053
    For timing of events, make a variable that always get +1 every loop. There's your timer. If variable > value, then do stuff, reset variable. and repeat.

    And as h3rk said those timers are the program's timers to know when to fire graphics, logic, and i/o.
    Fusion Brain Version 6 Released!
    1.9in x 2.9in -- 47mm x 73mm
    30 Digital Outputs -- Directly drive a relay
    15 Analogue Inputs -- Read sensors like temperature, light, distance, acceleration, and more
    Buy now in the MP3Car.com Store

  4. #4
    FLAC
    Join Date
    Oct 2006
    Location
    Las Vegas
    Posts
    1,286
    That makes sense. Thanks for the new feature.

  5. #5
    Low Bitrate
    Join Date
    Dec 2007
    Posts
    105
    I feel dumb now. I am not understanding the variable as a timer. I know that it is going to be one of those slap yourself in the forehead things. But give an old guy a break. I need to time how long it takes to burn a gallon of gas.

  6. #6
    Fusion Brain Creator 2k1Toaster's Avatar
    Join Date
    Mar 2006
    Location
    Colorado, but Canadian!
    Posts
    10,053
    Code:
    variable_timer = 0;
    
    loop
    {
      variable_timer = variable_timer + 1;
      if(fuel sender is between x and y)
      {
        number_of_times_in_loop = variable_timer;
        variable_timer = 0;
        time_to_burn = (number_of_times_in_loop * time_for_each_loop);
      }
    }
    So every time variable goes up by 1.

    Capture the 1 mile of gas being burned. In that capture moment, reset the varaible to 0. The time it took to get there was the variable value (number of times in the loop) multiplied by the time it takes each loop which is every "timer" value that you set. So if the timer is set to 100mS, and the variable is 4000, then it took 4000*100 = 400000mS = 400s = 6.66 minutes.
    Fusion Brain Version 6 Released!
    1.9in x 2.9in -- 47mm x 73mm
    30 Digital Outputs -- Directly drive a relay
    15 Analogue Inputs -- Read sensors like temperature, light, distance, acceleration, and more
    Buy now in the MP3Car.com Store

  7. #7
    Constant Bitrate
    Join Date
    Jun 2008
    Location
    Georgia, USA
    Posts
    188
    Instead of:

    Code:
        number_of_times_in_loop = variable_timer;
        variable_timer = 0;
        time_to_burn = (number_of_times_in_loop * time_for_each_loop);
    Why not:

    Code:
        time_to_burn = (variable_timer * time_for_each_loop);
        variable_timer = 0;
    Thanks,

    Dan

  8. #8
    Fusion Brain Creator 2k1Toaster's Avatar
    Join Date
    Mar 2006
    Location
    Colorado, but Canadian!
    Posts
    10,053
    Quote Originally Posted by Dan2008 View Post
    Instead of:

    Code:
        number_of_times_in_loop = variable_timer;
        variable_timer = 0;
        time_to_burn = (number_of_times_in_loop * time_for_each_loop);
    Why not:

    Code:
        time_to_burn = (variable_timer * time_for_each_loop);
        variable_timer = 0;
    I was just trying to make it easy with the variable names. Coding it in MDX looks a million times different anyways.

    And by storing it in a seperate variable, you can compare your current with your past.
    Fusion Brain Version 6 Released!
    1.9in x 2.9in -- 47mm x 73mm
    30 Digital Outputs -- Directly drive a relay
    15 Analogue Inputs -- Read sensors like temperature, light, distance, acceleration, and more
    Buy now in the MP3Car.com Store

  9. #9
    Constant Bitrate
    Join Date
    Jun 2008
    Location
    Georgia, USA
    Posts
    188
    Gotcha...it makes it easier to read too.

    I always make my code work then put it on a diet to try and get the smallest, most efficient code. Some times though, the smallest is not necessarily the most efficient.
    Thanks,

    Dan

  10. #10
    Low Bitrate
    Join Date
    Dec 2007
    Posts
    105
    SMACK!! (hits his forehead). Ok sounds good and makes sense. Now to play with that.

    Thanks
    Ron

Similar Threads

  1. 12 Volt Timer For Computer
    By kozmo in forum Power Supplies
    Replies: 20
    Last Post: 02-18-2007, 10:02 AM
  2. Replies: 19
    Last Post: 07-27-2006, 03:44 AM
  3. VB6 Crew, Timer Control Question
    By kamikaze2112 in forum Coders Corner
    Replies: 3
    Last Post: 04-09-2006, 06:23 PM
  4. Timer Circuit
    By Fox_Mulder in forum General Hardware Discussion
    Replies: 3
    Last Post: 11-04-2005, 09:47 AM
  5. sleep timer for lcd projector
    By ŠuTcH in forum Off Topic
    Replies: 1
    Last Post: 11-23-2004, 07:00 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •