diff --git a/keil_project/Services/Alimentation.c b/keil_project/Services/Alimentation.c index ad89e86..3e4d704 100644 --- a/keil_project/Services/Alimentation.c +++ b/keil_project/Services/Alimentation.c @@ -1,63 +1,53 @@ #include "Alimentation.h" -void alimentation_init(void){ - RCC -> CFGR |= (0x1<<15); - RCC-> CFGR &= ~ (0x1<<14); - LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_ADC1); - LL_APB1_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOC); - - LL_GPIO_InitTypeDef pc2; - LL_ADC_InitTypeDef adc; - LL_ADC_REG_InitTypeDef adcReg; - - LL_GPIO_StructInit(&pc2); - pc2.Pin = LL_GPIO_PIN_0; - pc2.Mode = LL_GPIO_MODE_ANALOG; - LL_GPIO_Init(GPIOC, &pc2); +void ALIMENTATION_Init(void){ + RCC -> CFGR |= (0x1<<15); + RCC-> CFGR &= ~ (0x1<<14); + LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_ADC1); + LL_APB1_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOC); + + LL_GPIO_InitTypeDef pc2; + LL_ADC_InitTypeDef adc; + LL_ADC_REG_InitTypeDef adcReg; + + LL_GPIO_StructInit(&pc2); + pc2.Pin = LL_GPIO_PIN_0; + pc2.Mode = LL_GPIO_MODE_ANALOG; + LL_GPIO_Init(GPIOC, &pc2); + + + adc.DataAlignment = LL_ADC_DATA_ALIGN_RIGHT; + adc.SequencersScanMode = LL_ADC_SEQ_SCAN_DISABLE; + LL_ADC_Init(ADC1, &adc); + + adcReg.TriggerSource = LL_ADC_REG_TRIG_SOFTWARE ; + adcReg.SequencerLength = LL_ADC_REG_SEQ_SCAN_DISABLE; + adcReg.SequencerDiscont = LL_ADC_REG_SEQ_DISCONT_DISABLE; + adcReg.ContinuousMode = LL_ADC_REG_CONV_SINGLE; + adcReg.DMATransfer = LL_ADC_REG_DMA_TRANSFER_NONE; - adc.DataAlignment = LL_ADC_DATA_ALIGN_RIGHT; - adc.SequencersScanMode = LL_ADC_SEQ_SCAN_DISABLE; - LL_ADC_Init(ADC1, &adc); - - adcReg.TriggerSource = LL_ADC_REG_TRIG_SOFTWARE ; - adcReg.SequencerLength = LL_ADC_REG_SEQ_SCAN_DISABLE; - adcReg.SequencerDiscont = LL_ADC_REG_SEQ_DISCONT_DISABLE; - adcReg.ContinuousMode = LL_ADC_REG_CONV_SINGLE; - adcReg.DMATransfer = LL_ADC_REG_DMA_TRANSFER_NONE; - - - LL_ADC_REG_Init(ADC1, &adcReg); - - /*LL_ADC_SetChannelSamplingTime(ADC2, LL_ADC_CHANNEL_10, LL_ADC_SAMPLINGTIME_1CYCLE_5); - LL_ADC_SetChannelSamplingTime(ADC2, LL_ADC_CHANNEL_11, LL_ADC_SAMPLINGTIME_1CYCLE_5); - - */ - LL_ADC_Enable(ADC1); - - //LL_ADC_EnableIT_EOS(ADC1); - //wait 0,2 µs, calibration is advised - //LL_ADC_StartCalibration(ADC1); - } -float u2; -unsigned int niv_batterie; + LL_ADC_REG_Init(ADC1, &adcReg); + LL_ADC_Enable(ADC1); +} + +float ALIMENTATION_GetBatteryLevel(void){ + float u2; float battery_level; - float get_battery_level(void){ - LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_1, LL_ADC_CHANNEL_12); - LL_ADC_REG_StartConversionSWStart(ADC1); - while (LL_ADC_IsActiveFlag_EOS(ADC1) != 1); - battery_level = LL_ADC_REG_ReadConversionData12(ADC1); - u2 = (battery_level*3.3)/4095.0; - float level = u2*13.0; - return level; + LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_1, LL_ADC_CHANNEL_12); + LL_ADC_REG_StartConversionSWStart(ADC1); + while (LL_ADC_IsActiveFlag_EOS(ADC1) != 1); + battery_level = LL_ADC_REG_ReadConversionData12(ADC1); + u2 = (battery_level*3.3)/4095.0; + float level = u2*13.0; + return level; } - int is_level_enough(void){ - if (get_battery_level()<(0.8*12)){ - return 0; - }else{ - return 1; - } +int ALIMENTATION_IsLevelEnough(void){ + if (ALIMENTATION_GetBatteryLevel()<(0.8*12)){ + return 0; + }else{ + return 1; } - \ No newline at end of file +} diff --git a/keil_project/Services/Alimentation.h b/keil_project/Services/Alimentation.h index 503541f..7effb3d 100644 --- a/keil_project/Services/Alimentation.h +++ b/keil_project/Services/Alimentation.h @@ -18,9 +18,9 @@ Les fonctions qui gèrent les IO (ajout par rapport à l'activité 1) =======================================================================================*/ -void alimentation_init(void); -float get_battery_level(void); -int is_level_enough(void); +void ALIMENTATION_Init(void); +float ALIMENTATION_GetBatteryLevel(void); +int ALIMENTATION_IsLevelEnough(void); #endif diff --git a/keil_project/Src/main.c b/keil_project/Src/main.c index 83f7709..f6e9dbc 100644 --- a/keil_project/Src/main.c +++ b/keil_project/Src/main.c @@ -56,7 +56,7 @@ int main(void) { /* Configure the system clock to 72 MHz */ SystemClock_Config(); - alimentation_init(); + ALIMENTATION_Init(); accelero_init(); RF_INPUT_Init(); DC_MOTOR_Init(); @@ -73,7 +73,7 @@ int main(void) while (1) { if(CONTROL_LOOP_Flag){ - battery_level_good = is_level_enough(); + battery_level_good = ALIMENTATION_IsLevelEnough(); angle_roulis_good = accelero_angle_bon(); if(!angle_roulis_good){