chipKIT® Development Platform

Inspired by Arduino™

Last edit: 2021-03-21 22:34 by Majenko

AnalogReadConversionStart

  1. Synopsis

  2. Parameter

  3. Description

  4. Return Value

  5. Conforming To

  6. Example

  7. See Also

Synopsis

 uint8_t analogReadConversionStart(uint8_t pin)

Parameter

Parameter Description
pin Analog Input Pin

Description

NOTE:

  • DO NOT mix blocking and non-blocking analog reads as it could hang your board.
  • This functionality was added in chipKIT-core 1.4.0 and is specific to chipKIT boards only. If you need your code to be compatible with Arduino boards you should use the original analogRead() function. There are workarounds that are available for Arduino but at this writing there is no standardized support in the Arduino wiring libraries for non-blocking analogRead().

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.

Return Value

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.

Conforming To

The non-blocking analogReadxxx Functions are specific to ChipKit 1.4.0 and later and exceed the Arduino 1.6.x specification.

Example

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);
    }
}

See Also

analogReadConversionStart(), analogReadConversionComplete(), analogReadConversion()