2 Replies Latest reply on Jul 3, 2015 3:48 PM by Intel_Alvarado

    Generating audio on edison using High speed PWM

    Sriranjan

      Hello,

       

      It is possible to generate a decent quality audio on AVR microcontrollers using fast PWM.

      http://brainwagon.org/2011/07/17/using-the-arduino-to-send-audio-via-pulse-width-modulation/

      There they use timers.A raw audio file can be played. Now I want to do the same in Edison.

       

      Please let me know.

        • 1. Re: Generating audio on edison using High speed PWM
          Sriranjan

          I meant it can be done on AVR micros but I want to do the same on edison. Code here:

           

          #include <avr/pgmspace.h>

           

           

          prog_uchar bwdat[] PROGMEM = {

          0x80, 0x80, 0x80, 0x7f, 0x80, 0x80, 0x80, 0x81, 0x80, 0x80, 0x80, 0x80,

          // ... lots of lines deleted for brevity...

          0x80, 0x80, 0x80, 0x80, 0x80, 0x81, 0x80, 0x7f, 0x7f, 0x80, 0x80, 0x80,

          0x80, 0x81, 0x81, 0x80, 0x80, 0x81

          } ;

           

          void

          setup()

          {

            pinMode(11, OUTPUT);

            TCCR2A = _BV(COM2A1) | _BV(WGM21) | _BV(WGM20);

            TCCR2B = _BV(CS20) ;

            OCR2A = 180;

          }

           

          void

          loop()

          {

            int i ;

            char ch ;

           

            for (i=0; i<sizeof(bwdat); i++) {

              ch = pgm_read_byte_near(bwdat+i) ;

              OCR2A = ch ;

              delayMicroseconds(125) ;

            }

          }

          • 2. Re: Generating audio on edison using High speed PWM
            Intel_Alvarado

            Hi,

             

            The same code would not work on the Edison due to the AVR dependencies. The Edison doesn’t have AVR architecture. To generate audio with a PWM you would need to make a PWM wave work with the frequency range that you need. You don’t need specifically this code. There are several examples that discuss how to make a PWM signal; I’d suggest you to look at Re: Edison PWM GPIO and at the Edison Arduino Hardware guide section 11.4 Intel® Edison Boards — Intel® Edison Kit for Arduino* Hardware Guide

             

            Sergio