Readadc10 values

sid

Senior Member
I'm making a circuit that uses more inputs and outputs that is available on any picaxe, so to reduce the number of inputs I thought I'd connect a number of switch's in parallel, each with a different resistance and connect them all to one readadc10 input. (see attached pic). While trying to work out the corresponding value for the switch being used I noticed that the readadc10 values did not increase or decrease in relation to the increase of resistance used but seemed to jump around, although this is not a problem now I know what readadc value a particular resister gives, I am interested to know why this is ?
findings are as follows....
resistor readadc10 value
1k 150-160
2.2k 65-75
4.7k 180-185
10k 250-255
22k 60-70
27k 10-20
47k 250-255
56k 150-160
 

Attachments

Dippy

Moderator
Why this is?

Could be many reasons...

First , post your code.
Second, describe the power supply precisely. Is it feeble, noisy, wobbley or cheap?
Third, have you tried a decoupling capacitor right next to PICAXE + - pins?

Your numbers do seem odd.

... needless to say you ARE using a word sized variable for ReadADC10 ????
(really?)
 

BeanieBots

Moderator
Think Dippy has a point about the word thing.
Seems funny that none of the numbers are > 255 and appear to roll over.

Let's take the example of 4k7 // 10k

The predicted value would be 10*1023/(10+4.7) = 696
If w0 were to hold 696, then b1 would be 2 and b0 would be 184.
Suspiciously close to what is observed.
 
Last edited:

sid

Senior Member
Doh :eek: How many times before I remember that readadc is a number variable and readadc10 is a word variable. I've written a lable in big black crayon on the front of my printed off manual 2 to this effect. The code is working much more sequentally now. Thank you.
 

Dippy

Moderator
Tattoo it on your typing hand :)

AND, decoupling caps as-close-to-PIC as possible WILL improve things.
AND crappy/noisy PSUs WILL NOT.

Add that tattoo if you have any space left ;)
 

BeanieBots

Moderator
Easily done. Most of have done it at one time or another.
After a while, you get to spot the 'pattern' that those Doh moments generate:)
 

westaust55

Moderator
I'm making a circuit that uses more inputs and outputs that is available on any picaxe ,
Exactly how many Inputs and outputs do you require?

Not knocking the analogue input method which has been discussed on the forum before, but as an alternative option, have you thought about an IO expander IC or two. Sure they do use more realestate on a PCB.

Use something like an MCP23017 for 16 more IO if the PICAXE of choice has i2c comms. Just add another for 16 more IO up to a total of 8 chips max. Interrupt line can be used for "on the fly" input detection.

Alternativey for non-i2c chips 74HC595 and 74HC165 gives 8 latching outputs and 8 latching inputs respectively. With just 4 PICAXE IO you could have a very large number of inputs and outputs by cascading these chips. Programming overheads may become a restrain however.
 

sid

Senior Member
I did look at this idea, but mate if I struggle getting the simple function of readadc/10 right think how hard my brain would have to work to understand latched input/outputs
 
Top