PIC16F684 Capabilities

Discussion in 'Programmer's Corner' started by DHEN, Dec 7, 2009.

  1. DHEN

    Thread Starter New Member

    Dec 7, 2009
    9
    0
    New to the Pic16f684! can it in any way generate sounds to output through a speaker in any way?

    Thanks for your help?
     
  2. mik3

    Senior Member

    Feb 4, 2008
    4,846
    63
    It has not an analog output and thus it is not able to generate sound in an analog manner. However, it is possible to use a PWM output and filter it to produce an analog signal which when amplified will be able to produce sound via a speaker. The PWM duty cycle variation will be according to the required sound to be produced.
     
  3. DHEN

    Thread Starter New Member

    Dec 7, 2009
    9
    0
    Do you know of a way to convert a .wav file into a PWM format.:confused:

    Thanks!
     
  4. beenthere

    Retired Moderator

    Apr 20, 2004
    15,815
    282
    The converted values correspond to loudness. Use the value of the conversions in the file to set the percentage of pulse width. You have to be able to separate the right and left channels values, as well as determine the length of the converted values. The .wav file format should have that information in it. Trimming the words to 8 bits may make life easier.
     
    Last edited: Dec 12, 2009
  5. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    Have a look at this page, it allows you to playback sound with just one digital output pin on a PIC;
    http://www.romanblack.com/picsound.htm

    There is also free windows software on that page to convert wave files to the 1bit sound format.

    The main problem is getting a decent length of sound playback, in most cases you need external memory. There is a low cost PCB here that will store 1 megabit of sound and play it in up to 255 separate sounds (controlled by serial);
    http://www.talkbotbrain.com/
     
  6. DHEN

    Thread Starter New Member

    Dec 7, 2009
    9
    0
    This is Great, Jest what i am looking for. What i don't understand is how to use the Algorithm. how is it entered into the code?
     
  7. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    The 1-bit playback is extremely simple. You just send the sound data byte to the PIC pin, 1 bit at a time, and when the 8 bits are sent you just start sending the next byte.

    The 1bit format stores the sound with MSB first so so send the sound out using a left shift, something like this;

    Code ( (Unknown Language)):
    1.  
    2.   MOVF databyte,w
    3.   MOVWF PORTB    
    4.  
    5.   RLF PORTB,f   ;   this RLF sends out 1 sound bit
    6.  
    And the sound will be output from the PIC pin for bit7.
     
Loading...