![]() ZBasic System Library
135
ZBasic Microcontrollers
Type
Function returning Integer
Invocation
GetADC(pin)
Parameter
Method
Type
Description
pin
ByVal
Byte
The pin from which to read an analog voltage.
Discussion
This function performs an analog-to-digital conversion of the voltage present on the specified pin which
must be one of the analog port pins (see Resource Usage below). The return value will be a 10-bit (for
ATmega-based and ATtiny-based devices) or 12-bit (for ATxmega-based devices) digital approximation
of the input voltage with a range from zero to the reference voltage (see below). The return value
represents the measured voltage voltage according to the formula V
ref
* adcVal / FS where V
ref
is
the reference voltage, adcVal is the value returned by GetADC(), and FS is 1024 for ATmega and
ATtiny-based devices and 4096 for ATxmega-based devices.
You must make the specified pin an input before calling this routine.
For ATtiny and ATmega target devices, the conversion is performed using the AVcc reference voltage
(connected internally to Vcc on the ZX-24, ZX-24a, ZX-24p, ZX-24n, ZX-24r, ZX-24s, ZX-24t, ZX-24e, ZX-
24ae, ZX-24ne, ZX-24pe, ZX-24nu, ZX-24pu, ZX-24ru, ZX-24su, ZX-328nu, ZX-128e, ZX-128ne, ZX-
1281e and ZX-1281ne). For ATxmega target devices, the conversion is performed using a reference
voltage of Vcc/1.6.
Resource Usage
Only analog port pins may be used to perform an analog-to-digital conversion. The number and location
of analog port pins vary depending on the ZBasic target device. See the section Analog-to-Digital
Converters for more information.
Most ZBasic target devices contain a single analog-to-digital converter thus allowing only one conversion
to be performed at a time (some have none at all). The conversion process takes approximately 220uS
during which time the calling task will be awaiting conversion completion.
Compatibility
Although the BasicX manual indicates that that it is not necessary to configure the pin to be an input
before calling, tests indicate that it is, in fact, necessary to do so. Consequently, the behavior of this
implementation matches the actual behavior of the BasicX platform.
|