HRI board firmware v2.1 Microcontroller firmware of the board used during the HRI labs.

adc.h
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2017 EPFL-LSRO (Laboratoire de Systemes Robotiques).
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #ifndef __ADC_H
18 #define __ADC_H
19
20 #include "../main.h"
21
22 #define ADC_HALL_PIN GPIO_Pin_1
23 #define ADC_HALL_PORT GPIOB
24 #define ADC_HALL_CHANNEL ADC_Channel_9
25
26 #define ADC_ANIN1_PIN GPIO_Pin_6
27 #define ADC_ANIN1_PORT GPIOA
28 #define ADC_ANIN1_CHANNEL ADC_Channel_6
29
30 #define ADC_ANIN2_PIN GPIO_Pin_7
31 #define ADC_ANIN2_PORT GPIOA
32 #define ADC_ANIN2_CHANNEL ADC_Channel_7
33
34 #define ADC_ANIN3_PIN GPIO_Pin_4
35 #define ADC_ANIN3_PORT GPIOC
36 #define ADC_ANIN3_CHANNEL ADC_Channel_14
37
38 #define ADC_ANIN4_PIN GPIO_Pin_5
39 #define ADC_ANIN4_PORT GPIOC
40 #define ADC_ANIN4_CHANNEL ADC_Channel_15
41
42 #define ADC_CURRENT_SENSE_PIN GPIO_Pin_3
43 #define ADC_CURRENT_SENSE_PORT GPIOA
44 #define ADC_CURRENT_SENSE_CHANNEL ADC_Channel_3
45
46 #define ADC_MAX 4095.0f // Maximum value of the ADC register (2^12 - 1).
47 #define ADC_MAX_CONVERSION_TIME 100 // To avoid locking if the conversion was not started properly.
48 #define ADC_BUFFER_SIZE 33 // Fadc =~300kHz -> TE_ADC = 3.33us -> Average over 32 sample => usable bandwidth <10kHz
49 #define ADC_CURRENT_SCALE (ADC_REF_VOLTAGE / (CURRENT_SHUNT_RESISTANCE * CURRENT_SHUNT_AMPLIFIER_GAIN * ADC_MAX)) // Scale between ADC increment and current [A/incr].
50 #define ADC_CALIB_N_SAMPLES 1000
51
78 typedef enum
79 {
80 ADC_CHANNEL_9 = 9,
81 ADC_CHANNEL_6 = 6,
82 ADC_CHANNEL_7 = 7,
83 ADC_CHANNEL_14 = 14,
84 ADC_CHANNEL_15 = 15,
85 } AdcChannel;
86
87 void adc_Init(void);
88 void adc_CalibrateCurrentSens(void);
89 float32_t adc_GetCurrent(void); // [mA].
90 float32_t adc_GetChannelVoltage(AdcChannel channel);
91
96 #endif
adc_CalibrateCurrentSens
void adc_CalibrateCurrentSens(void)
Compute the current sense offset.
Definition: adc.c:133
AdcChannel
AdcChannel
Enum that corresponds to the two ADC input channels of the board.
Definition: adc.h:78
ADC_CHANNEL_14
Pin AN_IN3 (37 & 38) of the connector J12 (analog extension).
Definition: adc.h:83
ADC_CHANNEL_9
Pin HALL_INPUT (5) of the connector J9 (Hall position sensor).
Definition: adc.h:80
ADC_CHANNEL_15
Pin AN_IN4 (41 & 42) of the connector J12 (analog extension).
Definition: adc.h:84
adc_GetCurrent
float32_t adc_GetCurrent(void)
Compute the current sense offset.
Definition: adc.c:152
adc_GetChannelVoltage
float32_t adc_GetChannelVoltage(AdcChannel channel)
Gets the voltage measured by the selected ADC channel.
Definition: adc.c:223
ADC_CHANNEL_6
Pin AN_IN1 (29 & 30) of the connector J12 (analog extension).
Definition: adc.h:81
adc_Init
void adc_Init(void)
Initialize the ADC converter (2 analog inputs + current sense).
Definition: adc.c:30
ADC_CHANNEL_7
Pin AN_IN2 (33 & 34) of the connector J12 (analog extension).
Definition: adc.h:82