ADC on PICAXE 20X2

Sean87

Member
Hi all,

Can someone please point me to a quick ADC setup on 20X2?

I have 6 LED's that are connected to pins 0 to 5 as output. I had a lot of fun making some LED dance moves once I manage to get the chip to work.

Now what I want to do is connect a 10k potentiometer that I have to board and want to do something like by increasing and decreasing it number of ON LED's to be increased or decreased.

Thanks.
 

westaust55

Moderator
You need to read up on the commands:
Adcsetup – manual 2 (V7.5) page 29
adcsetup = %0000000000000001 ; set ADC1 at pin B.0
And
Readadc – manual 2 (V7.5) page 170
readadc B.0,b1 ; read value from ASDC1 into b1

Without knowing how you have the hardware setup it is not possible to give an exact solution but tentatively you can “massage” the value in variable b0 and create a value (maybe in another variable as a result) that you can use use the command
pinsC or pinsB = (b0 or b1 etc)
to put a value onto the outputs driving the 6 LEDs as a bar graph
 

Sean87

Member
You need to read up on the commands:
Adcsetup – manual 2 (V7.5) page 29
adcsetup = %0000000000000001 ; set ADC1 at pin B.0
And
Readadc – manual 2 (V7.5) page 170
readadc B.0,b1 ; read value from ASDC1 into b1

Without knowing how you have the hardware setup it is not possible to give an exact solution but tentatively you can “massage” the value in variable b0 and create a value (maybe in another variable as a result) that you can use use the command
pinsC or pinsB = (b0 or b1 etc)
to put a value onto the outputs driving the 6 LEDs as a bar graph
Thanks for reply.

My current setup is very simple. I have the programmer cable connected to pins 1,2,20 including the 10k and 22k resistors. Also I have connected 6 LED's to pin B.0 to B.5

Can you tell me please how can I add a variable resistor to this setup? I read the manual and it says something about ADC setup and reference voltage and stuff, I couldn't figure them out yet.
 

geoff07

Senior Member
1) pick an adc input that isn't being used. Connect this to the 10k potentiometer wiper.
b) connect the ends of the pot to +5v and to ground
c) use readadc10 to read the value of the pot (range 0-1023 in a word variable)
d) interpret the input value found under c) to drive the behaviour of your program (e.g. select W_value/case <100 do this/case <200 do that/case < 300 do the other/endselect)

Actual syntax is in the manual (2) but you get the idea. Reference voltages etc are clever stuff for more sophisticated problems that as far as I can see you don't need.
 
Top