# Counter loop

Posted by Eric at 2/12/2001 5:24 PM EST

Coach on team FEDS from RHS sponsored by Visteon.

If you want to time a motor out (say run it for 1 second and stop) and you wanted to do it more accuratly than simply counting loops (presumably bad data could thow this method off) what would the progam code look like? (I’m trying to get a handle on the delta_t kind of thing.)

Posted by Joe Ross at 2/12/2001 7:14 PM EST

Engineer on team #330, Beach Bot, from Hope Chapel Academy and NASA/JPL , J&F Machine, and Raytheon.

Posted by Eric on 2/12/2001 5:24 PM EST:

: If you want to time a motor out (say run it for 1 second and stop) and you wanted to do it more accuratly than simply counting loops (presumably bad data could thow this method off) what would the progam code look like? (I’m trying to get a handle on the delta_t kind of thing.)

delta_t is the number of data packets that you missed.

to be able to time things you should use the following idea:

counter = couter + 1 + delta_t

If delta_t is 0 then no data was lost and your program loop is less than 1/40th of a second. If delta_t is not zero, then you missed that many packets.

using this code, when the counter reaches 40 then 1 second has passed.

Posted by Rick Berube at 2/16/2001 12:16 AM EST

Engineer on team #121, Rhode Warriors, from Middletown H.S…

In Reply to: Re: Counter loop
Posted by Joe Ross on 2/12/2001 7:14 PM EST:

Actually, I observed the loop time between consecutive cylces vary between alternate cycles even with a stripped down version of the default program. We were transferring no more than 8-10 bytes (I don’t remember exactly how many) between the player station & robot at the time. We measured 20-30 mS periods by simply toggling the state of the PWM signal at a relay channel every time through the main loop. We attached a scope to the channel and observed the period of PWM signal change from 20mS to 30 mS and continuously repeat. We also monitored delta_t during this time, using a debug statement to print a message whenever delta_t was not equal to zero, and never once saw the message!
I didn’t dig into it any more, I just made note of it. I wonder if one were to monitor the serial stream between the receiver and RF modem, if they would see the same delay in the data stream or if the delay is incurred inside the receiver.

Rick

Posted by Nate Smith at 2/16/2001 11:07 AM EST

Other on team #66, Frostbite, from Willow Run High School and GM Powertrain.

In Reply to: Re: Counter loop
Posted by Rick Berube on 2/16/2001 12:16 AM EST:

: Actually, I observed the loop time between consecutive cylces vary between alternate cycles even with a stripped down version of the default program. We were transferring no more than 8-10 bytes (I don’t remember exactly how many) between the player station & robot at the time. We measured 20-30 mS periods by simply toggling the state of the PWM signal at a relay channel every time through the main loop. We attached a scope to the channel and observed the period of PWM signal change from 20mS to 30 mS and continuously repeat. We also monitored delta_t during this time, using a debug statement to print a message whenever delta_t was not equal to zero, and never once saw the message!
: I didn’t dig into it any more, I just made note of it. I wonder if one were to monitor the serial stream between the receiver and RF modem, if they would see the same delay in the data stream or if the delay is incurred inside the receiver.

: Rick

One thing to keep in mind…even if you aren’t getting them in your serin statement, or not using the inputs on the RC or OI, all of the data is still sent both ways…I know its 26 bytes(same as the dashboard output) for the data from RC to OI, but I dunno about the other way around…

Nate