Novice question about using END twice (or more)

XRinger

Member
Here is some code that I'm trying out to control a fresh air fan in my basment (using X10)..
At the bottom of the main body, it calls the subroutine CALLER, with the next command being END..
 
CALLER starts off testing the hour of the day, to see if it's after 8AM. (don't want fan noise too early).
If it's after 8AM, it skips the next command, (END #2) and starts checking humidity etc..
After the last call in CALLER is done, it ends with RET, returns to the main body and hits the 'real' main body END.. 
 
But if it's before 8AM, it hits END (#2) and re-starts at START.. This end/restart keeps anything below it from executing.
 
Anyways, this seems to be working. So the question is, will it cause some error later many loops later?
 
Thanks,
Rich
 
 
START    
    DELAY 10   
    SET VAR6 0  
    SET VAR1 T1
    SET VAR2 T2
    SET VAR3 T3
    SET VAR4 H1
    SET RAM7 0  
    SET VAR7 0  
    MUL CH 60 RAM8
    ADD RAM8 CM VAR8
    CALLSUB CALLER   
    END    

CALLER:
    TSTLE CH 7  
    END    

    TSTGT H1[200] 79  
    CALLSUB FAN_OFF   
    TSTLE H1[200] 76  
    CALLSUB FAN_ON   
    RET    

FAN_ON:
    X10 2 7 ON
    SET OP1 1  
    SET RAM7 900  
    CALLSUB TIME10   
    SET RAM7 0  
    RET    

FAN_OFF:
    INC VAR6   
    X10 2 7 OFF
    SET OP1 0  
    SET RAM7 900  
    CALLSUB TIME10   
    SET RAM7 0  
    RET    

TIME10:
    SET VAR7 0  
MIDEE:
    DELAY 1000   
    TSTEQ VAR7 RAM7  
    RET    

    INC VAR7   
    GOTO MIDEE   
 
 
I am not sure the 2nd end will cause any problems but I am wondering why can't you use GOTO START in place of the second end? Just curious.
 
TJF1960 said:
I am not sure the 2nd end will cause any problems but I am wondering why can't you use GOTO START in place of the second end? Just curious.
 
Subroutine names are marked with a colon:  indicating a Label. whereas START and END aren't. But, the GOTO START does work.
I changed the lines to:
TSTLE CH 17  
GOTO START
and got looping in the main. Changed it to
 
TSTLE CH 7  
GOTO START 
And it's working as before..
 
If this doesn't over-flow some register and crash, these commands would make life easier for non-programers like me.. :)
 
The send END will cause program jump to START next line.  Your code is equivalent to
START    
    DELAY 10   
    SET VAR6 0  
    SET VAR1 T1
    SET VAR2 T2
    SET VAR3 T3
    SET VAR4 H1
    SET RAM7 0  
    SET VAR7 0  
    MUL CH 60 RAM8
    ADD RAM8 CM VAR8
    TSTLE CH 7  
    END  
 
when CH is 7
Please try to limit only use END once, so that it is clear what you really want to do.
 
Thanks for the reply.  Out of curiosity, I ran it overnight with:
CALLER:
    TSTLE CH 7  
    END   
 
This morning after 9AM with dropping humidity, the fan didn't come on.
When I looked at the display, there was no incrementing VAR7 counter occurring.
 
So, I assumed the END branch was the hang-up. It stalled.
Changed END to GOTO START and it starting working again.
 
Tomorrow is going to be another dry day.. :)
 
Cheers,
Rich
 
Because with that END, it will never run any other PLC code.
If you could put together a flowchart you will see where you logic flows clearly.
 
Thanks, for the relies. I'm trying to learn what works and what doesn't. I used to do some simple programing at work, (Basic, & C) but that was very long ago.
Never used PLC before, but I'm really starting to like it.  I love the way the time of day is segmented up and ready to use.
Not doing a flow chart yet, still learning the basics.
 
My Project goal, is to monitor outdoor humidity & 4 temperature sensors,  two DC current sensors (pwr from 2 solar panel arrays),
and use the data to control one basement fresh air blower, one solar hot air blower and one ASHP (A7 Airtap air source heat pump) hot water heater.  
 
Now I'm trying out a new Caller: with extra RETs..
Finding out if extra RETs in a subroutine will cause it to hang.. It looks okay so far (after 20 hours).
 
 
CALLER:
    TSTLE CH 7  
    RET    

    TSTGT CH 17  
    RET    

    TSTGT H1[200] 79  
    CALLSUB FAN_OFF   
    TSTLE H1[200] 76  
    CALLSUB FAN_ON   
    RET  
 
It is probably the extra RET caused logic looping in a small range with no action, so that it looked like hang. 
There is only one CPU running everything, if it was hang, then you would not able to do anything with the board.
 
Back
Top