Announcement

Collapse
No announcement yet.

Timer

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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?
    It's been a while...

    Comment


    • #3
      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

      Comment


      • #4
        That makes sense. Thanks for the new feature.
        It's been a while...

        Comment


        • #5
          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.

          Comment


          • #6
            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

            Comment


            • #7
              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

              Comment


              • #8
                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

                Comment


                • #9
                  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

                  Comment


                  • #10
                    SMACK!! (hits his forehead). Ok sounds good and makes sense. Now to play with that.

                    Thanks
                    Ron

                    Comment

                    Working...
                    X