Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PIC18F wav Player 8bit PCM 8KHz wav file

Status
Not open for further replies.
Joined
Jul 25, 2012
Messages
1,192
Helped
171
Reputation
342
Reaction score
162
Trophy points
1,343
Activity points
0
Hello!


I want to build a pwm based wav file player. I have done the sd part of it. I am able to read the file (i.e., 512 bytes at a time). I want to know should I send convert each byte read to integer and set it as duty cycle of PWM? How do I know the duration each byte has to play?

I want to play 8bit 8KHz pcm wav file


Thanks
Jayanth D
 

From what I understand, the simple way is that you send a byte value (8 bits) to the DAC.

The DAC converts each value to a volt level, which appears at the analog out terminal.

You'll do this 8,000 times a second. The result will be an audio waveform.

I don't know how it would implement PCM (pulse code modulation) or PWM.
 

Thanks BradtheRad for replying. How do I know which byte has to play how long? The duration of each byte?
 
Last edited:

At 8 kHz each sample should last 1/8000 of a second.

You'll jump to a new volt level, one sample after the next, as evenly as possible, with no spikes or dead areas.

Here is a screenshot of digitized audio in a popular free program called Audacity. It illustrates a typical signal that goes to your speaker.

7697268500_1352783041.png


The sample rate is 41.1 kHz, so the waveforms look smooth.

Data should range above and below the middle value. It should not touch the minimum (zero) or maximum. Your maximum will be 255.
 

From what I understand, the simple way is that you send a byte value (8 bits) to the DAC.

The DAC converts each value to a volt level, which appears at the analog out terminal.

You'll do this 8,000 times a second. The result will be an audio waveform.

I don't know how it would implement PCM (pulse code modulation) or PWM.


Hello! BradTheRad

Can I just interface DAC0808 to my PIC18F4620 PORTD outputs and give the output of DAC to earphones?

You said that I have to set the DAC i/p port i.e., PORTD with the byte of the wav file read. Is it right?

You said that it has to be done 8000 times a sec. How to do that?


Thanks
Jayanth D

- - - Updated - - -

Hello! BradtheRad

I changed my wav file to 8-bit PCM 22KHz WAV file. I have attached my proteus circuit, mikroC Pro files, and MMC image file (.mmc file).
Please have a look at it and tell me what I am doing wrong. My Fosc is 8 MHz.


Thanks
Jayanth D
 

Attachments

  • wavplyr.jpg
    wavplyr.jpg
    273.9 KB · Views: 149
  • Wave_Player mikroC Proteus.rar
    6.7 MB · Views: 275

Hello! BradTheRad

Can I just interface DAC0808 to my PIC18F4620 PORTD outputs and give the output of DAC to earphones?

I'd be surprised if the DAC provides sufficient power to drive earphones.

It's likely you'll need an audio amplifier. This can be made from an easy-to-use IC such as the LM386. There are many threads at this board discussing such projects.

You said that I have to set the DAC i/p port i.e., PORTD with the byte of the wav file read. Is it right?

In essence, yes, although there is probably more to it than that. I don't know the protocol. You'll have an easier job reading an 8-bit monaural file.

Nor have I used a microcontroller. I tried to do something similar with my VIC-20 about a quarter century ago, turning eight port contacts on and off, running it through an R-2R resistor network, all in hopes of hearing sine waves through my speakers. Not in the same league as a wav file.

You said that it has to be done 8000 times a sec. How to do that?

You must devise a loop that keeps track of time to the microsecond.

I was able to uncompress your program and read some files, but I would not know how to debug it.

I changed my wav file to 8-bit PCM 22KHz WAV file. I have attached my proteus circuit, mikroC Pro files, and MMC image file (.mmc file).
Please have a look at it and tell me what I am doing wrong. My Fosc is 8 MHz.

I have not used the DAC0808 (successfully), but I believe the B2 supply should be hooked up differently... other than putting it directly across the Vref+ and Vref- pins.

In order for the speaker to get AC, your ground (zero) needs to be between the bipolar supplies.

There is also the method of using a resistor network to perform DAC. Weighted values, or R-2R.

A few people have succeeded at the same project you are doing. See the link below. Some show videos.

**broken link removed**
 

Is there any example on how to use DAC to play wav files?

- - - Updated - - -

See this link. http://www.sparkfun.com/tutorials/160

You said: You must devise a loop that keeps track of time to the microsecond.

Instead can I use a delay of 45us in my example and load the dac every 45us? Will that do? or should I use a timer to count 45us?

My files open in mikroC Pro and .dsn file opens in proteus.
 

I believe I've heard that microcontrollers have an onboard timer function. (Call it TickCount and suppose it is in uSec.)

Suppose you want your loop to take 45 uSec.

Your code will have statements similar to these:

TargetTime = Tickcount + 45
Fetch a byte of data and send to the DAC
While TargetTime > TickCount
Wend

Then you repeat the above.

You may need to tweak a variable somewhere to make the sound come out right.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top