DUEMMEGI
MCP 4 – User's manual
Contatto
Example:
The following script converts to
C the 4 analog values read from a MODNTC (that are normally expressed
as Kelvin degrees multiplied by 10). The result of the conversion is written to register from R0 to R3. A
function will be used because the mathematical operations to be executed have to be repeated for each
channel. The main script passes to the function the Address:Channel information (as value); the result will be
returned in the variable CONVERT. Note that the instruction EXIT closes the script (it is like a GOTO to the
ENDSCRIPT instruction).
script
1
trigger
= 2
define
NTC1
AI1:1
define
NTC2
AI1:2
define
NTC3
AI1:3
define
NTC4
AI1:4
R0
= CONVERT(NTC1)
R1
= CONVERT(NTC2)
R2
= CONVERT(NTC3)
R3
= CONVERT(NTC4)
exit
sub
CONVERT(TEMPER)
CONVERT = TEMPER - 2730
CONVERT = CONVERT / 10
endsub
endscript
The same result can be achieved also using the following script, where the destination registers will be
passed as reference and therefore the subroutine works directly on them. Prefer however the version of the
previous example for its efficiency (for reasons going beyond the matter of this manual).
script
1
trigger
= 2
define
NTC1
AI1:1
define
NTC2
AI1:2
define
NTC3
AI1:3
define
NTC4
AI1:4
call
CONVERT(
R0
, NTC1)
call
CONVERT(
R1
, NTC2)
call
CONVERT(
R2
, NTC3)
call
CONVERT(
R3
, NTC4)
exit
sub
CONVERT([REG], TEMPER)
TEMPER = TEMPER - 2730
REG = TEMPER / 10
endsub
endscript
Example:
The following script shows how the
RET instruction
allows to exit from the subroutine (it is like a GOTO to
the instruction ENDSUB). This script converts to Celsius degrees the analog value read from a MODNTC and
it places the result in the register R1; in addition it switches ON the output O1.1 if the result is in the range 18
to 23 degrees, otherwise it switches OFF the output.
DUEMMEGI
s.r.l. - Via Longhena, 4 – 20139 MILANO
Tel. 02/57300377 - Fax 02/55213686 –
www.duemmegi.it
Rel.: 1.2 October 2018
Page 39 of 87