Reading voltages, only one correct.

Chris6969

New Member
Hi
I am trying to read two voltages from two inputs. One reading is correct and the other is messed up.
Reading off B.4 is correct. I get ADC value 618 which translates to 3.02 volts
Reading off B.3 is wrong. The adc value is 468=2.28V. It should be zero, since I have that input grounded. I don't know where is this coming from. Error in the code below?
Code:
#Picaxe 18M2
#no_data
symbol Baud = T9600_8
SetFreq M8
High c.2 
wait 1 ' wait for PICAXE LCD to boot
SerOut c.2, Baud, ("?G216")
wait 2
Do
SerOut c.2, Baud, ("?f") 'clear screen
ReadAdc10 B.4, w0
SerOut c.2, Baud, (#w0)
wait 1
w0 = w0 * 44 / 9
bintoascii w0,b2,b3,b4,b5,b6
SerOut c.2, Baud, ("?f")
pause 100
SerOut c.2, Baud,(" ",b3,".",b4,b5," volts ")
wait 2
w0 = 0
w1 = 0
ReadAdc10 B.3, w1
SerOut c.2, Baud, ("?f")
pause 100
SerOut c.2, Baud, (#w1)
wait 1
w1 = w1 * 44 / 9
bintoascii w1,b16,b17,b18,b19,b20
SerOut c.2, Baud, ("?f")
pause 100
SerOut c.2, Baud,(" ",b17,".",b18,b19," volts ")
wait 2
Loop
 

Aries

New Member
Have you checked the value with a multimeter? Measure the value on the Picaxe leg itself and make sure it is zero.
 

hippy

Senior Member
It is usually much better to use SERTXD and display data in the Terminal window than put it on an LCD when debugging. That way one can be more sure that what one is seeing is as it is, not a result of any LCD driving issue. It is also usually best to start with default operating speed and move up only when the code is proven to work ...
Code:
#Picaxe 18M2
#Terminal 4800
#No_Data
Do
  ReadAdc10 B.4, w4
  ReadAdc10 B.3, w3
  SerTxd( "B.4 = ", #w4, TAB,  "B.3 = ", #w3, CR, LF )
  Pause 500
Loop
 

Chris6969

New Member
I did measure with a multimeter on the input resistor, unfortunately not on the 18M2 leg directly. As it turns out, thanks to the little test above, it was a bad ic socket. Once I replaced the socket, problem solved. Great support here, thank you.
 

hippy

Senior Member
Glad you solved it. I was particularly impressed by the accuracy of "mV = Nadc * 44 / 9", giving "5001" for an Nadc=1023. That is optimal for a single multiply divide.

But that set me on the path to try and get Nadc=1023 to give exactly "5000", runs in simulation ...
Code:
w0 = 1023

w1 = w0 * 44 / 9
SerTxd( #w1, CR, LF )

w1 = w0 ** 5005 * 64
w1 = w0 *  5005 / 1024 + w1
SerTxd( #w1, CR, LF )
 
Top