Skip to content

ADC_set_channel

gicking edited this page Feb 8, 2018 · 3 revisions

Description

back to Command Reference / Analog-IO

Set ADC measurement channel for continuous conversion (see ADC_init()).

Notes:

  • Only pins marked as AINx in respective device datasheet have ADC capability.
  • For accurate ADC results configure the respective pin as INPUT via pinMode()
  • ADC_set_channel() has no effect in single shot mode
  • continuous ADC conversion consumes comparatively high power --> use single-shot mode in energy sensitive applications

Inclusion

  • defined in adc.h
  • not loaded by main_general.h
  • no #define required

Syntax

ADC_set_channel(channel)

Parameters

  • input:

    • channel: number x of AINx pin (see STM8 datasheet)
  • output:

    • none

Returns

  • Nothing

Example Code

The below code initializes the ADC for continuous measurements of pin AIN5.

#include "main_general.h"
#include "adc.h"

void setup()
{
  ADC_init(ADC_CONTINUOUS);
  ADC_set_channel(5);
  ADC_start_conversion();
}

void loop()
{
  uint16_t result;
  if (ADC_check_conversion_flag()) {
    result = ADC_get_result(5);
    ADC_reset_conversion_flag();
  }
  // ...do something with it
  delay(100);
}

Relevant Tutorial

  • tbd

Notes and Warnings

To avoid damage

  • do not expose I/Os to voltages outside [-0.3V; Vdd+0.3V], else limit injection currents to the specificied limits

See also

Clone this wiki locally