View Single Post
  #47   Spotlight this post!  
Unread 01-02-2013, 15:44
MisterG's Avatar
MisterG MisterG is offline
Think twice post once.
AKA: Alan Gilgenbach
FRC #2062 (C.O.R.E. - Community of Robotics Engineers)
Team Role: Team Spirit / Cheering
 
Join Date: Mar 2011
Rookie Year: 2011
Location: Waukesha, WI
Posts: 120
MisterG is a name known to allMisterG is a name known to allMisterG is a name known to allMisterG is a name known to allMisterG is a name known to allMisterG is a name known to all
Re: Best way to measure period between pulses? Counters and FPGA

Quote:
Originally Posted by sst.thad View Post
If you look at the code the only reason it has that function is to not have a divide by 0 error. In the get period function, it uses that bool in order to not make it divide by 0.
Note: the problem that we are dealing with is primarily due to the one pulse per revolution setup.

Agree that the stall feature is solving the zero divide problem but probably more importantly its dealing with the issue of period growing dramatically as rotational velocity approaches zero.

Take the following scenario: you decelerate very rapidly and your last transition happens at a time that is equivalent to 200 RPM. The wheel is stopped but the code continues to report 200 RPM. If the timeout (max period/min rate) is set for 10 RPM this will continue for 6 seconds.

Another interesting C++ fact that I never realized before (or once I knew but forgot):
For IEEE floats, division of a finite nonzero float by 0 is well-defined and results in +infinity (if the value was >zero) or -infinity (if the value was less than zero). The result of 0/0 is NaN. If you use integers, the behaviour is undefined.
__________________
Alan Gilgenbach
C.O.R.E 2062