Closed AndyLindsay closed 3 years ago
Is this related to #65?
I can reproduce the issue as described above using the above code.
Simpler code to show the problem:
# connect pin0 to 3V
for i in range(10):
if i == 5:
music.pitch(3000, 100)
print(pin0.read_analog())
I also wrote the equivalent code in pure C++:
int main() {
uBit.init();
for (int count = 0; count < 10; ++count) {
if (count == 5) {
uBit.audio.virtualOutputPin.setAnalogPeriodUs(1000000 / 3000);
system_timer_wait_us(100000);
uBit.audio.virtualOutputPin.setAnalogValue(0);
}
uBit.serial.printf("%d\r\n", uBit.io.P0.getAnalogValue());
}
return 0;
}
The same issue exists with the above C++ code (analog read after the virtual pin output is about 5% lower than it should be).
So this looks like a CODAL issue (or hardware limitation?).
Thank you Damien and @martinwork, and thank you @AndyLindsay for the report! I can confirm this is fixed in the latest builds from the CI., both the original script and the minimal from the previous comment now always output 1023 while it beeps.
Likely fixed in the latest CODAL added in 291e05c8440de4e90dcf1f443136d2b7005272a1.
The fix will be present in the next MicroPython release, in the meantime a hex can be downloaded from the CI artefacts in https://github.com/microbit-foundation/micropython-microbit-v2/actions/runs/887027270.
A call to music.pitch seems to affect the results of the next read_analog call.
Edit: The symptoms are evident with or without a sleep call between music.pitch and pin0.read_analog.
Test Script
Terminal Results
v0 = 1020 v0 = 1021 v0 = 1021 v0 = 1020 beep v0 = 958 pin0 measurement error v0 = 1021 v0 = 1021 v0 = 1020 v0 = 1021 beep v0 = 957 pin0 measurement error v0 = 1021 v0 = 1021 v0 = 1021 v0 = 1021 beep v0 = 957 pin0 measurement error v0 = 1021 v0 = 1021 v0 = 1021 v0 = 1021 beep v0 = 957