mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-27 16:54:15 +01:00
op-848 Splitted sample rate divider configuration for dlp and non_dlp settings (1kHz vs 8kHz sample rate).
Minor clean up, used constants in place of some hardcoded values
This commit is contained in:
parent
e27a07631e
commit
3986f93e68
@ -112,7 +112,9 @@ static const struct pios_mpu6000_cfg pios_mpu6000_cfg = {
|
||||
.exti_cfg = &pios_exti_mpu6000_cfg,
|
||||
.Fifo_store = PIOS_MPU6000_FIFO_TEMP_OUT | PIOS_MPU6000_FIFO_GYRO_X_OUT | PIOS_MPU6000_FIFO_GYRO_Y_OUT | PIOS_MPU6000_FIFO_GYRO_Z_OUT,
|
||||
// Clock at 8 khz, downsampled by 16 for 500 Hz
|
||||
.Smpl_rate_div = 15,
|
||||
.Smpl_rate_div_no_dlp = 15,
|
||||
// Clock at 1 khz, downsampled by 2 for 500 Hz
|
||||
.Smpl_rate_div_dlp = 1,
|
||||
.interrupt_cfg = PIOS_MPU6000_INT_CLR_ANYRD,
|
||||
.interrupt_en = PIOS_MPU6000_INTEN_DATA_RDY,
|
||||
.User_ctl = PIOS_MPU6000_USERCTL_FIFO_EN | PIOS_MPU6000_USERCTL_DIS_I2C,
|
||||
|
@ -136,64 +136,66 @@ int32_t PIOS_MPU6000_Init(uint32_t spi_id, uint32_t slave_num, const struct pios
|
||||
* @brief Initialize the MPU6000 3-axis gyro sensor
|
||||
* \return none
|
||||
* \param[in] PIOS_MPU6000_ConfigTypeDef struct to be used to configure sensor.
|
||||
*
|
||||
*/
|
||||
*
|
||||
*/
|
||||
static void PIOS_MPU6000_Config(struct pios_mpu6000_cfg const * cfg)
|
||||
{
|
||||
|
||||
PIOS_MPU6000_Test();
|
||||
|
||||
|
||||
//initialize settings for acc/gyro Scale and filter
|
||||
Mpu6000SettingsInitialize();
|
||||
|
||||
|
||||
// Reset chip
|
||||
while (PIOS_MPU6000_SetReg(PIOS_MPU6000_PWR_MGMT_REG, PIOS_MPU6000_PWRMGMT_IMU_RST) != 0);
|
||||
PIOS_DELAY_WaitmS(300);
|
||||
|
||||
|
||||
// Reset chip and fifo
|
||||
while (PIOS_MPU6000_SetReg(PIOS_MPU6000_USER_CTRL_REG,
|
||||
PIOS_MPU6000_USERCTL_GYRO_RST |
|
||||
PIOS_MPU6000_USERCTL_SIG_COND |
|
||||
while (PIOS_MPU6000_SetReg(PIOS_MPU6000_USER_CTRL_REG,
|
||||
PIOS_MPU6000_USERCTL_GYRO_RST |
|
||||
PIOS_MPU6000_USERCTL_SIG_COND |
|
||||
PIOS_MPU6000_USERCTL_FIFO_RST) != 0);
|
||||
|
||||
|
||||
// Wait for reset to finish
|
||||
while (PIOS_MPU6000_GetReg(PIOS_MPU6000_USER_CTRL_REG) &
|
||||
(PIOS_MPU6000_USERCTL_GYRO_RST |
|
||||
PIOS_MPU6000_USERCTL_SIG_COND |
|
||||
while (PIOS_MPU6000_GetReg(PIOS_MPU6000_USER_CTRL_REG) &
|
||||
(PIOS_MPU6000_USERCTL_GYRO_RST |
|
||||
PIOS_MPU6000_USERCTL_SIG_COND |
|
||||
PIOS_MPU6000_USERCTL_FIFO_RST));
|
||||
|
||||
|
||||
//Power management configuration
|
||||
while (PIOS_MPU6000_SetReg(PIOS_MPU6000_PWR_MGMT_REG, cfg->Pwr_mgmt_clk) != 0) ;
|
||||
while (PIOS_MPU6000_SetReg(PIOS_MPU6000_PWR_MGMT_REG, cfg->Pwr_mgmt_clk) != 0);
|
||||
|
||||
// Interrupt configuration
|
||||
while (PIOS_MPU6000_SetReg(PIOS_MPU6000_INT_CFG_REG, cfg->interrupt_cfg) != 0) ;
|
||||
while (PIOS_MPU6000_SetReg(PIOS_MPU6000_INT_CFG_REG, cfg->interrupt_cfg) != 0);
|
||||
|
||||
// Interrupt configuration
|
||||
while (PIOS_MPU6000_SetReg(PIOS_MPU6000_INT_EN_REG, cfg->interrupt_en) != 0) ;
|
||||
while (PIOS_MPU6000_SetReg(PIOS_MPU6000_INT_EN_REG, cfg->interrupt_en) != 0);
|
||||
|
||||
// FIFO storage
|
||||
#if defined(PIOS_MPU6000_ACCEL)
|
||||
// Set the accel range
|
||||
dev->accel_range = getAccelRange(cfg->accel_range);
|
||||
while (PIOS_MPU6000_SetReg(PIOS_MPU6000_ACCEL_CFG_REG, dev->accel_range) != 0);
|
||||
|
||||
|
||||
while (PIOS_MPU6000_SetReg(PIOS_MPU6000_FIFO_EN_REG, cfg->Fifo_store | PIOS_MPU6000_ACCEL_OUT) != 0);
|
||||
#else
|
||||
while (PIOS_MPU6000_SetReg(PIOS_MPU6000_FIFO_EN_REG, cfg->Fifo_store) != 0);
|
||||
#endif
|
||||
|
||||
// Sample rate divider
|
||||
while (PIOS_MPU6000_SetReg(PIOS_MPU6000_SMPLRT_DIV_REG, cfg->Smpl_rate_div) != 0) ;
|
||||
|
||||
// Digital low-pass filter and scale
|
||||
// Digital low-pass filter
|
||||
uint8_t filterSetting;
|
||||
filterSetting = getFilterSetting(cfg->filter);
|
||||
while (PIOS_MPU6000_SetReg(PIOS_MPU6000_DLPF_CFG_REG, filterSetting) != 0) ;
|
||||
|
||||
|
||||
// Sample rate divider, chosen upon digital filtering settings
|
||||
while (PIOS_MPU6000_SetReg(PIOS_MPU6000_SMPLRT_DIV_REG,
|
||||
filterSetting == PIOS_MPU6000_LOWPASS_256_HZ ?
|
||||
cfg->Smpl_rate_div_no_dlp : cfg->Smpl_rate_div_dlp) != 0);
|
||||
|
||||
while (PIOS_MPU6000_SetReg(PIOS_MPU6000_DLPF_CFG_REG, filterSetting) != 0);
|
||||
|
||||
// Gyro range
|
||||
dev->gyro_range = getGyroRange(cfg->gyro_range);
|
||||
while (PIOS_MPU6000_SetReg(PIOS_MPU6000_GYRO_CFG_REG, dev->gyro_range) != 0) ;
|
||||
|
||||
while (PIOS_MPU6000_SetReg(PIOS_MPU6000_GYRO_CFG_REG, dev->gyro_range) != 0);
|
||||
|
||||
// Interrupt configuration
|
||||
while (PIOS_MPU6000_SetReg(PIOS_MPU6000_USER_CTRL_REG, cfg->User_ctl) != 0) ;
|
||||
|
||||
|
@ -151,8 +151,11 @@ struct pios_mpu6000_cfg {
|
||||
const struct pios_exti_cfg * exti_cfg; /* Pointer to the EXTI configuration */
|
||||
|
||||
uint8_t Fifo_store; /* FIFO storage of different readings (See datasheet page 31 for more details) */
|
||||
uint8_t Smpl_rate_div; /* Sample rate divider to use (See datasheet page 32 for more details) */
|
||||
uint8_t interrupt_cfg; /* Interrupt configuration (See datasheet page 35 for more details) */
|
||||
|
||||
/* Sample rate divider to use (See datasheet page 32 for more details).*/
|
||||
uint8_t Smpl_rate_div_no_dlp; /* used when no dlp is applied (fs=8KHz)*/
|
||||
uint8_t Smpl_rate_div_dlp; /* used when dlp is on (fs=1kHz)*/
|
||||
uint8_t interrupt_cfg; /* Interrupt configuration (See datasheet page 35 for more details) */
|
||||
uint8_t interrupt_en; /* Interrupt configuration (See datasheet page 35 for more details) */
|
||||
uint8_t User_ctl; /* User control settings (See datasheet page 41 for more details) */
|
||||
uint8_t Pwr_mgmt_clk; /* Power management and clock selection (See datasheet page 32 for more details) */
|
||||
|
@ -175,8 +175,10 @@ static const struct pios_exti_cfg pios_exti_mpu6000_cfg __exti_config = {
|
||||
static const struct pios_mpu6000_cfg pios_mpu6000_cfg = {
|
||||
.exti_cfg = &pios_exti_mpu6000_cfg,
|
||||
.Fifo_store = PIOS_MPU6000_FIFO_TEMP_OUT | PIOS_MPU6000_FIFO_GYRO_X_OUT | PIOS_MPU6000_FIFO_GYRO_Y_OUT | PIOS_MPU6000_FIFO_GYRO_Z_OUT,
|
||||
// Clock at 8 khz, downsampled by 8 for 1khz
|
||||
.Smpl_rate_div = 11,
|
||||
// Clock at 8 khz, downsampled by 12 for 666Hz
|
||||
.Smpl_rate_div_no_dlp = 11,
|
||||
// with dlp on output rate is 500Hz
|
||||
.Smpl_rate_div_dlp = 1,
|
||||
.interrupt_cfg = PIOS_MPU6000_INT_CLR_ANYRD,
|
||||
.interrupt_en = PIOS_MPU6000_INTEN_DATA_RDY,
|
||||
.User_ctl = PIOS_MPU6000_USERCTL_FIFO_EN | PIOS_MPU6000_USERCTL_DIS_I2C,
|
||||
|
@ -216,8 +216,10 @@ static const struct pios_exti_cfg pios_exti_mpu6000_cfg __exti_config = {
|
||||
static const struct pios_mpu6000_cfg pios_mpu6000_cfg = {
|
||||
.exti_cfg = &pios_exti_mpu6000_cfg,
|
||||
.Fifo_store = PIOS_MPU6000_FIFO_TEMP_OUT | PIOS_MPU6000_FIFO_GYRO_X_OUT | PIOS_MPU6000_FIFO_GYRO_Y_OUT | PIOS_MPU6000_FIFO_GYRO_Z_OUT,
|
||||
// Clock at 8 khz, downsampled by 8 for 1khz
|
||||
.Smpl_rate_div = 11,
|
||||
// Clock at 8 khz, downsampled by 12 for 666Hz
|
||||
.Smpl_rate_div_no_dlp = 11,
|
||||
// with dlp on output rate is 500Hz
|
||||
.Smpl_rate_div_dlp = 1,
|
||||
.interrupt_cfg = PIOS_MPU6000_INT_CLR_ANYRD,
|
||||
.interrupt_en = PIOS_MPU6000_INTEN_DATA_RDY,
|
||||
.User_ctl = PIOS_MPU6000_USERCTL_FIFO_EN | PIOS_MPU6000_USERCTL_DIS_I2C,
|
||||
|
Loading…
x
Reference in New Issue
Block a user