code examples with remarks

I'm a hardware guy with no code experience.
I was wondering if some of you code people could post some examples with remarks?
Just the basics, so us non-coders can build upon it and understand the flow.

Thanks!!
 
Have you checked the user guide? There are some code examples on the programming section. Otherwise, tell us what you want to do, everyone can suggest how to do it.
 
That is easy to do,
start
tsteq ch 8 <--- check current hour is 8 AM
callsun ip1on <--- if true, call your next function
set var1 0 <--- clear flag, for next time to be able to call setop1 subroutine
end

ip1on:
tsteq ip1 0 <----- this is for your ip1 = 1 condition, put first check, since this is mroe general check
ret
tsteq cdw 2 <----- this is to check if this is Tuesday
ret
tsteq cdw 4 <---- this is to check if this is Thursday
ret
tsteq cdw 6 <---- this is to check if this is Saturday
ret
tsteq var1 0 <-----If this flag is zero, means the op1 has not been on yet
callsub setop1 <---- this will set op1
TSTEQ OP1[60000] 1 <---- set delay 60000 microseconds
SET OP1 0 <------- turn it off after delay.
nop <----- make sure to have this for the tsteq failed condition.
ret

setop1:
set var1 1 <---- this set up to prevent to call called again.
set op1 1 <-----turn this one on.
ret

I am sure a lot people have better way than this, but I think this will work
 
I would like to turn on op1 at 8:00 AM, for 1 minute, on Monday, Wednesday and Saturday's IF ip1 = 1.

I'd personally have done something far less complicated than the above example:

Code:
START    
    ANDB CDW 1 RAM1   # mon, wed, fri will have bit1=0
    MUL CH 3600 RAM2
    MUL CM 60 RAM3
    ADD RAM2 RAM3 RAM3
    ADD CS RAM3 RAM3  # get current second-of-day in RAM3
    TSTEQ RAM3 28800   # is current second exactly 8:00:00 ?
    XOR RAM1 1 OP1  # if so, set output 1 only on days with bit1=0
    TSTEQ RAM3 28860   # is current second exactly 8:01:00 ?
    SET OP1 0  # if so, turn off output
END
 
Oops, forgot "if inp1 = 1".

Code:
START   
        ANDB CDW 1 RAM1   # mon, wed, fri will have bit1=0
        XOR 1 RAM1 RAM1 # RAM1 is now '1' on days we want output 
        MUL CH 3600 RAM2
        MUL CM 60 RAM3
        ADD RAM2 RAM3 RAM3
        ADD CS RAM3 RAM3  # get current second-of-day in RAM3
        TSTEQ RAM3 28800   # is current second exactly 8:00:00 ?
        AND RAM1 IP1 OP1  # if so, set output only if IP1=1 on required day.
        TSTEQ RAM3 28860   # is current second exactly 8:01:00 ?
        SET OP1 0  # if so, turn off output
END
 
Actually, on reflection, even that is more complex than it needs.
If you are only turning on for 1 hour between 8am and 9am (ie, 8:00:00 to 8:59:59) then this should work and is even simpler:
(it could be simplified further if you were prepared to invert IP1 in the configuration, or to turn on if IP1=0)
Code:
START
	 TSTNE CH 8 RAM1    # is it outside 8:00:00 to 8:59:59?
	 ANDB CDW 1 RAM2    # mon, wed, fri will have bit1=0
	 OR RAM1 RAM2 RAM1    # RAM1 is 1 if either condition is not met
	 XOR 1 RAM1 RAM1    # RAM1 is now '1' on days we want output between 8-9am
	 AND RAM1 IP1 OP1    # set or clear output
END
 
Back
Top