mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-05 21:52:10 +01:00
Clean up previous commit a bit and make the sampling rate a variable (and adapt
the sampling time accordingly).
This commit is contained in:
parent
3acbfbe96c
commit
d018d93e88
@ -133,12 +133,12 @@ static void altitudeTask(void *parameters)
|
|||||||
|
|
||||||
// Update the temperature data
|
// Update the temperature data
|
||||||
PIOS_MS5611_StartADC(TemperatureConv);
|
PIOS_MS5611_StartADC(TemperatureConv);
|
||||||
vTaskDelay(5);
|
vTaskDelay(PIOS_MS5611_GetDelay());
|
||||||
PIOS_MS5611_ReadADC();
|
PIOS_MS5611_ReadADC();
|
||||||
|
|
||||||
// Update the pressure data
|
// Update the pressure data
|
||||||
PIOS_MS5611_StartADC(PressureConv);
|
PIOS_MS5611_StartADC(PressureConv);
|
||||||
vTaskDelay(5);
|
vTaskDelay(PIOS_MS5611_GetDelay());
|
||||||
PIOS_MS5611_ReadADC();
|
PIOS_MS5611_ReadADC();
|
||||||
|
|
||||||
|
|
||||||
|
@ -45,10 +45,10 @@ MS5611CalibDataTypeDef CalibData;
|
|||||||
/* Straight from the datasheet */
|
/* Straight from the datasheet */
|
||||||
static int32_t X1, X2, X3, B3, B5, B6, P;
|
static int32_t X1, X2, X3, B3, B5, B6, P;
|
||||||
static uint32_t B4, B7;
|
static uint32_t B4, B7;
|
||||||
static volatile uint32_t RawTemperature;
|
static uint32_t RawTemperature;
|
||||||
static volatile uint32_t RawPressure;
|
static uint32_t RawPressure;
|
||||||
static volatile int64_t Pressure;
|
static int64_t Pressure;
|
||||||
static volatile int64_t Temperature;
|
static int64_t Temperature;
|
||||||
|
|
||||||
static int32_t PIOS_MS5611_Read(uint8_t address, uint8_t * buffer, uint8_t len);
|
static int32_t PIOS_MS5611_Read(uint8_t address, uint8_t * buffer, uint8_t len);
|
||||||
static int32_t PIOS_MS5611_WriteCommand(uint8_t command);
|
static int32_t PIOS_MS5611_WriteCommand(uint8_t command);
|
||||||
@ -58,9 +58,11 @@ static uint32_t oversampling;
|
|||||||
static const struct pios_ms5611_cfg * dev_cfg;
|
static const struct pios_ms5611_cfg * dev_cfg;
|
||||||
static int32_t i2c_id;
|
static int32_t i2c_id;
|
||||||
|
|
||||||
|
static enum pios_ms5611_osr osr = MS5611_OSR_256;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialise the BMP085 sensor
|
* Initialise the MS5611 sensor
|
||||||
*/
|
*/
|
||||||
int32_t ms5611_read_flag;
|
int32_t ms5611_read_flag;
|
||||||
void PIOS_MS5611_Init(const struct pios_ms5611_cfg * cfg, int32_t i2c_device)
|
void PIOS_MS5611_Init(const struct pios_ms5611_cfg * cfg, int32_t i2c_device)
|
||||||
{
|
{
|
||||||
@ -90,10 +92,10 @@ int32_t PIOS_MS5611_StartADC(ConversionTypeTypeDef Type)
|
|||||||
{
|
{
|
||||||
/* Start the conversion */
|
/* Start the conversion */
|
||||||
if (Type == TemperatureConv) {
|
if (Type == TemperatureConv) {
|
||||||
while (PIOS_MS5611_WriteCommand(MS5611_TEMP_ADDR) != 0)
|
while (PIOS_MS5611_WriteCommand(MS5611_TEMP_ADDR + osr) != 0)
|
||||||
continue;
|
continue;
|
||||||
} else if (Type == PressureConv) {
|
} else if (Type == PressureConv) {
|
||||||
while (PIOS_MS5611_WriteCommand(MS5611_PRES_ADDR) != 0)
|
while (PIOS_MS5611_WriteCommand(MS5611_PRES_ADDR + osr) != 0)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,21 +104,39 @@ int32_t PIOS_MS5611_StartADC(ConversionTypeTypeDef Type)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Return the delay for the current osr
|
||||||
|
*/
|
||||||
|
int32_t PIOS_MS5611_GetDelay() {
|
||||||
|
switch(osr) {
|
||||||
|
case MS5611_OSR_256:
|
||||||
|
return 2;
|
||||||
|
case MS5611_OSR_512:
|
||||||
|
return 2;
|
||||||
|
case MS5611_OSR_1024:
|
||||||
|
return 3;
|
||||||
|
case MS5611_OSR_2048:
|
||||||
|
return 5;
|
||||||
|
case MS5611_OSR_4096:
|
||||||
|
return 10;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return 10;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Read the ADC conversion value (once ADC conversion has completed)
|
* Read the ADC conversion value (once ADC conversion has completed)
|
||||||
* \param[in] PresOrTemp BMP085_PRES_ADDR or BMP085_TEMP_ADDR
|
* \param[in] PresOrTemp BMP085_PRES_ADDR or BMP085_TEMP_ADDR
|
||||||
* \return 0 if successfully read the ADC, -1 if failed
|
* \return 0 if successfully read the ADC, -1 if failed
|
||||||
*/
|
*/
|
||||||
volatile int64_t Offset;
|
|
||||||
volatile int64_t Sens;
|
|
||||||
volatile int64_t deltaTemp;
|
|
||||||
|
|
||||||
int32_t PIOS_MS5611_ReadADC(void)
|
int32_t PIOS_MS5611_ReadADC(void)
|
||||||
{
|
{
|
||||||
uint8_t Data[3];
|
uint8_t Data[3];
|
||||||
Data[0] = 0;
|
Data[0] = 0;
|
||||||
Data[1] = 0;
|
Data[1] = 0;
|
||||||
Data[2] = 0;
|
Data[2] = 0;
|
||||||
|
|
||||||
|
static int64_t deltaTemp;
|
||||||
|
|
||||||
/* Read and store the 16bit result */
|
/* Read and store the 16bit result */
|
||||||
if (CurrentRead == TemperatureConv) {
|
if (CurrentRead == TemperatureConv) {
|
||||||
@ -128,9 +148,10 @@ int32_t PIOS_MS5611_ReadADC(void)
|
|||||||
|
|
||||||
deltaTemp = RawTemperature - (CalibData.C[4] << 8);
|
deltaTemp = RawTemperature - (CalibData.C[4] << 8);
|
||||||
Temperature = ((2000l + deltaTemp * CalibData.C[5]) >> 23);
|
Temperature = ((2000l + deltaTemp * CalibData.C[5]) >> 23);
|
||||||
// Temperature /= 100.0f;
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
int64_t Offset;
|
||||||
|
int64_t Sens;
|
||||||
|
|
||||||
/* Read the pressure conversion */
|
/* Read the pressure conversion */
|
||||||
if (PIOS_MS5611_Read(MS5611_ADC_READ, Data, 3) != 0)
|
if (PIOS_MS5611_Read(MS5611_ADC_READ, Data, 3) != 0)
|
||||||
@ -142,7 +163,6 @@ int32_t PIOS_MS5611_ReadADC(void)
|
|||||||
Sens = Sens + ((((int64_t) CalibData.C[2]) * deltaTemp) >> 8);
|
Sens = Sens + ((((int64_t) CalibData.C[2]) * deltaTemp) >> 8);
|
||||||
|
|
||||||
Pressure = (((((int64_t) RawPressure) * Sens) >> 21) - Offset) >> 15;
|
Pressure = (((((int64_t) RawPressure) * Sens) >> 21) - Offset) >> 15;
|
||||||
// Pressure /= 1000.0f;
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -58,6 +58,14 @@ struct pios_ms5611_cfg {
|
|||||||
uint32_t oversampling;
|
uint32_t oversampling;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum pios_ms5611_osr {
|
||||||
|
MS5611_OSR_256 = 0,
|
||||||
|
MS5611_OSR_512 = 2,
|
||||||
|
MS5611_OSR_1024 = 4,
|
||||||
|
MS5611_OSR_2048 = 6,
|
||||||
|
MS5611_OSR_4096 = 8,
|
||||||
|
};
|
||||||
|
|
||||||
/* Public Functions */
|
/* Public Functions */
|
||||||
extern void PIOS_MS5611_Init(const struct pios_ms5611_cfg * cfg, int32_t i2c_device);
|
extern void PIOS_MS5611_Init(const struct pios_ms5611_cfg * cfg, int32_t i2c_device);
|
||||||
extern int32_t PIOS_MS5611_StartADC(ConversionTypeTypeDef Type);
|
extern int32_t PIOS_MS5611_StartADC(ConversionTypeTypeDef Type);
|
||||||
@ -65,6 +73,7 @@ extern int32_t PIOS_MS5611_ReadADC(void);
|
|||||||
extern float PIOS_MS5611_GetTemperature(void);
|
extern float PIOS_MS5611_GetTemperature(void);
|
||||||
extern float PIOS_MS5611_GetPressure(void);
|
extern float PIOS_MS5611_GetPressure(void);
|
||||||
extern int32_t PIOS_MS5611_Test();
|
extern int32_t PIOS_MS5611_Test();
|
||||||
|
extern int32_t PIOS_MS5611_GetDelay();
|
||||||
|
|
||||||
#endif /* PIOS_MS5611_H */
|
#endif /* PIOS_MS5611_H */
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user