-
Notifications
You must be signed in to change notification settings - Fork 61
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
Implement ADC self-calibration #233
Conversation
Implement the ACD self-calibration procedure, which is defined in the RM377 reference manual as follows: The ADC has a calibration feature. During the procedure, the ADC calculates a calibration factor which is internally applied to the ADC until the next ADC power-off. The application must not use the ADC during calibration and must wait until it is complete. Calibration should be performed before starting A/D convers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good but I'm a bit hesitant about the 1000 loop iterations. Would it be better to use a while
loop and make the assumption that the hardware will always clear ADCAL?
Also, the manual says:
Calibration can only be initiated when the ADC is disabled (when ADEN = 0)
Is that ensured in the context of calibrate()
? I'm not familiar with the ADC code in this crate.
Thanks for looking at this, @jamwaffles
Yes, I'm not too proud about that loop, but also I'm kind paranoid about introducing potential infinite loops so deep down. If you are happy with it, I'll change it to a
Yep, I'm checking for that here: https://github.com/stm32-rs/stm32l0xx-hal/pull/233/files#diff-09d1f58a7f7c271d63f1a9a00c0c48c886e094bc98c207a8d7688c9f874259bbR132 |
The reference manual says that software should wait until ADCAL = 0. Do that instead of being paranoid and eventually timing out if this does not happen.
By the way, on my STM32L072, the ADC errors dropped from 6% to 0.05% after |
Let's go for a
Ah thanks, I missed that... 💤 |
Nice! It's great to validate these changes, and that's a huge improvement. |
Thanks! |
Implement the ACD self-calibration procedure, which is defined in the RM377 reference manual as follows:
The ADC has a calibration feature. During the procedure, the ADC calculates a calibration factor which is internally applied to the ADC until the next ADC power-off. The application must not use the ADC during calibration and must wait until it is complete. Calibration should be performed before starting A/D conversion.