-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Fix for issue #3383 - SAMD5x microcontroller.cpu.voltage #4862
Conversation
I will test this on Monday or Tuesday with a SAMD51 board that has this problem. Could you point to the solution you found? |
I found the issue mentioned and answered at https://community.atmel.com/forum/samd51-using-intref-adc-voltage-reference |
https://community.atmel.com/forum/samd51-using-intref-adc-voltage-reference is a thread I started (username "danhalbert"), and reported on some experimentation I was doing. I think that solution ended up not working consistently, but I'll retry it to find out. |
@dhalbert , I apologize for not noticing your login! All I can report is that my Itsy-Bitsy M4 Express was hanging before I put the patch in and is now working with the patch. |
I have a Metro M4 that was exhibiting the voltage hang in 5.3.1. It does not have that problem in 6.3.0, and it also works with your patch. This is the diff of the relevant code between 5.3.1 and 6.3.0: -#ifdef SAMD51
+#ifdef SAM_D5X_E5X
hri_supc_set_VREF_SEL_bf(SUPC, SUPC_VREF_SEL_1V0_Val);
- // ONDEMAND must be clear, and VREFOE must be set, or else the ADC conversion will not complete.
- // See https://community.atmel.com/forum/samd51-using-intref-adc-voltage-reference
- hri_supc_clear_VREF_ONDEMAND_bit(SUPC);
hri_supc_set_VREF_VREFOE_bit(SUPC);
+
adc_sync_set_reference(&adc, ADC_REFCTRL_REFSEL_INTREF_Val);
+
+ // On some processor samples, the ADC will hang trying to read the voltage. A simple
+ // delay after setting the SUPC bits seems to fix things. This appears to be due to VREFOE
+ // startup time. There is no synchronization bit to check.
+ // See https://community.atmel.com/forum/samd51-using-intref-adc-voltage-reference
+ mp_hal_delay_ms(1); What happened originally is that @jepler noticed a problem on his SAME54 dev board. I added the delay, which helped on some boards but not all. Once the delay was in place, the Currently circuitpython/ports/atmel-samd/mpconfigport.h Lines 76 to 78 in c4f685a
Then, @jepler, could you test the artifact on your SAME54 Xplained board? I tried |
Yes, let's have both. I think there may be two problems in the internal circuitry and we have to compensate for both. |
Hi! Sorry for the delay in replying. First off, it's important to note that sometimes reading the CPU voltage alone is fine. On the sam e54 board I have, the problem occurs after reading temperature: >>> import microcontroller
>>> microcontroller.cpu.voltage
3.33089
>>> microcontroller.cpu.temperature
27.201
>>> microcontroller.cpu.voltage
[hangs forever] (this is "7.0.0-alpha.3-29-gc6dee5288-dirty" on a same54_xplained but with VOLTAGE_DISABLE re-enabled) .. recommendation: the testing procedure for reading The good news is, that with the board that failed above, it can now read CPU voltage, including after reading temperature or an arbitrary analog input:
|
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.
Testing on a SAM E54 Xplained worked (yay!) but some small improvements can be made to the PR.
I didn't see your suggestions for this. |
I retested my bad board as well, and it will read voltage after reading temperature without hanging. |
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! Thanks for revisiting this.
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.
Thanks for making those changes
Issue #3383. Found an answer online; we need to clear the VREF_ONDEMAND bit before reading SAMD5x voltage. Tested OK on an Itsy-Bitsy M4 Express(SAMD51); I don't have an SAMD54 to test with.