bigdogguru
Administrator
- Joined
- Mar 12, 2010
- Messages
- 9,821
- Helped
- 2,350
- Reputation
- 4,694
- Reaction score
- 2,272
- Trophy points
- 1,413
- Location
- Southwest, USA
- Activity points
- 62,394
its normal that the RPM starts at 2000 or approximate value near to it...
there is something called cold start where it starts from 2000 or 3000......
check this discussion
Why does my car start with high rpm's everytime? - SaturnFans Forums
You can't use the RPM or RPS as time intervals, you have to use some timer and count the pulses for a specific duration.
In your code you are manually incrementing the RPS for one second and then you show its value, I don't see any measuring of the external pulses.
Alex
Yes but now my post doesn't make sense :sad:
Perhaps implementing a moving average, as Alex mentioned previously in this discussion, would be a viable solution.
Your interrupt routine upon receiving the first pulse increments a counter and starts a timer. After a set number of pulses, say 50 or 100, the timer is stopped. You now have the number of revolutions per a known time period which allows you to calculate RPM.
BigDog
1) Wait for pulse.
2) Start timer.
3) Use next pulse to stop timer.
Elapsed time is the period. Invert to get frequency, then multiply
by 60 to get RPMs.
Or, you could have a sample window and count the pulses:
1) Start timer.
2) Count pulses until timer stops.
Frequency is pulses divided by timer interval.
If you have a low RPM motor then it is probably better to use a capture input to count the time it take for the motor to give a rotation, then you can use it to calculate the RPM ( 60/measured_time)
If you measure 0.1sec then a simple 60/0.1 will give you the result
Alex
A slightly better variation of the method 1 would be to count a set number of pulses, say 100, instead of just one pulse. Doing so will give you a moving average and a more stable RPM value for display purposes.
If you have a low RPM motor then it is probably better to use a capture input to count the time it take for the motor to give a rotation, then you can use it to calculate the RPM ( 60/measured_time)
If you measure 0.1sec then a simple 60/0.1 will give you the result
Alex
Also on method 2 you may want to use an even fraction of second for the timer duration say, 0.1 or 0.01 seconds.
You should keep in mind your dealing with an 8-bit RISC processor, so you should attempt to keep as many values as possible within the range of a unsigned byte (0,255) and avoid division as a rule.
It may not be an issue with this app, but in real life applications, arithmetic with long and long long variables coupled with multiplication and division can really be MCU cycle consuming.
BigDog
---------- Post added at 18:54 ---------- Previous post was at 18:53 ----------
Exactly, Alex you beat me to it.
If you have a low RPM motor then it is probably better to use a capture input to count the time it take for the motor to give a rotation, then you can use it to calculate the RPM ( 60/measured_time)
If you measure 0.1sec then a simple 60/0.1 will give you the result
Alex
Romel,
Keep in mind if you use a duration of say 0.1 sec as Alex and myself suggested, then X/0.1 is equivalent to 10*X so you can avoid division.
BigDog
yes but the time mentioned there is not always 0.1 sec it's the time measured between pulse with respect to the motors RPM speed.
I believe Alex and I were referring to method 2, number of pulses in a specified duration. So rather than the number of pulses in a second, you could count the number of pulses in a tenth of a second, etc.
BigDog
I believe Alex and I were referring to method 2, number of pulses in a specified duration. So rather than the number of pulses in a second, you could count the number of pulses in a tenth of a second, etc.
BigDog
Im afraid if I can measure a very short pulse like 0.001 say if the motor is very fast... ..
or the CCP module can be able to measure time something like this 0.1234
Actually I was referring to the first method, capture the timer counts for 1 rotation to calculate the period and the RPM mainly because Romel said that the motor is a 50 RPM model so for 1sec the count of rotations will still be 0.
If the motor is a higher speed model that can give a few rotations/sec then a pulse count/sec would be fine.
I mean if the motor is very slow let say 50RPM only..
Actually I was referring to the first method, capture the timer counts for 1 rotation to calculate the period and the RPM mainly because Romel said that the motor is a 50 RPM model so for 1sec the count of rotations will still be 0.
If the motor is a higher speed model that can give a few rotations/sec then a pulse count/sec would be fine.
this will not be a problem, for example a timer with a clock of just 100000Hz can give you a resolution of 10us which can measure a few thousands rounds/sec (which is hundreds of thousand rounds/min)
Alex
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?