diff --git a/docs/readme.md b/docs/readme.md index 3c01f87..031ec2f 100644 --- a/docs/readme.md +++ b/docs/readme.md @@ -56,7 +56,7 @@ void loop() { #### ADC Multichannel (GIGA R1 WiFi) This library supports concurrent usage of up to **three** ADCs (_ADC1_, _ADC2_ and _ADC3_). -Each ADC instance can handle up to **five** channels. +Each ADC instance can handle up to **16** channels. **Note:** It's important to be aware that certain pins cannot be used across multiple ADCs or cannot share the same ADC. diff --git a/src/AdvancedADC.h b/src/AdvancedADC.h index 844985b..994687c 100644 --- a/src/AdvancedADC.h +++ b/src/AdvancedADC.h @@ -36,19 +36,23 @@ class AdvancedADC { template AdvancedADC(pin_size_t p0, T ... args): n_channels(0), descr(nullptr) { static_assert(sizeof ...(args) < AN_MAX_ADC_CHANNELS, - "A maximum of 5 channels can be sampled successively."); + "A maximum of 16 channels can be sampled successively."); for (auto p : {p0, args...}) { adc_pins[n_channels++] = analogPinToPinName(p); } } - AdvancedADC(): n_channels(0), descr(nullptr) {} + AdvancedADC(): n_channels(0), descr(nullptr) { + } ~AdvancedADC(); bool available(); SampleBuffer read(); int begin(uint32_t resolution, uint32_t sample_rate, size_t n_samples, size_t n_buffers); - int begin(uint32_t resolution, uint32_t sample_rate, size_t n_samples, size_t n_buffers, size_t n_pins, pin_size_t *pins) { - if (n_pins > AN_MAX_ADC_CHANNELS) n_pins = AN_MAX_ADC_CHANNELS; + int begin(uint32_t resolution, uint32_t sample_rate, size_t n_samples, size_t n_buffers, + size_t n_pins, pin_size_t *pins) { + if (n_pins > AN_MAX_ADC_CHANNELS) { + n_pins = AN_MAX_ADC_CHANNELS; + } for (size_t i = 0; i < n_pins; ++i) { adc_pins[i] = analogPinToPinName(pins[i]); } diff --git a/src/AdvancedAnalog.h b/src/AdvancedAnalog.h index c9c55f6..d2c46d6 100644 --- a/src/AdvancedAnalog.h +++ b/src/AdvancedAnalog.h @@ -35,7 +35,7 @@ enum { typedef uint16_t Sample; // Sample type used for ADC/DAC. typedef DMABuffer &SampleBuffer; -#define AN_MAX_ADC_CHANNELS (5) +#define AN_MAX_ADC_CHANNELS (16) #define AN_MAX_DAC_CHANNELS (1) #define AN_ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) diff --git a/src/HALConfig.cpp b/src/HALConfig.cpp index 984d9f7..f62e1be 100644 --- a/src/HALConfig.cpp +++ b/src/HALConfig.cpp @@ -164,7 +164,10 @@ int hal_dac_config(DAC_HandleTypeDef *dac, uint32_t channel, uint32_t trigger) { } static uint32_t ADC_RANK_LUT[] = { - ADC_REGULAR_RANK_1, ADC_REGULAR_RANK_2, ADC_REGULAR_RANK_3, ADC_REGULAR_RANK_4, ADC_REGULAR_RANK_5 + ADC_REGULAR_RANK_1, ADC_REGULAR_RANK_2, ADC_REGULAR_RANK_3, ADC_REGULAR_RANK_4, + ADC_REGULAR_RANK_5, ADC_REGULAR_RANK_6, ADC_REGULAR_RANK_7, ADC_REGULAR_RANK_8, + ADC_REGULAR_RANK_9, ADC_REGULAR_RANK_10, ADC_REGULAR_RANK_11, ADC_REGULAR_RANK_12, + ADC_REGULAR_RANK_13, ADC_REGULAR_RANK_14, ADC_REGULAR_RANK_15, ADC_REGULAR_RANK_16 }; int hal_adc_config(ADC_HandleTypeDef *adc, uint32_t resolution, uint32_t trigger, PinName *adc_pins, uint32_t n_channels) { @@ -196,7 +199,7 @@ int hal_adc_config(ADC_HandleTypeDef *adc, uint32_t resolution, uint32_t trigger adc->Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_RISING; adc->Init.ConversionDataManagement = ADC_CONVERSIONDATA_DMA_CIRCULAR; - if (HAL_ADC_Init(adc) != HAL_OK + if (HAL_ADC_Init(adc) != HAL_OK || HAL_ADCEx_Calibration_Start(adc, ADC_CALIB_OFFSET, ADC_SINGLE_ENDED) != HAL_OK) { return -1; }