Creating a "standby" delay until rated RPM is reached using coding.

si_90

New Member
Hi all,

For my project at college I am doing a shaft "Overspeed/Underspeed RPM indicator" using an CHI030B project board, IR Sensor and displaying RPM and the respective speed condition on a LCD. I'm currently using 2 LED's, red for "Overspeed/Underspeed" and green for "NORMAL". I'm currently using 4 speed conditions.

At the moment, at start up due to being in the range of "Underspeed" the red LED will illuminate highlighting that there is an underspeed condition. Is there anyway I can delay this alarm until after rated speed is achieved of the motor? I'm looking to include a flashing amber LED indicating that the motor has just started and is approaching rated speed. This is my finalised coding for the project:

symbol LCD = B.2 ; change name of pin to LCD
symbol irsensor = C.7 ; change name of pin to irsensor

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 0.5 sec
w2=w1*120/9 ; formula for RPM
serout LCD, N2400, (254, 192) ; move to start of second line
serout LCD, N2400, (" RPM:",#w2," ") ; display RPM values
serout LCD, N2400,(254,128) ; first row of the first line


OVERSPEED:

if w1 < 12 then NORMAL ; less than 12 pulses = normal
serout LCD, N2400,(254,128) ; first row of the first line
serout LCD, N2400,(" Overspeed ") ; print message
high B.7 ; Red LED on
low B.3 ; Green LED off
goto main ; return to start

NORMAL:

if w1 < 7 then UNDERSPEED ; less than 7 pulses = underspeed
serout LCD, N2400, (254, 128) ; first row of first line
serout LCD, N2400, (" Normal ") ; print message
low B.7 ; Red LED off
high B.3 ; Green LED on
goto main ; return to start

UNDERSPEED:

if w1 = 0 then STANDSTILL ; 0 pulses = stationary
serout LCD, N2400, (254, 128) ; first row of first line
serout LCD, N2400, (" Underspeed ") ; print message
high B.7 ; Red LED on
low B.3 ; Green LED off
goto main ; return to start

STANDSTILL:

serout LCD, N2400, (254, 128) ; first row of first line
serout LCD, N2400, (" Standstill ") ; print message
low B.7 ; Red LED off
low B.3 ; Green LED off
goto main


Is there anyway I can include a delay, such as within the first few moments of start up to avoid illuminating the RED LED for Underspeed?

Thanks a lot in advance

Steven
 

hippy

Ex-Staff (retired)
Could you not just put something like this before the main: label ... ?

Code:
waituntiluptospeed:
  count irsensor, 500, w1; ; count pulses from motor 0.5 sec
  w2=w1*120/9 ; formula for RPM
  if w2 < [i]whatever[/i] then waituntiluptospeed
You could even have "if time < 5 and w2 < whatever" to have it come out of the loop after 5 seconds in case it is running below speed.
 

si_90

New Member
Hi Hippy thanks for the prompt reply. Still no joy with this, is it better to enter code before the main? i tried something it and still no joy. I tried using the below code but it seems to skip underspeed all together now and when it goes w1 < 7 it goes straight to standby no matter what the if time command is.

NORMAL:

if w1 < 7 and time >5000 then UNDERSPEED
if w1 < 7 and time <5000 then STANDBY
serout LCD, N2400, (254, 128) ; first row of first line
serout LCD, N2400, (" Normal ") ; print message
low B.7 ; Red LED off
high B.3 ; Green LED on
goto main ; return to start


UNDERSPEED:

if w1 = 0 then STANDSTILL ; 0 pulses = stationary
serout LCD, N2400, (254, 128) ; first row of first line
serout LCD, N2400, (" Underspeed ") ; print message
high B.7 ; Red LED on
low B.3 ; Green LED off
goto main ; return to start

STANDBY:
if time > 5000 and w1 < 7 then UNDERSPEED
if w1 = 0 then STANDSTILL
serout LCD, N2400, (254, 128) ; first row of first line
serout LCD, N2400, (" Standby ") ; print message
high B.7
pause 400
low B.7
pause 400
low B.3
goto main

thanks again

Steve
 

AllyCat

Senior Member
Hi Steve,

The "time" variable is measured in seconds, so your code willl not work "as intended" until more than 1.5 hours has elapsed!

Do you want to suppress just the Red LED, or also the text to the LCD? Personally, I would introduce a "Flag" (any spare variable taking a value of 0 or 1 should be fine for your code). The flag is only set (=1, or "True") when your "starting condition" has been met and would be used as a condition for the Red LED being switched on.

Cheers, Alan.
 

si_90

New Member
Hi Alan

Oh dear haha, i'm just used to time variable being in mSecs ! I've taken that code out aswell and returned it as it was previously I may try it again.

At the moment at start up it says Underspeed and the red LED will come on, just as it should and is programmed to do at that speed. However I'm looking to create a "standby" , like for the first 5 seconds if w1 < 7 that the LED would flash and it say "standby" on the LCD rather than trigger "Underspeed". This would be the case until > 5 seconds if w1 is still < 7 then the "Underspeed" condition would appear. Basically giving it a chance to reach rated speed. How do i go about inserting the "flag" or is there an easier way?

Cheers

Steve
 

AllyCat

Senior Member
Hi Steve,

You already have a 5 second delay with the PAUSE 5000, so you may need to change or replace that.

If you wnat to suppress/flash the Red LED and send a different text message, then it probably makes more sense to include the appropriate (looping) code in the "initiate:" part of the Program (i.e. before the main: ) exactly as hippy suggested. Then "fall through" into "main:" when the required startup condition has been met (which is probably either the speed > minimum OR a time > some seconds.

But if you only wanted to flash the Red LED during the startup phase you might use something like:
Code:
symbol running = b10     ; flag to indicate the startup condition has been met
symbol REDLED = b.7
.......
init:
     running = 0      ; Or FALSE
.....
main:
....
    if w1 > 6 then
         running = 1    ; Or TRUE
    endif
....
    if w1 < 7 then            ; Underspeed
       if running = 1 then
           High REDLED
.....
        else                    ; Still starting up
            Toggle REDLED
            Pause 200        ; To ensure flashing isn't too fast
        endif
    endif
......
    goto main
Cheers, Alan.
 

si_90

New Member
Thanks alot folks that's me finally finished the project :)
Managed to get it working with the following code before "main:"

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 3000
count irsensor, 500, w1;
w2=w1*120/9
if time < 10 and w1 < 7 then STANDBY

STANDBY:

serout LCD, N2400,(254,128) ; first row of the first line
serout LCD, N2400,(" Standby ") ; print message
high B.7
pause 500
low B.7
pause 500
if time > 9 then main
goto STANDBY


Thanks again for your help guys

Steve
 
Top