Data Sheet
dScript
dScript User Manual v2.15
analogport TSensor 100 ; on-board temp sensor
analogport PSU 101 ; DC power voltage
var Temperature
var Volts
Temperature = ((TSensor*3223)-500000)/1000
Volts = PSU*18369/100000
The final dScript program is:
tcpip.hostname "dS3484"
tcpip.ip "192.168.0.136"
tcpip.mask "255.255.255.0"
digitalport Rly1 1
analogport TSensor 100 ; on-board temp sensor
analogport PSU 101 ; DC power voltage
var Temperature
var Volts
main: do
Temperature = ((TSensor*3223)-500000)/1000
Volts = PSU*18369/100000
loop
You now have a simple web page which you can toggle a relay and show the relay state by the
button colour, and display module temperature and incoming voltage.
The calculations for converting the analogue readings into into degrees C and volts were
derived like this:
The ADC gives a 10 bit (0-1023) result over the range 0-3.3v. The ADC is returning 3.3/1024
= 3.223mV/bit, or 3223uV/bit. The ADC value is therefore multiplied by 3223 to give us the
input voltage in uV. The temperature sensor gives an output of 10mV/degree C, or as we are
working in uV, 10000uV/degree C. The temperature sensor has an offset of 0.5v or 500000uV
so we need to subtract this from the result. Now we can divide by 10000 go give us the
temperature, as an integer, in degrees C. However we only divide by 1000 which means the
number is 10 times bigger than it should be. 21.5 degrees will be 215. We will use Javascript in
the browser to divide this by 10 and display the result to 0.1 degrees.
A similar trick happens with the input voltage. We use 4k7 and 1k resistors in series to divide
down the supply voltage to a safe level for the processor. So 12v will feed 12*(1/(4.7+1)) =
12/5.7 = 2.1v to the ADC. This will convert to 2.1/3.3*1024 = 652. We need change 652 to
12000000uV (or 12v), so we multiply by 12000000/652 = 18405. Because that is full of
rounding errors to make the numbers small and readable the actual answer is 18369.
12000000/(((12/5.7)/3.3)*1024) = 18369.
So the voltage is PSU*18369uV. We can divide this by 1000000 to get the volts, however as
with the temperature, we only divide by 100000 to give a result 10 times larger. Again,
Javascript will divide this by 10 and display the result to 0.1 volts.
Copyright © 2016, Devantech Ltd.
All rights reserved.
www.robot-electronics.co.uk
44