ADICON Support Forum Applied Digital, Inc.
Page 1 of 2 12>
Topic Options
#17152 - 01/18/07 02:39 PM Code for Blinds - SECU16
Andre Ramos Offline
newbie


Registered: 02/21/03
Posts: 23
Loc: Portugal Europe
I'm trying to control 24 Blinds using 6 ea SECU16. I've got the wiring on the SECU16 as:

Input 0: Blind 1: UP Key
Input 1: Blind 1: DOWN Key
Input 2: Blind 2: UP Key
Input 3: Blind 2: DOWN Key
...
Relay 8: Blind 1: UP Motor
Relay 9: Blind 1: DOWN Motor
Relay 10: Blind 2: UP Motor
Relay 11: Blind 2: DOWN Motor

I've tried the following code:

1: IF Module #1 -SECU16 Input #0 Turns ON // Up Key Press
2: AND Module #1 -SECU16 Relay #8 Is OFF // Test if UP Motor is OFF
3: THEN Module #1 -SECU16 Relay #9 Turn OFF // Ensure Down Motor is OFF
4: THEN Module #1 -SECU16 Relay #8 Turn ON // Turns UP Motor ON
5: THEN Skip to line 337 // Goto End of Program - Don't test more
6: ELSE Module #1 -SECU16 Relay #8 Turn OFF // "Else": Up Motor was ON, so Stop it
7: ELSE Skip to line 337 // End of Job concerning the Input #0 Keypress
8: IF Module #1 -SECU16 Input #1 Turns ON
9: AND Module #1 -SECU16 Relay #9 Is OFF
10: THEN Module #1 -SECU16 Relay #8 Turn OFF
11: THEN Module #1 -SECU16 Relay #9 Turn ON
12: THEN Skip to line 337
13: ELSE Module #1 -SECU16 Relay #9 Turn OFF
14: ELSE Skip to line 337
15: IF Module #1 -SECU16 Input #2 Turns ON
16: AND Module #1 -SECU16 Relay #10 Is OFF
17: THEN Module #1 -SECU16 Relay #11 Turn OFF
18: THEN Module #1 -SECU16 Relay #10 Turn ON
19: THEN Skip to line 337
20: ELSE Module #1 -SECU16 Relay #10 Turn OFF
21: ELSE Skip to line 337
22: IF Module #1 -SECU16 Input #3 Turns ON
23: AND Module #1 -SECU16 Relay #11 Is OFF
24: THEN Module #1 -SECU16 Relay #10 Turn OFF
25: THEN Module #1 -SECU16 Relay #11 Turn ON
26: THEN Skip to line 337
27: ELSE Module #1 -SECU16 Relay #11 Turn OFF
28: ELSE Skip to line 337

The above Code doesn't work... anybody would have a clue ?

Then I tried the following:
1: IF Module #4 -SECU16 Input #2 Turns ON
2: AND Module #4 -SECU16 Relay #10 Is OFF
3: THEN Module #4 -SECU16 Relay #11 Turn OFF
4: THEN Module #4 -SECU16 Relay #10 Turn ON
5: IF Module #4 -SECU16 Input #2 Turns ON
6: AND Module #4 -SECU16 Relay #10 Is ON
7: THEN Module #4 -SECU16 Relay #10 Turn OFF
8: THEN Skip to line 33 //
9: IF Module #4 -SECU16 Input #3 Turns ON
10: AND Module #4 -SECU16 Relay #11 Is OFF
11: THEN Module #4 -SECU16 Relay #10 Turn OFF
12: THEN Module #4 -SECU16 Relay #11 Turn ON
13: IF Module #4 -SECU16 Input #3 Turns ON
14: AND Module #4 -SECU16 Relay #11 Is ON
15: THEN Module #4 -SECU16 Relay #11 Turn OFF
16: THEN Skip to line 33
17: IF Module #4 -SECU16 Input #0 Turns ON
18: AND Module #4 -SECU16 Relay #8 Is OFF
19: THEN Module #4 -SECU16 Relay #9 Turn OFF
20: THEN Module #4 -SECU16 Relay #8 Turn ON
21: IF Module #4 -SECU16 Input #0 Turns ON
22: AND Module #4 -SECU16 Relay #8 Is ON
23: THEN Module #4 -SECU16 Relay #8 Turn OFF
24: THEN Skip to line 33
25: IF Module #4 -SECU16 Input #1 Turns ON
26: AND Module #4 -SECU16 Relay #9 Is OFF
27: THEN Module #4 -SECU16 Relay #8 Turn OFF
28: THEN Module #4 -SECU16 Relay #9 Turn ON
29: IF Module #4 -SECU16 Input #1 Turns ON
30: AND Module #4 -SECU16 Relay #9 Is ON
31: THEN Module #4 -SECU16 Relay #9 Turn OFF
32: THEN Skip to line 33
33: End Program

This one WORKS... but it's slow and sometimes I have to wait more than 2 seconds to see the motor responding.

Would anyone kindly help me getting an optimum code for this application ?

Thanks

Andre
_________________________
Freedom is having an ELSE for every THEN

Top
#17153 - 01/18/07 02:54 PM Re: Code for Blinds - SECU16 [Re: Andre Ramos]
Guy Lavoie Administrator Offline
Beyond All Hope
*****

Registered: 12/21/02
Posts: 6548
Loc: Montreal, QC, Canada
There is not much you can really do to speed it up. The delays you are seeing correspond to the bus communications latency. There is latency in both reading the buttons on the inputs and then sending output commands for the relays.

In the first non-working version of the program, the ELSE statments trigger for every program pass where a button is NOT pressed (ELSE means if the whole statement is false). This will try to send a bus command on every pass and the system may appear to freeze. The second program is the right way to do it.
_________________________
"If you don't know what you're doing, do it neatly..."

Top
#17154 - 01/18/07 04:48 PM Re: Code for Blinds - SECU16 [Re: Andre Ramos]
Dowser Offline
journeyman


Registered: 12/04/06
Posts: 73
Loc: Sweden
Not an answer to your question, but...

You don't seem to have any form of time-out for the motors, does the hardware take care of turning the motor of in the end-possitions?

Top
#17155 - 01/19/07 07:46 AM Re: Code for Blinds - SECU16 [Re: Dowser]
Andre Ramos Offline
newbie


Registered: 02/21/03
Posts: 23
Loc: Portugal Europe
The Motors have Switches for the end positions, this is no problem if they are powered continously.
Aditionally, the wiring to the motors goes through a circuit of 2 relays in order to ensure that only one channel (up or down) is powered.
_________________________
Freedom is having an ELSE for every THEN

Top
#17156 - 01/19/07 07:56 AM Re: Code for Blinds - SECU16 [Re: Guy Lavoie]
Andre Ramos Offline
newbie


Registered: 02/21/03
Posts: 23
Loc: Portugal Europe
Guy,

Thanks !
I'm an old fashioned "basic" programmer So I thought that my "ELSE" branches were "inside" the IF's. Now I realize that for structuring I need to use the skips all the time.

My main idea here is to reduce the "reads" in order to speed up each pass. As I have 2 buttons per double-winding motor (total 24 motors), I neet to test 48 buttons plus the status of each corresponding relay.

I will try now to "isolate" the buttons press by making a first read just on buttons, and only then, test the relay conditions.
I will post the results here if it works.

Thanks
_________________________
Freedom is having an ELSE for every THEN

Top
#17157 - 01/19/07 08:30 AM Re: Code for Blinds - SECU16 [Re: Andre Ramos]
Andre Ramos Offline
newbie


Registered: 02/21/03
Posts: 23
Loc: Portugal Europe
This is the code I will try:
0001 - IF Module #1 -SECU16 Input #0 Turns ON // Keypress Detected on M01-00: UP
0002 - ELSE Skip to line 8 // No Keypress: Test Next Button
0003 - IF Module #1 -SECU16 Relay #8 Is OFF // No UP movement
0004 - THEN Module #1 -SECU16 Relay #9 Turn OFF // Ensure no DOWN movement
0005 - THEN Module #1 -SECU16 Relay #8 Turn ON // Turn UP winding ON
0006 - IF Module #1 -SECU16 Relay #8 Is ON // Motor was moving UP
0007 - THEN Module #1 -SECU16 Relay #8 Turn OFF // Stop moving UP
0008 - IF Module #1 -SECU16 Input #1 Turns ON // Keypress Detected on M01-01: DOWN
0009 - ELSE Skip to line 15 // No Keypress on this button
0010 - IF Module #1 -SECU16 Relay #9 Is OFF // No DOWN movement
0011 - THEN Module #1 -SECU16 Relay #8 Turn OFF // Ensure no UP movement
0012 - THEN Module #1 -SECU16 Relay #9 Turn ON // Turn DOWN winding ON
0013 - IF Module #1 -SECU16 Relay #9 Is ON // Motor was moving DOWN
0014 - THEN Module #1 -SECU16 Relay #9 Turn OFF // Stop moving DOWN

(I lent my own ocelot away, and have a couple on backorders by my supplier, so I will have to test it by a customer)
_________________________
Freedom is having an ELSE for every THEN

Top
#17158 - 01/19/07 09:01 AM Re: Code for Blinds - SECU16 [Re: Andre Ramos]
Guy Lavoie Administrator Offline
Beyond All Hope
*****

Registered: 12/21/02
Posts: 6548
Loc: Montreal, QC, Canada
Quote:

Guy,
My main idea here is to reduce the "reads" in order to speed up each pass.




Actually, the speed of the program execution is not affected by the number of reads of an input (or of any instruction type). The only thing that makes any difference is the total number of lines. Reading the inputs or controlling relays is done by the bus scanning routine, which runs independantly of the program looping. The bus routine updates a status table in memory whenever an input changes (your IF statements read from this table) and commands to relays are put in an output buffer, to eventually get sent out by the bus routine. This is where the variable bus latency comes from. In all cases, the program execution continues immediately. This is the very basis of a ladder logic controller; to loop constantly as fast as possible.
_________________________
"If you don't know what you're doing, do it neatly..."

Top
#17159 - 01/19/07 09:11 AM Re: Code for Blinds - SECU16 [Re: Guy Lavoie]
Andre Ramos Offline
newbie


Registered: 02/21/03
Posts: 23
Loc: Portugal Europe
Guy,

Thanks.
By the way, what you think of the latest proposed code ?
_________________________
Freedom is having an ELSE for every THEN

Top
#17160 - 01/19/07 09:22 AM Re: Code for Blinds - SECU16 [Re: Andre Ramos]
Guy Lavoie Administrator Offline
Beyond All Hope
*****

Registered: 12/21/02
Posts: 6548
Loc: Montreal, QC, Canada
The code looks good. If it all works as you expect it to, then that's about as compact as you can make it!
_________________________
"If you don't know what you're doing, do it neatly..."

Top
#17161 - 01/19/07 11:13 AM Re: Code for Blinds - SECU16 [Re: Guy Lavoie]
Andre Ramos Offline
newbie


Registered: 02/21/03
Posts: 23
Loc: Portugal Europe
Guy,

So, actually (if I got it right) the response speed would be affected by:

- Total Number of inputs and outputs, as I understand the table gets updated regardless the program uses them or not.
- Number of program lines.
- "stuff" sent out to the bus line.

Being the case, it wouldn't make such a big difference (except for program execution time) if I call only a few points or if I call a lot of them.

I put this question because yesterday I was testing a routine only with a partial amount of points... and the response time was acceptable to the customer.

Am I right ?
_________________________
Freedom is having an ELSE for every THEN

Top
#17162 - 01/19/07 11:18 AM Re: Code for Blinds - SECU16 [Re: Andre Ramos]
Andre Ramos Offline
newbie


Registered: 02/21/03
Posts: 23
Loc: Portugal Europe
Also...

Using these program jumps (skiping) speeds up execution... right ?
_________________________
Freedom is having an ELSE for every THEN

Top
#17163 - 01/19/07 12:51 PM Re: Code for Blinds - SECU16 [Re: Andre Ramos]
Guy Lavoie Administrator Offline
Beyond All Hope
*****

Registered: 12/21/02
Posts: 6548
Loc: Montreal, QC, Canada
Quote:

Guy,

So, actually (if I got it right) the response speed would be affected by:

- Total Number of inputs and outputs, as I understand the table gets updated regardless the program uses them or not.
- Number of program lines.
- "stuff" sent out to the bus line.

Being the case, it wouldn't make such a big difference (except for program execution time) if I call only a few points or if I call a lot of them.

I put this question because yesterday I was testing a routine only with a partial amount of points... and the response time was acceptable to the customer.

Am I right ?




Essentially yes, that's it. I'd like to know more about your test "with a partial amount of points". Was it noticeably faster then a program looking at more i/o points, or are you just saying that with whatever delay you were seeing, you were wondering if adding more i/o points to the same program would affect its speed? Adding more code for additionnal i/o points should not be noticeable. A greater source of slowdowns would be to add a few more expansion modules. To really see any difference with program length, you would need to go say from a 100 line program to a 1000 line one. Even then, your source of delays is more related to the bus scanning routine then program looping speed. A 300 line program will loop maybe 3 or 4 times per second. At 1000 lines, it will loop about 2 times per second.

If your programs start to get really long (1000 lines or more) then you can often optimize it with Skip To statements (to answer your last post). If a code section is dealing exclusively with looking for changes in i/o module inputs, you could read all the module inputs as a data value (IF Data for Module...) and compare that against the value from the previous pass. If nothing has changed, then you can skip the entire input reading routine. The same can be done with: Leopard button presses, Incoming X-10 commands and received IR. My own program is over 2100 lines long and it runs like a 500 line one. Let me know if you want to know more about this.

Lastly, is the Comms LED on your Ocelot blinking rapidly and constantly, with the occasional short pause every 10 seconds or so?
_________________________
"If you don't know what you're doing, do it neatly..."

Top
#17164 - 01/19/07 01:25 PM Re: Code for Blinds - SECU16 [Re: Guy Lavoie]
Andre Ramos Offline
newbie


Registered: 02/21/03
Posts: 23
Loc: Portugal Europe
The Comms LED blinks more like rapidly and constantly.
The actual hardware layout is:
- Ocelot
- 6 ea SECU16
- 11 ea Infrared Receivers - Vishay TSOP1238 (I had a lot of interference with the 1738, 1238 works fine all in parallel).
- XM10 (powerline interface, European)
- SC9000 SafeGuard (aka Protector Plus) Console for 16 addresses telephone communication.
- For lights and other appliances I use X10 modules and micromodules.

The Ocelot program will have "this part" for controlling the blinds, then other sections:

- Read IR digits (from 0 to 9) and compose them into a decimal pair like 11,12,13....99. This will be the addressing of every point infraredwise. Read IR commands and convert to X10 functions.
- Conversion Section of decimal reads of IR and X10 addresses like: A1=11, A2=12...,...F9=99.
- Conversion Section of X10 addresses and the blinds ran by SECU's.

The idea is:
- use X10 addresses on the CM11 for creating scenarios and timers, crating Macros on address from G
- use remote control in any location of the house to control any address from A01 to F08, with the same remote, that's why I change it to decimal, otherwise using the X10 addresses I could only run one House Code at a time.
- Trigger Macro (stored on CM11) by telephone.
- Control over the internet using BlueIris and Zeus (www.zeushome.com), similar to our demo site on http://camera.domvs-sapiens.com
_________________________
Freedom is having an ELSE for every THEN

Top
#17165 - 01/19/07 01:51 PM Re: Code for Blinds - SECU16 [Re: Andre Ramos]
Dowser Offline
journeyman


Registered: 12/04/06
Posts: 73
Loc: Sweden
The demo-site you link to requires authentication, is it available for us?
Top
#17166 - 01/19/07 02:07 PM Re: Code for Blinds - SECU16 [Re: Dowser]
Andre Ramos Offline
newbie


Registered: 02/21/03
Posts: 23
Loc: Portugal Europe
ups....
of course... usually this info is on my main site, but it will be down for another couple of days.

username: guest
password: 1234

so easy....
_________________________
Freedom is having an ELSE for every THEN

Top
#17167 - 01/19/07 02:09 PM Re: Code for Blinds - SECU16 [Re: Andre Ramos]
Andre Ramos Offline
newbie


Registered: 02/21/03
Posts: 23
Loc: Portugal Europe
Note that the demo site will require:
- java, for the X10 applet
- Accept an ActiveX from Perspective software to run the video.
_________________________
Freedom is having an ELSE for every THEN

Top
#17168 - 01/19/07 02:15 PM Re: Code for Blinds - SECU16 [Re: Andre Ramos]
Andre Ramos Offline
newbie


Registered: 02/21/03
Posts: 23
Loc: Portugal Europe
... and there is another site that I use with my cell phone to get the last 25 movement detection pictures:
http://www.apalmaramos.com/video/

Those pictures are sent away by FTP to my server, so I keep them on a secure place in case of intrusion, and because they are small (9-10k) it's fast downloading to the cell phone (and cheaper, as I pay on traffic).
_________________________
Freedom is having an ELSE for every THEN

Top
#17169 - 01/23/07 03:34 AM Re: Code for Blinds - SECU16 [Re: Guy Lavoie]
Andre Ramos Offline
newbie


Registered: 02/21/03
Posts: 23
Loc: Portugal Europe
Guy,

Yesterday I tested the program with full control of the 6 SECU16 + X10 Control for the same. This is not the full version, as another section will be added to make the conversion of IR inputs into X10 commands.
The program is now 673 lines of code (7 lines for each keypress + 7 for each X10, all times 48 Keys).

The actual version:
[1st part: Detect keypresses]
0001 - IF Module #1 -SECU16 Input #0 Turns ON // Keypress Detected on M01-00: UP
0002 - ELSE Skip to line 8 // No Keypress: Test Next Button
0003 - IF Module #1 -SECU16 Relay #8 Is OFF // No UP movement
0004 - THEN Module #1 -SECU16 Relay #9 Turn OFF // Ensure no DOWN movement
0005 - THEN Module #1 -SECU16 Relay #8 Turn ON // Turn UP winding ON
0006 - IF Module #1 -SECU16 Relay #8 Is ON // Motor was moving UP
0007 - THEN Module #1 -SECU16 Relay #8 Turn OFF // Stop moving UP
0008 - IF Module #1 -SECU16 Input #1 Turns ON // Keypress Detected on M01-01: DOWN
0009 - ELSE Skip to line 15 // No Keypress: Test Next Button
0010 - IF Module #1 -SECU16 Relay #9 Is OFF // No DOWN movement
0011 - THEN Module #1 -SECU16 Relay #8 Turn OFF // Ensure no UP movement
0012 - THEN Module #1 -SECU16 Relay #9 Turn ON // Turn DOWN winding ON
0013 - IF Module #1 -SECU16 Relay #9 Is ON // Motor was moving DOWN
0014 - THEN Module #1 -SECU16 Relay #9 Turn OFF // Stop moving DOWN
...
[2nd part: Detect x10 Commands]
0337 - IF X-10 House A / Unit 1, ON Command Pair // X10 Command for M01-00: UP
0338 - ELSE Skip to line 344 // Not this X10 Command go Next
0339 - IF Module #1 -SECU16 Relay #8 Is OFF // No UP movement
0340 - THEN Module #1 -SECU16 Relay #9 Turn OFF // Ensure no DOWN movement
0341 - THEN Module #1 -SECU16 Relay #8 Turn ON // Turn UP winding ON
0342 - IF Module #1 -SECU16 Relay #8 Is ON // Motor was moving UP
0343 - THEN Module #1 -SECU16 Relay #8 Turn OFF // Stop moving UP
0344 - IF X-10 House A / Unit 1, OFF Command Pair // X10 Command for M01-01: DOWN
0345 - ELSE Skip to line 351 // Not this X10 Command go Next
0346 - IF Module #1 -SECU16 Relay #9 Is OFF // No DOWN movement
0347 - THEN Module #1 -SECU16 Relay #8 Turn OFF // Ensure no UP movement
0348 - THEN Module #1 -SECU16 Relay #9 Turn ON // Turn DOWN winding ON
0349 - IF Module #1 -SECU16 Relay #9 Is ON // Motor was moving DOWN
0350 - THEN Module #1 -SECU16 Relay #9 Turn OFF // Stop moving DOWN
...

In a previous post you asked if "...the Comms LED on your Ocelot blinking rapidly and constantly, with the occasional short pause every 10 seconds or so? ". The answer is yes. It eventually stops for a while.

Now, comparing "this" version of the CODE with a previous test I made with only the first 15 lines of this code: The performance is similar, I do not notice much difference. Most of the times the response is immediate; I could say 1 in every 5 or 6 takes a while ( 0.5sec to 1.5sec ).

I will go into the next phase (inclusion of IR) during this week.


Edited by Andre Ramos (01/23/07 03:40 AM)
_________________________
Freedom is having an ELSE for every THEN

Top
#17170 - 01/23/07 07:38 AM Re: Code for Blinds - SECU16 [Re: Andre Ramos]
Guy Lavoie Administrator Offline
Beyond All Hope
*****

Registered: 12/21/02
Posts: 6548
Loc: Montreal, QC, Canada
Quote:


Now, comparing "this" version of the CODE with a previous test I made with only the first 15 lines of this code: The performance is similar, I do not notice much difference. Most of the times the response is immediate; I could say 1 in every 5 or 6 takes a while ( 0.5sec to 1.5sec ).





This is pretty well what I would have expected, inculding the occasional slower response every 5 or 6 times. It looks like your program is as optimized as it can be.
_________________________
"If you don't know what you're doing, do it neatly..."

Top
#17171 - 07/18/07 05:13 PM Re: Code for Blinds - SECU16 [Re: Andre Ramos]
Just Another Joe Offline
enthusiast
****

Registered: 09/02/03
Posts: 204
Loc: Adanac
At line 003, you have IF RELAY IS OFF, two THEN lines, and at line 006 IF RELAY IS ON followed by a THEN line at line 007. Couldn't you replace line 007 with an ELSE, and remove line 006? I.e. musn't the relay be either on or off; no other state?

In any case, just to reinforce Guy's comments about the 'skip' instruction: I presently have a 2000 line program which loops 12 to 14 times per second, because when there are no input stimuli, most of the code is 'skipped' over.
_________________________
Just Another Joe
Why be politically correct, when you can be right?

Top
Page 1 of 2 12>


Moderator:  Dan Smith, Monte G, ADI Tech Support, Guy Lavoie 
Hop to:
Who's Online
0 registered and 65 anonymous users online.
Recent Posts
Secu16 inputs not working correctly
by ADI Tech Support
10/03/17 06:01 AM
Ocelot Battery
by ADI Tech Support
09/22/17 07:38 AM
Shout Box

Newest Members
brigiel, vevevie, zhutree, 416, saiqul
3003 Registered Users
Forum Stats
3003 Members
19 Forums
4003 Topics
23440 Posts

Max Online: 132 @ 11/13/16 10:07 AM
October
Su M Tu W Th F Sa
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31