Hello I have a question about the readADC command and the circuit for it. I understand you can attached a potentiometer to the ADC pin and get some value out of 256 but how can I know what value it will be? Say we took a 1k resistor and hooked it up to the pin and read its value with readADC, what value would I get? What if I used a 2k instead, would it bedouble the value ? or is there a set value internally for th epicaxe for a 2k resistor? Is there a table or a formula I can refer to so I can predict the value before actually empirically obtaining it? Thanks.
While you mention initially a potentiometer, you then proceed to discuss a single resistor such as 1K Ohm or 2 kOhm.
A single resistor does not give a voltage divider that thus typically you will tie one end to ground or +5V so that is what the analog input will see and register as (0 or 255 respectively).
Going back to your potentiometer, the voltage at the PICAXE input and thus the value you will receive from the READADC command is a function of the ratio between the resistances on either side of the potentiometer wiper contact.
The READADC value uses the Vcc (PICAXE supply voltage) as a reference so the value can vary with the PICAXE voltage if the input voltage is using a different supply source.
By way of example/calculation:
The potentiometer voltage = Vcc
The potentiometer total resistance (across outer terminals) = 10 kOhm (10,000 Ohms)
The potentiometer wiper is at 60% of the travel towards the Vcc terminal
So resistance ground to wiper = Low_Side_Res = 10,000 * 0.6 = 6,000 Ohms
The resistance wiper to Vcc = High_Side_Res = 10,000 * (1 - 0.4) = 4,000 Ohms
Then the input volatge to the PICAXE ADC pin = Vcc * Low_Side_Res / ( Low_Side_Res + High_Side_Res)
Vin = 5 * 6000 / (6000 + 4000) = 3.0 Volts
READADC value (within accuracy) = Vin * 255 / PICAXE Vcc
= 3 * 255 / 5 =
153