Some help programming :)

olech

New Member
Hei, im trying to program 2 fans to cool my room.

The 2 fans are controlled by 2 relays.

i have a push button to, to turn off the fans. The push button is momentary, or RESET button for a old computer :)

The fans turn on when the value is higher then 24c and turn off at 23,5.

But if i turn off the fans at 25Degc, it will automatic turn it self on again... Goes back to START.

START
TSTGT T3 240
CALLSUB VIF1_ON
TSTLE T3 235
CALLSUB VIF1_OFF
TSTEQ IP8 1
CALLSUB BUTT_NF
END

VIF1_ON:
SET OP4 1
SET OP5 1
RET

VIF1_OFF:
SET OP4 0
SET OP5 0
RET

BUTT_NF:
TSTEQ OP4 1
GOTO BUTT_OFF
TSTEQ OP4 0
GOTO BUTT_ON
RET

BUTT_ON:
TSTGT T3 240
AND IP8 1
SET OP4 1
SET OP5 1
NOP

BUTT_OFF:
SET OP4 0
SET OP5 0
DELAY 2000


Must i make a loop? to hold it 0 until i push it again.?


Thanks for advice.
 
TSTGT T3 240

i do not want to make this TSTEQ. It will solve the problem from my point off view.
But it will not start again, if the temp gets higher then 240 = 24 degc. :/
 
Hi Olech,

In your code, you have this section:
BUTT_ON:
TSTGT T3 240
AND IP8 1
SET OP4 1
SET OP5 1
NOP

BUTT_OFF:
SET OP4 0
SET OP5 0
DELAY 2000

your logic will from BUTT_ON fall through BUTT_OFF. Is that what you want? Please state what you want to do, so that we can see clearly what you want the logic flow. We can help you on this forum for getting it work.
 
This Works.. But it sound like the relays hurts.. It loops so fasr.

START
TSTGT T3 240
CALLSUB VIF1_ON
TSTLE T3 235
CALLSUB VIF1_OFF
TSTEQ IP8 1
CALLSUB BUTT_NF
END

VIF1_ON:
SET OP4 1
SET OP5 1
RET

VIF1_OFF:
SET OP4 0
SET OP5 0
RET

BUTT_NF:
SET OP4 0
SET OP5 0
GOTO BUTT_INN
NOP

BUTT_INN:
TSTGT IP8 0
GOTO START
GOTO BUTT_INN

END
 
To my knowledge, there is no way to have the fans turn on/off with temp and a button. I could see it working with two buttons. One would be to turn them on/off and the other sets a ram that lets the board run the temps. Better yet a three way switch. Position one would be off, position two would be on and positon 3 would use the temps for fan control. Using a three way switch is the way I would go with it. You could set rams according to switch position which runs with logic is being used to control the fans.

This is my code for relays and it works great for me.

ON:
SET OP1 1
DELAY 500
SET OP1 0
SET RAM2 1
DELAY 250
RET

OFF:
SET OP2 1
DELAY 500
SET OP2 0
SET RAM2 0
DELAY 250
RET
 
If you want to use momentary switch to turn on and off fans, you could do it with additional logic to check the button is pushed, then call a sub routine to toggle a RAM value from 0 to 1 and from 1 to 0. Then in your main logic part, first check to see if this RAM state is 1, then check the temperature, etc.

I realized this seciton of your code is for debounce the pushbutton, so that util operator released button, it will keep loop there:
BUTT_INN:
TSTGT IP8 0
GOTO START
GOTO BUTT_INN

If you want to have manually turn off the fan than the fan would stay off, even temprature is beyond the 24C, then you will need to check a RAMx condition after START. Set a RAMx as a flag to indicate someone already pushed start/stop button. Then in your BUTT_NF subroutine to toggle the RAMx state. If you want this manual turn off only working during the day, you can select a time to reset RAMx at that hour in your logic. Or you can make it reset this manual off flag RAMx only when temperature is blow certain degree.
 
Exactly. :)

Today i have added 3 lights into the picture and a Alarm. But i can't make any god alarm setpoints.. and i do not understand the RET and NOP commands.

Need help to make it better.

Fans Turns on 24DegC
Fans Turns off 23,5DegC

When the TEMP/DegC hits 23.5 my first LED light will light.
At 24,3 TEMP/DegC my second LED will light
At 25,5 TEMP/DegC my third LED will light
At 26,5 my Alarm will go on.
Same other way...
At 26 DegC my alarm will go off
And So on...

And got a 2 way switch today. ON OR OFF. not an momentary.
Is it possible to end the loop if its above 24,1 DegC and turn off the light.

When i go to bed, this will help.
Thanks for advice.

START
TSTGT T3 240
CALLSUB VIF1_ON
TSTLE T3 235
CALLSUB VIF1_OFF
TSTGE T3 235
CALLSUB LIGHTS
TSTEQ IP8 1
CALLSUB BUTT_NF
TSTGT T3 265
GOTO ALARM
END

VIF1_ON:
SET OP4 1
SET OP5 1
RET

VIF1_OFF:
SET OP4 0
SET OP5 0
SET OP6 0
RET

LIGHTS:
SET OP6 1
TSTGE T3 242
CALLSUB LIGHTS2
TSTLT T3 234
GOTO START
LIGHTS2:
SET OP7 1
TSTGE T3 255
CALLSUB LIGHTS3
TSTLT T3 239
CALLSUB LIG2
LIG2:
SET OP7 0
GOTO LIGHTS
LIGHTS3:
TSTGE T3 265
CALLSUB ALARM
TSTLT T3 253
CALLSUB LIG3
ALARM:
SET OP8 1
TSTEQ OP2[500] 0
SET OP2 1
TSTEQ OP2[500] 1
SET OP2 0
TSTLE T3 260
GOTO LIGHTS3
GOTO ALARM
GOTO START
END

LIG3:
SET OP8 0
SET OP2 0
GOTO LIGHTS2
SHOW:
GOTO START
RET

BUTT_NF:
SET OP4 0
SET OP5 0
GOTO BUTT_INN
BUTT_INN:
TSTEQ IP8 0
CALLSUB SHOW
GOTO BUTT_INN
NOP
 
And the OP7 keeps flashing when i hit refresh button on webcontrol. Site.. Need more power`?
 
I'm new to this (just received my WebControl yesterday), but looking at the structure of your program, I see some things that I'd work towards changing.

The main body of the program begins with START, and ends with END. That's fine.

But your subroutines should begin with the subroutine name, and end with RET. You have some that end with a GOTO, end with a NOP, or end with an END. That's not the right form for the subroutines. The RET will return the program execution to the point from which it was called. For example, your CALLSUB V1F1_ON is correct - your execution branch will jump to the subroutine V1F1_ON, and then return to your main program once V1F1_ON is complete. Your other subroutines will get lost with all those gotos and NOPs.

NOP is no operation. In the manual, it seems to be used when you have a conditional test and only need to store the contents of the test in a variable (since the conditional test uses the 'next line' if it's true, and skips the next line if it's 'false'). If you have a NOP after a TSTEQ line, for example. In "plain english", this would look like:

If (variable 1) is equal to (variable 2) then store a "1" in RAM1 memory location
NOP (skipped if v1 != v2, otherwise it doesn't do anything)
next line of code...

So I think you need to go through your code, turn your subroutines in to the proper structure (with a

NAME:
{code}
RET

format, and then go from there. And try to get rid of the GOTO jumping around and use callsubs instead.
 
NOP is useful when you having a test condition that is last line of your code. For example, if you have a program:
START
do thing one
do thing two
do thing three
tstgt ram3 10 ram4
NOP
END

If you don't have NOP in that code, when tstgt not true, it will skip next instruction. Which is the next instruction?
do thing one
will be skipped. That may not what you wanted.
 
Thanks :)

This works well-

START
TSTGE T3 240
CALLSUB VIF1_ON
TSTLE T3 235
CALLSUB VIF1_OFF
TSTGE T3 236
CALLSUB LIGHTS
TSTEQ IP8 1
CALLSUB BUTT_NF
TSTGT T3 265
GOTO ALARM
END

VIF1_ON:
SET OP4 1
SET OP5 1
SET OP7 1
CALLSUB LIGHTS2
CALLSUB LIGHTS3
CALLSUB LIGHTS4
TSTGE T3 255
CALLSUB LIGHTS3
RET

VIF1_OFF:
SET OP4 0
SET OP5 0
SET OP6 0
SET OP7 0
SET OP8 0
SET OP2 0
RET

LIGHTS:
SET OP6 1
RET

LIGHTS2:
TSTLE T3 239
SET OP7 0
RET

LIGHTS3:
TSTLE T3 254
SET OP8 0
RET

LIGHTS4:
TSTLE T3 264
SET OP2 0
RET

ALARM:
SET OP8 1
TSTEQ OP2[500] 0
SET OP2 1
TSTEQ OP2[500] 1
SET OP2 0
RET

SHOW:
GOTO START
RET

BUTT_NF:
SET OP4 0
SET OP5 0
GOTO BUTT_INN
BUTT_INN:
TSTEQ IP8 0
CALLSUB SHOW
GOTO BUTT_INN
NOP
 
Im just wondering.. Is it possible to see posistion off my garage and door? like if its open or not?

Do someone know where to buy these switches?

if motion sensor, does it work with CAI?

is there something called 5 volt relay to 12 volt? :) i do not know what voltage my garage opener is.. but i guess ~10-230v :p
 
Im just wondering.. Is it possible to see posistion off my garage and door? like if its open or not?

Do someone know where to buy these switches?

if motion sensor, does it work with CAI?

is there something called 5 volt relay to 12 volt? :) i do not know what voltage my garage opener is.. but i guess ~10-230v :p

Normal garage door alarm contacts is what you need. Hook the 5v source on the cai board up to one lead and connect the other lead to the cai digital input. When the door is closed, it closes the circuit and feeds 5v back into the cai input which will then indicate "1". When the door opens, it will indicate "0".

If you want cai to be able to control the garage door, use a ttl relay connected a cai output. Run a wire to the two contacts on your garage door opener from the relay. When cai powers the relay, it closes the contacts which is the same as pushing the garage door button.
 
Back
Top