Adcsetup With 28x2

Dave E

Senior Member
Hello all,
I seem to be having a problem with a 28X2 (5 volt version, B.0 firmware) and analog inputs.
I have tried this with 2 different chips but don't seem to get what I think I should get.

I have a simple program that reads ADC0(leg2) of the 28X2 and display it on an LCD. I use:

INPUT A.0
ADCSETUP = 1

in the beginning of the code to set ADC0 to be an analog input. With nothing attached to the pin, I read 4.7 volts. With a 1k resistor attached to the leg and ground I still read 0.12 volts. When I use two 1k resistors as a voltage divider to give 2.58 volts on the pin, the bit count for READADC10 is 667. Chip voltage (Vref) is 5.03 so bit count should be 524.

Am I setting the ADC up correctly? The manual states that ADCSETUP is actually used to disconnect the digital workings so that "the internal digital input circuitry does not affect the analogue reading". So I am wondering if it is set right from the beginning.

I have searched the forum for past issues but have not found anything that sounds like this issue.
I have used 20X2s with ADCs without a problem. They use individual masking where the 5volt version of the 28X2 uses sequential masking. So maybe it is a set up issue.

Any input will be welcome.

Dave E
 

Haku

Senior Member
I just did a test with one of my 28x2's firmware B.1 running this code:
Code:
#picaxe 28x2
#no_table
#no_data

' 28x2 ADC test

adcsetup=1
do
 readadc10 0,w0
 sertxd(#w0,cr,lf)
 pause 100
loop
Nothing attached to pin 2 I get random numbers because the pin is floating.
4k7 between pin 2 & ground I get 3.
4k7 between pin 2 & 5v I get 1023.
Two 4k7's as a voltage divider I get 516.


What do you get if you run the same code?
 

Dave E

Senior Member
Sertxd doesn't do anything. Never used it before but think it is used to output to computer monitor.
If I use DEBUG in your code, W0 = 666 which is what I get on my LCD.

Strange that I get this on 2 different chips. One at home and one at work. However, both are firmware B0.

I have another, will check it.

Thanks for the help,
Dave E
 

Haku

Senior Member
If you press F8 in the programming editor it brings up the serial terminal which displays the output of sertxd. I've just gotten used to using it instead of debug for testing stuff.
 

Dave E

Senior Member
Thanks.
Got it working but get the same thing. 666.

With 1k from 5v to pin2 = 1023.
With 1k from ground to pin2 = 53-54

Odd.

Dave E

Tried another chip. Same thing, same firmware.
 
Last edited:

Dave E

Senior Member
Thanks for the input.

With the 1k attached to ground and pin2, the voltage on pin2 = 0.1352 per Fluke. ADC reads 58 bits with or without meter attached.
With 1k attached to 5.03 Volts (Vref and V supply)and pin2, voltage on pin = 4.8211, bit count = 1023.
1k--1k voltage divider gives 2.5871 volts on pin, bit count = 667.

It seems like the ADC is trying to work, it just reads high. That is why I was thinking that I did not have it set up correctly. The manual states that the ADC is always on but the setup command turns off the digital circuitry that may cause incorrect readings.

Here is my code:

#PICAXE 28X2
#NO_DATA
#NO_TABLE
SETFREQ M8

SYMBOL LCD = B.7
SYMBOL BAUD = T9600_8

HIGH LCD
PAUSE 25
SEROUT LCD, BAUD, (22, 12, 17)
PAUSE 25
ADCSETUP = 1

DO
READADC10 0, W2
SEROUT LCD, BAUD, (128, #W2)
PAUSE 100
LOOP


I did notice something else:
If I enable an ADC, attach the resistor to the pin and ground BUT do not actually read the ADC, the voltage on the pin is very close to ground (0.012).
If I use this code:

ADCSETUP = 2

DO
PAUSE 5000
READADC10 1, W2
SEROUT LCD, BAUD, (128, #W2)
PAUSE 5000
LOOP

The voltage on pin3 is at ground during the first PAUSE 5000 command then jumps to 0.15 when the ADC reads and stays there from then on.

Dave E
 

hippy

Ex-Staff (retired)
Also, are you using just a two resistor download interface or the enhanced download interface ( page 38 of Picaxe Manual 1 ) ? The enhanced interface should not be required if using AXE027 download cable.

I tested using Haku's post #2 code on 28X2 B.1 firmware and I am unaware of any changes relating to ADC between B.0 and B.1 versions. With my hardware ( AXE090 development board, AXE026 PC serial port cable ) I'm reading zero for leg 2 through any R to 0V, 1023 when R to +V, and full 0 to 1023 with a pot connected.

This looks to be some sort of hardware issue; check that both 0V legs of the 28X2 ( leg 8 and 19 ) are connected to 0V, and there is no short circuit or solder bridge between leg 2 and any adjacent or opposite pins or elsewhere.

As an aside - Adding "#Terminal" to a program will force the Terminal to be displayed after download, and "#Terminal <baud>" will also select the desired baud rate. It's a good idea to include this when a program uses SERTXD. For X2's that will be "#Terminal 9600" and "#Terminal 4800" for non-X2's in most cases.
 

hippy

Ex-Staff (retired)
The voltage on pin3 is at ground during the first PAUSE 5000 command then jumps to 0.15 when the ADC reads and stays there from then on.
That's quite possible and seems reasonable. Leg 3 starts as a digital input, then the leg is set to be analogue and the ADC hardware is turned on when the first READADC10 occurs. You are then looking at leg 3 which is effectively floating and not driven by anything but connected to the internal analogue hardware ( which isn't precisely described in datasheets ), its pull-ups and pull-downs and impedance may lead to a meter reading some low voltage present, it may be mains pick-up, the meter may actually be leaking some current. Is your meter calibrated ?

That does lead to another course of action; how does the program behave when reading from an ADC channel other than ADC 0 ?

Also remove the LCD hardware connections and use SERTXD. The LCD hardware may be adversely affecting things.
 

Dave E

Senior Member
Thanks again, Haku, Martin and Hippy.
Found the problem when I connected the other ground connection. Noticed that the V+ wire was not the next pin over from the ground wire.
It helps to connect Vsupply to the V+ pin and not the B.0 pin.

Dave E

Good thing is that ADC12 seems to be OK.
However, digitally, B.0 will not source current any more. It will sink current though.
 
Last edited:

hippy

Ex-Staff (retired)
Glad you've found the problem. This effect is known as 'phantom powering' where a PICAXE / PICmicro gets its power through an I/O leg and the internal clamping diodes let that current through to the internal power rail. As the PICAXE can run on quite low voltages it then appears to work though can throw up oddities, and ADC misreadings is obviously one of those.

I think you've been unlucky with the damage to the B.0 pin. Normally pins can survive such connections but if a pin is output low and has 5V connected to it ( similarly output high and 0V connected ) too much current flows and the magic smoke gets released, often with a load crack or bang. In that respect, unlucky but also lucky.

As it's impossible to say exactly what damage has been done to the chip we would not recommend using it for production work but it may be okay to use for hobbyist purposes though that cannot be guaranteed. Our recommendation would be to mark this as damaged ( and in what way ) and continue with another 28X2 which has never been damaged. That way any other oddities which may be a result of damage won't appear to be PICAXE issues and cause confusion.

The damaged 28X2 may be usable in some project but you will have to take the risk of doing so. A damaged chip may cause damage to other circuitry. In some cases that may be acceptable.
 
Top