Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.


Log in or register to post/reply in the forum.

Enable and disable 8 ports of the SDM-CD16 device, SDMCD16Mask instruction.


Enripsc Jan 5, 2021 09:46 AM

Hello, I am using a modification of the SDMCD16Mask instruction to control 8 ports/sites. I am having problems with the ports 5, 6, 7 and 8. The first 4 ports are measuring well, however those from 5 to 8 are measuring poorly. I think the problem may be in the line “mask_timedcontrol = &h000F”. Thank you very much in advance

This is the code:

'The following program shows the use of the SDMCD16Mask instruction To control an SDM-CD16 device.
PipeLineMode

Const SECONDS_ON_SITE_1 = 5
Const SECONDS_ON_SITE_2 = 5
Const SECONDS_ON_SITE_3 = 5
Const SECONDS_ON_SITE_4 = 5
Const SECONDS_ON_SITE_5 = 5
Const SECONDS_ON_SITE_6 = 5
Const SECONDS_ON_SITE_7 = 5
Const SECONDS_ON_SITE_8 = 5

Const NUMBER_SITES = 8

Const CYCLE_TIME = SECONDS_ON_SITE_1+SECONDS_ON_SITE_2+SECONDS_ON_SITE_3+SECONDS_ON_SITE_4+SECONDS_ON_SITE_5+SECONDS_ON_SITE_6+SECONDS_ON_SITE_7+SECONDS_ON_SITE_8

Const SITE_1 = &h0001
Const SITE_2 = &h0002
Const SITE_3 = &h0004
Const SITE_4 = &h0008
Const SITE_5 = &h0016
Const SITE_6 = &h0032
Const SITE_7 = &h0064
Const SITE_8 = &h00128

Public sdmcd16ac_port(8) As Boolean 'SDM-CD16AC port status.

'TimedControl () variables.
Dim set_valve(NUMBER_SITES,2) As Long
Dim index As Long
Dim mask_timedcontrol As Long


TimedControl (NUMBER_SITES,CYCLE_TIME,Sec,&h0000,index,set_valve,1)

BeginProg
set_valve(1,1) = SITE_1
set_valve(2,1) = SITE_2
set_valve(3,1) = SITE_3
set_valve(4,1) = SITE_4
set_valve(5,1) = SITE_5
set_valve(6,1) = SITE_6
set_valve(7,1) = SITE_7
set_valve(8,1) = SITE_8

set_valve(1,2) = SECONDS_ON_SITE_1
set_valve(2,2) = SECONDS_ON_SITE_2
set_valve(3,2) = SECONDS_ON_SITE_3
set_valve(4,2) = SECONDS_ON_SITE_4
set_valve(5,2) = SECONDS_ON_SITE_5
set_valve(6,2) = SECONDS_ON_SITE_6
set_valve(7,2) = SECONDS_ON_SITE_7
set_valve(8,2) = SECONDS_ON_SITE_8

mask_timedcontrol = &h000F

Scan (1,Sec,10,0)

SDMCD16Mask (set_valve,mask_timedcontrol,0) 'Timed control of ports 1 through 8.
'Indicate SDM-CD16AC port 1 through 8 status.
If ( index <> 0 ) Then
sdmcd16ac_port(1) = set_valve(index,1) AND SITE_1
sdmcd16ac_port(2) = set_valve(index,1) AND SITE_2
sdmcd16ac_port(3) = set_valve(index,1) AND SITE_3
sdmcd16ac_port(4) = set_valve(index,1) AND SITE_4
sdmcd16ac_port(5) = set_valve(index,1) AND SITE_5
sdmcd16ac_port(6) = set_valve(index,1) AND SITE_6
sdmcd16ac_port(7) = set_valve(index,1) AND SITE_7
sdmcd16ac_port(8) = set_valve(index,1) AND SITE_8

EndIf


NextScan

EndProg


GeodeNZ Jan 6, 2021 07:06 AM

Try changing the line “mask_timedcontrol = &h000F” to “mask_timedcontrol = &h00FF”


Enripsc Jan 7, 2021 02:34 AM

Thanks GeodeNZ.

Change to mask_timedcontrol = & h00FF not work. So I decided to write the instructions in binary which is more intuitive (1 opens the port and 0 closes the port). Now everything works correctly. I leave the code here in case someone needs it.

Thanks.

'The following program shows the use of the SDMCD16Mask instruction To control an SDM-CD16 device.
PipeLineMode


Const SECONDS_ON_SITE_1 = 5
Const SECONDS_ON_SITE_2 = 5
Const SECONDS_ON_SITE_3 = 5
Const SECONDS_ON_SITE_4 = 5
Const SECONDS_ON_SITE_5 = 5
Const SECONDS_ON_SITE_6 = 5
Const SECONDS_ON_SITE_7 = 5
Const SECONDS_ON_SITE_8 = 5

Const SITE_1 = &b0000000000000001
Const SITE_2 = &b0000000000000010
Const SITE_3 = &b0000000000000100
Const SITE_4 = &b0000000000001000
Const SITE_5 = &b0000000000010000
Const SITE_6 = &b0000000000100000
Const SITE_7 = &b0000000001000000
Const SITE_8 = &b0000000010000000

Const NUMBER_SITES = 8
Const CYCLE_TIME = SECONDS_ON_SITE_1+SECONDS_ON_SITE_2+SECONDS_ON_SITE_3+SECONDS_ON_SITE_4+SECONDS_ON_SITE_5+SECONDS_ON_SITE_6+SECONDS_ON_SITE_7+SECONDS_ON_SITE_8

Public sdmcd16ac_port(8) As Boolean 'SDM-CD16AC port status.
'TimedControl () variables.
Dim set_valve(NUMBER_SITES,2) As Long
Dim index As Long


'Main Program
TimedControl (NUMBER_SITES,CYCLE_TIME,Sec,&b0000000000000000,index,set_valve,1)

BeginProg
set_valve(1,1) = SITE_1
set_valve(2,1) = SITE_2
set_valve(3,1) = SITE_3
set_valve(4,1) = SITE_4
set_valve(5,1) = SITE_5
set_valve(6,1) = SITE_6
set_valve(7,1) = SITE_7
set_valve(8,1) = SITE_8
set_valve(1,2) = SECONDS_ON_SITE_1
set_valve(2,2) = SECONDS_ON_SITE_2
set_valve(3,2) = SECONDS_ON_SITE_3
set_valve(4,2) = SECONDS_ON_SITE_4
set_valve(5,2) = SECONDS_ON_SITE_5
set_valve(6,2) = SECONDS_ON_SITE_6
set_valve(7,2) = SECONDS_ON_SITE_7
set_valve(8,2) = SECONDS_ON_SITE_8


Scan (1,Sec,0,0)

SDMCD16Mask (set_valve,&b0000000011111111,0) 'Timed control of ports 1 through 8.
'Indicate SDM-CD16AC port 1 through 8 status.
If ( index <> 0 ) Then
sdmcd16ac_port(1) = set_valve(index,1) AND SITE_1
sdmcd16ac_port(2) = set_valve(index,1) AND SITE_2
sdmcd16ac_port(3) = set_valve(index,1) AND SITE_3
sdmcd16ac_port(4) = set_valve(index,1) AND SITE_4
sdmcd16ac_port(5) = set_valve(index,1) AND SITE_5
sdmcd16ac_port(6) = set_valve(index,1) AND SITE_6
sdmcd16ac_port(7) = set_valve(index,1) AND SITE_7
sdmcd16ac_port(8) = set_valve(index,1) AND SITE_8

EndIf

NextScan
EndProg

Log in or register to post/reply in the forum.