Slow RPM code advice

SMUTTLEY

New Member
I build Stirling model engines and installing a hall effect sensor to measure the RPM of the flywheel and also an LM335 temperature sensor (it's a heat engine), and would like to add more temp sensors once I can get my head around the first problem.

Sorry if this has been asked before, but could not find the answer on the forum, to my needs.

I have connected the hall effect sensor output too pin17 (input 0) with the following code to my 18X:

main:
count 0, 5000, w1 ‘ count pulses in 2 seconds
debug w1 ‘ display value
goto main ‘ else loop back to start

This worked ok for a test when I passed the magnet in front of the sensor. The confusing part is whether to use the count or pules commands. The engine runs anywhere from 60 to 1000 RPM depending on the amount of heat applied and other variables. Can anyone suggest the best code to use, and the maths involved?

I would also be interested in any program that can display the results on the screen in a nice looking format, RPM and Temp gauges if any available,

Thank in advance for any help,

Kind regards

Smuttley (Steve)
 

Rickharris

Senior Member
Count has a MAX RPM of 1500 RPM when clocked at 4 Mhz so assuming a single magnet you should be within this range.

Is the magnet close enough to the hall effect to trigger it.

most small engine builders use a reflective sensor (IR or light) to avoid the ballance issues of attaching magnets.

For display why not use an LCD screen or a 7 seg display unless you need / want an analogue type display.

For an analogue display you could use a ring of LEDs and a suitable LED driver or build an analogue display driven by a modified servo.

http://www.mikesflightdeck.com/DIY_servo_instruments.htm

for example.





Your code although basic should give you a reading.
 

hippy

Ex-Staff (retired)
@ Rickharris : Count has a MAX RPM of 1500 RPM when clocked at 4 Mhz

I think there's a maths error there or I'm not understdanding how you mean. I thought count was capable of something like 25kHz, which would good for detecting over a million RPM ( one pulse per revoluton ).

@ SMUTTLEY : I'd geenrally use COUNT. With PULSIN you have to deal with f=1/t where witha COUNT for one second will give an RPS as is, COUNT for 60 seconds any you get RPM ( assuming one pulse per revolution ).

The downside is the slow RPM's you are looking at which means timing for a long period to get an accurate result, and you cannot do anything else during that time. Even if using PULSIN to measure the passing of the sensor, at 60 RPM you'll have to wait a second for each pulse to appear. You can add extra magnets to the flywheel which will make things easier.

As to what's best and maths to do it - What resolution and accuracy do you want to determine RPM to, how often must the display be updated ?
 

westaust55

Moderator
@ Rickharris : Count has a MAX RPM of 1500 RPM when clocked at 4 Mhz

I think there's a maths error there or I'm not understdanding how you mean. I thought count was capable of something like 25kHz, which would good for detecting over a million RPM ( one pulse per revoluton ).
The 25kHz is what the manual states.

For what it is worth, with a PICAXE 18X at 4MHz, I have managed to accurately count a 32,768 kHz signal from another IC.
 

lanternfish

Senior Member
As a suggestion, if you want to stick with hall effect sensing then put 4 magnets equidistant around the flywheel(?). This gives you four pulses per revolution (or parts thereof). And keeps the flywheel balanced.

Cheers
 

SMUTTLEY

New Member
Speed will not be the issue for us, as we only want to measure RPM over time with relationship with temperature variations, I think the flow would be something like this:

MAIN:
count pulses within 1 second (or more)
pulses X 60 = RPM
hold that data on PC screen : Is this possible guys?

Take temp 1
Hold that on PC screen
Take temp 2
Hold that on PC screen

Goto MAIN : do it over again

So not important to get fast feed back on temp or RPM, just the relationship between the two and how this effects performance. The engine has a hot and also a cold cylinder, the hotter the hot side and also the colder the cold side increases speed (differential temperature engine). So the test is for testing different heating and cooling for the engine.

Is the logic ok you think, and what would you suggest for the best code in the program, in regards to RPM?

Thanks for helping with this,

Smuttley
 

MPep

Senior Member
You should be able to use SEROUT or SERTXD to send the data to a computer. Look up the commands in the manual.
For your info: many people use SERTXD instead of DEBUG to obtain just the info that they are after. (rather than a collection of all the registers).
In fact, if you use SERTXD, then the programming cable can be left in place.

Within your code if you add the following line:
Code:
#terminal 4800
(change to whatever Baud rate you need), then the PE terminal will automatically open, once the program is downloaded.

For an "analogue" display, try this : Click here.

A question for you: why use a LM335? Temp range is -40 to +100 degrees Celsius.
If you use the DS18B20 (temp range -50 to +125), then you can have the required temperatures directly in digital format. Much easier to use, if you use the "readtemp" or "readtemp12" commands. Which one you use depends on the accuracy required.

My 2c worth.:)
 

westaust55

Moderator
Using the Programming Editor, if you press F8 you open a terminal window and the SERTXD command that MPep has mentioned will display the data you send in that terminal window.

How many temperature sensors are you ultimately intending to connect?

Do you intend to record and graph the data?
If not, then why not however consider an LCD module as a display. More portable to move from engine to engine and no mains power required.
Size of the LCD will depend on how many values you wish to display simultaneously.
 

SMUTTLEY

New Member
[/post].
A question for you: why use a LM335? Temp range is -40 to +100 degrees Celsius.
If you use the DS18B20 (temp range -50 to +125), then you can have the required temperatures directly in digital format. Much easier to use, if you use the "readtemp" or "readtemp12" commands. Which one you use depends on the accuracy required.

My 2c worth.:)
I did not know they existed, but after reading about them here and other places, I have decided to order some from http://www.microzed.com.au/index.htm as I am in Western Australia. Thanks for telling me about them.

I would like to get the RPM coding done first and then when the DS18B20's get here, I will get cracking on that section.

Anyone do me a little code for the RPM?
 

westaust55

Moderator
I did not know they existed, but after reading about them here and other places, I have decided to order some from http://www.microzed.com.au/index.htm as I am in Western Australia. Thanks for telling me about them.
Altronics in Perth Also stock a fair range of PICAXE related items as well.
You pay a fraction more per PICAXE chip etc but if you live in Perth you avoid postage and can have them the same day.
 
Last edited:

tiscando

Senior Member
Simple, for every 1 sec and one pulse per rev at PICAXE clock speed of 4MHz:

Code:
#terminal 4800
 
symbol tenthous=b4
symbol thous=b5
symbol hunds=b6
symbol tens=b7
symbol units=b8
 
main:
COUNT speed_sensor_pin, 1000, w1    'count number of pulses in 1 sec
w1=w1*60    'convert RPS to RPM
 
BINTOASCII w1, tenthous,thous,hunds,tens,units     'convert value to ASCII characters ready to be sent to PC
SERTXD ("speed = ", tenthous,thous,hunds,tens,units, "RPM", 13,10)   'send RPM value to PC
goto main
Keep the programming cable connected to receive values to the PC's terminal on programming editor.
 
Last edited:

SMUTTLEY

New Member
I did not know they existed, but after reading about them here and other places, I have decided to order some from http://www.microzed.com.au/index.htm as I am in Western Australia. Thanks for telling me about them.
QUOTE]

Altronics in Perth Also stock a fair range of PICAXE related items as well.
You pay a fraction more per PICAXE chip etc but if you live in Perth you avoid postage and can have them the same day.
Thanks for that, just placed the order with Altronics to post them out to me:)
 

SMUTTLEY

New Member
Using the Programming Editor, if you press F8 you open a terminal window and the SERTXD command that MPep has mentioned will display the data you send in that terminal window.

How many temperature sensors are you ultimately intending to connect?

Do you intend to record and graph the data?
If not, then why not however consider an LCD module as a display. More portable to move from engine to engine and no mains power required.
Size of the LCD will depend on how many values you wish to display simultaneously.
Two sensor, one on the cold cylinder and one on the Ali support for the hot section, and one RPM.

Yes we would like to record the data and store this on the PC if possible, and as we are testing in our workshop, this will not be a problem being stationary. We most test the engine to the max as we are going to manufacture them here in Australia for sale here and overseas,

Smuttley
 

westaust55

Moderator
Fair enough then - the PC is the better option.

The PICAE can easily hold the three values, RPM, temp 1 and temp 2 and send then in a single SERTXD command to the PC via your existing programming cable to be visibile in the Terminal Window.
By adding some commas between text it is also possible from the Programming Editor to save the data in a comma delimited file that you can then read into Excel and graph or what ever you wish (within the limits of Excel).


EDIT:
@SMUTTLEY,

have just sent you a PM on this topic
 
Last edited:

MPep

Senior Member
I did not know they existed, but after reading about them here and other places, I have decided to order some from http://www.microzed.com.au/index.htm as I am in Western Australia. Thanks for telling me about them.
No problems. ALways a pleasure to help.:)

For those that haven't realised it: the LM335 is an analogue output temp sensor.
The DS18B20 has a digital output, for which the PICAXE range has its own command especially for it. Namely READTEMP and READTEMP12.
 

manuka

Senior Member
- as we are going to manufacture them here in Australia for sale here and overseas-
I'm a long time Stirling fan, & predictably you've now got my interest up - how about some details?! Stan.
 

SMUTTLEY

New Member
I'm a long time Stirling fan, & predictably you've now got my interest up - how about some details?! Stan.
No problem, I will fire the camera up and get some pics and maybe some film. I will install the sensors first, so others can see what and how it was done,

Steve
 

SMUTTLEY

New Member
I am soooo stupid. I wanted to get exact RPM and took the count like this:

count 0, 1000, w0 ‘ count pulses in 1 second
w0=w0*60
RPM=w0

But that will only give results with multiplications of, 60,120, 180, 240 and so on, and not the actual RPM. I am using one single hall effect sensor on a flywheel, so I will never get the correct speed reading using this, or is there a way or a calc I could use?

Just a note on the TEMP sensors, they work perfectly, so thanks to the guys for recommending them (DS18B20),

Regards

Steve
 

MartinM57

Moderator
With one pulse per revolution you are pretty limited for resolution, as you have found out.

You could measure for 2 seconds and multiply by 30, but then you won't get an update every second - and be limited to mutiples of 30...so you could measure for 10 seconds and multiply by 6....or if you want ultimate accuracy, measure for 60 seconds and mutiply by 1 :D But the updates would only be once per minute - probably "sub-optimal"

If:
- you absolutely can't get more than one pulse per rev
- you must update the display every second
- you want the answer to the nearest single rpm for the last second
... then you can't do it.

You could think about keeping the count for each second over the last, say, 10 seconds and doing a computation of these every second (i.e. averaging) ... the downside is that the display won't be for the last second only. So if the engine instantaneously stops, the display wouldn't go to zero until 10 seconds later.

Bottom line is that at such low rpm, given you apparent requirements, you need more than 1 pulse per rev...
 

SMUTTLEY

New Member
I guess you know of this German company IMHO (until I see better) the Rolls Royce of Stirlings, although NOt cheap.

http://www.stirling-technik.de/htmlpages/home_engl.htm
Yes, we know of them and they are unique in design, and very beautiful and a credit to there design.

Our engines are much larger and unlike many engines on the market will run for a very long time. We have tested one engine to run for at least 4 hrs per day, five days a week, and that has been going on for over five months now.

Our first engine is to be released soon, and will have a glass cylinder with a graphite piston. Keep an eye open for Willstead engines, coming soon.

If you can PM me with your private email address, I will send some pics for you,

Regards

Smuttley
 

SMUTTLEY

New Member
With one pulse per revolution you are pretty limited for resolution, as you have found out.
Time is not a limiting factor, as we only want to get a basic RPM reading, I have done the code this way:

count 0, 4000, w0 ‘ count pulses in 4 second
w0=w0*15
RPM=w0

So am now counting every 4 seconds *15, is this ok you think to get a better resolutions?

Smuttley
 

westaust55

Moderator
Looking at the PULSIN command, I don't believe you will do much better there.

Using at least 4 magnets around the flywheel will improve the situation but only to a limited extent.
 

BCJKiwi

Senior Member
As noted previously, to improve sensitivity to change and to report more frequently;
1. a lot more sensors required - improves resolution
2. shorter count period - more updates
3. some form of 'averaging' - to provide smooth out fluctuating rpms.

e.g. Have count working over a period of .5 sec (8MHz PICAXE), a 4 step fifo type buffer to average the readings and 20 targets.
This would give a count value of only 10 at 60 rpm but use it on machines at up to 6000 rpm but is still only giving a very low value for count.

What does the flywheel or any other rotating part look like? Do any have spokes or holes or can a reflective tape be applied anywhere?

Above application uses automotive detailing chrome tape cut to 3mm wide and the Rohm RPR-220 reflective sensor.

Better results would be achieved with pulsin at slow rpm but again more sensors would be needed.
 

SMUTTLEY

New Member
As noted previously, to improve sensitivity to change and to report more frequently;
1. a lot more sensors required - improves resolution
2. shorter count period - more updates
3. some form of 'averaging' - to provide smooth out fluctuating rpms.

e.g. Have count working over a period of .5 sec (8MHz PICAXE), a 4 step fifo type buffer to average the readings and 20 targets.
This would give a count value of only 10 at 60 rpm but use it on machines at up to 6000 rpm but is still only giving a very low value for count.

What does the flywheel or any other rotating part look like? Do any have spokes or holes or can a reflective tape be applied anywhere?

Above application uses automotive detailing chrome tape cut to 3mm wide and the Rohm RPR-220 reflective sensor.

Better results would be achieved with pulsin at slow rpm but again more sensors would be needed.
The flywheel is 120mm diameter and currently has 10 holes in it, and I could install a reflective disk on the side of the wheel or even better, machine a new flywheel with as many holes on the outer rim as needed, and then use a photo transistor. So the more holes the better for accuracy, yes?

See attched pic of engine.
 

Attachments

Last edited:

tater1337

Member
The flywheel is 120mm diameter and currently has 10 holes in it, and I could install a reflective disk on the side of the wheel or even better, machine a new flywheel with as many holes on the outer rim as needed, and then use a photo transistor. So the more holes the better for accuracy, yes?

See attched pic of engine.
since you are using a hall effect sensor and a magnet, why not just add more magnets? did I miss a post on this?
 

papaof2

Senior Member
since you are using a hall effect sensor and a magnet, why not just add more magnets? did I miss a post on this?
A single photosensor pair doesn't require accurate positioning on the circumference of the wheel for balance (the holes are already evenly spaced); a photosensor will also work with a (nearly) unlimited number of holes. A modulated IR beam is relatively immune to outside interference and there's nothing that can come off the flywheel at maximum speed...

John
 

BCJKiwi

Senior Member
Yes, the more sensors the better.
Word value maxes out at 65535 so at 1000 rpm that is 16.66' rpsec, 8.33' per half second. 65535/16.66' means there would have to be 3932 sensors before W maxed out. So it is pretty clear that to get usable count values a lot of sensing actions per rev are required. The lower the revs, the more sensing actions per rev.

Is the flywheel brass or plated steel?
If plated steel you may run into problems when the magnets are inserted into drilled holes - the effective magnetic field will reduce dramatically - some testing required.

Through holes would be an issue as a sender/receiver would be required across the flywheel and may not be unobtrusive on the finished machine.

Reflective strips would be better - easy to put say 100 3mm wide reflector/3.x mm gap in that sort of circumference. Just need to shroud the sensor area to maximise light/dark in all lighting conditions.

Pulsin works the other way around. With a single sensor, the slower the RPM, the higher the pulsin value between pulses. At 60 rpm (1 rpsec) at least two sensing actions per rev would be required as pulsin times out at .655 sec (@4MHz clock - less time at higher clock speeds). Sure there is some math to convert back to rpm but that is just a subroutine.
 
Last edited:

SMUTTLEY

New Member
since you are using a hall effect sensor and a magnet, why not just add more magnets? did I miss a post on this?
The engine has a Brass flywheel, although it is slightly magnetic, sticking lots of magnets around the wheel will be a problem,

Smuttley
 

SMUTTLEY

New Member
As this is one of our test engines, I can knock up a bridge or "C" section that sits over the wheel. IR beam on one side and the sensor on the other and use the existing 10 hole flywheel, I will post back with results.

Just on the UGN3503LT hall effect sensor, the magnet has to be on it's edge, so as to pull from high to low pules, if you have it either north or south facing, then it will not pull from one state say high back to low again,
 

BCJKiwi

Senior Member
The hall effect unit that you have is ratiometric. That means the output changes with the strength of the magnetic field.

There are units which have switching built in (as does the Rohm rpr-220 referred to above). Switched types cost virtually the same amount but have the advantege of a step response and are simpler to set up and give a good clean square wave type pulse output.

If the sensor is changed recommend you use a switched type.

Alternatively you could use the hall effect you have and stick the magnet on the back of it. Machine a toothed disk from steel and mount it on the shaft between the frame and flywheel. The steel teeth passing the front of the Hall effect will alter the magnetic field seen by the hall effect. A large number of teeth are simple to arrange when the teeth are cut in the disc.

This is how car wheel rpm are sensed for ABS and KPH etc.
 
Last edited:

SMUTTLEY

New Member
The hall effect unit that you have is ratiometric. That means the output changes with the strength of the magnetic field.

There are units which have switching built in (as does the Rohm rpr-220 referred to above). Switched types cost virtually the same amount but have the advantege of a step response and are simpler to set up and give a good clean square wave type pulse output.

If the sensor is changed recommend you use a switched type.

Alternatively you could use the hall effect you have and stick the magnet on the back of it. Machine a toothed disk from steel and mount it on the shaft between the frame and flywheel. The steel teeth passing the front of the Hall effect will alter the magnetic field seen by the hall effect. A large number of teeth are simple to arrange when the teeth are cut in the disc.

This is how car wheel rpm are sensed for ABS and KPH etc.
Thanks for that BCJKiwi, did have me stumped for a bit why the picaxe would not see the high state, but found after a google, that the magnet had to be on its edge, or as you say needs to swing from North and South to go from high to low.

Thanks again,

Smuttley
 
Top