For the LDR example, yes you do need a resistor in series with the LDR to form a voltage divider.Any varying resistance device, e.g. LDR, POT, Thermistor used in
a voltage divider arrangement ( another fixed resistor in series )
will vary the voltage at the junction point of the two components.
This is the point where the ADC input is taken from.
See Below -
Taken in the context of GB's original question (bare bones newbie, and there's nothing wrong with that )If the output of these devices is not a voltage then it needs to be converted to a voltage for the PICAXE to analyse.
While the various PICAXE versions have differing numbers of ADC inputs, these are in fact multiplexed into a single sample and hold circuit for a single ADC module.
Multiplexing is like an electronic switch that rotates though each of the ADC input channels in turn making the analogue signal available to the actual sample and hold circuit and ADC module within the PICAXE (= Microchip PIC) chips.
In terms of timing there are several steps:
1. The input amplifier settling time
2. The time for the charge holding capacitor (CHOLD) to fully charged to the ADC channel input signal voltage level.
3. Time based upon the temperature coefficient
4. The timer to carry out a conversion from the analogue signal to the digital value
5. The time to transfer the result of the ADC to the PICAXE variable specified in the BASIC command.
Items 1,2 and 3 are the ADC acquisition time Tacq
The amplifier settling time is given in the datasheet as 2usec.
The charge holding capacitor time (TC) is a function of the resistance and is expressed as:
TC = –CHOLD * (RIC+RSS+Rs) * ln(1/2047)
Where:
Rs is the source impedance (a function of the external circuit),
Rss is the sampling switch impedance which varies with the voltage Vdd (10 kOhm at 3V, 8 kOhm at 4V and ~6.5 kOhm at 5V), and
Ric is the interconnect resistance, stated in datasheet as < 1 kOhm
The Microchip datasheets recommend a maximum value for RS of 10 kOhm.
So Tc can vary over a range depending upon supply voltage and source impedance.
With Vdd = 5V and Rs = 5 kOhm then Tc = 0.95usec
With Vdd = 4V and Rs= 10 kOhms then Tc = 1.45usec, and
With Vdd = 3V and Rs = 20 kOhms then Tc = 2.3usec
The Temperature Coefficient time TCOFF is stated as Temperature - 25°C0.05μs/°C
So, if the PICAXE chip internally is at 50 DegC then TCOFF = (50-25) * 0.05 == > 1.25uSec
Therefore the total Tacq can vary but typically may be in the range 4usec to 6usec
The PICAXE uses the supply voltage Vdd (e.g. 4.5V or 5V) as a reference voltage against which the analogue to digital conversion is done.
The conversion time Tad for a 10-bit conversion is dependant on further factors.
The source of the conversion clock is software selectable via the ADCS bits of the ADCON0 register. ADCON0 is SFR 31 ($1F). Please consult the Microchip datasheet specific to your PICAXE before trying any changes to this SFR.
There are several possible clock options depending upon which PICAXE version used. Some typical options are:
• FOSC/2
• FOSC/8
• FOSC/32
• FRC (dedicated internal oscillator)
The time to complete one bit conversion is defined as TAD. One full 10-bit conversion requires 11 TAD periods
The conversion time TAD for the clock settings relative to PICAXE speed based upon Microchip recommended ADC clock settings are (For the 08M and40X1 at least):
PICAXE Fosc = 4MHz and ADC Fosc/8 ==> 2.0uSec
PICAXE Fosc = 8MHz and ADC Fosc/32 ==> 4.0uSec
So based upon the full 10-bit conversion, the time to complete one A to D conversion will typically be 11 x 2 = 22usec. (when operating at 4MHz)
Note that this is the time to convert one analogue signal.
Internally the PICAXE interpreter will take some further unspecified time to transfer the result of each conversion into the nominated variable.
Based upon the time for each step, the toal time from initiating a READADC command to having the data available in the nominated variable can vary but values in the range 27usec to 30usec could be expected with the PICAXE operating at 4MHz.
These time will rise to 49usec to 51usec with the PICAXE operating at 8MHz and using recommended conversion clock settings.
I agree entirely with sputz, a well presented description.Westaust, that was one of the best explanations describing a feature! In my opinion, very few people possess the skill to express technical information into easy-to-comprehend sentences, you are one of them!
Step back and have a think about it. You are using a POTENTIOMETER.I had a 10k pot being read by a ADC pin, and discovered that the range of the pot was not quite 0-10k but the ADC values were 0-255. This made me think there was something I didnt understand, so I changed the pot to a 1k pot and still got the full 0-255 ADC range.
Have I got a messed up pot, or does READADC deal with this in some way I don't understand?
Hmm. Is that legal in your country?However, in the Real World, the value of the pot IS important.
1. Too small = smoking pot . I=V/R.
Effectively a READADC measures how far you've turned the pot so it doesn't matter what the actual value of pot is. You can always turn a pot between 0% and 100% and the READADC reports that as 0 to 255, READADC10 as 0 to 1023.I had a 10k pot being read by a ADC pin, and discovered that the range of the pot was not quite 0-10k but the ADC values were 0-255. This made me think there was something I didnt understand, so I changed the pot to a 1k pot and still got the full 0-255 ADC range.
Have I got a messed up pot, or does READADC deal with this in some way I don't understand?
And now strangely, this makes sense!Step back and have a think about it. You are using a POTENTIOMETER.
If you have it connected correctly (I think you have), it is just a resistor connected between 0v at one end and +5v at the other. This resistor has a wiper that contacts the resistive element. At one end of its travel, the wiper will have a potential of 0v and at the other end, it will be at +5v.
What will happen if you replace your 10k potentiometer with one of 100 ohms? The current flowing through the resistive element will increase by 100 times (I=E/R 5/10000 = 0.5mA to 5/100 = 50mA) However, the potentials at each of the wiper positions will not change. The ADC input of the PICAXE is reading these potentials: from 0 (min of 0v) to 255 (max of +5v)
WIKI stands for "What I Know Is", a PIKI would be ..........???Come on Rev-Ed.... a Wiki .... but please call it a different name as I hate that one, how about a 'Piki'.
I love it. An excellent answer indeed.Perhaps I Know It.