uint8_t analogReadConversionStart(uint8_t pin)
Parameter | Description |
---|---|
pin | Analog Input Pin |
NOTE:
In an effort to increase the number of times per second the loop() function is called while using analogRead functions, non-blocking equivalent functions have been implemented into the chipKIT-core. Test have shown that these non-blocking analogRead functions are about 2x faster on a PIC32MX (Lenny, FubarinoSD) based chipKIT board and about 4.9x faster on a PIC32MZ (Wi-Fire) based boards.
chipKIT Board | PIC32 | Clock Freq | loop() Frequency Blocking Analog Read | loop() Frequency Non-Blocking Analog Read | Improvement |
---|---|---|---|---|---|
Lenny | MX | 40MHz | 49.14 kHz | 127.39 kHz | 2.59 |
Fubarino | MX | 80MHz | 90.91kHz | 217.39 kHz | 2.39 |
Wi-Fire | MZEFG | 200MHz | 233.10 kHz | 1162.79 kHz | 4.98 |
analogReadConversionStart() instructs the analog to digital converter to start a conversion. Once a conversion is started you can continue to execute other code and periodically check to see if a result is ready using the analogReadConveresionComplete() function. When a result is ready you then call analogReadConversion() to get the result.
Value | Description |
---|---|
False | Invalid pin is specified |
True | Analog read has successfully started |
Note: If either ALT_ADC_IMPL or PIC32MZECADC are defined, analogReadConversionStart() will still return True. However, the analogReadConversion() will be blocking when called.
The non-blocking analogReadxxx Functions are specific to ChipKit 1.4.0 and later and exceed the Arduino 1.6.x specification.
This example starts an analog read in setup() and then checks to see if the result is ready in the loop() function. If a result is ready the ADC value is assigned to the 'value' variable and a new non-blocking analog read is started. If a result is not ready the code simply continues to execute and does not wait. The ability to continue is why we call this non-blocking.
#define ADC_TEST_PIN 16
void setup() {
analogReadConversionStart(ADC_TEST_PIN);
}
void loop() {
uint32_t value;
if ( analogReadConversionComplete() ) {
value = analogReadConversion();
analogReadConversionStart(ADC_TEST_PIN);
}
}
analogReadConversionStart(), analogReadConversionComplete(), analogReadConversion()