Shop OBEX P1 Docs P2 Docs Learn Events
Counters for DAC... — Parallax Forums

Counters for DAC...

siljamickesiljamicke Posts: 66
edited 2011-02-08 01:27 in Propeller 1
Ok, I need clarification...
The AN001 gives the impression that the DUTY-mode is the most suited for DAC, but I've also seen people stating that the PWM-mode is the way to go... I'm confused...

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-02-05 11:27
    It depends on the application. DUTY mode is the easiest to filter to an analog voltage, because it has the highest frequency components. But, for that same reason, it's totally unsuitable for PWMing a MOSFET, say, to drive an inductive load. BTW, the so-called "PWM" mode is not really a self-contained counter mode, since constant program intervention is required to maintain it.

    -Phil
  • siljamickesiljamicke Posts: 66
    edited 2011-02-05 12:29
    Ok, well my specific application is audio, so that would mean I should go for duty-mode then? I think I saw the opposite being mentioned in another thread, but I might be mistaken...
    And just because I'm curious, why is it unsuitable for driving inductive loads?
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-02-05 12:34
    For audio, I'd go with DUTY mode. The reason DUTY mode is unsuitable for switching inductive loads via a MOSFET is that it switches too fast. The gate capacitance of a MOSFET is such that, at very high switching speeds, the MOSFET will spend too much time in its linear region and overheat.

    -Phil
  • Ahle2Ahle2 Posts: 1,179
    edited 2011-02-05 13:08
    Go with duty mode.
    I have listened to just one sound driver that used the PWM mode and the result was bad.
    Either you will get good resolution and low mixing frequency or you will get high mixing frequency and poor resolution.
    And it is harder to implement.

    /Johannes
  • siljamickesiljamicke Posts: 66
    edited 2011-02-05 16:28
    Thanks for the clarification guys!
    I have trouble understanding the DUTY-mode though. PWM I think i get, at a fixed frequency I alter the length of the high vs. low time of the output, resulting in a power proportionate to the ratio of high vs. low, right? But how does DUTY differ? My best bet so far is that a stream of pulses, all of equal length, is output at a very high frequency, and the number of pulses constitutes the amplitude. Is this somewhat correct?
    But wouldn't that mean that the resolution is somewhat overkill for audio DA-conversion? I thought I read that at the lowest counter setting there would be some 50 minutes or so between the pulses, and no filters in the world could ever turn that into a sinusoid of any audible frequency, or am I just terribly mistaken about how this all works?
  • siljamickesiljamicke Posts: 66
    edited 2011-02-07 07:51
    I'm bumping this, because I'm so curious. I would really want to understand this, but the counters document just leaves me scratching my head :(
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-02-07 09:06
    siljamicke wrote:
    But how does DUTY differ? My best bet so far is that a stream of pulses, all of equal length, is output at a very high frequency, and the number of pulses constitutes the amplitude. Is this somewhat correct?
    That's an apt description, if you accept that two "pulses" can be side-by-side, thus forming a longer pulse. For example, with an 80 MHz clock and 50% duty (frqx = $8000_0000), the output wlll be a 40MHz square wave (12.5ns pulse every 25ns). At 25% duty frqx = $4000_0000), there will be a 12.5ns pulse every 50ns. At 75% duty cycle, there will be a 37.5ns pulse (i.e. three 12.5ns pulses cheek-to-jowl) every 50 ns. IOW, a 12.5ns "pulse" occurs every time adding frqx to phsx causes a carry, and that addition is performed every 12.5ns.

    Don't worry about DUTY mode being "overkill". The main thing is that the output is easy to generate without program hand-holding, and the DUTY doody is easy to filter because the frequency is so high.
  • AribaAriba Posts: 2,690
    edited 2011-02-07 09:32
    siljamicke wrote: »
    I have trouble understanding the DUTY-mode though. PWM I think i get, at a fixed frequency I alter the length of the high vs. low time of the output, resulting in a power proportionate to the ratio of high vs. low, right? But how does DUTY differ? My best bet so far is that a stream of pulses, all of equal length, is output at a very high frequency, and the number of pulses constitutes the amplitude. Is this somewhat correct?
    For DUTY mode it's the same: Output, results in a power proportionate to the ratio of high vs. low.
    But you have not a constant frequency. Instead the shorter of the two puls states (high and low) is always one clock cycle, and the longer is adjusted so that you get the desired high/low ratio. For a 50:50 ratio both states are one clock so you get a frequency of 1/2 the clockfrequency (40MHz @ 80MHz clock). That is ideal for audio because at 50:50 is the virtual zero for audio and therfore low signal amplitudes have a very high PWM frequency. The downside is that the PWM frequency changes havy with the audio signal, and that results in serious EMC noise. That can be a reason for one to use a normal PWM.
    siljamicke wrote: »
    But wouldn't that mean that the resolution is somewhat overkill for audio DA-conversion? I thought I read that at the lowest counter setting there would be some 50 minutes or so between the pulses, and no filters in the world could ever turn that into a sinusoid of any audible frequency, or am I just terribly mistaken about how this all works?
    I would say 50 seconds not minutes ;) But this is only if you use the full 32 bit range (FREQx value of $0000_0001 or $FFFF_FFFF). If you limit the audio amplitude to 1/2 of the possible range (which is still 1.6V), the FREQx range is $4000_0000...$C000_0000, middle is $8000_0000. This give still a very high PWM frequency.

    Andy
  • siljamickesiljamicke Posts: 66
    edited 2011-02-07 10:54
    Sorry, I meant seconds... So the idea is to use freq values around the center, because it will be equally wrong at the other end, i.e. $ffff ffff will be high for a minute or so and low for one clock, if I understand it correctly? So negative swing is between $8000 0000 and $4000 0000, and positive swing is $8000 0000 to $C000 0000. That's what, like 15 bits worth of dynamics? What is the lowest frequency component that could come out of this (I'm referring to the "carrier wave", not my audio), is it never lower than clockfreq/2 with different partials on top of that? IOW is the filter mentioned in AN001 the proper filter? I don't care too much about random white noise, but I'm somewhat allergic to weird harmonics.
    But then again, I probably won't hear a 40mhz tone...
  • siljamickesiljamicke Posts: 66
    edited 2011-02-07 11:03
    Ok, so I pondered this a bit more, and $4000_0000 is probably not gonna be a 40 mhz tone. Come to think of it, a lot of the different freq values will give weird waveforms, with different cycle rates. Is the a pattern to what the stream will look like if I would sweep from $0000_0000 to $FFFF_FFFF?
    If I narrow the sweep to the suggested range $4000_0000, to $C000_0000, will some sequences be audible?
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-02-07 11:14
    To get a 0-3.3V DAC output, you would have to use the entire range, $0000_0000 to $ffff_ffff. But you don't need to use all the bits. For example, if you only needed 8-bit resolution, your values would be $0000_0000, $0100_0000, $0200_0000, ..., $ff00_0000. (As an alternative: $0000_0000, $0101_0101, $0202_0202, ..., $ffff_ffff.)

    And, you're right, some frqx values (those which do not integer-divide 232) can produce (barely) audible subharmonics. Chip has successfully used phase dithering to spread these out to the point that they're virtually inaudible.

    -Phil
  • siljamickesiljamicke Posts: 66
    edited 2011-02-07 12:25
    But practically speaking, is a 12,5ns pulse every 50 seconds or so really equivalent to a low voltage? I mean, I get that one could mathematically argue that the power dissipated over a period of one minute would equal a very low voltage, but in this frame of time, is there a filter that would turn this into the proportionate voltage? I can see in a scope that a 3,3V square wave in the mhz range through an rc filter really is 3,3/2 V, but is that really true for $0000_0001 or $FFFF_FFFE in the duty mode?

    It really doesn't matter, as long as there aren't any audible tones in the range you suggest. Is the fact that I'm using a 6mhz xtal (96mhz) gonna do much to push the artifacts beyond hearing frequencies? Any pointers to where I might learn about the dithering business you mention?
    Thanks guys for you help!
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-02-07 13:34
    Don't worry about it. A singleton 12.5ns pulse will not make it through a lowpass filter with a corner frequency in the high audio range. A 6MHz crystal will not make a significant difference.

    For info on dithering, look at the code for Parallax's Prop-based audio player.

    -Phil
  • siljamickesiljamicke Posts: 66
    edited 2011-02-07 14:39
    Big thanks!
    This thread will come back alive in the near future when I get my demo board I ordered a few days ago and I actually get to code something instead of filling this forum with all my gibberish! Until then wish me good luck with understanding dithering ;)
  • Ahle2Ahle2 Posts: 1,179
    edited 2011-02-07 15:10
    Don't buy the demo board if you want clear audio output; It has a cutoff frequency of just ~1.6 kHz, and it is hard to modify thanks to small component sizes.
    You as a professional musician should understand the need for frequencies above 1.6 kHz. A "little" thing called overtones sometimes seems to be neglected by engineers.
    Buy the propeller platform instead with a suitable add on.

    BTW, download the audio file that is included in the "Listen up C3 owners" thread.
    The C3 has got a cutoff frequency of 1.6 kHz as well, and then you will be able to decide for yourself.

    /Johannes
  • siljamickesiljamicke Posts: 66
    edited 2011-02-08 01:27
    Damn, I read the thread about C3's audio filter, and I thought that it was a new "feature". So it's on the demo board to... :(
    Well I ordered the demo board so that I didn't have to solder the VGA connector, what a bummer that I traded that for resoldering smd's, a task predestined to have me have a nervous breakdown as well as a demo board breakdown :(
    I think I'll be using two other pins for my audio then.

    Hey, if I toggle wich pins will output audio between my pins and those already prefitted with filter, I have an, admittedly very coarse, "sweepable" filter!
    ... Just kidding... :(
Sign In or Register to comment.