|
HardFOC Core
API reference
|
BaseAdc adapter for all TMC9660 ADC channels. More...
#include <Tmc9660Handler.h>
Public Member Functions | |
| Adc (Tmc9660Handler &parent) | |
| Construct the ADC wrapper. | |
| ~Adc () noexcept override=default | |
| Default destructor. | |
BaseAdc Interface Implementation | |
| bool | Initialize () noexcept override |
| Initialize ADC wrapper (no-op; TMC9660 ADC is always available). | |
| bool | Deinitialize () noexcept override |
| Deinitialize ADC wrapper (no-op). | |
| hf_u8_t | GetMaxChannels () const noexcept override |
| Returns the total number of readable channels (15). | |
| bool | IsChannelAvailable (hf_channel_id_t channel_id) const noexcept override |
| Check if a channel ID is valid per the TMC9660 channel scheme. | |
| hf_adc_err_t | ReadChannelV (hf_channel_id_t channel_id, float &channel_reading_v, hf_u8_t numOfSamplesToAvg=1, hf_time_t timeBetweenSamples=0) noexcept override |
| Read a channel and return the voltage. | |
| hf_adc_err_t | ReadChannelCount (hf_channel_id_t channel_id, hf_u32_t &channel_reading_count, hf_u8_t numOfSamplesToAvg=1, hf_time_t timeBetweenSamples=0) noexcept override |
| Read a channel and return the raw count. | |
| hf_adc_err_t | ReadChannel (hf_channel_id_t channel_id, hf_u32_t &channel_reading_count, float &channel_reading_v, hf_u8_t numOfSamplesToAvg=1, hf_time_t timeBetweenSamples=0) noexcept override |
| Read a channel and return both raw count and voltage. | |
| hf_adc_err_t | ReadMultipleChannels (const hf_channel_id_t *channel_ids, hf_u8_t num_channels, hf_u32_t *readings, float *voltages) noexcept override |
| Read multiple channels in a batch. | |
| hf_adc_err_t | GetStatistics (hf_adc_statistics_t &statistics) noexcept override |
| Get accumulated ADC statistics (conversion counts, timing). | |
| hf_adc_err_t | GetDiagnostics (hf_adc_diagnostics_t &diagnostics) noexcept override |
| Get ADC health diagnostics (error counts, health status). | |
| hf_adc_err_t | ResetStatistics () noexcept override |
| Reset all accumulated statistics to zero. | |
| hf_adc_err_t | ResetDiagnostics () noexcept override |
| Reset diagnostics counters and health flags. | |
TMC9660-Specific Channel Methods | |
Direct accessors for specific TMC9660 ADC channel types. | |
| hf_adc_err_t | ReadAinChannel (uint8_t ain_channel, hf_u32_t &raw_value, float &voltage) noexcept |
| Read an external analog input (AIN) channel. | |
| hf_adc_err_t | ReadCurrentSenseChannel (uint8_t current_channel, hf_u32_t &raw_value, float &voltage) noexcept |
| Read a phase current sense channel. | |
| hf_adc_err_t | ReadVoltageChannel (uint8_t voltage_channel, hf_u32_t &raw_value, float &voltage) noexcept |
| Read a voltage monitoring channel. | |
| hf_adc_err_t | ReadTemperatureChannel (uint8_t temp_channel, hf_u32_t &raw_value, float &voltage) noexcept |
| Read a temperature channel. | |
| hf_adc_err_t | ReadMotorDataChannel (uint8_t motor_channel, hf_u32_t &raw_value, float &voltage) noexcept |
| Read a motor data channel. | |
Private Member Functions | |
| hf_adc_err_t | ValidateChannelId (hf_channel_id_t channel_id) const noexcept |
| Validate a channel ID against all valid ranges. | |
| hf_adc_err_t | ReadChannelLocked (hf_channel_id_t channel_id, hf_u32_t &raw, float &voltage) noexcept |
| Internal channel read that returns both raw count and correct voltage. | |
| hf_adc_err_t | UpdateStatistics (hf_adc_err_t result, uint64_t start_time_us) noexcept |
| Update conversion timing statistics. | |
| uint64_t | GetCurrentTimeUs () const noexcept |
| Get current time in microseconds from RTOS tick counter. | |
| void | UpdateDiagnostics (hf_adc_err_t error) noexcept |
| Update error diagnostics (consecutive error tracking, health flag). | |
| const char * | GetChannelTypeString (hf_channel_id_t channel_id) const noexcept |
| Get a human-readable string for a channel type (for logging). | |
Private Attributes | |
| Tmc9660Handler & | parent_ |
| Owning handler. | |
| RtosMutex | mutex_ |
| Thread-safety for statistics. | |
| hf_adc_statistics_t | statistics_ |
| Accumulated conversion statistics. | |
| hf_adc_diagnostics_t | diagnostics_ |
| Health and error diagnostics. | |
| std::atomic< hf_adc_err_t > | last_error_ |
| Most recent error code. | |
BaseAdc adapter for all TMC9660 ADC channels.
Provides a unified BaseAdc interface for reading the TMC9660's various analog and telemetry data channels. Channels are identified by a numeric ID scheme:
| Channel ID Range | Type | Description |
|---|---|---|
| 0 - 3 | AIN channels | External analog inputs (GPIO5) |
| 10 - 13 | Current sense | Phase current ADC (I0-I3) |
| 20 - 21 | Voltage monitor | 20=supply, 21=driver voltage |
| 30 - 31 | Temperature | 30=chip, 31=external NTC |
| 40 - 42 | Motor data | 40=current, 41=velocity, 42=pos |
The wrapper includes thread-safe statistics and diagnostics tracking via RtosMutex. Voltage conversions use a default 3.3V / 16-bit scale; for temperature and motor data channels, the "voltage" field contains the physical value directly (degrees Celsius, mA, etc.).
BaseAdc*, use Tmc9660AdcWrapper which delegates to this instance.| Tmc9660Handler::Adc::Adc | ( | Tmc9660Handler & | parent | ) |
Construct the ADC wrapper.
| parent | Reference to the owning Tmc9660Handler. |
|
overridedefaultnoexcept |
Default destructor.
|
overridenoexcept |
Deinitialize ADC wrapper (no-op).
|
privatenoexcept |
Get a human-readable string for a channel type (for logging).
|
privatenoexcept |
Get current time in microseconds from RTOS tick counter.
|
overridenoexcept |
Get ADC health diagnostics (error counts, health status).
|
overridenoexcept |
Returns the total number of readable channels (15).
The TMC9660 uses a non-contiguous channel ID scheme (0-3, 10-13, 20-21, 30-31, 40-42). Since IDs are sparse, callers should use IsChannelAvailable(channel_id) to validate specific channel IDs rather than iterating 0..GetMaxChannels()-1.
|
overridenoexcept |
Get accumulated ADC statistics (conversion counts, timing).
|
overridenoexcept |
Initialize ADC wrapper (no-op; TMC9660 ADC is always available).
|
overridenoexcept |
Check if a channel ID is valid per the TMC9660 channel scheme.
| channel_id | Channel ID to validate. |
|
noexcept |
Read an external analog input (AIN) channel.
| ain_channel | AIN channel number (0-3). | |
| [out] | raw_value | Raw 16-bit ADC count. |
| [out] | voltage | Converted voltage (3.3V / 65535 scale). |
|
overridenoexcept |
Read a channel and return both raw count and voltage.
| channel_id | Channel ID. | |
| [out] | channel_reading_count | Raw count. |
| [out] | channel_reading_v | Voltage / physical value. |
| numOfSamplesToAvg | Number of samples to average. | |
| timeBetweenSamples | Delay between samples in ms. |
|
overridenoexcept |
Read a channel and return the raw count.
| channel_id | Channel ID. | |
| [out] | channel_reading_count | Raw ADC count or integer value. |
| numOfSamplesToAvg | Number of samples to average. | |
| timeBetweenSamples | Delay between samples in ms. |
|
privatenoexcept |
Internal channel read that returns both raw count and correct voltage.
Dispatches to the appropriate sub-reader (AIN, current, voltage, temperature, motor data) and returns both the raw count and the correctly-converted voltage. Caller must hold mutex_.
| channel_id | Channel ID per the TMC9660 channel scheme. | |
| [out] | raw | Raw ADC count or integer value. |
| [out] | voltage | Correctly-converted voltage or physical value. |
|
overridenoexcept |
Read a channel and return the voltage.
| channel_id | Channel ID per the scheme above. | |
| [out] | channel_reading_v | Voltage reading (or physical value for temp/motor channels). |
| numOfSamplesToAvg | Number of samples to average (currently unused). | |
| timeBetweenSamples | Delay between samples in ms (currently unused). |
|
noexcept |
Read a phase current sense channel.
| current_channel | Current channel number (0=I0, 1=I1, 2=I2, 3=I3). | |
| [out] | raw_value | Raw ADC count. |
| [out] | voltage | Converted voltage. |
|
noexcept |
Read a motor data channel.
| motor_channel | 0=current (mA), 1=velocity (internal), 2=position (counts). | |
| [out] | raw_value | Raw integer value. |
| [out] | voltage | Float representation of the same value. |
|
overridenoexcept |
Read multiple channels in a batch.
| channel_ids | Array of channel IDs to read. | |
| num_channels | Number of channels. | |
| [out] | readings | Array to store raw counts. |
| [out] | voltages | Array to store voltages. |
|
noexcept |
Read a temperature channel.
| temp_channel | 0=chip temperature (Celsius), 1=external NTC raw. | |
| [out] | raw_value | Raw value (temp*100 for chip, raw ADC for external). |
| [out] | voltage | Temperature in Celsius (chip) or voltage (external). |
|
noexcept |
Read a voltage monitoring channel.
| voltage_channel | 0=supply voltage, 1=driver voltage. | |
| [out] | raw_value | Raw value (voltage * 1000 as integer mV). |
| [out] | voltage | Voltage in volts. |
|
overridenoexcept |
Reset diagnostics counters and health flags.
|
overridenoexcept |
Reset all accumulated statistics to zero.
|
privatenoexcept |
Update error diagnostics (consecutive error tracking, health flag).
|
privatenoexcept |
Update conversion timing statistics.
|
privatenoexcept |
Validate a channel ID against all valid ranges.
|
mutableprivate |
Health and error diagnostics.
|
private |
Most recent error code.
|
mutableprivate |
Thread-safety for statistics.
|
private |
Owning handler.
|
mutableprivate |
Accumulated conversion statistics.