- I allocate a DAC and then set up a sawtooth. First, buf = array.array ('B', range(256)). Then dac.write_timed(buf, freq, mode=pyb.DAC.CIRCULAR). A scope confirms that the DAC produces the correct sawtooth.
- Overwrite some elements of buf; e.g., buf[128:256]=0. The scope confirms that the waveform changes appropriately. Conclusion: dac.write_timed() is referencing my original buffer rather than copying the data into safe storage somewhere
- Write a function that encapsulates the two lines above; i.e., create a buffer and give it to dac.write_timed(). The scope shows a nice sawtooth at first. Then a few seconds later, it becomes random noise.
- Declare the buffer to be a global variable. The sawtooth no longer disintegrates into noise.
Any other explanations? I would be happy to add the full code if anyone is interested. A few potentially-relevant bits:
- I'm on a PyBoard v1.1 with firmware v1.12. I would burn newer firmware, but haven't quite figured out how yet.
- The rest of the software does have an event timer with an interrupt loop, which then calls micropython.schedule() to read an ADC.
/Joel