PDA

View Full Version : RPM Counting Continuous



CluckShot
- 22nd May 2007, 18:04
It is fairly simple to produce a disk which provides a pulse which is say 5 degrees wide of a rotation. This pulse can be measured relative to the width of the pulse in time. The resulting time will tell by calculation the RPM of the disk. I am wanting to do such a thing and wondered if anyone out there knew the best way to measure this pulse width. The RPM may vary greatly and as such the time probably needs to be a 14 or 16 bit time value. I have an PIC18F4620 chip I am working on.

Ideas Please!

skimask
- 22nd May 2007, 20:03
It is fairly simple to produce a disk which provides a pulse which is say 5 degrees wide of a rotation. This pulse can be measured relative to the width of the pulse in time. The resulting time will tell by calculation the RPM of the disk. I am wanting to do such a thing and wondered if anyone out there knew the best way to measure this pulse width. The RPM may vary greatly and as such the time probably needs to be a 14 or 16 bit time value. I have an PIC18F4620 chip I am working on.

Ideas Please!

So, what's your hardware actually going to look like? How are you wanting to drive the pulse input from the wheel? IR? Beam-breaker? Hall effect?

When you can get a good pulse coming from the disk, you can time the difference between the pulses, 1st pulse starts the timer, 2nd pulse stops the timer, saves the value, code resets the timer/counter and awaits the 3rd (actually back to the 1st) pulse.
Use any 16 bit timer with a pre- and/or post -scaler.
Just as an example here...if the rpm gets too great, the pulses get too close together, less than 256 counts, you could turn down the prescaler (down to a point anyways) to make the timer 'more accurate' for those speeds.
If the rpm falls off, and you get close to maxing out the timer/counter, say above 50,000, and you could turn up the prescaler to make the timer 'less accurate'. The accuracy won't be changing, but the method in which you calculate the rpm will.

Acetronics2
- 22nd May 2007, 20:09
Hi,

<< The RPM may vary greatly >> ... ha,ha ...

YES, but from how much to how much ??? and what is the precision looked for ???

The simplest way would be to use a 16 Bits timer/counter ... you have 3 aboard.
could feed another 16 bits soft counter ... if really needed.

as our INTERNATIONALs Mel & Darrel showed us how to deal with 31 bits numbers, DIV32 could be used to recover some "easy to use" 16 bits results.

Then Just read result when needed ...

Alain

Other simple solutions using a soft-switchable pre-divider ...

43 to 32000 rpm with a simple 16C84 ( PbP programmed ! ) ...i.e. with .1% precision.

Pic_User
- 22nd May 2007, 20:10
Hi Paul,

Is there a reason to use 5% and measure pulse width?
Could you just count the revolutions, for a time period and multiply to get revolutions per minute?

Search the forum for: rpm*

http://www.picbasic.co.uk/forum/showthread.php?t=2811

http://www.picbasic.co.uk/forum/showthread.php?t=1150

http://www.picbasic.co.uk/forum/showthread.php?t=366

Skimask, the adjustable prescaler idea is a really good idea.

-Adam-

skimask
- 22nd May 2007, 20:58
Skimask, the adjustable prescaler idea is a really good idea.
-Adam-

I thought it was kinda slick. Came in handy for a low end freq counter from awhile back, worked from near 0 to something like 50khz with oscillator precision, (+/- 1 count of course). Same principle on the rpm thing.

CluckShot
- 23rd May 2007, 19:56
I have first to thank everyone for responding quickly.
The problem with my RPM calculation is that it needs to be fairly precise and in fairly close to real time. The preferred device I have to count is an optical counter which will have a wheel and blank spaces so I have the option of counting either the length of the width of the blank space or of the null from the disk. High or low pulse counting option is what I am looking at. I really need to count the specific one pulse width issue and maybe keep a sum of these like 5 in a stack because this is fairly "now" use data.

The next thing I need to do is execute a pulse to do my control function that varies in length with RPM. (Function of degrees of turn of the device and latency of the control circuit) This I expect will be on a lookup or a formula depending on the math I can do. This pulse will be executed a period of time delay after the timing (RPM count) pulse comes in and will execute a turn off of the pulse after a short period of time based on the RPM.

I am needing help figuring out the way to count the pulse so that the counter does not affect timer accuracy and responds with about 1/10,000 sec accuracy.

The RPM will be slow relative to some of the response posts. It will be 0-1,800 RPM. At this time it is more likely to stay below 600 RPM. The device will have extreme torques on it allowing a substantial variance of the RPM in time so I need to respond in real time. It may seem that the speed of response is not critical but the device is definitely needing this accuracy. 1/1,000 it too inaccurate. Honestly I would like to push it closer to 1/100,000 sec.

If somebody thinks Hall Effect is better for this I can use it. The latency is the issue. The sensor latency needs to be low. I am looking at 1/1000 to 5/1000 delay in the sensor as is. Circuit delays are real issues in this device. If somebody knows a sensor with wheel package already done up I am all ears.

So I have 2 issues. Pulse width measuring or RPM counting by other means and timer interrupt On and timer interrupt off counting without the first timer failing the operations of the second timer.

This could be 3 timers operating, I expect that. (1) to keep up with RPM. (2) To time the initiation pulse ON condition. (3) To time the initiation of Pulse Off condition.
Better Ideas are always welcome.

skimask
- 23rd May 2007, 20:31
Better Ideas are always welcome.

The method I mentioned above will give you an almost instantaneous rpm reading, so long as you can figure out how to keep good track of time (that's up to you, I'll help you along, others here will help you along, somebody here might spell it out for you and even write the whole program, but I, for one, am not going to write the complete code for you).
You read one pulse, save the time that pulse happened (read one of the timers), you read the next pulse, save the time the 2nd pulse happened, and subtract the 1st pulse from it. Read the 3rd pulse, subtract the 2nd pulse from it, etc.etc.
After reading a pulse, do the math on it, reciprical functions (i.e. 1 pulse per second = 1 rpm, 2 pulses per second = 2 rpm, etc., less time per pulse = more rpm).
Assuming you use PBP math functions to do the multiplication/division on it, you could easily get a solution within 1/1000 of a second. Use a few look-up tables and a fast PIC, and that number could go down into the microseconds.
As far as controlling whatever you are controlling, you're looking at using a PID control loop to keep the rpm constant under varying loads. It's the same principle with microprocessor controlled voltage regulators, only an electrical load vs. a mechanical load.

And give a hard thought about what you really NEED vs. what YOU want . I can't think of very many things that need instantaneous correction within one us...and I can think of fewer things that can possibly respond inside of a handful of microseconds, much less 10 us.

CluckShot
- 25th May 2007, 12:37
I have really only wanted a basic description of the process solution. I am not asking for code so much as use timerO to count ... and timer1 to count. This is sort of a process thing rather than expecting detailed answers. I did ask and get a detail question on pull-up resistors because I simply didn't know the answer for sure. Thanks all