move includes, center and scale accelerometer reading
This commit is contained in:
parent
c5f0beac0b
commit
bad2a4bd54
1 changed files with 31 additions and 12 deletions
|
@ -1,5 +1,24 @@
|
|||
#include "Accelerometer.h"
|
||||
|
||||
#include "stm32f103xb.h"
|
||||
#include "stm32f1xx_ll_adc.h"
|
||||
#include "stm32f1xx_ll_bus.h"
|
||||
#include "stm32f1xx_ll_rcc.h"
|
||||
#include "stm32f1xx_ll_gpio.h"
|
||||
#include <math.h>
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265358979323846
|
||||
#endif
|
||||
|
||||
#define ANGLE_LIMIT_DEG 40
|
||||
#define ANGLE_LIMIT_RAD ANGLE_LIMIT_DEG * (180.0 / M_PI)
|
||||
|
||||
#define ZERO_G_VOLTAGE 1.65
|
||||
#define ZERO_G_READING (ZERO_G_VOLTAGE / 3.3) * 4095
|
||||
|
||||
#define VOLT_PER_G 0.48
|
||||
|
||||
void ACCELEROMETER_Init(void){
|
||||
RCC -> CFGR |= (0x1<<15);
|
||||
RCC-> CFGR &= ~ (0x1<<14);
|
||||
|
@ -39,16 +58,16 @@ 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);
|
||||
double x= LL_ADC_REG_ReadConversionData12(ADC1);
|
||||
double x= (LL_ADC_REG_ReadConversionData12(ADC1) - ZERO_G_READING) * VOLT_PER_G;
|
||||
return x;
|
||||
}
|
||||
|
||||
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);
|
||||
double y = LL_ADC_REG_ReadConversionData12(ADC1);
|
||||
return y;
|
||||
while (LL_ADC_IsActiveFlag_EOS(ADC1) != 1);
|
||||
double y = (LL_ADC_REG_ReadConversionData12(ADC1)-ZERO_G_READING) * VOLT_PER_G;
|
||||
return y;
|
||||
}
|
||||
|
||||
int ACCELEROMETER_AngleGood(void){
|
||||
|
@ -56,12 +75,12 @@ int ACCELEROMETER_AngleGood(void){
|
|||
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
|
||||
if (angle>tan(ANGLE_LIMIT_RAD)){
|
||||
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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue