How fast is your webcontrol

salesguy

Member
I have some simple code setup to measure the execution speed of my PLC program, so that I know if I'm really bogging down the board to the point that I might miss an "event" that I'm looking to detect with this board.

Does anyone else do this?

My code is currently executing at a rate of about 180 cycles per second (or 180 Hertz).

My code is pretty basis to do this and if anyone has more refined code they want to share or comments please do. I'd like to see more code examples on this board. there are obviously some very experienced coders on this board and many of us could learn alot.

My full PLC code is below, with "SPEED" being the part that checks the execution time (at least I think it does that):



START
SET VAR2 0
SET VAR3 0
SET VAR4 0
SET VAR5 0
SET RAM1 0
SET RAM2 0
SET RAM7 0
SET RAM6 CTS
SET RAM8 0
EMAIL EM7
LOOP:
INC VAR5
TSTGT VAR5 20000
CALLSUB SPEED
TSTEQ VAR4 1
CALLSUB FROZEN
TSTEQ OP5[500] 1
CALLSUB WOL
TSTEQ VAR2[10000] 1
CALLSUB DISARM
TSTEQ VAR3 1
CALLSUB GARAGE
TSTEQ OP4[500] 1
CALLSUB SWITCH
TSTEQ OP3[5000] 1
CALLSUB POWER
TSTGT AIP2 70
CALLSUB ALARM
TSTLT AIP2 50
SET RAM2 0
TSTLT AIP1 435
CALLSUB DOORBELL
GOTO LOOP
END

SPEED:
SUB CTS RAM6 RAM8
DIV VAR5 RAM8 VAR6
SET RAM6 CTS
SET VAR5 0
RET

FROZEN:
SET VAR4 0
EMAIL EM8
RET

DISARM:
SET VAR2 0
RET

DOORBELL:
TSTEQ RAM1 1
RET

SET RAM1 1
EMAIL EM1
RET

ALARM:
TSTEQ RAM2 1
RET

SET RAM2 1
EMAIL EM2
RET

WOL:
SET OP5 0
EMAIL EM5
RET

GARAGE:
TSTEQ VAR2 0
RET

SET OP6 1
DELAY 500
SET OP6 0
EMAIL EM6
SET VAR3 0
RET

SWITCH:
SET OP4 0
EMAIL EM4
RET

POWER:
SET OP3 0
EMAIL EM3
RET
 
I think the time will be different depending on if you have temperature sensors or not. DS18B20 would take about 850ms to finish one conversion. Email can also cause slow down. If you use it to detect door open or window open, I think it will be good enough. But if you want to use it as counter, depending on application it may not be fast enough.
 
What event are you worried about missing? I only see two test of inputs (analog input 1 and 2). Will the values be very short lived such that you are worried about missing them?

You would have to ask CAI themselves, but my recollection is that the resolution of the inputs is not the same as how fast the code runs. The inputs are checked something like every 20ms and updated to a buffer where the code can check the value. Again, please confirm with CAI. So even if your code is cycling every 5ms, that doesn't mean that input value resolution is that fast.

Also, fwd03 is totally correct regarding the one wire temp sensors. This runs slower. Not sure about email. I don't think either of these bogs down how fast the code cycles. It is just how fast the values get updated to the buffer where the plc code has access to them. Again, cai support should probably chime in to confirm.
 
I have this board receiving input from my alarm system, so I can know if a door/window opens when I'm not home. My alarm isn't web enabled, so I tapped into the wiring that goes to the speaker, and then detect that voltage & trigger an email. It's low voltage so can be tricky to detect without using an opamp to boost the signal.

But it was more of a question of curiosity, since i try hard to write the code in a way that flows through without delays.
 
I have this board receiving input from my alarm system, so I can know if a door/window opens when I'm not home. My alarm isn't web enabled, so I tapped into the wiring that goes to the speaker, and then detect that voltage & trigger an email. It's low voltage so can be tricky to detect without using an opamp to boost the signal.

But it was more of a question of curiosity, since i try hard to write the code in a way that flows through without delays.

The thing with cai is that it is a single thread processor. So you can't throw it into any kind of loop unless that is the one and only task you want it to perform. When I write cai code, I always avoid any kind of loops by using variables as "place holders" that you might instead do as a loop.
 
I have this board receiving input from my alarm system, so I can know if a door/window opens when I'm not home. My alarm isn't web enabled, so I tapped into the wiring that goes to the speaker, and then detect that voltage & trigger an email. It's low voltage so can be tricky to detect without using an opamp to boost the signal.

But it was more of a question of curiosity, since i try hard to write the code in a way that flows through without delays.

When your alarm triggers, the alarm will last much longer than 100mS. If, for example, you connects an input to siren output through a resistor, you will be able to get email send to you within the same second, then it will depend on how often you check email. If you do some additional wiring by connecting I/O to your door contact, window contacts, then the email will have information which one caused trigger. Most wired alarm has contact as normally closed, so that it is zero volt when door and window closed. When any door or window open, the contact will disconnect, then the input pins to your alarm panel will be pulled up to logic 1 by the pull up resistors inside the alarm panel.
 
Back
Top