Displaying RPM on LCD Module rather than pulses per second.

si_90

New Member
Hello,

I am just looking for some help regarding the final part of my project at college. Using a IR sensor (IR LED, Phototransistor) I am feeding the pulses picked up from reflective markers on the motor disc into the 18M2 Project Board using the COUNT command;

count irsensor, 1000, w1; ;count pulses from motor over second

Depending on the amount of pulses picked up from the markers with varying speed, I am looking to display an RPM value on my LCD screen, with a varying speed condition (Standstill, Underspeed, Normal, Overspeed).

Currently I am seeing a smooth transition through the conditions when I adjust the speed the motor, however the value that is being displayed on the motor is pulses per second rather than RPM. On my motor there are 9 reflective markers per revolution, I have attempted to write a formula based on the variable: (w1=w1/9*60) However the LCD doesn't appear to respond correctly. My program is relatively short:

initiate:

pause 500
serout LCD, N2400, (254,1) ; clear display for startup
serout LCD, N2400, (254, 128) ; move to start of first line
serout LCD, N2400, (" Shaft RPM ") ; Print message Shaft RPM
pause 5000

main:

serout LCD, N2400, (254, 192) ; move to start of second line
serout LCD, N2400, (" RPM:",#w1) ; display pulse values
count irsensor, 1000, w1; ;count pulses from motor over second


OVERSPEED:

if w1 < 24 then NORMAL ; less than 25 pulses = normal
serout LCD, N2400,(254,128) ; first row of the first line
serout LCD, N2400,(" Overspeed ") ; print message
goto main ; return to start

NORMAL:

if w1 < 14 then UNDERSPEED ; less than 14 pulses = underspeed
serout LCD, N2400, (254, 128) ; first row of first line
serout LCD, N2400, (" Normal ") ; print message
goto main ; return to start

UNDERSPEED:

if w1 = 0 then STANDSTILL
serout LCD, N2400, (254, 128)
serout LCD, N2400, (" Underspeed ")
goto main

STANDSTILL:

serout LCD, N2400, (254, 128)
serout LCD, N2400, (" Standstill ")
goto main


Is there any way to display RPM rather than pulses per second? The model of motor I'm using is very old, I have emailed the company with regards to specs but they couldn't help. Its a DC permanent magnet servo motor, I am adjusting the speed with a varying power supply (0-15V).IMG_1217.JPGIMG_1283.JPG

Thanks a lot in advance

Steven
 

erco

Senior Member
What's the estimated RPM? Any chance you're overflowing past 65535? Probably not. This is likely an LCD error.

I'd suggest first using DEBUG or SERTXD to display your calculated RPM onscreen to verify your math is correct, then sort out your LCD problem.

You are counting for a full second (1000 ms) but of course you can probably count for a much shorter interval (changing the math accordingly) to sample more often.

Edit: I see that 14-24 PPS is normal. Nice & slow, should be easy to do. Assuming your LCD commands are right, try this:

Code:
initiate:

pause 500
serout LCD, N2400, (254,1) ; clear display for startup
serout LCD, N2400, (254, 128) ; move to start of first line
serout LCD, N2400, (" Shaft RPM ") ; Print message Shaft RPM
pause 5000

main:
count irsensor, 1000, w1; ;count pulses from motor over second
w2=w1*60/9
serout LCD, N2400, (254, 192) ; move to start of second line
serout LCD, N2400, (" RPM:",#w2) ; display pulse values

serout LCD, N2400,(254,128) ; first row of the first line

OVERSPEED:

if w1 < 24 then NORMAL ; less than 25 pulses = normal
serout LCD, N2400,(" Overspeed ") ; print message
goto main ; return to start 

NORMAL:

if w1 < 14 then UNDERSPEED ; less than 14 pulses = underspeed
serout LCD, N2400, (" Normal ") ; print message
goto main ; return to start

UNDERSPEED:

if w1 = 0 then STANDSTILL
serout LCD, N2400, (" Underspeed ")
goto main ; return to start 

STANDSTILL:

serout LCD, N2400, (" Standstill ")
goto main
 
Last edited:

hippy

Technical Support
Staff member
I have attempted to write a formula based on the variable: (w1=w1/9*60)
It could be that you have fallen victim to the way PICAXE limits numbers to integers and performs maths strictly left to right.

If you rewrite your equation as w1=w1/9/60 that may give you better results but that may always give you a low reading. Perhaps try w1=w1/9 first to get RPS.
 

si_90

New Member
Thanks a lot I got it to display the the speed condition with respect to the calculated RPM.

0 Standstill
0-93RPM Underspeed
93-160 RPM Normal
>160RPM Overspeed

I used the display w2 variable which seems to have done the trick. One more thing, I have reduced the count duration to 500 ms, and changed the maths respectively in a bid to make the transition through the numbers more sensitive to changes in speed. It seems to be quite laggy, its not very sensitive to smaller changes in speed, and when i reduce the speed its as if the values on the LCD lag, for example at the moment its reading "standstill" however the value of RPM being shown is 036. Appears to be stuck unless is a reset the LCD completely.

Thanks a lot in advance again guys.

Steven
 

erco

Senior Member
Steven: It shouldn't be laggy or stick at 036. You may be confusing w1 and w2 in your program. Please attach your entire new program so we can assist.
 

si_90

New Member
Hi erco

The text is correct for the standstill position, its the rpm variable number that is displayed that appears to be lagging as the speed comes back down, it is fine on the way up. The value looks fine until it reaches over 100 RPM, as it goes below 100 the last digit appears to stick. I have basically just halfed the count sample time and halfed the required pulses for each condition accordingly.

initiate:

pause 500
serout LCD, N2400, (254,1) ; clear display for startup
serout LCD, N2400, (254, 128) ; move to start of first line
serout LCD, N2400, (" Shaft RPM ") ; Print message Shaft RPM
pause 5000

main:

count irsensor, 500, w1; ;count pulses from motor over second
w2=w1*120/9
serout LCD, N2400, (254, 192) ; move to start of second line
serout LCD, N2400, (" RPM:",#w2) ; display pulse values

serout LCD, N2400,(254,128) ; first row of the first line


OVERSPEED:

if w1 < 12 then NORMAL ; less than 25 pulses = normal
serout LCD, N2400,(254,128) ; first row of the first line
serout LCD, N2400,(" Overspeed ") ; print message
goto main ; return to start

NORMAL:

if w1 < 7 then UNDERSPEED ; less than 14 pulses = underspeed
serout LCD, N2400, (254, 128) ; first row of first line
serout LCD, N2400, (" Normal ") ; print message
goto main ; return to start

UNDERSPEED:

if w1 = 0 then STANDSTILL
serout LCD, N2400, (254, 128)
serout LCD, N2400, (" Underspeed ")
goto main

STANDSTILL:

serout LCD, N2400, (254, 128)
serout LCD, N2400, (" Standstill ")
goto main


thanks again
 

AllyCat

Senior Member
Hi,

It's probably the issue which crops up regularly on the forum: When the speed drops below "100", the SEROUT sends only two digits to the LCD (e.g. "99") and leaves the third (was the "units") digit on the LCD.

If you have no other characters to the right of the digits then just change the serout to: serout LCD, N2400, (" RPM:",#w2," ") .

To keep the digits field of constant width you can add: if w2 < 100 then : serout LCD, N2400, (" ") : endif after the "RPM" serout command , and then again for w2 < 10 .

Or to display the digits "right justified" (i.e. with units always at the same cursor position), use the BINTOASCII command and send the digits individually as say: serout LCD, N2400, (" RPM:",b5,b6,b7) where b5 and b6 might be shown as zeros (i.e. not spaces).

Cheers, Alan.
 

erco

Senior Member
Good to hear, Steven. Per Alan, an LCD must "paint over" old 3-digit numbers with spaces, before or after a lesser digit number.
 
Top