FUNCTION AD ( expression ) AS INTEGER
AD will return 0..65472 that corresponds to the voltage on the pin corresponding to expression . The value returned will have the top 10 bits of significance followed by bits 5..0 will be 0. 0 would be read for 0V and 65472 for 3.3V.
An analog conversion on pin expression is performed when this built-in FUNCTION is called. This process takes less than 6 usec.
AD pins are configured as ADs. To make them to IOs, the PINSEL register needs to be written which is done when you access the corresponding IO(x)
IO(11) ' make AD(0) an IO
x = IO(32) ' make AD(1) an IO
x = IO(33) ' make AD(2) an IO
x = IO(34) ' make AD(3) an IO
x = IO(35) ' make AD(4) an IO
x = IO(36) ' make AD(5) an IO
For BASICchip firmware version 8.14, this will make the pin an output, but to make it an input
' convert AD(5) to digital input or output
IOCON_SWDIO_PIO1_3 = &H90 'AD(4)
IOCON_R_PIO1_2 = &H91 'AD(3)
IOCON_R_PIO1_1 = &H91 'AD(2)
IOCON_R_PIO1_0 = &H91 'AD(1)
IOCON_R_PIO0_11 = &H91 'AD(0)
SuperPRO and PROplus version
The LPC17xx series have a 12 bit converter, so the top 12 bits of the 16 bit value are returned by AD. Version 8.14 of the firmware allows the AD pins to be changed to digital pins using IO(x), INPUT(x), DIR(x) and OUTPUT(x) commands. AD(6) and AD(7) are on shared pins with RXD(0) and TXD(0), and to use those the PINSEL registers have to be re-programmed.
ARMmite and PRO version
Eight 10-bit ADs are available.
AD pins are configured as ADs. To return them to IOs, the PINSEL register needs to be written (details in the NXP LPC2138 User Manual)
PINSEL1 AND= &HC003FFFF ' return ADs to IOs
ARMexpress LITE version
The ARMexpress LITE supports up to 6 channels of AD converters.
On the ARMexpress LITE and ARMweb these pins are configured as digital IOs at reset, but will be switched to AD operation when AD(x) is read.
|AD(0)||IO( 7 )|
|AD(1)||IO( 10 )|
|AD(2)||IO( 8 )|
|AD(5)||IO( 9 )|
|AD(6)||IO( 11 )|
IO( 12 )