Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport v3.5-branch] drivers: sensor: ams_as5600: Fix calculation of fractional part #70144

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions drivers/sensor/ams_as5600/ams_as5600.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ LOG_MODULE_REGISTER(ams_as5600, CONFIG_SENSOR_LOG_LEVEL);
#define AS5600_ANGLE_REGISTER_H 0x0E
#define AS5600_FULL_ANGLE 360
#define AS5600_PULSES_PER_REV 4096
#define AS5600_MILLION_UNIT 1000000

struct as5600_dev_cfg {
struct i2c_dt_spec i2c_port;
Expand Down Expand Up @@ -60,8 +61,8 @@ static int as5600_get(const struct device *dev, enum sensor_channel chan,
val->val1 = ((int32_t)dev_data->position * AS5600_FULL_ANGLE) /
AS5600_PULSES_PER_REV;

val->val2 = ((int32_t)dev_data->position * AS5600_FULL_ANGLE) -
(val->val1 * AS5600_PULSES_PER_REV);
val->val2 = (((int32_t)dev_data->position * AS5600_FULL_ANGLE) %
AS5600_PULSES_PER_REV) * (AS5600_MILLION_UNIT / AS5600_PULSES_PER_REV);
} else {
return -ENOTSUP;
}
Expand Down
Loading