ADC with a 28x2

SAborn

Senior Member
Can someone tell me whats wrong with this code, as from my understanding it should work.

Code:
#picaxe 28x2

symbol Adc_reading =    w1
symbol voltage =       w2
symbol calibrate =    123

symbol adc_pin =       0

   adcsetup = %0000000000000001
main:


   readadc10 adc_pin, Adc_reading
   
   Adc_reading = Adc_reading * 10
   
   voltage = Adc_reading / calibrate
   
   debug
   
   pause 500
   
   goto main
I have not used a 28x2 very much and perhaps i have missed something
All it returns is a value in W1 of 10230, that dont change with varing the voltage to the ADC pin.
 

Svejk

Senior Member
What 28x2 are you using? For 28x2 -5 V version you will need to use ADCSETUP = %10 (see p. 31-33 in manual #2)
 

SAborn

Senior Member
I think its a 5v version chip, as the code was a test program i wrote for someone else.

So it would be correct to use "adcsetup = 1" and not "adcsetup = %0000000000000001" as i have it.
 

inglewoodpete

Senior Member
I think its a 5v version chip, as the code was a test program i wrote for someone else.

So it would be correct to use "adcsetup = 1" and not "adcsetup = %0000000000000001" as i have it.
I have successfully used a 28X2 to read a windvane potentiomenter. This was in 8-bit ADC mode: relevent bits of code below. Try yours in 8-bit mode as an experiment.

You shouldn't need to set the Dir as input but you could try that.

PICAXE Voltage rating? Check the PIC model in Manual 1.

Code:
Symbol iWindVane = 0                    'ADC0 (Also called A.0) Define input from wind vane potentiometer
Symbol bWindDir = b18                   'w9     Wind Direction - ADC value 0-255 for 0 to 360deg
Init:   ADCSetUp = %0000000000000001    'Select ADC0 as used for ADC (All those 0's are not really needed)
        Do
            ReadADC iWindVane, bWindDir 'Fetch the potentiometer value (wind direction)
            Debug
            Pause 1000
        Loop
 

SAborn

Senior Member
IWP,

Thanks for your input.

It would seem you used a 3 volt version of the chip, as you used the same ADCSETUP as i did, and even though it passes syntax, it would seem there is 2 different ADCSETUP required depending on what version chip is used.

If i now understand manual 2 correctly.

ADCSetUp = %0000000000000001 would be correct for ADC0 on a 3v chip.

ADCSetUp = 1 would be correct for ADC0 a 5v chip.
 

hippy

Ex-Staff (retired)
Whilst an ADCSETUP should be used for analogue inputs, analogue inputs will often work without it. Getting ADCSETUP wrong should not overly affect the ADC readings unless the command reconfigured the Vref+ or Vref- references.

You are reading a maximum value on the ADC channel ( $3FF / 1023 ) which suggests there might be something wrong with your hardware.

I would go right back to basics, no SYMBOL definitions, no ADCSETUP, no maths, and see what that gives you -

Code:
#Picaxe 28X2
#Terminal 9600
Do
  ReadAdc10 0, w0
  SerTxd(#w0, " ")
  Pause 500
Loop
Once that's showing sensible readings as you vary the pot then add the ADCSETUP and check it still keeps working. Then move the ADC pin into a SYMBOL definition.
 
Top