Classes | |
| struct | ADC_Sample |
| ADC sample with value and associated channel. More... | |
| struct | RMS_FIFO |
| Circular buffer for efficient RMS calculation. More... | |
Functions | |
| void IRAM_ATTR | on_adc_data_ready () |
| Interrupt service routine for completed ADC conversions. | |
| void | task_adquisicion (void *pvParameters) |
| ADC data acquisition task with improved multiplexer handling. | |
| void | task_procesamiento (void *pvParameters) |
| Sample processing and RMS calculation task. | |
| int | get_rms_history (int channel, float *output_buffer, int count) |
| Gets RMS value history for a specific channel. | |
Variables | |
| const float | CONVERSION_FACTORS [NUM_CHANNELS] |
| Channel-specific conversion factors for each ADC channel. | |
| QueueHandle_t | queue_adc_samples |
| Communication queue for ADC samples. | |
| RMS_FIFO | fifos [NUM_CHANNELS] |
| Array of FIFOs for each measurement channel. | |
| float | rms_history_ch0 [RMS_HISTORY_SIZE] |
| RMS value history for channel 0. | |
| float | rms_history_ch1 [RMS_HISTORY_SIZE] |
| RMS value history for channel 1. | |
| float | rms_history_ch2 [RMS_HISTORY_SIZE] |
| RMS value history for channel 2. | |
| volatile int | rms_history_head = 0 |
| Write index for RMS histories. | |
| SemaphoreHandle_t | rms_history_mutex |
| Mutex for concurrent access protection to RMS histories. | |
| volatile bool | adc_data_ready = false |
| ADC data ready flag (ISR). | |
| volatile uint8_t | current_isr_channel = 0 |
| Current channel in sampling sequence (ISR). | |
| const int | FIFO_SIZE = 320 |
| Circular FIFO buffer size for RMS calculation. | |
| const int | PROCESS_INTERVAL_MS = 1000 |
| RMS processing interval in milliseconds. | |
| const int | RMS_HISTORY_SIZE = 100 |
| RMS value history size for each channel. | |
| const float | CONVERSION_FACTOR = 0.618f |
| Global conversion factor (maintained for compatibility). | |
This module implements analog signal acquisition via ADS1015 and the complete flow of:
Flow summary:
1) ADC initialization
2) Sample acquisition
3) RMS processing
4) History management
5) Channel calibration
6) Incremental RMS algorithm
Warnings and best practices:
| int get_rms_history | ( | int | channel, |
| float * | output_buffer, | ||
| int | count ) |
Gets RMS value history for a specific channel.
Extracts the last N RMS values in a thread-safe manner using mutex. Values are returned in chronological order (oldest first).
| channel | Channel number (0, 1 or 2). |
| output_buffer | Output buffer for RMS values. |
| count | Number of requested values. |
| void IRAM_ATTR on_adc_data_ready | ( | ) |
Interrupt service routine for completed ADC conversions.
Executes when ADS1015 completes a conversion and activates ALERT line.
| void task_adquisicion | ( | void * | pvParameters | ) |
ADC data acquisition task with improved multiplexer handling.
Manages ADC conversion sequence in round-robin mode between channels. Implements explicit multiplexer configuration selection for each channel. Enqueues samples in queue_adc_samples for subsequent processing.
| pvParameters | Task parameters (unused). |
Explicit multiplexer configuration selection per channel.
Direct mapping from channel number to ADS1015 multiplexer configuration constant to avoid addressing errors.
| void task_procesamiento | ( | void * | pvParameters | ) |
Sample processing and RMS calculation task.
Consumes samples from queue_adc_samples, stores them in circular FIFOs and periodically calculates RMS values using efficient incremental algorithms. Updates RMS history in a thread-safe manner.
| pvParameters | Task parameters (unused). |
| const float CONVERSION_FACTOR = 0.618f |
Global conversion factor (maintained for compatibility).
| const float CONVERSION_FACTORS[NUM_CHANNELS] |
Channel-specific conversion factors for each ADC channel.
Enables individual channel calibration to compensate for differences in sensors, signal conditioning or specific measurement ranges.