Elenco Snap Circuits SnapMicro ® I Standard User Manual

Page 60

Advertising
background image

59

Voltmeter Program;


Make sure baud rate is at 2400 when using terminal window.


The variable w5 stores the reading between 0000 and 1023 that represents the reference voltage. If the
battery voltage equals 4.5 volts and the reference voltage equals .74 volts the w5 variable should read
(.74/4.5)x1023 or 168 (decimals not allowed). The highest number the micro-controller can use
mathematically is 65,335. If the highest number for w5 is 1023, multiplying by 60 will not exceed this limit
(1023x60=61,380). These larger numbers allow for two decimals in the final reading. The program then
calculates the voltage at pin 2 using the number 80 for w6 as follows … w2=(w5 x 60) / w6 or VR =
(168 x 60) / 80 or 126. Since the reference voltage is 74 (or .74 volts), the variable w6 is increased by 1
and the calculation is repeated. When the 74 number is calculated the variable w6 has been found and
the micro-controller uses the 1 pin to measure voltages.

By comparing the input voltages to a known reference many undesired variables can be eliminated.

Advertising