Open microbit-carlos opened 1 year ago
This is still replicable in v0.2.55.
I can confirm this is still replicable with CODAL v0.2.57
The first call to setAnalogPeriodUs does nothing because the pin hasn't been configured as an analogue output. https://github.com/martinwork/codal-nrf52/blob/master/source/NRF52Pin.cpp#L633
Thanks Martin!
I can confirm that switch the order and executing first setAnalogValue()
and then setAnalogPeriodUs()
fixes the issue.
However, it makes sense for the user to want to set up the analog out configuration before changing the pin mode to start outputting the signal.
Yes, I don't know why it doesn't call setAnalogValue(0) if the pin isn't already configured, but it might be awkward to remember the setting until setAnalogValue is called. https://github.com/lancaster-university/codal-nrf52/blob/master/source/NRF52Pin.cpp#L631
The DAL would have to change too. https://github.com/lancaster-university/microbit-dal/blob/js-event-semantics/source/drivers/MicroBitPin.cpp#L417
It can't find an explicit mention in the CODAL source or Python docs, but it's there in DAL and MakeCode. https://github.com/lancaster-university/microbit-dal/blob/js-event-semantics/source/drivers/MicroBitPin.cpp#L413 https://lancaster-university.github.io/microbit-docs/ubit/io/#setanalogperiodus https://makecode.microbit.org/reference/pins/analog-set-period https://microbit-micropython.readthedocs.io/en/v2-docs/pin.html?highlight=write_analog#microbit.MicroBitDigitalPin.set_analog_period
Discussed with @finneyj and we should be able to configure analog settings before using the pin as an analog input/output, so we can consider this a bug to fix.
With that in mind, this MicroPython issue is also related:
This example programme produces a weird noise the first loop iteration, and the correct tone the others. MICROBIT.hex.zip