renaming functions and minor cleanup
This commit is contained in:
parent
ef3b6b03e2
commit
41f7b66f5d
3 changed files with 22 additions and 49 deletions
|
@ -1,9 +1,6 @@
|
||||||
#include "Accelerometer.h"
|
#include "Accelerometer.h"
|
||||||
double x;
|
|
||||||
double y;
|
|
||||||
double angle;
|
|
||||||
|
|
||||||
void accelero_init(void){
|
void ACCELEROMETER_Init(void){
|
||||||
RCC -> CFGR |= (0x1<<15);
|
RCC -> CFGR |= (0x1<<15);
|
||||||
RCC-> CFGR &= ~ (0x1<<14);
|
RCC-> CFGR &= ~ (0x1<<14);
|
||||||
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_ADC1);
|
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_ADC1);
|
||||||
|
@ -23,7 +20,6 @@ void accelero_init(void){
|
||||||
pc1.Mode = LL_GPIO_MODE_ANALOG;
|
pc1.Mode = LL_GPIO_MODE_ANALOG;
|
||||||
LL_GPIO_Init(GPIOA, &pc1);
|
LL_GPIO_Init(GPIOA, &pc1);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
adc.DataAlignment = LL_ADC_DATA_ALIGN_RIGHT;
|
adc.DataAlignment = LL_ADC_DATA_ALIGN_RIGHT;
|
||||||
adc.SequencersScanMode = LL_ADC_SEQ_SCAN_DISABLE;
|
adc.SequencersScanMode = LL_ADC_SEQ_SCAN_DISABLE;
|
||||||
|
@ -35,55 +31,37 @@ void accelero_init(void){
|
||||||
adcReg.ContinuousMode = LL_ADC_REG_CONV_SINGLE;
|
adcReg.ContinuousMode = LL_ADC_REG_CONV_SINGLE;
|
||||||
adcReg.DMATransfer = LL_ADC_REG_DMA_TRANSFER_NONE;
|
adcReg.DMATransfer = LL_ADC_REG_DMA_TRANSFER_NONE;
|
||||||
|
|
||||||
|
|
||||||
LL_ADC_REG_Init(ADC1, &adcReg);
|
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_Enable(ADC1);
|
||||||
|
|
||||||
//LL_ADC_EnableIT_EOS(ADC1);
|
|
||||||
//wait 0,2 µs, calibration is advised
|
|
||||||
//LL_ADC_StartCalibration(ADC1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double ACCELEROMETER_GetX(void){
|
||||||
double accelero_get_x(void){
|
|
||||||
LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_1, LL_ADC_CHANNEL_1);
|
LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_1, LL_ADC_CHANNEL_1);
|
||||||
LL_ADC_REG_StartConversionSWStart(ADC1);
|
LL_ADC_REG_StartConversionSWStart(ADC1);
|
||||||
while (LL_ADC_IsActiveFlag_EOS(ADC1) != 1){
|
while (LL_ADC_IsActiveFlag_EOS(ADC1) != 1);
|
||||||
//__asm__"nope";
|
|
||||||
}
|
|
||||||
double x= LL_ADC_REG_ReadConversionData12(ADC1);
|
double x= LL_ADC_REG_ReadConversionData12(ADC1);
|
||||||
return x;
|
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_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_1, LL_ADC_CHANNEL_11);
|
||||||
LL_ADC_REG_StartConversionSWStart(ADC1);
|
LL_ADC_REG_StartConversionSWStart(ADC1);
|
||||||
while (LL_ADC_IsActiveFlag_EOS(ADC1) != 1){
|
while (LL_ADC_IsActiveFlag_EOS(ADC1) != 1);
|
||||||
//__asm__"nope";
|
|
||||||
}
|
|
||||||
double y = LL_ADC_REG_ReadConversionData12(ADC1);
|
double y = LL_ADC_REG_ReadConversionData12(ADC1);
|
||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ACCELEROMETER_AngleGood(void){
|
||||||
int accelero_angle_bon(void){
|
double x = ACCELEROMETER_GetX();
|
||||||
x = accelero_get_x();
|
double y = ACCELEROMETER_GetY();
|
||||||
y = accelero_get_y();
|
double angle = x/y;
|
||||||
angle = x/y;
|
|
||||||
|
|
||||||
if (angle>tan(0.698132)){
|
if (angle>tan(0.698132)){
|
||||||
return 0;
|
return 0;
|
||||||
}else {
|
}else {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
//le flag EOC n'est jamais mis à un ....
|
//le flag EOC n'est jamais mis à un ....
|
||||||
// Soit la conversion est mal faite soit on n'utilise pas bien la simulation
|
// Soit la conversion est mal faite soit on n'utilise pas bien la simulation
|
||||||
//soit on n'utilise pas bien isActiveFlag dans la boucle
|
//soit on n'utilise pas bien isActiveFlag dans la boucle
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,13 +18,13 @@
|
||||||
Les fonctions qui gèrent les IO (ajout par rapport à l'activité 1)
|
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
|
#endif
|
||||||
|
|
|
@ -37,13 +37,7 @@ void SystemClock_Config(void);
|
||||||
|
|
||||||
/* Private functions ---------------------------------------------------------*/
|
/* Private functions ---------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
// global variables for monitoring in keil
|
||||||
* @brief Main program
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
int battery_level_good = 0;
|
int battery_level_good = 0;
|
||||||
int angle_roulis_good = 0;
|
int angle_roulis_good = 0;
|
||||||
|
@ -52,12 +46,18 @@ int RF_Input_Duty = 0;
|
||||||
int TX_Flag = 0, CONTROL_LOOP_Flag = 0;
|
int TX_Flag = 0, CONTROL_LOOP_Flag = 0;
|
||||||
|
|
||||||
char wait_for_girouette[] = "En attente d'initialisation de la girouette\r\n";
|
char wait_for_girouette[] = "En attente d'initialisation de la girouette\r\n";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Main program
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
/* Configure the system clock to 72 MHz */
|
/* Configure the system clock to 72 MHz */
|
||||||
SystemClock_Config();
|
SystemClock_Config();
|
||||||
ALIMENTATION_Init();
|
ALIMENTATION_Init();
|
||||||
accelero_init();
|
ACCELEROMETER_Init();
|
||||||
RF_INPUT_Init();
|
RF_INPUT_Init();
|
||||||
DC_MOTOR_Init();
|
DC_MOTOR_Init();
|
||||||
SAIL_Init();
|
SAIL_Init();
|
||||||
|
@ -69,12 +69,11 @@ int main(void)
|
||||||
LL_mDelay(500);
|
LL_mDelay(500);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Infinite loop */
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
if(CONTROL_LOOP_Flag){
|
if(CONTROL_LOOP_Flag){
|
||||||
battery_level_good = ALIMENTATION_IsLevelEnough();
|
battery_level_good = ALIMENTATION_IsLevelEnough();
|
||||||
angle_roulis_good = accelero_angle_bon();
|
angle_roulis_good = ACCELEROMETER_AngleGood();
|
||||||
|
|
||||||
if(!angle_roulis_good){
|
if(!angle_roulis_good){
|
||||||
SAIL_SetAngle(90);
|
SAIL_SetAngle(90);
|
||||||
|
@ -107,10 +106,6 @@ void SysTick_Handler(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief System Clock Configuration
|
* @brief System Clock Configuration
|
||||||
* The system Clock is configured as follow :
|
* The system Clock is configured as follow :
|
||||||
|
|
Loading…
Reference in a new issue