- Notifications
You must be signed in to change notification settings - Fork 506
Description
Thanks for the work to get support for RP2040 working in Arduino IDE. Very much appreciated. Attached is test code. I am using BSP 1.1.0 on a standard / reference PI PICO. Arduino IDE is 1.8.13 (Windows Store 1.8.42.0)
I am having trouble getting tone to work well on the 2040. There appear to be two problems.
-
Processor crashes (not PIO) when tone is in use. I am able to loop through code 14902 times and then the processor stops. The test code does only 4 things.
-read and scale analog input (pot)
-noTone / set tone to scaled analog value
-increment loop counter
-print values to usb console
After processor code execution stops PIO tone generation continues. Jitter and long/short pulses stop as expected - you get a nice jitter free frequency. USB serial monitor goes off line and the IDE cannot reach the 2040 to upload programs. Power cycle and if you start upload before next crash you can load new code. As loop execution time goes down, the number of times through the loop before crash increases. There is no significant variation in loop count (1) for a given code loop. -
There appears to be no way to do 'synchronous' updates to the waveform. That is to say, change the frequency on the next transition. As a result any update to tone (all require a noTone) cuts off the waveform presently being generated such that sometimes very short or extra long pulses are generated and there is a lot of jitter in the waveform. Changing my code to update only when there is a change in frequency will not solve problem. Possibly lessen but you will still have the same problem when control value is alternating rapidly between values 1 apart. This will not be audible unless there are stray short and long period pulses as is the case now.
It looks like the hardware has sufficient registers to prevent this problem. How exactly to do this in the Arduino IDE is beyond my ability. I am just getting my feet wet.
I have another very closely related issue. I would like to use a piezo speaker connected to produce audio from tone. With the caveats above, this works. However, as you might expect, the speaker performs less well at higher frequencies than at very low ones. The volume change across the spectrum is substantial. In an effort to help minimize this, I would like to try narrowing the pulse width (less energy available) at lower frequencies as part of a scheme to level and possibly even control volume. I would try this with PWM but I haven't found handles to adjust frequency of PWM waveform to test this idea.
Thanks again and I will be happy to test or post an issue if I should. First I wanted to make certain I am not missing something obvious to those who have more experience.