diff --git a/keil_project/Services/Accelerometer.c b/keil_project/Services/Accelerometer.c index 14141dc..ac4bcb7 100644 --- a/keil_project/Services/Accelerometer.c +++ b/keil_project/Services/Accelerometer.c @@ -1,9 +1,6 @@ #include "Accelerometer.h" -double x; -double y; -double angle; -void accelero_init(void){ +void ACCELEROMETER_Init(void){ RCC -> CFGR |= (0x1<<15); RCC-> CFGR &= ~ (0x1<<14); LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_ADC1); @@ -23,7 +20,6 @@ void accelero_init(void){ pc1.Mode = LL_GPIO_MODE_ANALOG; LL_GPIO_Init(GPIOA, &pc1); - adc.DataAlignment = LL_ADC_DATA_ALIGN_RIGHT; adc.SequencersScanMode = LL_ADC_SEQ_SCAN_DISABLE; @@ -35,55 +31,37 @@ void accelero_init(void){ 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); } - -double accelero_get_x(void){ +double ACCELEROMETER_GetX(void){ LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_1, LL_ADC_CHANNEL_1); LL_ADC_REG_StartConversionSWStart(ADC1); - while (LL_ADC_IsActiveFlag_EOS(ADC1) != 1){ - //__asm__"nope"; - } + while (LL_ADC_IsActiveFlag_EOS(ADC1) != 1); double x= LL_ADC_REG_ReadConversionData12(ADC1); return x; } -double accelero_get_y(void){ +double ACCELEROMETER_GetY(void){ LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_1, LL_ADC_CHANNEL_11); LL_ADC_REG_StartConversionSWStart(ADC1); - while (LL_ADC_IsActiveFlag_EOS(ADC1) != 1){ - //__asm__"nope"; - } + while (LL_ADC_IsActiveFlag_EOS(ADC1) != 1); double y = LL_ADC_REG_ReadConversionData12(ADC1); return y; } - -int accelero_angle_bon(void){ - x = accelero_get_x(); - y = accelero_get_y(); - angle = x/y; +int ACCELEROMETER_AngleGood(void){ + double x = ACCELEROMETER_GetX(); + double y = ACCELEROMETER_GetY(); + double angle = x/y; if (angle>tan(0.698132)){ return 0; }else { return 1; } - //le flag EOC n'est jamais mis à un .... // Soit la conversion est mal faite soit on n'utilise pas bien la simulation //soit on n'utilise pas bien isActiveFlag dans la boucle } - diff --git a/keil_project/Services/Accelerometer.h b/keil_project/Services/Accelerometer.h index 8389738..d05ce28 100644 --- a/keil_project/Services/Accelerometer.h +++ b/keil_project/Services/Accelerometer.h @@ -18,13 +18,13 @@ Les fonctions qui gèrent les IO (ajout par rapport à l'activité 1) =======================================================================================*/ -void accelero_init(void); +void ACCELEROMETER_Init(void); -double accelero_get_x(void); +double ACCELEROMETER_GetX(void); -double accelero_get_y(void); +double ACCELEROMETER_GetY(void); -int accelero_angle_bon(void); +int ACCELEROMETER_AngleGood(void); #endif diff --git a/keil_project/Src/main.c b/keil_project/Src/main.c index f6e9dbc..8655e79 100644 --- a/keil_project/Src/main.c +++ b/keil_project/Src/main.c @@ -37,13 +37,7 @@ void SystemClock_Config(void); /* Private functions ---------------------------------------------------------*/ -/** - * @brief Main program - * @param None - * @retval None - */ - - +// global variables for monitoring in keil int counter = 0; int battery_level_good = 0; int angle_roulis_good = 0; @@ -52,12 +46,18 @@ int RF_Input_Duty = 0; int TX_Flag = 0, CONTROL_LOOP_Flag = 0; char wait_for_girouette[] = "En attente d'initialisation de la girouette\r\n"; + +/** + * @brief Main program + * @param None + * @retval None + */ int main(void) { /* Configure the system clock to 72 MHz */ SystemClock_Config(); ALIMENTATION_Init(); - accelero_init(); + ACCELEROMETER_Init(); RF_INPUT_Init(); DC_MOTOR_Init(); SAIL_Init(); @@ -69,12 +69,11 @@ int main(void) LL_mDelay(500); } - /* Infinite loop */ while (1) { if(CONTROL_LOOP_Flag){ battery_level_good = ALIMENTATION_IsLevelEnough(); - angle_roulis_good = accelero_angle_bon(); + angle_roulis_good = ACCELEROMETER_AngleGood(); if(!angle_roulis_good){ SAIL_SetAngle(90); @@ -107,10 +106,6 @@ void SysTick_Handler(void) } - - - - /** * @brief System Clock Configuration * The system Clock is configured as follow :