Shop OBEX P1 Docs P2 Docs Learn Events
Differences between playing WAV on Propeller vs PICs — Parallax Forums

Differences between playing WAV on Propeller vs PICs

DonEduardoDonEduardo Posts: 54
edited 2010-04-09 00:29 in Propeller 1
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?

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-04-07 21:38
    I haven't looked at the WAV player code for some time, but I believe that it does DAC the same way that it's done in other applications which is by varying the duty cycle of a fixed frequency signal using a cog counter as described in the application note on the cog counters (AN001).

    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.
  • JonnyMacJonnyMac Posts: 9,208
    edited 2010-04-07 21:40
    The Propeller WAV players that I've worked with (and the one I'm writing for myself) actually vary the duty cycle of the output which is fed into a RC filter (simple DAC) to convert to a voltage output.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon McPhalen
    Hollywood, CA
  • AribaAriba Posts: 2,690
    edited 2010-04-07 23:12
    The Prop generates a special PWM signal with the DUTY mode of the counters. This signal has not a fixed frequency but
    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
  • DonEduardoDonEduardo Posts: 54
    edited 2010-04-08 02:48
    Whoa Andy. Thanks for that explanation. I don't quite have my head wrapped around it yet but I see how the Prop is handling things differently.

    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.
  • AribaAriba Posts: 2,690
    edited 2010-04-08 05:51
    For what do you need the 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
  • DonEduardoDonEduardo Posts: 54
    edited 2010-04-08 15:57
    Thanks Andy, my preference is to use the Propeller for the whole thing, not the PIC. I'm going to try the Sigma-Delta. When I looked up ADC in the threads a few months ago it seemed that the original poster always ended up choosing an external ADC for some reason. I even saw one where one guy wanted to measure when the battery was low and a few responses seemed wishy-washy about the sigma-delta method. I chose the external ADC at that time cause I wanted it to work and build my confidence. But with that under my belt, and armed with a little more knowledge and experience, I'll give the Sigma-Delta a shot. I want to measure audio levels and also some general current sensing.

    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.
  • localrogerlocalroger Posts: 3,452
    edited 2010-04-09 00:29
    Don, I've successfully used delta-sigma for some tests, but that was using a Protoboard with the passive components right on the nearest pins to the SMT chip. The method can be picky about trace runs, particularly if you're using a DIP40 Prop; I'm pretty sure I'd have gotten garbage for results if I tried the exact same thing on a PropRPM. So it's worth testing because it can save a lot of bucks and be another example of the prop doing its hardware to software magic if it works, but it's also good to have a backup plan because depending on a lot of specific stuff about your project it just might not be workable at all.
Sign In or Register to comment.