Name:
adcsetup
Syntax:

{LET} adcsetup = channels

Channels - is the number / mask of ADC to enable.

Description:

On M2, 28X2, 40X2 parts the appropriate adcsetup bit is set automatically by the readadc/readadc10/touch command. Therefore on these parts the only real use of adcsetup is to change a pin back from analogue to digital setup.

On older X2 parts (20X2, 28X2-5V, 28X2-3V, 40X2-5V, 40X2-3V) it is necessary to configure the ADC pins for use with the readadc/readadc10 commands. On all other parts this configuration is automatic.

Note that adcsetup is technically a variable (word length), not a command, and so can be used in let assignments and mathematics (e.g bit masking using & ). Using adcsetup does NOT actually 'connect' the internal adc to the input pin - the adc is always connected! Using adcsetup just disconnects the digital input buffer, so that the internal digital input circuitry does not effect the analogue reading. Therefore readadc commands may still work without correctly configuring adcsetup, however the analogue readings may not be as reliable as expected.

If a pin has been configured as an analogue input (adcsetup bit is set) then the normal 'digital' input circuit is internally disconnected. Therefore if you try to read the digital input (e.g. using if pinX.Y = 1 then) the result will always be 0. 

Due to advances in microcontroller technology the use of 'adcsetup' varies slightly according to the part in use. Please ensure you study the correct page for the part you are using.

There are separate sections for:

PICAXE-28X2 (PIC18F25K22)
PICAXE-40X2 (PIC18F45K22)
PICAXE-28X2-5V (PIC18F2520)
PICAXE-40X2-5V (PIC18F4520)
PICAXE-28X2-3V (PIC18F25K20)
PICAXE-40X2-3V (PIC18F45K20)
PICAXE-20X2 (PIC18F14K22)
Any M2 part (08M2, 14M2, 18M2, 20M2)

 

PICAXE-28X2 (PIC18F25K22), PICAXE-40X2 (PIC18F45K22) (not older -5V or -3V versions)

Individual Pin Masking

With individual pin masking any pin can be individually controlled. Setting the bit disconnects the corresponding digital input to dedicate to analogue operation.

Note that with these parts the appropriate bit is always automatically set upon any readadc / readadc10 / touch / touch16 command. Therefore the only real use of this command is to turn an analogue pin back into a digital pin by clearing the appropriate bit.

adcsetup variable:

Bit 0 -ADC0 Bit 8 -ADC8
Bit 1 -ADC1 Bit 9 -ADC9
Bit 2 -ADC2 Bit 10 - ADC10
Bit 3 -ADC3 Bit 11 - ADC11
Bit 4 -ADC4 Bit 12 - ADC12
Bit 5 -ADC5 Bit 13 - ADC13
Bit 6 -ADC6 Bit 14 - ADC14
Bit 7 -ADC7 Bit 15 - not used

adcsetup2 variable:

Bit 0 - ADC16 Bit 8 - ADC24
Bit 1 - ADC17 Bit 9 - ADC25
Bit 2 - ADC18 Bit 10 - ADC26
Bit 3 - ADC19 Bit 11 - ADC27
Bit 4 - ADC20 Bit 12 - not used
Bit 5 - ADC21 Bit 13 - not used
Bit 6 - ADC22 Bit 14 - not used
Bit 7 - ADC23 Bit 15 - not used

Voltage Reference

The default Vref+signal is the power supply (V+) and Vref- signal is 0V, so the analogue voltage range is the same as the power supply to the PICAXE chip. However, if desired, the Vref signals can be altered to external pins instead by using the adcconfig command.

 

PICAXE-28X2 -5V (PIC18F2520), PICAXE-40X2 -5V (PIC18F4520)

Sequential Masking

With sequential masking pins can only be configured for analogue readings if:

  -the internal pin of the microcontroller supports analogue (see pinout)
  -the pin is already configured as an input
  - all ADC with a lower number are also enable

With the sequential system, for instance, it is only possible to enable ADC3 if ADC0-2 are also enabled. This is an internal design restraint of the PICmicro, not the PICAXE bootstrap. The number of channels and active ADC pins are shown below.   

Channels 28X2-5V 40X2-5V
0 none none
1 ADC0 ADC0
2 ADC0,1 ADC0,1
3 ADC0,1,2 ADC0,1,2
4 ADC0,1,2,3 ADC0,1,2,3
5 ADC0,1,2,3,8 ADC0,1,2,3,5
6 ADC0,1,2,3,8,9 ADC0,1,2,3,5,6
7 ADC0,1,2,3,8,9,10 ADC0,1,2,3,5,6,7
8 ADC0,1,2,3,8,9,10,11 ADC0,1,2,3,5,6,7,8
9 ADC0,1,2,3,8,9,10,11,12 ADC0,1,2,3,5,6,7,8,9
10 - ADC0,1,2,3,5,6,7,8,9,10
11 - ADC0,1,2,3,5,6,7,8,9,10,11
12 - ADC0,1,2,3,5,6,7,8,9,10,11,12

ADC4,5,6,7 do not exist on the 28X2-5V parts.

ADC4 does not exist on the 40X2-5V parts.

Voltage Reference

The default Vref+signal is the power supply (V+) and Vref- signal is 0V, so the analogue voltage range is the same as the power supply to the PICAXE chip. However, if desired, the Vref signals can be altered to external pins instead by setting bits 15 and 14 of adcsetup.

Bit15 = 1 VRef- is ADC2
  = 0 VRef- is 0V
Bit14 = 1 VRef+ is ADC3
  = 0 VRef+ is V+ (power supply)

 

PICAXE-20X2 (PIC18F14K22), PICAXE-28X2-3V (PIC18F25K20), PICAXE-40X2-3V (PIC18F45K20)

Individual Pin Masking

With individual pin masking any pin can be individually controlled. Setting the bit disconnects the corresponding digital input to dedicate to analogue operation.

Bit 0 -ADC0 (not on 20X2) Bit 8 -ADC8
Bit 1 -ADC1 Bit 9 -ADC9
Bit 2 -ADC2 Bit 10 - ADC10
Bit 3 -ADC3 Bit 11 - ADC11
Bit 4 -ADC4 Bit 12 - ADC12
Bit 5 -ADC5 Bit 13 -not used
Bit 6 -ADC6 Bit 14 - VRef+
Bit 7 -ADC7 Bit 15 -VRef- (not available on 20X2)

Voltage Reference

The default Vref+signal is the power supply (V+) and Vref- signal is 0V, so the analogue voltage range is the same as the power supply to the PICAXE chip. However, if desired, the Vref signals can be altered to external pins instead by setting bits 15 and 14 of adcsetup.

Bit15 = 1 VRef-is ADC2(28X2, 40X2) (not available on 20X2)
  = 0 VRef-is 0V
Bit14 = 1 VRef+ ADC3 (28X2, 40X2) or ADC1 (20X2)
  = 0 VRef+ is V+ (power supply)

 

ALL M2 series parts

Individual Pin Masking

With individual pin masking any pin can be individually controlled. Setting the bit disconnects the corresponding digital input to dedicate to analogue operation.

Note that with M2 parts the appropriate bit is always automatically set upon any readadc / readadc10 / touch / touch16 command. Therefore the only real practical use of this command is to turn an analogue pin back into a digital pin by clearing the appropriate bit.

08M2

Bit 1 - ADC on C.1
Bit 2 - ADC on C.2
Bit 4 - ADC on C.4

14M2, 18M2, 20M2

Bit 0 - ADC on B.0 Bit 8 - ADC on C.0
Bit 1 - ADC on B.1 Bit 9 - ADC on C.1
Bit 2 - ADC on B.2 Bit 10 - ADC on C.2
Bit 3 - ADC on B.3 Bit 11 - ADC on C.3
Bit 4 - ADC on B.4 Bit 12 - ADC on C.4
Bit 5 - ADC on B.5 Bit 13 -ADC on C.5
Bit 6 - ADC on B.6 Bit 14 -ADC on C.6
Bit 7 - ADC on B.7 Bit 15 -ADC on C.7

Voltage Reference

The default Vref+signal is the power supply (V+) and Vref- signal is 0V, so the analogue voltage range is the same as the power supply to the PICAXE chip. However, if desired, the Vref signals can be altered to external pins instead by use of the adcconfig command.

Applies To:
08M2, 14M2, 18M2, 20M2, 20X2, 28X2, 40X2
See Also:
Related Create:
Share:
Print:

Individual masking

This initialisation configures ADC2 and ADC1 by setting bit 2 and bit 1 respectively in the 'adcsetup' variable.

Code Example:
	let adcsetup = %0000000000000110
Copy Code Submit an Example

Sequential masking

This initialisation configures ADC2 and ADC1 by setting the 'adcsetup' variable to the value 3. Note that this will also configure ADC0.

Code Example:
	let adcsetup = 3
Copy Code Submit an Example

Submit Your Own Code!

You must be logged in to submit code examples. Login now.