Play & Record PWM audio?


Closed Thread
Results 1 to 9 of 9
  1. #1
    Join Date
    Aug 2003
    Posts
    985

    Default Play & Record PWM audio?

    Hi Guys,
    I’m wondering if anything has been done in the way of converting audio directly to PWM
    and playback with hardware PWM? Or am I on my own?

    Recording either analogue input, or digitising to 1 bit and counting frequency directly.
    I’m going to try the latter first.

    I know about RB’s pic sound playback, but IIRC the PBP implementation could not be fast enough.
    Cheers, Art.

  2. #2
    Join Date
    Oct 2004
    Posts
    440


    Did you find this post helpful? Yes | No

    Default Re: Play & Record PWM audio?

    It can be done and it sounds decent.

    Norm

  3. #3
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: Play & Record PWM audio?

    Which method and at what speed are you talking about?
    Even at 10MHz with midrange pic I can:
    Code:
    loop:
    outputpin = inputpin
    goto loop
    and that starts to get somewhat intelligible, but you couldn’t do anything with it.
    If I sample the audio frequency for a period, then set the HPWM,
    I find the more often I set the HPWM, the less gate time I get to count the input.

  4. #4
    Join Date
    Oct 2004
    Posts
    440


    Did you find this post helpful? Yes | No

    Default Re: Play & Record PWM audio?

    Art

    I used a 18F26K20 hardware PWM and a timer interrupt to set 10 bit data read from an SD card WAV file to an audio amp at a 44.1K data rate.
    If I remember right that's CD mono quality.
    There are very few components i.e. PIC, SD card, audio amp and a speaker.


    Norm

  5. #5
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: Play & Record PWM audio?

    If the CD player had a 1 bit DAC.
    I’ve used RB’s audio reading from EEPROM fine in projects, the slow down is processing incoming audio as well.
    I’ll wait for a faster crystal to continue, but might be better off measuring the width of an audio wave rather than counting zero crossings,
    so then there is more time to do something with the data.

    HPWM command is a bit crook as well trying to update it fast. I’m sure it has to figure out,
    and write all four registers associated with HPWM each time it’s called.
    I got it smoother by limiting the frequency range and only altering the PR2 value.
    Still I don’t think it can be saved to EEPROM, even if interleaved to avoid the 10ms wait.

    I have so far kind of a voice controlled PWM, some fun could be had there, so I’ll look at making that faster.

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,517


    Did you find this post helpful? Yes | No

    Default Re: Play & Record PWM audio?

    Yeah, the HPWM command adds a bit of overhead (write configuration register, period register, duty register) so if you need fast duty cycle updates just configure the CCP module manually and write the duty register each update.

  7. #7


    Did you find this post helpful? Yes | No

    Default Re: Play & Record PWM audio?

    Hi guys,

    This is a very interesting topic.
    Does anyone has a sample code so we can try?

    Regards
    Rui

  8. #8
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: Play & Record PWM audio?

    It’s really a matter of reading a pin for a period and outputting that frequency.
    You could probably use PULSIN for a period after sorting out mic hardware to trigger the pic input.
    I used an LM358 op-amp to drive a condenser mic.

    I’m using DT’s timer, and most assembler now, but still a simple program.
    On interrupt, a frequency value is written to hardware PWM one way or another (that I haven’t settled on),
    then the frequency variable cleared before returning to main program.
    The main program only counts audio transitions with the frequency variable in a loop.

    Tonight I got desperate and connected a 64.5 MHz crystal to the pic 16F628A and it works fine!
    I don’t know if it’s actually clocking at that frequency, but I have used 24/25 MHz crystals which have always gone fine,
    and it’s now much faster than them.
    Last edited by Art; - 10th April 2015 at 14:59.

  9. #9
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: Play & Record PWM audio?

    The example where it’s the loudest in the video (quite an obvious one),
    I think I would have 80’s style speech recognition down.
    That variation of the code was very repeatable for words/phrases.


Similar Threads

  1. Port indexing & PWM for LED fade
    By MOUNTAIN747 in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 2nd December 2013, 23:56
  2. Pwm & dac
    By J. Mark Wolf in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 24th October 2010, 13:59
  3. Audio Record/Playback Circuit
    By The Master in forum Off Topic
    Replies: 8
    Last Post: - 12th February 2010, 19:58
  4. 4 Low Speed PWM & HSERIN
    By MasterSparky in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 8th October 2007, 20:12
  5. MOSFET control using PWM & 16C711?
    By droptail in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 27th June 2005, 03:24

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts