How to run pulse-code modulation(PCM) on the Arduino Leonardo?

Hi,

I am trying to get the PCM examples from this Arduino page to work. Unfortunately the Leonardo is based on the ATMega32u4 and not - like the UNO - on the ATmega328.

Googling around the internet led me to believe that converting the used (but not available) TIMER2 to the TIMER4. But I still am stuck trying to convert ASSR, EXCLK, AS2 to variables that the ATMega32u4 understands.

Did someone figure this out?

I have found one example on Github, which compiles, but I do not hear any sounds... I already checked that I can play normal melodies with the tone() function - so at least the speaker is working.

Any help would be greatly appreciated!

The code on Github is “tested with Teensy 2.0 only”.
When I look at the code of Timer3, it seems that only pin 2, 3 or 5 can be used. But that is for the ATmega328P.

I don’t know how to tell if those same pins can be on the Arduino Leonardo.
These are the pinmappings for them:
pinmapping ATmega328P : http://arduino.cc/en/Hacking/PinMapping168
pinmapping ATmega32u4 : http://arduino.cc/en/Hacking/PinMapping32u4

You could try pin 2 or 3 or 5.
When it runs on the Teensy 2.0, it should be possible to run on the Leonardo.

The Mozzi library should be compatible with the Leonardo. Pin 9 is used for the speaker.
Can you try it ? It’s super fun.

I think Arduino pin 5 is the Teensy 2.0 pin 9. Perhaps it will work with the speaker at pin 5.

You'll probably have more luck mapping UNno Timer2 to Leonardo Timer3.

Leonardo Timer3 can work in 8-bit PCM mode (see TCCR3A).