114 of 323
ZBasic System Library 104 ZX Microcontroller Family GetADC (subroutine form) Type Subroutine Invocation GetADC(pin, val) GetADC(pin, val, fullScale) GetADC(pin, val, fullScale, offset) Parameter Method Type Description pin ByVal Byte The pin from which to read an analog voltage. Val ByRef Single The variable in which to return the result. fullScale ByVal Single The full-scale voltage value. offset ByVal Integral The offset to apply before scaling. Discussion This function performs an analog-to-digital conversion on the signal present on the specified pin that must be one of the analog port pins (see the table below). The return value will be a 10-bit (for ATxmega- 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). For the first form, the returned value is scaled to the range 0.0 to 1.0 and for the remaining forms it is scaled to the range 0.0 to value of the fullScale parameter. For the third form, the value of the offset parameter (which could be negative) is added to the 10-bit ADC value before scaling. This is useful, for example, for removing the effect of a non-zero offset voltage of the ADC. You must make the pin an input before calling this routine. For ATmega-based 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-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-based 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 analog port pins vary depending on the ZX model and some ZX models have more analog input pins available. Also, on some devices (e.g. ZX-32n, ZX-32l and ZX-328nu) some of the pins are dedicated analog inputs; having no digital functions. Analog Ports and Pins ZX Models Port Pins Port Pins ZX-24, ZX-24a, ZX-24p, ZX-24n, ZX-24r, ZX-24s PortA 13-20 - - ZX-40, ZX-40a, ZX-40p, ZX-40n, ZX-40r, ZX-40s PortA 33-40 - - ZX-44, ZX-44a, ZX-44p, ZX-44n, ZX-44r, ZX-44s PortA 30-37 - - ZX-328n, ZX-328l PortC 23-28 - - ZX-32n, ZX-32l PortC 23-28, 19, 22 - - ZX-1281, ZX-1281n PortF 54-61 - - ZX-1280, ZX-1280n PortF 90-97 PortK 82-89 ZX-24x PortA 13-20 PortB 7-9 ZX-32a4 PortA 40-44, 1-3 PortB 4-7 ZX-128a1 PortA 95-100, 1, 2 PortB 5-12 ZX-24e, ZX-24ae, ZX-24ne, ZX-24pe, ZX-24nu, ZX-24pu, ZX-24ru, ZX-24su PortA 29-36 - - ZX-24xu PortA 29-36 PortB 25-28 ZX-128e, ZX-128ne, ZX-1281e, ZX-1281ne PortF 29-36 - - ZX-328nu PortC 17-24 - -