Skip to content

nrf: fix adc read near zero #4710

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

Merged
merged 1 commit into from
Jan 23, 2025
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
7 changes: 6 additions & 1 deletion src/machine/machine_nrf52xxx.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,12 @@ func (a *ADC) Get() uint16 {
resolutionAdjustment = 4 // 12bit
}

return rawValue.Get() << resolutionAdjustment
value := int16(rawValue.Get())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be a cast to uint16

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't that previous cast to int16?

value := int16(rawValue.Get())

if value < 0 {
value = 0
}

return uint16(value << resolutionAdjustment)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@deadprogram we do return uint16 in the end, if that's you after.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just repeated exact logic as we had before: casting register value to int16, checking for 0 and then casting to uint16 after applying resolution adjustment

}

// SPI on the NRF.
Expand Down
Loading