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.
BASICchip
AD pins are configured as ADs. To make them to IOs, the IOCON register needs to be written which is done when you access the corresponding IO(x)
For BASICchip firmware versions before 8.28, to convert from AD to digital IO the following code must be used
#include <LPC11xx.bas>
IOCON_R_PIO0_11 =
&H91 ' convert
AD(0) to digital input or output
IOCON_R_PIO1_0 =
&H91
'AD(1)
IOCON_R_PIO1_1 = &H91 'AD(2)
IOCON_R_PIO1_2 =
&H91
'AD(3)
IOCON_SWDIO_PIO1_3 = &H90 'AD(4)
IOCON_PIO1_4 =
&H90
'AD(5)
for firmware versions after 8.28 you can convert to digital IOs by access using IO for either input or output
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
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.
ARMweb
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(3) | not available |
| AD(4) | not available |
| AD(5) | IO( 9 ) |
| AD(6) | IO( 11 ) |
| AD(7) |
IO( 12 ) |