92 lines
1.8 KiB
C
92 lines
1.8 KiB
C
#include "ADC.h"
|
|
#include "stm32f1xx_ll_bus.h"
|
|
#include "stm32f1xx_ll_adc.h"
|
|
#include "stm32f1xx_ll_rcc.h"
|
|
|
|
/**
|
|
* @brief Configure l'ADC pour les différents channels
|
|
* @note
|
|
* @param None
|
|
* @retval None
|
|
*/
|
|
void conf_ADC (void) {
|
|
|
|
//Activation de la clock de l'ADC
|
|
|
|
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_ADC1);
|
|
|
|
//Division pour etre < 14 MHz
|
|
|
|
LL_RCC_SetADCClockSource(LL_RCC_ADC_CLKSRC_PCLK2_DIV_6);
|
|
|
|
//Bit ADON à 1 pour lancer la conversion
|
|
|
|
LL_ADC_Enable(ADC1);
|
|
|
|
//Définition
|
|
|
|
LL_ADC_REG_InitTypeDef My_LL_ADC_REG_Init_Struct;
|
|
|
|
//Initialisation
|
|
|
|
LL_ADC_REG_StructInit(&My_LL_ADC_REG_Init_Struct);
|
|
|
|
My_LL_ADC_REG_Init_Struct.SequencerDiscont = LL_ADC_REG_SEQ_DISCONT_1RANK ;
|
|
|
|
LL_ADC_StartCalibration(ADC1);
|
|
|
|
//Application a l'ADC1
|
|
|
|
LL_ADC_REG_Init(ADC1,&My_LL_ADC_REG_Init_Struct);
|
|
|
|
//Configuration du Sampling Time
|
|
|
|
LL_ADC_SetChannelSamplingTime(ADC1, LL_ADC_CHANNEL_10, LL_ADC_SAMPLINGTIME_239CYCLES_5);
|
|
LL_ADC_SetChannelSamplingTime(ADC1, LL_ADC_CHANNEL_11, LL_ADC_SAMPLINGTIME_239CYCLES_5);
|
|
}
|
|
|
|
/**
|
|
* @brief Règle les différentes entrées et sortie nécessaire à la girouette
|
|
* @note
|
|
* @param None
|
|
* @retval valeur du rapport "X/Y" [0 infini]
|
|
*/
|
|
uint32_t X;
|
|
uint32_t Y;
|
|
float rapport;
|
|
|
|
float start_ADC (void) {
|
|
|
|
//Conversion X
|
|
|
|
LL_ADC_REG_SetSequencerRanks(ADC1,LL_ADC_REG_RANK_1,LL_ADC_CHANNEL_10);
|
|
|
|
LL_ADC_Enable(ADC1);
|
|
|
|
LL_ADC_REG_StartConversionSWStart(ADC1);
|
|
|
|
while ( LL_ADC_IsActiveFlag_EOS(ADC1) == 0);
|
|
|
|
X=LL_ADC_REG_ReadConversionData32(ADC1);
|
|
|
|
|
|
//Conversion Y
|
|
|
|
LL_ADC_REG_SetSequencerRanks(ADC1,LL_ADC_REG_RANK_1,LL_ADC_CHANNEL_11);
|
|
|
|
LL_ADC_Enable(ADC1);
|
|
|
|
LL_ADC_REG_StartConversionSWStart(ADC1);
|
|
|
|
while ( LL_ADC_IsActiveFlag_EOS(ADC1) == 0);
|
|
|
|
Y=LL_ADC_REG_ReadConversionData32(ADC1);
|
|
|
|
|
|
//Calcul rapport
|
|
|
|
rapport = X/Y;
|
|
|
|
return rapport;
|
|
|
|
}
|