EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Topics / 2 parallel time measurements

2 parallel time measurements

|

Microcontroller › AVR › 2 parallel time measurements

  • This topic has 3 replies, 4 voices, and was last updated 10 years, 10 months ago by nehal kriti.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • June 26, 2011 at 5:11 pm #975
    prerit
    Participant

    i need a system to to measure the timing of two athletes simultaneously. i want to know if it’s possible because differentiating between start/stop triggers of different persons is an issue and the code that should run for these measurements seems to be difficult.

    i will be extremely thankful if anyone can provide me with the code (i can provide the psuedo code) otherwise any sort of help is welcome.

    June 29, 2011 at 12:20 pm #6395
    Alex
    Participant
    int time1, time2;
     
    ISR(TIMER1_COMPA_vect)
    {
        if(a){
            time1++;
        }
         if(b){
            time2++;
        }
    }
     
    void init()
    {
       time1=0;
       time2=0;
    }
    ???? () {time1;}
     

    July 4, 2011 at 12:09 pm #6418
    reachrishikh
    Participant

    Hi,
    This is what we’re looking for.

    We need to create this timer system. We already have the pseudo-code, logic, requirements and everything sorted out. But our electronics engineer, Prerit, cannot figure out what microcontroller to use for this, and what language to code the appropriate microcontroller selected in.

     

    You can imagine we’re taking the time taken to cross between two given points. It’s a race where athletes have to cross this race-distance (the distance between the two given points) and have their time recorded. Ideally, there should be one athlete crossing that distance at a time to get his time recorded, but since the course is large enough to accommodate them such that they don’t get in the way of each other, and since we have to record the time of a large number of people, so to save overall time, we can have two people on the race-distance at any given point of time.

    Also, if an athlete covers the race-distance within a certain pre-set amount of time, a beep sounds.

    I’m listing out the description and pseudo-code below.

    Would someone please be kind enough to tell us what microcontroller to use, and what language would be required for it. And yeah, some code in the target language would also be appreciated, since I don’t speak low-level.

     

    We have IR pair triggers at two points, both triggering a Start and a Stop each. When the Start is triggered, it needs to start counting time, and displaying it on our LED display in Hours, Minutes, Seconds, Milliseconds format. When the stop is triggered, the time counter stops, and the display freezes on the last incremented time, till it is reset by another Start trigger.
    There are two such displays, meaning we can have two timers counting simultaneously, triggered by the same physical IR pair Start and Stop triggers. Timer 1 is connected to Display 1, and Timer 2 is connected to Display 2.

     

     

    pseudo-code:

     

    variable latch //this variable stores which timer was triggered last. this can even be a boolean value with 0 assigned to timer_1 and 1 assigned to timer_2

     

    constant preset_time = //assign pre-set time value here in hours:minutes:seconds:milliseconds format

     

    Start trigger event handler

    if (both timers running)

    {

     do nothing

    }

    else

    {

     if (both timers stopped)

     {

      trigger timer_1 //the first display device starts showing time being counted upwards

      add timer_1 to latch

     }

     elseif (timer_1 is running)

     {

      trigger timer_2 //the second display device starts showing the time being counted upwards

      add timer_2 to latch

     }

     elseif (timer_2 is running)

     {

      trigger timer_1

      add timer_1 to latch

     }

    }

     

     

    Stop trigger event handler
    if (both timers running) //if both timers are running at the same time, stop the one which was triggered first, which is established by seeing which was the last trigger added to the latch, then stop the other one which is not in the latch

    {

     if (timer_1 in latch)

     {

      stop timer_2

      if (timer_2.time <= preset_time)

      {

       sound beep

      }

     }

     elseif (timer_2 in latch)

     {

      stop timer_1

      if (timer_1.time <= preset_time)

      {

       sound beep

      }

     }

    }

    else //only one timer is running, then stop whichever timer is running

    {

     if (timer_1 is running)

     {

      stop timer_1

      if (timer_1.time <= preset_time)

      {

       sound beep

      }

     }

     elseif (timer_2 is running)

     {

      stop timer_2

      if (timer_2.time <= preset_time)

      {

       sound beep

      }

     }

    }

     

     

    As an example to put things into perspective, if I were to do this in Visual Basic Dot Net (a language I am familiar with), I would code it like this:

     

    Dim latch as Boolean = Nothing ‘this variable stores which timer was triggered last. is a boolean value with 0 assigned to timer_1 and 1 assigned to timer_2

     

    Const presettime as integer = 60000 ‘store time in milliseconds.

     

    Dim WithEvents Timer_1 As New Windows.Forms.Timer()

    Dim WithEvents Timer_2 As New Windows.Forms.Timer()

     

    Sub StartTrigger()

     

     If Timer_1.Enabled = True AND Timer_2.Enabled = True Then

      ‘do nothing

     Else

      If Timer_1.Enabled = False AND Timer_2.Enabled = False Then

       Timer_1.Start()

       latch = 0

      ElseIf Timer_1.Enabled = True Then

       Timer_2.Start()

       latch = 1

      ElseIf Timer_2.Enabled = True Then

       Timer_1.Start()

       latch = 0

      End If

     End If

     

    End Sub

     

    Sub StopTrigger()

     

    If Timer_1.Enabled = True AND Timer_2.Enabled = True Then

     If latch = 0 Then

      Timer_2.Stop()

      ComparePresetTime(Timer_2.Interval)

     ElseIf latch = 1 Then

      Timer_1.Stop()

      ComparePresetTime(Timer_1.Interval)

    Else

     If Timer_1.Enabled = True Then

      Timer_1.Stop()

      ComparePresetTime(Timer_1.Interval)

     ElseIf Timer_2.Enabled = True Then

      Timer_2.Stop()

      ComparePresetTime(Timer_2.Interval)

    End If

     

    End Sub

     

    Sub ComparePresetTime(ByVal TimeToCompareInMilliseconds As Integer)

     

    If TimeToCompareInMilliseconds <= presettime Then

     ‘sound beep

    End If

     

    End Sub

    However, like I said above, I am not familiar with low level languages, and we need help with machine-level code for the microcontroller we select that is appropriate for this job.

     

    Once we know the microcontroller model to use and have the code ready and programmed into it, we will try setting the hardware of the timer system up, and also need some interfacing help to connect the microcontroller to show the countdown on some large LED 7 segment displays. These LED displays need to be large enough to be seen from a distance of 50 feet in broad daylight. Now Prerit knows how to wire smaller LED displays, but we’re stuck at the interfacing aspect when concerned with larger displays.

    September 3, 2014 at 6:19 am #12122
    nehal kriti
    Participant

    i want a circuit which will generate a beep sound after certain counting done with the help of up-counter.As i want to dtect the number of items passing through the sensor ina conveyor belt in an industry. And after reaching the limit of production,it will give a beep sound.For example, after the production of every 500 bottles. We will be doing the counting with a help of microcontroller(89C51).

     

    I will be very grateful if anyone can provide me with details or any kind of help n this project.

    Thanks.

     

     

  • Author
    Posts
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.
Log In

RSS Recent Posts

  • The Analog Gods Hate Me July 14, 2025
  • Impact of Tariffs on PCB Fab July 14, 2025
  • More fun with ws2812 this time XC8 and CLC July 14, 2025
  • I Wanna build a robot July 14, 2025
  • Wierd makita battery July 14, 2025

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise