Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F90361788
adc.h
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Thu, Oct 31, 23:37
Size
3 KB
Mime Type
text/x-c
Expires
Sat, Nov 2, 23:37 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
22062223
Attached To
R2671 HHRI-software
adc.h
View Options
#ifndef __ADC_H
#define __ADC_H
#include "../main.h"
#define ADC1_Input_Pin GPIO_Pin_4 // Analog diff. input 1
#define ADC1_Input_Port GPIOC
#define ADC1_Input_Chan ADC_Channel_14
#define ADC2_Input_Pin GPIO_Pin_5 // Analog diff. input 2
#define ADC2_Input_Port GPIOC
#define ADC2_Input_Chan ADC_Channel_15
#define ADC_Current_Sens_Pin GPIO_Pin_3 // Current sense channel
#define ADC_Current_Sens_Port GPIOA
#define ADC_Current_Sens_Chan ADC_Channel_3
#define ADC_MAX 4095 // Maximum value of the ADC register (2^12 - 1).
#define ADC_MAX_CONVERSION_TIME 100 // To avoid locking if the conversion was not started properly.
#define ADC_BUFFER_SIZE 33 // Fadc =~300kHz -> TE_ADC = 3.33us -> Average over 32 sample => usable bandwidth <10kHz
#define ADC_CURRENT_SCALE (STM_SUPPLY_VOLTAGE / (CURRENT_SHUNT_RESISTANCE * CURRENT_SHUNT_AMPLIFIER_GAIN * ADC_MAX)) // Scale between ADC increment and current [A/incr].
#define ADC_CALIB_N_SAMPLES 1000
/** @defgroup ADC Driver / ADC
* @brief 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 pins. In the HRI board, there are two pins that
* can be used. An intermediate electronic stage allows to modify the input
* range from +-33mV to +-10V, in order to get the best sensitivity and range
* for a wide range of analog sensors. Note that the input connector
* (J2-ANALOG IN) provides differential inputs, so one pair of pins per
* channel.
*
* 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.
*
* @addtogroup ADC
* @{
*/
// Switches-selectable scale of the ADC circuit.
// Could be useful to perform a calibration, to precise readings.
#define ADC_SCALE_0_033_V 0.033f ///< +-33mV, switches position: 0100
#define ADC_SCALE_0_165_V 0.165f ///< +-165mV, switches position: 0010
#define ADC_SCALE_0_400_V 0.400f ///< +-400mV, switches position: 1100
#define ADC_SCALE_0_830_V 0.830f ///< +-830mV, switches position: 0001
#define ADC_SCALE_2_V 2.000f ///< +-2V, switches position: 1010
#define ADC_SCALE_10_V 10.00f ///< +-10V, switches position: 1001
/**
* @brief Enum that corresponds to the two ADC input channels of the board.
*/
typedef enum
{
ANIN1=1, ///< Channel 1, pins ANIN1+ (3) and ANIN1- (4) of the connector J2.
ANIN2=2 ///< Channel 2, pins ANIN2+ (7) and ANIN2- (8) of the connector J2.
} AdcChannel;
void adc_Init(void);
void adc_CalibrateCurrentSens(void);
float32_t adc_GetCurrent(void); // [mA].
float32_t adc_GetChannelVoltage(AdcChannel channel, float32_t scale);
/**
* @}
*/
#endif
Event Timeline
Log In to Comment