28 of 307
ZBasic System Library 18 ZX Microcontroller Family ADCtoCom1 Type Subroutine Invocation ADCtoCom1(pin, rate) Parameter Method Type Description pin ByVal Byte The pin number from which analog readings will be taken. Valid pins are those corresponding to PortA, pins 13 to 20. rate ByVal int16 The rate at which conversions will be performed. The value is the number of conversions per second and may range from 28 to 11000 samples per second. Discussion Calling this subroutine causes a continuous series of analog-to-digital conversions to be performed on the signal appearing at the specified pin. Each 8-bit digital result is automatically sent out the Com1 serial port. Before starting the conversions, the baud rate of Com1 is set to 115,200. The specified pin is automatically set to the proper state for A/D conversion so no additional setup is required prior to use. The conversion stream will continue until ADCToCom1() is called again with the pin parameter set to zero (the rate parameter being meaningless in this case). The analog input range is approximately 0.25 to 0.75 times Vcc (1.25 volts to 3.75 volts when running on 5 volts) and the resulting digital range is 0 to 255. Analog input levels below the low end of the range and above the high end of the range will produce the low and high digital values, respectively. Note that the subroutine Com1ToDAC() is designed to receive the data stream generated by this Subroutine. For best accuracy, state changes on other pins of PortA should be avoided during the conversion process. Resource Usage This subroutine uses the processor’s A/D converter, Com1 and the I/O Timer. No other use of these resources should be attempted while the conversion is active. For native code devices, the following ISRs are required. ISRs Required Underlying CPU ISR Name mega644P, mega328P, mega128 Timer1_CompA mega1281 Timer4_CompA mega1280 Timer4_CompA Example ' Begin the conversion stream on pin 12 at 500 samples per second Call ADCtoCom1(12, 500) ' Stop the conversion process after two minutes Call Delay(120.0) Call ADCtoCom1(0, 0) See Also Com1toDAC