Differences between playing WAV on Propeller vs PICs
DonEduardo
Posts: 54
One of the biggest reasons I chose the Propeller last year was because of its capability to play WAV files. There are some great objects in the Exchange that I've used for that purpose. One thing I find lacking in the Prop is an analog to digital converter. For one project I just purchased a standalone ADC to work with the prop. Then I saw that some PIC microcontrollers with built in ADCs are actually cheaper than a stand alone ADC. So, for the next project I purchased a cheap PIC and used it as my ADC to feed the Propeller. For my latest project, I think that same cheap PIC would be enough for the whole thing, but I still want to play a couple of short WAV files. I didn't want to add a Prop just for the sole purpose of playing the WAV's. But in looking for sample code/schematics for playing WAV on PICs, I found that nearly all require a separate 4th order Butterworth low-pass filter to play decently. Yet the Propeller plays beautifully with just a resistor and capacitor attached to the pin. Why?
I'm trying to figure that out. From looking at the code samples for each platform, it looks like all the PIC's are playing audio by varying the duty cycle over a constant PWM frequency. But the Prop code looks to me like it is actually varying the frequency on the pin instead of the duty cycle.
Questions: 1) Does that make sense? Am I on the right track there? 2) Why can't the PIC's do that? Not fast enough?
I'm trying to figure that out. From looking at the code samples for each platform, it looks like all the PIC's are playing audio by varying the duty cycle over a constant PWM frequency. But the Prop code looks to me like it is actually varying the frequency on the pin instead of the duty cycle.
Questions: 1) Does that make sense? Am I on the right track there? 2) Why can't the PIC's do that? Not fast enough?
Comments
I suspect that the Propeller's signal is cleaner than the PIC's because the Propeller is producing the variable duty cycle signal at a much higher frequency than the PIC is capable of, therefore more easily filtered.
Read AN001 which is downloadable from Parallax's Propeller download page.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon McPhalen
Hollywood, CA
varies the Pulswidth by changing the frequency, so that the shorter pulsstate (high or low) is always 1 clock cycle.
In the best case at 50% you get a PWM with a frequency of 1/2 the clock (=40 MHz @ 80MHz clock!). And this 50% case is at
the virtual Zero of the Audiosignal. So at low audio signals you have a very high frequency, which is easy to filter out. The lower
frequency at loud signal parts is not hearable because it is covered by the loud audio ouput.
This DUTY mode is only possible because the counters in the Propeller have another architecture than all the other Micro-
controllers, they work more like a DDS with phase accumulator. And they are clocked with a higher rate than most other
controllers.
The downside of this architecture is: you can't produce a normal PWM without the help of a cog, and this normal PWMs
are necessary to drive Motors, LEDs and such.
Andy
Good for the Prop. Bad for my plan to use the PIC as the sole microcontroller in my project. That Butterworth filter had some really odd resistor and capacitor values and a bunch of them. It's just one of those things that won't be fun to solder up. I know I'll get something wrong and spend hours trying to figure out what I shorted or cold-solder jointed. I want to minimize the number of components I have to work with.
Again, wish the Prop had a built-in ADC.
To convert Audio signals you can use the "built in" Sigma-Delta ADCs of the Propeller. You need two pins, two resistors,
a capacitor, and a counter in Feedback mode. With a little software in a cog this makes a fast ADC (see the AN001 Application note).
If you like more to use a PIC, there are dsPICs with a 16bit stereo Audio DAC: dsPIC33FJ64GP802 / 804.
Andy
I read through the App-note as recommended and from that it seems better than I thought. 12bit resolution even. I thought it was only 8 bit for some reason.
Thanks all for the information.