PDA

View Full Version : Way



jetpr
- 20th August 2007, 14:19
This work
if (RPM > 3) then
low Estarter
else
high Estarter
pause 100
endif

this no work

if (RPM <= 3) then
high Estarter
pause 100
low Estarter
endif

Bruce
- 20th August 2007, 14:27
Is rpm less than or equal to 3 when it doesn't work?

jetpr
- 20th August 2007, 17:05
This work
if (RPM > 3) then
low Estarter
else
high Estarter
pause 100
endif

this no work

if (RPM <= 3) then (when is less the 3)
high Estarter
pause 100
low Estarter
endif

mackrackit
- 20th August 2007, 17:55
IF THEN with out an else has to have the THEN condition on the same line. This should work assuming "Estarter" is a Label or Statement.


if (RPM <= 3) then high Estarter
pause 100
low Estarter

Bruce
- 20th August 2007, 21:26
It should work fine as-is, but if you expect to see the LED blink, you would probably
want a short pause after each logic state change.

I.E.;



RPM VAR BYTE
SYMBOL Estarter = PORTB.0
PORTB.0=0
TRISB.0=0

Main:
for RPM = 0 TO 255
if (RPM > 3) then
low Estarter
pause 100
else
high Estarter
pause 100
endif

if (RPM <= 3) then
high Estarter
pause 100
low Estarter
pause 100
endif
next RPM
goto Main

END
This definitely works. LED blinks 4 times on each pass through the loop.

Darrel Taylor
- 21st August 2007, 02:01
I'm thinking they weren't meant to be in the same program.
They are attemping to do the same thing, 2 different ways.


This work

if (RPM > 3) then
low Estarter
else
high Estarter
pause 100
endif
this no work

if (RPM <= 3) then
high Estarter
pause 100
low Estarter
endif

In which case, the second example is simply missing the else...
if (RPM <= 3) then
high Estarter
pause 100
else
low Estarter
endif