Skip to content

Conversation

@lgehreke
Copy link

Some fixups and additions:

Power management

PM_DEVICE_ACTION_TURN_OFF is only used by power domains. To correctly power down the sensor it needs to react to PM_DEVICE_ACTION_SUSPEND.

Twos complement conversion

The sensor outputs the adc value as twos complement. Even though
it is given in the datasheets example code, performing a xor
with 0x800000 is not the correct way to convert the value.
See https://en.wikipedia.org/wiki/Two%27s_complement for details.

Addition

  • Added HX711_SENSOR_CHAN_RAW to get the raw adc output

PM_DEVICE_ACTION_TURN_OFF is only ised by power domains.
To correctly power down the chip it needs to handle the
PM_DEVICE_ACTION_SUSPEND action instead of PM_DEVICE_ACTION_TURN_OFF.
The sensor outputs the adc value as twos complement. Even though
it is given in the datasheets example code, performing a xor
with 0x800000 is not the correct way to convert the value.
See https://en.wikipedia.org/wiki/Two%27s_complement for details.
@nobodyguy
Copy link
Owner

Hello @lgehreke, thank you for the PR,
I'll check and test the changes and let you know asap. It's weird that the two complement calculation is wrong, because the formula is used by multiple other projects, but I haven't dug deeper into it yet.

@lgehreke
Copy link
Author

I did some research on it. What the xor does is mapping the negative values coming from the chip from [−8388608, 8388607] to [0, 16777215]. For this use case it is perfectly usable. Maybe the "correct" conversion can be added as Kconfig option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants