3. Analyzing The Demonstration Example

This section analyzes an application example which demonstrates using both the GPADC and battery adapters. The example is based on the freertos_retarget sample code found in the SDK. It adds two additional freeRTOS tasks which are responsible for various GPADC operations. One task performs analog-to-digital measurements on a dedicated pin on the Pro DevKit (P1.2), while the second task performs analog-to-digital measurements on the internal pin which is connected to the attached battery. The code also enables the wake-up timer for handling external events. Both synchronous and asynchronous GPADC operations are demonstrated.

3.1. Application Structure

  1. The key goal of this demonstration is for the device to perform a few GPADC operations following an event. For demonstration purposes the K1 button on the Pro DevKit has been configured as a wake-up pin. For more detailed information on how to configure and set a pin for handling external events, read the External Interruption tutorial.

    At each external event (produced at every K1 button press), a dedicated callback function named wkup_cb() is triggered. In this function, the task responsible for the battery measurements is signaled so that it can unblock. This freeRTOS task performs a synchronous battery measurement and, upon finishing the analog-to-digital conversion, the raw ADC result is converted into millivolt (mV) so that it is easier for the developer to interpret the results. A debugging message with the converted data is also printed out on the serial console.

'Battery Measurements SW FSM - Main Execution Path'

Fig. 11 Battery Measurements SW FSM - Main Execution Path

  1. At the same time, at every 1 second time interval, the task responsible for performing GPADC operations is executed. Depending on the value of the POT_ASYNC_EN macro, a synchronous or an asynchronous GPADC conversion is performed. At the end of every GPADC operation, the raw ADC value is converted into mV and a debugging message with the converted data is sent to the serial console.
'GPADC Conversions SW FSM - Main Execution Path'

Fig. 12 GPADC Conversions SW FSM - Main Execution Path

  1. The POT_ASYNC_EN macro can be used to enable asynchronous GPADC operations. Please note that for asynchronous operations, developers must not call asynchronous related APIs without guaranteeing that the previous asynchronous operation is finished. To ensure this, after calling the ad_gpadc_read_async() function, the code waits for the arrival of a signal, indicating the end of the current GPADC operation.
'GPADC Conversions SW FSM - Main Execution Path'

Fig. 13 GPADC Async Conversions SW FSM - Callback Function Execution Path