Arduino Zero AudioZero killing AnalogWrite (PWM) after use? Please help

I have a very simple code where I play an audio file using the AudioZero example library

I need digital PWM for other activities, in the attached a simpligied example in which I am just playing with the the pin 6 pwm. which does not function at all after the audio has been played

Please can someone help, this is driving me mad..

Highly appreciated.

#include <SD.h>
#include <SPI.h>
#include <AudioZero.h>

void setup()
{

pinMode(6, OUTPUT); // PWM digital pin

Serial.begin(115200); Serial.print("Initializing SD card...");

if (!SD.begin(4)) { Serial.println(" failed!"); while(true); }

Serial.println(" done.");

AudioZero.begin(44100);
}

void loop()
{

File myFile = SD.open("1234.wav");
if (!myFile) { Serial.println("error opening test.wav"); while (true); }

Serial.print("Playing");

AudioZero.play(myFile); AudioZero.end();

Serial.println("End of file. Thank you for listening!");

while (1){
analogWrite(6, 10);
analogWrite(6, 68);
analogWrite(6, 255);
}
}

Hi aqibi2000,

I believe the issue might be that you're calling analogWrite() three times in an infinite loop. This is continuously changing the PWM duty cycle many times faster than the duration of a single PWM output pulse.

MartinL:
Hi aqibi2000,

I believe the issue might be that you're calling analogWrite() three times in an infinite loop. This is continuously changing the PWM duty cycle many times faster than the duration of a single PWM output pulse.

I wrote this as as short example (I should have included a delay between each value)
nonetheless even when there is just one statement containing an anlaogWrite it does not work.

The library breaks the PWM functionality of the Arduino Zero

Please try this library : GitHub - AloyseTech/Zerodio: Non blocking audio library for Arduino Zero

I'm unable to test your issue right now but maybe this could help.

AloyseTech:
Please try this library : GitHub - AloyseTech/Zerodio: Non blocking audio library for Arduino Zero

I'm unable to test your issue right now but maybe this could help.

Thank you, this does work however the play back quality is extremely poor, doesn't sound anything like a 10-bit DAC :frowning:

You have to change some settings, like the sample rate. And only 8bit are used with this library.