4.1.3.1 12-bit ADCC with Context

12-bit Analog-to-Digital Converter with Computation and Context (ADC3)

4.1.3.1.1 Introduction

The Analog-to-Digital Converter with Computation and Context (ADC3) conversion of both single-ended and differential analog input signals to a 12-bit binary representation of that signal. This device uses analog inputs, which are multiplexed into a single sample and hold circuit. The output of the sample and hold is connected to the input of the converter. The converter generates a 12-bit binary result via successive approximation and stores the conversion result into the ADC result registers.

4.1.3.1.2 Supported Device Families

PIC18F-Q71 PIC18F-Q8x

4.1.3.1.3 Required Header Files:

#include "mcc_generated_files/adc/adc.h"

4.1.3.1.4 How to use the ADC3 PLIB Driver

The ADC3 Module driver generates an API interface to support the features of the peripheral. Some use cases of are linked below. Click the links to view the code snippets associated with each.

4.1.3.1.5 Module Documentation

ADC

This is the generated header file for the ADC driver.

Module description

This is the generated header file for the ADC driver.

Version: ADC Driver Version 1.0.1
Typedefs
  • typedef uint16_t adc_result_t

    Displays the result of the Analog-to-Digital (A/D) conversion.

Definitions
Enumerations
Functions

Definition Documentation

ADC_ClearAccumulator

#define ADC_ClearAccumulator ADC_ClearAccumulator

Defines the Custom Name for the ADC_ClearAccumulator API.

ADC_DefineSetPoint

#define ADC_DefineSetPoint ADC_DefineSetPoint

Defines the Custom Name for the ADC_DefineSetPoint API.

ADC_DisableChannelScan

#define ADC_DisableChannelScan ADC_DisableChannelScan

Defines the Custom Name for the ADC_DisableChannelScan API.

ADC_DisableChannelSequencer

#define ADC_DisableChannelSequencer ADC_DisableChannelSequencer

Defines the Custom Name for the ADC_DisableChannelSequencer API.

ADC_DisableContinuousConversion

#define ADC_DisableContinuousConversion ADC_DisableContinuousConversion

Defines the Custom Name for the ADC_DisableContinuousConversion API.

ADC_DischargeSampleCapacitor

#define ADC_DischargeSampleCapacitor ADC_DischargeSampleCapacitor

Defines the Custom Name for the ADC_DischargeSampleCapacitor API.

ADC_EnableChannelScan

#define ADC_EnableChannelScan ADC_EnableChannelScan

Defines the Custom Name for the ADC_EnableChannelScan API.

ADC_EnableChannelSequencer

#define ADC_EnableChannelSequencer ADC_EnableChannelSequencer

Defines the Custom Name for the ADC_EnableChannelSequencer API.

ADC_EnableContinuousConversion

#define ADC_EnableContinuousConversion ADC_EnableContinuousConversion

Defines the Custom Name for the ADC_EnableContinuousConversion API.

ADC_EnableDoubleSampling

#define ADC_EnableDoubleSampling ADC_EnableDoubleSampling

Defines the Custom Name for the ADC_EnableDoubleSampling API.

ADC_GetAccumulatorValue

#define ADC_GetAccumulatorValue ADC_GetAccumulatorValue

Defines the Custom Name for the ADC_GetAccumulatorValue API.

ADC_GetConversionResult

#define ADC_GetConversionResult ADC_GetConversionResult

Defines the Custom Name for the ADC_GetConversionResult API.

ADC_GetConversionStageStatus

#define ADC_GetConversionStageStatus ADC_GetConversionStageStatus

Defines the Custom Name for the ADC_GetConversionStageStatus API.

ADC_GetCurrentCountofConversions

#define ADC_GetCurrentCountofConversions ADC_GetCurrentCountofConversions

Defines the Custom Name for the ADC_GetCurrentCountofConversions API.

ADC_GetErrorCalculation

#define ADC_GetErrorCalculation ADC_GetErrorCalculation

Defines the Custom Name for the ADC_GetErrorCalculation API.

ADC_GetFilterValue

#define ADC_GetFilterValue ADC_GetFilterValue

Defines the Custom Name for the ADC_GetFilterValue API.

ADC_GetPreviousResult

#define ADC_GetPreviousResult ADC_GetPreviousResult

Defines the Custom Name for the ADC_GetPreviousResult API.

ADC_GetSingleConversion

#define ADC_GetSingleConversion ADC_GetSingleConversion

Defines the Custom Name for the ADC_GetSingleConversion API.

ADC_HasAccumulatorOverflowed

#define ADC_HasAccumulatorOverflowed ADC_HasAccumulatorOverflowed

Defines the Custom Name for the ADC_HasAccumulatorOverflowed API.

ADC_HasErrorCrossedLowerThreshold

#define ADC_HasErrorCrossedLowerThreshold ADC_HasErrorCrossedLowerThreshold

Defines the Custom Name for the ADC_HasErrorCrossedLowerThreshold API.

ADC_HasErrorCrossedUpperThreshold

#define ADC_HasErrorCrossedUpperThreshold ADC_HasErrorCrossedUpperThreshold

Defines the Custom Name for the ADC_HasErrorCrossedUpperThreshold API.

ADC_Initialize

#define ADC_Initialize ADC_Initialize

Defines the Custom Name for the ADC_Initialize API.

ADC_IsConversionDone

#define ADC_IsConversionDone ADC_IsConversionDone

Defines the Custom Name for the ADC_IsConversionDone API.

ADC_SelectContext

#define ADC_SelectContext ADC_SelectContext

Defines the Custom Name for the ADC_SelectContext API.

ADC_SetAcquisitionRegister

#define ADC_SetAcquisitionRegister ADC_SetAcquisitionRegister

Defines the Custom Name for the ADC_SetAcquisitionRegister API.

ADC_SetADIInterruptHandler

#define ADC_SetADIInterruptHandler ADC_SetADIInterruptHandler

Defines the Custom Name for the ADC_SetADIInterruptHandler API.

ADC_SetChannel

#define ADC_SetChannel ADC_SetChannel

Defines the Custom Name for the ADC_SetChannel API.

ADC_SetContext1ThresholdInterruptHandler

#define ADC_SetContext1ThresholdInterruptHandler ADC_SetContext1ThresholdInterruptHandler

Defines the Custom Name for the ADC_SetContext1ThresholdInterruptHandler API.

ADC_SetContext2ThresholdInterruptHandler

#define ADC_SetContext2ThresholdInterruptHandler ADC_SetContext2ThresholdInterruptHandler

Defines the Custom Name for the ADC_SetContext2ThresholdInterruptHandler API.

ADC_SetContext3ThresholdInterruptHandler

#define ADC_SetContext3ThresholdInterruptHandler ADC_SetContext3ThresholdInterruptHandler

Defines the Custom Name for the ADC_SetContext3ThresholdInterruptHandler API.

ADC_SetContext4ThresholdInterruptHandler

#define ADC_SetContext4ThresholdInterruptHandler ADC_SetContext4ThresholdInterruptHandler

Defines the Custom Name for the ADC_SetContext4ThresholdInterruptHandler API.

ADC_SetLowerThreshold

#define ADC_SetLowerThreshold ADC_SetLowerThreshold

Defines the Custom Name for the ADC_SetLowerThreshold API.

ADC_SetPrechargeRegister

#define ADC_SetPrechargeRegister ADC_SetPrechargeRegister

Defines the Custom Name for the ADC_SetPrechargeRegister API.

ADC_SetRepeatCount

#define ADC_SetRepeatCount ADC_SetRepeatCount

Defines the Custom Name for the ADC_SetRepeatCount API.

ADC_SetStopOnInterrupt

#define ADC_SetStopOnInterrupt ADC_SetStopOnInterrupt

Defines the Custom Name for the ADC_SetStopOnInterrupt API.

ADC_SetUpperThreshold

#define ADC_SetUpperThreshold ADC_SetUpperThreshold

Defines the Custom Name for the ADC_SetUpperThreshold API.

ADC_StartConversion

#define ADC_StartConversion ADC_StartConversion

Defines the Custom Name for the ADC_StartConversion API.

ADC_StartConversionOnChannel

#define ADC_StartConversionOnChannel ADC_StartConversionOnChannel

Defines the Custom Name for the ADC_StartConversionOnChannel API.

ADC_StopConversion

#define ADC_StopConversion ADC_StopConversion

Defines the Custom Name for the ADC_StopConversion API.

Typedef Documentation

adc_result_t

adc_result_t

Displays the result of the Analog-to-Digital (A/D) conversion.

Function Documentation

ADC_ADCH1_ISR()

void ADC_ADCH1_ISR (void )

Implements the ADCH1 ISR for the interrupt-driven implementations.

Parameters:
None.
Returns:

None.

ADC_ADCH2_ISR()

void ADC_ADCH2_ISR (void )

Implements the ADCH2 ISR for the interrupt-driven implementations.

Parameters:
None.
Returns:

None.

ADC_ADCH3_ISR()

void ADC_ADCH3_ISR (void )

Implements the ADCH3 ISR for the interrupt-driven implementations.

Parameters:
None.
Returns:

None.

ADC_ADCH4_ISR()

void ADC_ADCH4_ISR (void )

Implements the ADCH4 ISR for the interrupt-driven implementations.

Parameters:
None.
Returns:

None.

ADC_ADI_ISR()

void ADC_ADI_ISR (void )

Implements the ADC Interrupt (ADI) ISR for the interrupt-driven implementations.

Parameters:
None.
Returns:

None.

ADC_ClearAccumulator()

void ADC_ClearAccumulator (void )[inline]

Clears the accumulator.

Parameters:
None.
Returns:

None.

ADC_DefineSetPoint()

void ADC_DefineSetPoint (uint16_t setPoint)

Sets the value of the ADC Threshold Setpoint (ADSTPT) register.

Parameters:
setPoint

- 16-bit value for the ADC Threshold Setpoint register.

Returns:

None.

ADC_DisableChannelScan()

void ADC_DisableChannelScan (adc_context_t context)

Excludes a channel context from the scan sequence. Select the correct context using ADC_SelectContext before calling this API.

Parameters:
context

- Context which needs to be excluded from the scan. Refer to the adc_context_t enum for the list of available contexts.

Returns:

None.

ADC_DisableChannelSequencer()

void ADC_DisableChannelSequencer (void )[inline]

Disables the ADC channel sequencer. Initialize the ADC module using ADC_Initialize before calling this API.

Parameters:
None.
Returns:

None.

ADC_DisableContinuousConversion()

void ADC_DisableContinuousConversion (void )[inline]

Disables continuous conversion.

Parameters:
None.
Returns:

None.

ADC_DischargeSampleCapacitor()

void ADC_DischargeSampleCapacitor (void )[inline]

Discharges the input sample capacitor for the selected context by setting the channel to AVss. Use ADC_SelectContext to select the correct ADC context before calling this API.

Parameters:
None.
Returns:

None.

ADC_EnableChannelScan()

void ADC_EnableChannelScan (adc_context_t context)

Includes a channel context in the scan sequence. Select the correct context using ADC_SelectContext before calling this API.

Parameters:
context

- Context which needs to be included in the scan. Refer to the adc_context_t enum for the list of available contexts.

Returns:

None.

ADC_EnableChannelSequencer()

void ADC_EnableChannelSequencer (void )[inline]

Enables the ADC channel sequencer. Initialize the ADC module using ADC_Initialize before calling this API.

Parameters:
None.
Returns:

None.

ADC_EnableContinuousConversion()

void ADC_EnableContinuousConversion (void )[inline]

Enables continuous conversion.

Parameters:
None.
Returns:

None.

ADC_EnableDoubleSampling()

void ADC_EnableDoubleSampling (void )[inline]

Enables the Double-Sample Enable bit.

Parameters:
None.
Returns:

None.

ADC_GetAccumulatorValue()

uint24_t ADC_GetAccumulatorValue (void )[inline]

Retrieves a 24-bit value from the ADC accumulator.

Parameters:
None.
Returns:

Value of the ADC accumulator.

ADC_GetConversionResult()

adc_result_t ADC_GetConversionResult (void )[inline]

Retrieves the result of the latest A/D conversion.

Precondition:

Call ADC_StartConversion() before calling this function and check the completion status using the ADC_IsConversionDone() API.

Parameters:
None.
Returns:

The result of the A/D conversion. Refer to adc_result_t.

ADC_GetConversionStageStatus()

uint8_t ADC_GetConversionStageStatus (void )[inline]

Retrieves the ADC module cycle multi-stage status.

Precondition:

Call ADC_StartConversion() before calling this function.

Parameters:
None.
Returns:

Contents of the ADC Status (ADSTAT) register.

ADC_GetCurrentCountofConversions()

uint8_t ADC_GetCurrentCountofConversions (void )[inline]

Retrieves the current value of the ADC Repeat Counter (ADCNT) register.

Precondition:

Call ADC_StartConversion() before calling this function.

Parameters:
None.
Returns:

Current value of the ADC Repeat Counter register.

ADC_GetErrorCalculation()

int16_t ADC_GetErrorCalculation (void )[inline]

Retrieves the value of the ADC Setpoint Error (ADERR) register.

Precondition:

Call ADC_StartConversion() before calling this function.

Parameters:
None.
Returns:

16-bit value obtained from the high byte ADERR (ADERRH) and low byte ADERR (ADERRL) registers.

ADC_GetFilterValue()

uint16_t ADC_GetFilterValue (void )[inline]

Retrieves the value of the ADC Filter (ADFLTR) register.

Parameters:
None.
Returns:

16-bit value obtained from the high byte ADFLTR (ADFLTRH) and low byte ADFLTR (ADFLTRL) registers.

ADC_GetPreviousResult()

uint16_t ADC_GetPreviousResult (void )[inline]

Retrieves the value of the ADC Previous Result (ADPREV) register.

Precondition:

Call ADC_StartConversion() before calling this function.

Parameters:
None.
Returns:

16-bit value obtained from the high byte ADPREV (ADPREVH) and low byte ADPREV (ADPREVL) registers.

ADC_GetSingleConversion()

adc_result_t ADC_GetSingleConversion (adc_channel_t channel)

Retrieves the result of a single A/D conversion on the given channel in Single-Ended mode.

Precondition:

Call ADC_DisableContinuousConversion() before calling this function.

Parameters:
channel

- Analog channel number on which the A/D conversion has to be applied. Refer to adc_channel_t for the available channels.

Returns:

The result of the A/D conversion. Refer to adc_result_t.

ADC_HasAccumulatorOverflowed()

bool ADC_HasAccumulatorOverflowed (void )[inline]

Determines if the ADC accumulator has overflowed.

Precondition:

Call ADC_StartConversion() before calling this function.

Parameters:
None.
Return values:
True

- ADC accumulator has overflowed.

False

- ADC accumulator has not overflowed.

ADC_HasErrorCrossedLowerThreshold()

bool ADC_HasErrorCrossedLowerThreshold (void )[inline]

Determines if the ADC error is less than the lower threshold.

Precondition:

Call ADC_StartConversion() before calling this function.

Parameters:
None.
Return values:
True

- ADC error is less than the lower threshold.

False

- ADC error is higher than the lower threshold.

ADC_HasErrorCrossedUpperThreshold()

bool ADC_HasErrorCrossedUpperThreshold (void )[inline]

Determines if the ADC error is higher than the upper threshold.

Precondition:

Call ADC_StartConversion() before calling this function.

Parameters:
None.
Return values:
True

- ADC error has crossed the upper threshold.

False

- ADC error has not crossed the upper threshold.

ADC_Initialize()

void ADC_Initialize (void )

Initializes the ADC module. This routine must be called before other ADC APIs.

Parameters:
None.
Returns:

None.

ADC_IsConversionDone()

bool ADC_IsConversionDone (void )[inline]

Checks if the ongoing A/D conversion is complete.

Precondition:

Call ADC_StartConversion() before calling this function.

Parameters:
None.
Return values:
True

- Conversion is complete.

False

- Conversion is ongoing.

ADC_SelectContext()

void ADC_SelectContext (adc_context_t context)[inline]

Selects an ADC context to perform read/write operations on context-specific registers.

Parameters:
context

- Context to be selected. Refer to the adc_context_t enum for the list of available contexts.

Returns:

None.

ADC_SetAcquisitionRegister()

void ADC_SetAcquisitionRegister (uint16_t acquisitionValue)

Loads the ADC Acquisition Time Control (ADACQ) register with the specified value.

Parameters:
acquisitionValue

- Value to be loaded in the ADC Acquisition Time Control register.

Returns:

None.

ADC_SetADIInterruptHandler()

void ADC_SetADIInterruptHandler (void(*)(void) InterruptHandler)

Sets the callback for the ADC Interrupt Service Routine (ISR).

Parameters:
InterruptHandler

- Callback function to be called.

Returns:

None.

ADC_SetChannel()

void ADC_SetChannel (adc_channel_t channel)[inline]

Sets the positive channel as per user selection.

Precondition:

Initialize the ADC with ADC_Initialize() before calling this API.

Parameters:
channel

- Desired analog channel. Refer to the adc_channel_t enum for the list of available analog channels.

Returns:

None.

ADC_SetContext1ThresholdInterruptHandler()

void ADC_SetContext1ThresholdInterruptHandler (void(*)(void) InterruptHandler)

Sets the callback for the ADC Context 1 (ADCH1) interrupt.

Parameters:
InterruptHandler

- Callback function to be called.

Returns:

None.

ADC_SetContext2ThresholdInterruptHandler()

void ADC_SetContext2ThresholdInterruptHandler (void(*)(void) InterruptHandler)

Sets the callback for the ADC Context 2 (ADCH2) interrupt.

Parameters:
InterruptHandler

- Callback function to be called.

Returns:

None.

ADC_SetContext3ThresholdInterruptHandler()

void ADC_SetContext3ThresholdInterruptHandler (void(*)(void) InterruptHandler)

Sets the callback for the ADC Context 3 (ADCH3) interrupt.

Parameters:
InterruptHandler

- Callback function to be called.

Returns:

None.

ADC_SetContext4ThresholdInterruptHandler()

void ADC_SetContext4ThresholdInterruptHandler (void(*)(void) InterruptHandler)

Sets the callback for the ADC Context 4 (ADCH4) interrupt.

Parameters:
InterruptHandler

- Callback function to be called.

Returns:

None.

ADC_SetLowerThreshold()

void ADC_SetLowerThreshold (uint16_t lowerThreshold)

Sets the value of the ADC Lower Threshold (ADLTH) register.

Parameters:
lowerThreshold

- 16-bit value for the ADC Lower Threshold register.

Returns:

None.

ADC_SetPrechargeRegister()

void ADC_SetPrechargeRegister (uint16_t prechargeTime)

Loads the ADC Precharge Time Control (ADPRE) register with the specified value.

Parameters:
prechargeTime

- Value to be loaded in the ADC Precharge Time Control register.

Returns:

None.

ADC_SetRepeatCount()

void ADC_SetRepeatCount (uint8_t repeatCount)[inline]

Loads the ADC Repeat Counter (ADCNT) with the specified value.

Parameters:
repeatCount

- Value to be loaded to the ADC Repeat Counter register.

Returns:

None.

ADC_SetStopOnInterrupt()

void ADC_SetStopOnInterrupt (void )[inline]

Enables the Stop-on-Interrupt bit.

Precondition:

Call ADC_EnableContinuousConversion() before calling this function.

Parameters:
None.
Returns:

None.

ADC_SetUpperThreshold()

void ADC_SetUpperThreshold (uint16_t upperThreshold)

Sets the value of the ADC Upper Threshold (ADUTH) register.

Parameters:
upperThreshold

- 16-bit value for the ADC Upper Threshold register.

Returns:

None.

ADC_StartConversion()

void ADC_StartConversion (void )[inline]

Starts the A/D conversion on the selected channel.

Parameters:
None.
Returns:

None.

ADC_StartConversionOnChannel()

void ADC_StartConversionOnChannel (adc_channel_t channel)

Starts the A/D conversion on the selected channel.

Parameters:
channel

- Analog channel number on which the A/D conversion has to be applied. Refer to adc_channel_t for the list of available channels.

Returns:

None.

ADC_StopConversion()

void ADC_StopConversion (void )[inline]

Stops the ongoing A/D conversion.

Precondition:

Call ADC_StartConversion() before calling this function.

Parameters:
None.
Returns:

None.

Enumeration Type Documentation

adc_channel_t

enum adc_channel_t

Contains the available ADC channels.

channel_ADCG1
channel_OPA1IN_pos
channel_OPA2IN_pos
channel_DAC2
channel_DAC3
channel_VSS
channel_Temp
channel_DAC1
channel_FVR_Buffer1
channel_FVR_Buffer2
channel_OPA1IN0_pos
channel_OPA1IN1_pos
channel_OPA1IN2_pos
channel_OPA1IN3_pos
channel_OPA2IN0_pos
channel_OPA2IN1_pos
channel_OPA2IN2_pos
channel_OPA2IN3_pos

4.1.3.1.6 File Documentation

source/adc.c File Reference

This is the generated driver implementation file for the ADC driver.

#include <xc.h>
#include "../adc.h"

Functions

Detailed Description

This is the generated driver implementation file for the ADC driver.

ADC Generated Driver File

Version: ADC Driver Version 1.0.1

Function Documentation

ADC_DefaultADI_ISR()

static void ADC_DefaultADI_ISR (void )[static]

ADC_DefaultContext1Threshold_ISR()

static void ADC_DefaultContext1Threshold_ISR (void )[static]

ADC_DefaultContext2Threshold_ISR()

static void ADC_DefaultContext2Threshold_ISR (void )[static]

ADC_DefaultContext3Threshold_ISR()

static void ADC_DefaultContext3Threshold_ISR (void )[static]

ADC_DefaultContext4Threshold_ISR()

static void ADC_DefaultContext4Threshold_ISR (void )[static]

Variable Documentation

ADC_Context1ThresholdHandler

void(* ADC_Context1ThresholdHandler) (void)[static]

ADC_Context2ThresholdHandler

void(* ADC_Context2ThresholdHandler) (void)[static]

ADC_Context3ThresholdHandler

void(* ADC_Context3ThresholdHandler) (void)[static]

ADC_Context4ThresholdHandler

void(* ADC_Context4ThresholdHandler) (void)[static]

ADC_ConversionCompleteHandler

void(* ADC_ConversionCompleteHandler) (void)[static]

Section: Included Files

source/adc.h File Reference

#include <stdint.h>
#include <stdbool.h>

Functions

Macros

Typedefs

  • typedef __uint24 uint24_t

  • typedef uint16_t adc_result_t

    Displays the result of the Analog-to-Digital (A/D) conversion.

Enumerations

Detailed Description

ADC Generated Driver API Header File

Typedef Documentation

Enumeration Type Documentation

adc_context_t

enum adc_context_t

context_1
context_2
context_3
context_4

4.1.3.1.7 Module Documentation

Melody ADCCC Use Cases

Melody ADCCC Use Case 1 - Configure ADC Basic Mode and Data Streamer

For new users it is recommended to start with a Single-Ended ADC read to make the learning curve easier. The output will be displayed using Data Streamer.

The use cases show example uses of the ADCCC Driver, within an MCC Melody project:
  • Add the following drivers/libraries to the project:
    1. Data Streamer

    2. ADC

  • DataStreamer Configuration:
    1. UART Dependency: UART2

    2. Variable type: uint16_t

    3. Variable name: adc_result  

  • ADC Easy View Configuration:
    1. Single-ended mode

    2. Right-justified

    3. VDD 3.3V

    4. Clock Selection ADCRC

  • ADC Context 1 Configuration:
    1. Positive Channel: ANA2

    2. Positive Reference: VDD -Other:

    3. Any other peripherals or pins needed for the use case.

  • Configure Pin Grid View:
    1. PORTA Pin 2 as ANPx input

  • Generate the code

  • Add the code snippet(s) to the application code

  • Program the board

#include "mcc_generated_files/system/system.h"
volatile bool SEND_FRAME = false;
void DS_Frame_Update(void){
    DataStreamer.adc_result = ADC_GetSingleConversion(channel_ANA2);
    SEND_FRAME = true;
}
int main(void)
{
    SYSTEM_Initialize();
    
    DataStreamer.adc_result = 0; 

    while(1)
    {
        DS_Frame_Update();      // write the result of an ADC read to the Data Streamer struct
        if(SEND_FRAME)  {       // if the Data Streamer frame has been updated
            WriteFrame();       // Write the new frame 
            SEND_FRAME = false; // Set the boolean back to false for next time
            LED_Toggle();       // Toggle the LED as a visual indicator
        }
    }    
}

Melody ADCCC Use Case 2: ADCCC in Burst_Average_mode with DataStreamer of ADC Result

The ADC is configured to take 16 samples and then average. This is useful for mitigating random noise. The averaged ADC result is sent to DataStreamer, for display in Data Visualizer. After each ADC conversion is completed and sent to DataStreamer the onboard LED is toggled.

Device Resources:
  1. Add ADC

  2. Add DataStreamer

ADC Easy View Configuration:
  1. Single-ended mode

  2. Right-justified

  3. VDD 3.3V

  4. External Positive Reference Voltage: 3.3V

  5. Clock Selection ADCRC ADC Context 1 Configuration:

  6. Positive Channel: ANA2

  7. Positive Reference: VDD

  8. Operating Mode Selection: Burst_Average_mode

  9. Error Calculation Mode: First derivative of filtered value

  10. Upper Threshold: 3.3V

  11. Lower Threshold: 0V

  12. Threshold Setpoint: 0V

  13. Repeat Threshold: 64

  14. Accumulator Right Shift: 6

  15. Acquisition Count: 1 (minimum, dependent on analog circuit output impedance)

DataStreamer:
  • Configuration Settings:
    1. Variable type: uint16_t

    2. Variable name: adc_result

  • Dependency Selector:  

    1. UART Dependency: UART2.

System:
  • Clock Configuration: Default (1 MHz)

  • Pins: (For all pins check board schematics)
    1. Pin Grid View: Select an ANx (ANA2).

    2. Pin Grid View: Select pin for UART Transmit - Tx (RB4).

    3. Pin Grid View: Select LED pin as output.  

    4. Pins: Rename Custom Name to "LED".

After configuring the components as described above, click 'Generate' to generate the code. Then add the following code snippets to your application:

#include "mcc_generated_files/system/system.h"
volatile bool SEND_FRAME = false;
void DS_Frame_Update(void){
    ADC_SetChannel(channel_ANA2);
    ADC_StartConversion();
    while(!(ADC_IsConversionDone()));
    DataStreamer.adc_result = ADC_GetFilterValue();
    SEND_FRAME = true;
}
int main(void)
{
    SYSTEM_Initialize();
    
    DataStreamer.adc_result = 0;

    while(1)
    {
        DS_Frame_Update();
        if(SEND_FRAME)  {
            WriteFrame();
            SEND_FRAME = false;
            LED_Toggle();
        }
    }    
}