PWM Audio Output?

Hello,

I’m sorry if this is a very basic question or answered elsewhere, but is it possible to output not actual analog output but rather PWM output? I’m trying to use input audio to drive a motor driver breakout board. If so, what pins / what is the best way of going about this? I know it’s possible on something like a Teensy for example.

Thank you!

Hello!
PWM can be outputted from any of the GPIO pins (labeled with the letter D).
So I believe you would need to use hardware PWM for motors rather than software PWM.
For pretty much all of the PWM examples (like lighting up a standard LED) for the Daisy, those are using software PWM. But, there was a PR that was merged for hardware PWM several months back, and we hope to document more about this in the future (especially because it’s good for using addressable LEDs I believe).
Are you using .cpp with VS Code? If so, you can try out that PR for the hardware PWM. Otherwise, PWM in other languages (like Oopsy) are software PWM at the moment.

I see that is very helpful thank you! When doing something like an analog write along these lines, is it possible to change the analog write frequency like on other microcontrollers? I tried doing analogWriteFrequency() but it didn’t seem to be effective, as I could still hear some high frequencies being emitted by what I’m driving.

Thank you!

Are you using the Arduino IDE?

Yes, I am.

I see!
So you use AnalogWrite() for software PWM output (you can see how it’s used with Daisy in this vid)

I’m not sure if there’s a function called analogWriteFrequency() for the Arduino. That may just be a Teensy thing.

As a followup, is it possible to output PWM on the DAC pins? So analog 7/8? To my understanding, if I do analogWrite, it is actually outputting an analog voltage.

For context, I am trying to use analogWrite rapidly in the loop function to control a motor driver using PWM - but I’m only getting on/off states, not a gradient in between.

If you’re doing `analogWrite()` with the DAC pins, it should be DAC output and not PWM output.

What motor and driver are you using?