November 23, 2024, 11:28:01 PM

News:

Got VSA?  Want to use your Prop-SX?  Now you can!  See the VSA section of the Library forum for Prop-SX code that works with VSA.


Calculating RPM

Started by Jadams, February 27, 2011, 07:13:47 PM

Previous topic - Next topic

Jadams

This is from the same project as the previous post.  After reading in the March issue of Nuts&Volts about the air/steam engine, I decided to turn my old weedeater engine into a project.  I used a 3 way solenoid valve (Valve1) mounted in the spark plug hole, a reed switch (Trigger) mounted to pick up the magnets on the flywheel, and it works really good.

Is it possible to use the Trigger as a counter and calculate the RPM?  The article explained how is was done in their project, but I don't understand.  Any help would be appreciated.

This is the code that allows my engine to run on compressed air:

' =========================================================================
'
'   File...... Air_Steam Engine
'   Purpose...
'   Author....
'   E-mail....
'   Started... 2/23/2011
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------


' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

SYMBOL  Trigger         = PIN6                 ' SETUP = DN
SYMBOL  Valve1          = PIN0

' -----[ Constants ]-------------------------------------------------------

SYMBOL  IsOn            = 1                     ' for active-high in/out
SYMBOL  IsOff           = 0

SYMBOL  Yes             = 1                     ' for active-high inputs
SYMBOL  No              = 0

' -----[ Variables ]-------------------------------------------------------

SYMBOL  delay           = W4



' -----[ Initialization ]--------------------------------------------------

Reset:
  PINS = %00000000                              ' clear all outputs
  DIRS = %00000001                              ' P0 output

' -----[ Program Code ]----------------------------------------------------

Main:
  POT 7, 98, delay
  Valve1 = IsOff
  IF Trigger = IsOff THEN Main
  Valve1 = IsOn
  delay = delay * 35/100
  PAUSE delay

  GOTO Main






' -----[ Subroutines ]-----------------------------------------------------


' -------------------------------------------------------------------------


' -----[ User Data ]-------------------------------------------------------
Jim Adams

JonnyMac

Not in the same Prop-1 that's controlling the air to the engine. That's working because you have a tight loop; if you start adding calculations and then sending them out to a display your loop timing will be wrecked and the motor will stop running (smoothly, if at all).
Jon McPhalen
EFX-TEK Hollywood Office

Jadams

Yep, I found out it doesn't take very many extra lines of code to mess up the timing.  If I use a stand alone prop to measure RPM, can you give me an example?  I've tried a few things with no results.  I see the 'count' command is not available with the Prop 1.

Thanks
Jim Adams

JonnyMac

It's not going to be easy without a very clean output. If you get a clean output (like from a Hall-effect sensor), then you can use PULSIN to measure both the high and low times of the signal, then calculate from there.  Keep in mind, though, that you're going to be limited to a period of 65535, which in 2u units is 131,070 microseconds, or 0.131 seconds.

This means that your lowest measurable speed is a rotation in 0.131 seconds -- this is 7.63 rotations per second, which works out to 458 RPM.
Jon McPhalen
EFX-TEK Hollywood Office

bsnut

February 28, 2011, 09:06:06 PM #4 Last Edit: March 01, 2011, 01:25:20 AM by bsnut
I agree with Jon on using the PULSIN and the Hall-effect sensor and here is some test code out of the Basic Stamp Editor help file
' {$STAMP BS1}
' {$PBASIC 1.0}

SYMBOL  Pulse           = 7             ' pulse input pin

SYMBOL  time            = W1            ' pulse width (10 uS units)


Main:
 PULSIN Pulse, 1, time                 ' measure positive pulse
 IF time = 0 THEN Main                 ' if 0, try again
 DEBUG CLS, time                       '   else display result
 GOTO Main
 END


I also pulled this PULSIN explanation from the editor help file, which should help understand what we are talking about.

QuotePULSIN is like a fast stopwatch that is triggered by a change in state (0 or 1) on the specified pin. The entire width of the specified pulse (high or low) is measured, in units shown above and stored in Variable.

Many analog properties (voltage, resistance, capacitance, frequency, duty cycle) can be measured in terms of pulse duration. This makes PULSIN a valuable form of analog-to-digital conversion.
William Stefan
The Basic Stamp Nut

Jadams

I ordered a couple of hall effects and will give it a try when they arrive.

Thanks
Jim Adams

Jadams

I have a hall-effect in place.  With the engine running I get a time of about 8000.  Do I understand that  the 8000 is for 10us?  That would be 800 for 1us or .008 sec for 1 rev.  Am I on the right track?
Jim Adams

bsnut

March 05, 2011, 09:11:57 PM #7 Last Edit: March 05, 2011, 09:15:02 PM by bsnut
It sounds like you are using the test code out of the Basic Stamp Editor help file that I posted.  It would be 8000 for 10us, because the BS1 processor on the Prop1 can handle 10us units. I don't know if you have the PDF of the BS1 app notes. Because app note #5 shows you how to do a tach measurement and here is the link for you.
http://www.parallax.com/Portals/0/Downloads/appnt/stamps/bs1Appnotes.pdf.  
Here is the code as well

' Listing 1: TACH.BAS
' The BASIC Stamp serves as a tachometer. It accepts pulse input through pin 7,
' and outputs rpm measurements at 2400 baud through pin 0.
input 7
output 0
Tach: pulsin 7,1,w2 ' Read positive-going pulses on pin 7.
let w2 = w2/100 ' Dividing w2/100 into 60,000 is the same as dividing
let w2 = 60000/w2 ' w2 into 6,000,000 '(60 seconds in 10 us units).
' Transmit data followed by carriage return and linefeed.
serout 0,N2400,(#w2," rpm",10,13)
pause 1000 ' Wait 1 second between readings
goto Tach


In order to get to see what is happening, you need to replace this code

serout 0,N2400,(#w2," rpm",10,13)

with this code

DEBUG CLS, w2

These app notes go back to good old days of Parallax. I also maintian a copy of these notes and they help me with my project that I am doing. I guess didn't see this the first time I post help file code and I have a copy this app notes. Sorry for the delay:o.
William Stefan
The Basic Stamp Nut

JonnyMac

That App Note uses a flip-flop to convert one high and one low cycle into a single high or low cycle so you only have to use PULSIN one time.  Without the flip-flop you need to use PULSIN twice: one for the high side, one for the low side, and then add them to together.  The rest is the same.

Good job, Bill, for remembering those old App Notes.  Back in '94 and '95 I spent a lot of time with them.
Jon McPhalen
EFX-TEK Hollywood Office

Jadams

Hey, hey, I have a working tach.  Thanks Bill, for the App Notes.  There is a wealth of information in there, thanks for sharing.
Jim Adams

bsnut

March 06, 2011, 05:10:46 PM #10 Last Edit: March 06, 2011, 05:19:59 PM by bsnut
You're welcome. I had some feeling that, the app notes was some of Jon's handy work.
William Stefan
The Basic Stamp Nut

JonnyMac

Nope, not my doing; the original BASIC Stamp App Notes were created by Scott Edwards. Thanks to him, I really got into the BASIC Stamp and ultimately took over his column in Nuts & Volts.
Jon McPhalen
EFX-TEK Hollywood Office

bsnut

Thanks to you and Scott Edwards we have these App Notes and the Nuts&Volts articles to help us with projects like the one here.
William Stefan
The Basic Stamp Nut