jimfraseruk
New Member
I am trying to write a multi event timing device. Upto three dog agility rings will be timed at once, each with start/ finish gate (IR Beam Break). Those start/ finish signals will be sent to a central timing device. This will calculate and transmit times to a PC via USB and start large LED displays for each ring to show spectators each dogs time.
Sounds like a huge project to me but I am breaking this down into small projects as I am a beginner.
I initially copied a stopwatch type program (posted on this site, thankyou!) that uses TMR2 interrupts to count 1/100ths of a second which worked well. But I want three timers running at the same time so I changed it so that there are three Start/Stop buttons. When a button is pressed the start time is saved to a register (just like a timestamp) on the next button press the finish time is saved. I then subtract them to find the elapsed time.
1. Problem is that I cannot release the buttons quickly enough so it starts/ stops the time (not TMR2) many times before finally starting properly. I don't think I can use a delay or wait for a release, as a trigger from another ring may be missed. As this bouncing will occur at both the start and finish of the timing maybe they cancel each other out. What does your experience tell you I should do?
2. Should I abandon the datalogging approach (finish time - start time) and do everying in the interupt routine? I am worried an interupt may occur in the middle of saving the datalogged start/ stop time. I cannot save the registers as they must increment. I could have three incrementing counters in the interupt using a 'flagrunning' and 'flagbuttonpressed' for each ring to determine if I count or not, but then I could be out on the timing by max 10ms as I wait for an interupt to start timing. I am not sure which method would have the most accurate times. Recommendations please.
3. Should I do this all another way as I the dog people may want to scale to more rings?
I am a beginner so be gentle (probably inefficient code) and all this is being done in the simulator until the parts arrive and I have learnt more.
Sounds like a huge project to me but I am breaking this down into small projects as I am a beginner.
I initially copied a stopwatch type program (posted on this site, thankyou!) that uses TMR2 interrupts to count 1/100ths of a second which worked well. But I want three timers running at the same time so I changed it so that there are three Start/Stop buttons. When a button is pressed the start time is saved to a register (just like a timestamp) on the next button press the finish time is saved. I then subtract them to find the elapsed time.
1. Problem is that I cannot release the buttons quickly enough so it starts/ stops the time (not TMR2) many times before finally starting properly. I don't think I can use a delay or wait for a release, as a trigger from another ring may be missed. As this bouncing will occur at both the start and finish of the timing maybe they cancel each other out. What does your experience tell you I should do?
2. Should I abandon the datalogging approach (finish time - start time) and do everying in the interupt routine? I am worried an interupt may occur in the middle of saving the datalogged start/ stop time. I cannot save the registers as they must increment. I could have three incrementing counters in the interupt using a 'flagrunning' and 'flagbuttonpressed' for each ring to determine if I count or not, but then I could be out on the timing by max 10ms as I wait for an interupt to start timing. I am not sure which method would have the most accurate times. Recommendations please.
3. Should I do this all another way as I the dog people may want to scale to more rings?
I am a beginner so be gentle (probably inefficient code) and all this is being done in the simulator until the parts arrive and I have learnt more.