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 / Replies / Hi,This is what we’re looking

Hi,This is what we’re looking

|

Microcontroller › AVR › 2 parallel time measurements › Hi,This is what we’re looking

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.

RSS Recent Posts

  • Can I use this charger in every country? May 14, 2025
  • LED circuit for 1/6 scale diorama May 14, 2025
  • Electronic board faulty?!? May 13, 2025
  • using a RTC in SF basic May 13, 2025
  • An Update On Tarrifs May 13, 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