drivers: sensor: st: qdec_stm32: addition of fractional part
The fractional part of the qdec sensor readout is set to zero (val2 = 0). Changed the format of the run time data to Q26.6 and adjusted the assignment of val1 and val2 accordingly. Signed-off-by: Juraj Lieskovský <lieskovsky.juraj@gmail.com>
This commit is contained in:
parent
3f58d49843
commit
7f78eb75dc
1 changed files with 6 additions and 4 deletions
|
@ -38,7 +38,7 @@ struct qdec_stm32_dev_cfg {
|
||||||
|
|
||||||
/* Device run time data */
|
/* Device run time data */
|
||||||
struct qdec_stm32_dev_data {
|
struct qdec_stm32_dev_data {
|
||||||
int32_t position;
|
uint32_t position;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int qdec_stm32_fetch(const struct device *dev, enum sensor_channel chan)
|
static int qdec_stm32_fetch(const struct device *dev, enum sensor_channel chan)
|
||||||
|
@ -56,7 +56,9 @@ static int qdec_stm32_fetch(const struct device *dev, enum sensor_channel chan)
|
||||||
* can be ignored
|
* can be ignored
|
||||||
*/
|
*/
|
||||||
counter_value = LL_TIM_GetCounter(dev_cfg->timer_inst) % dev_cfg->counts_per_revolution;
|
counter_value = LL_TIM_GetCounter(dev_cfg->timer_inst) % dev_cfg->counts_per_revolution;
|
||||||
dev_data->position = (counter_value * 360) / dev_cfg->counts_per_revolution;
|
|
||||||
|
/* The angle calculated in the fixed-point format (Q26.6 format) */
|
||||||
|
dev_data->position = (counter_value * 23040) / dev_cfg->counts_per_revolution;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -67,8 +69,8 @@ static int qdec_stm32_get(const struct device *dev, enum sensor_channel chan,
|
||||||
struct qdec_stm32_dev_data *const dev_data = dev->data;
|
struct qdec_stm32_dev_data *const dev_data = dev->data;
|
||||||
|
|
||||||
if (chan == SENSOR_CHAN_ROTATION) {
|
if (chan == SENSOR_CHAN_ROTATION) {
|
||||||
val->val1 = dev_data->position;
|
val->val1 = dev_data->position >> 6;
|
||||||
val->val2 = 0;
|
val->val2 = (dev_data->position & 0x3F) * 15625;
|
||||||
} else {
|
} else {
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue