HRI board firmware  v2.1
Microcontroller firmware of the board used during the HRI labs.
Enumerations | Functions
Driver / ADC

Driver for the analog-to-digital peripheral of the STM32. More...

Enumerations

enum  AdcChannel {
  ADC_CHANNEL_9 = 9, ADC_CHANNEL_6 = 6, ADC_CHANNEL_7 = 7, ADC_CHANNEL_14 = 14,
  ADC_CHANNEL_15 = 15
}
 Enum that corresponds to the two ADC input channels of the board. More...
 

Functions

void adc_Init (void)
 Initialize the ADC converter (2 analog inputs + current sense). More...
 
void adc_CalibrateCurrentSens (void)
 Compute the current sense offset. More...
 
float32_t adc_GetCurrent (void)
 Compute the current sense offset. More...
 
float32_t adc_GetChannelVoltage (AdcChannel channel)
 Gets the voltage measured by the selected ADC channel. More...
 

Detailed Description

Driver for the analog-to-digital peripheral of the STM32.

An analog-to-digital converter (ADC) is used to measure the voltage of one or several microcontroller analog pins.

In addition, there is an additional channel to measure the current going through the motor (useful for current regulation).

Call adc_Init() first, in the initialization code. Then, call adc_GetChannelVoltage() every time you need the voltage.

To measure accurately the motor current, a calibration has to be performed first. Call dc_CalibrateCurrentSens() in the main(), when the current regulation is disabled (see H-bridge documentation). Then, call adc_GetCurrent() every time it is needed. This function returns the last value transfered by the DMA, so there is no conversion delay when calling this function.

Enumeration Type Documentation

◆ AdcChannel

enum AdcChannel

Enum that corresponds to the two ADC input channels of the board.

Enumerator
ADC_CHANNEL_9 

Pin HALL_INPUT (5) of the connector J9 (Hall position sensor).

ADC_CHANNEL_6 

Pin AN_IN1 (29 & 30) of the connector J12 (analog extension).

ADC_CHANNEL_7 

Pin AN_IN2 (33 & 34) of the connector J12 (analog extension).

ADC_CHANNEL_14 

Pin AN_IN3 (37 & 38) of the connector J12 (analog extension).

ADC_CHANNEL_15 

Pin AN_IN4 (41 & 42) of the connector J12 (analog extension).

Function Documentation

◆ adc_CalibrateCurrentSens()

void adc_CalibrateCurrentSens ( void  )

Compute the current sense offset.

Note
Run before enabling current regulation.

◆ adc_GetChannelVoltage()

float32_t adc_GetChannelVoltage ( AdcChannel  channel)

Gets the voltage measured by the selected ADC channel.

Parameters
channelthe channel of the ADC.
Returns
the measured voltage [V].

◆ adc_GetCurrent()

float32_t adc_GetCurrent ( void  )

Compute the current sense offset.

Return values
Themeasured current in [mA].

◆ adc_Init()

void adc_Init ( void  )

Initialize the ADC converter (2 analog inputs + current sense).