marcel-licence / ML_SynthTools

ML_SynthTools
GNU General Public License v3.0
149 stars 25 forks source link

Usage Question: RP2040 with PWM audio out #29

Closed bradanlane closed 1 year ago

bradanlane commented 1 year ago

I am assuming, to use a Raspberry Pi PICO and PWM output, I need to first set the defines for ARDUINO_RASPBERRY_PI_PICO and RP2040_AUDIO_PWM.

(1) What is not clear is the declaration of which GPIO pin(s) to use the code appears to use 0 and 1 but no mechanism to override them?

(2) Are two pins used for mono audio?

marcel-licence commented 1 year ago

Hi, ARDUINO_RASPBERRY_PI_PICO is set by Arduino when the board Pi Pico is selected during compilation. RP2040_AUDIO_PWM should be selected in your configuration / config.h or main project file. I can add a mechanism to override the output pins soon. It is stereo output.

marcel-licence commented 1 year ago

The pin is defined in https://github.com/marcel-licence/ML_SynthTools/blob/main/src/audio_module.h line 159. I will update this to allow using an optional define outside of the library.

bradanlane commented 1 year ago

Thanks for the quick reply.

I'll likely fork the library as I only have mono PWM audio output. (although, I could probably add support for stereo output on my board)

marcel-licence commented 1 year ago

You are welcome.

I've added RP2040_AUDIO_PWM_PIN as optional define to setup a specific start pin for stereo output. Stereo sound makes a big different especially for the multi saw synthesizer project.

bradanlane commented 1 year ago

Appreciate the change and the recommendations. I'll revisit my HW design.

I will also check which pins I am using for MIDI data (serial).

When using the library with the RP2040, I am assuming I need to pick one of the PWM pairs: image

marcel-licence commented 1 year ago

I didn't test any other pin / pair yet. For efficient DMA usage it is recommended to use two PWM channels next to each other. In that case you should be able to use the library without any changes

bradanlane commented 1 year ago

I tested several alternate pins for PWM.

Pin 0,1 work (default) Pin 16,17 work

Pin 2,3 did not work Pin 18,19 did not work Pin 26,27 did not work

I can use pins as long as they result in PWM on Slice 0 (eg pins 0,1 and pins 16,17). any other slice does not produce sound output.

The code does compute the correct slice for other pins but for some reason, there is no output.

marcel-licence commented 1 year ago

Seems that PWM0 A/B does work and others don't. It may be possible that something else is missing. Do you know if the IRQ was triggered? Thank you very much for your investigation

bradanlane commented 1 year ago

I don't have a hardware debugger configured (at the moment) so checking the IRQ will take some time to figure out.

bradanlane commented 1 year ago

Can you suggest a way to TEST the IRQ without a hardware debugger ?