Shop OBEX P1 Docs P2 Docs Learn Events
DAC PWM charge up speed — Parallax Forums

DAC PWM charge up speed

kevinjkevinj Posts: 9
edited 2007-03-28 22:46 in BASIC Stamp
The Basic Analog and Digital guide shows how to create a DAC. I've tried this and it works with the Basic Stamp.

My question regards the choice of the R and C. I want to lower each so my charge time is only 1 micro second or·as low as possible·to output a 0 to 5 volt signal.

Do I need a faster processor to do this? Is there a formula relating pulse width to charge time (R & C)?

Specifically, what would the cycles formula be?

Thank you.

Post Edited (kevinj) : 3/26/2007 12:22:27 AM GMT

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-03-26 02:31
    It sounds like the Stamps are not fast enough for what you want. Look at this site for information on the speed of Stamp statements www.emesystems.com. If you look through this application note, you'll find some information on the Propeller's DAC speed www.parallax.com/dl/appnt/prop/AN001-PropellerCounters-v1.0.zip as well as examples.
  • Sarten-XSarten-X Posts: 32
    edited 2007-03-26 07:18
    I don't know about the circuit in question, but I do know from experience you can create a high-speed DAC with a bunch of identical resistors. It's bulky but fast. Look for "R-2R" on Wikipedia for the circuit and an explanation of its workings. I've used it to drive a speaker, and managed to replicate low-frequency audible sounds with a BS2px and a LTC1298 ADC.

    I took your comment to mean there's a capacitor involved... capacitors take longer than a resistor ladder, I believe. I may be entirely wrong, though.
  • kevinjkevinj Posts: 9
    edited 2007-03-26 20:30
    I'm interested in the fastest DAC the stamp can output. The stamp can only do this by charging a capacitor with a RC circuit.

    I would like to know how the frequency of the stamp (PWM) comes into play because if you choose your RC circuit with small values (1KOhm and 1nF) vs. large values (10KOhm and 1uF as given in the tutorial/"basic analog and digital guide") you can make a very fast DAC.

    Does that make sense? Thanks. kevinj.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-03-26 20:50
    Sarten-X is correct. The fastest DAC is a parallel one, usually using an R-2R network. There are no capacitors involved (unless you want to slow it down). You'd write to the I/O pins involved all at the same time using the output register (OUTS) or one of its subsets (for 4-bit or 8-bit access). Tracy Allan's website (www.emesystems.com) has information on statement execution time that can help you figure out how fast you can execute the statements involved.

    The frequency of the PWM statement doesn't really apply since it's not really intended for very fast DAC. It basically puts out a pseudo-random pulse sequence for a specified time that is averaged by the RC network to produce the voltage requested. Once the statement finishes, the pulse train ceases and the capacitor acts as a "sample and hold" to maintain the output voltage.
  • Sarten-XSarten-X Posts: 32
    edited 2007-03-27 03:03
    As it so happens, right now I'm using the same computer I used when I built my DAC, so here's my test code. Note that the Test=(254... line is the formula for the output signal. I don't remember what this one is. Anyway, change it to whatever you want.

    ' {$STAMP BS2px}
    ' {$PBASIC 2.5}
    
    temp VAR Byte
    Amplitude VAR Byte
    Location VAR Word
    
    Temp = 0
    FOR Location = 0 TO 1024
    
    Temp = (254-temp) * location / 1024 + 1
    DEBUG HEX Temp," "
    WRITE Location, Temp + 1
    NEXT
    WRITE Location + 1, 0
    OUTPUT 0
    OUTPUT 1
    OUTPUT 2
    OUTPUT 3
    OUTPUT 4
    OUTPUT 5
    OUTPUT 6
    OUTPUT 7
    FREQOUT 7,8000, 2500
    DO
     FOR Location = 0 TO 1024
      READ Location, Amplitude
      OUTL = Amplitude
      PAUSE 1
      'OUTH = Amplitude
      'LOW 2
      'IF Amplitude THEN HIGH 2
     NEXT
    LOOP
    
  • Mike GreenMike Green Posts: 23,101
    edited 2007-03-27 03:11
    By the way, you can do all the OUTPUTs with a "DIRL = %11111111".
  • Sarten-XSarten-X Posts: 32
    edited 2007-03-27 14:34
    Good to know... At the time, that was a quick hack while trying to make sound work. The code looked right, but nothing worked, so I tried everything I could think to to make it work. The OUTPUT statement worked, so I copied & pasted without thinking what it did.
  • kevinjkevinj Posts: 9
    edited 2007-03-28 21:41
    I believe you two are correct regarding the R-2R as being a fast DAC.

    But my question is about using the stamp·and a·RC to implement·a fast DAC.

    I wanted to know if I use a small R and a small C then I should be able to create the fastest DAC in the world.
    I know this isn't possible, and I wanted to know what the bottle neck is. Is it the PWM output frequency?
    Is there a formula relating PWM frequency to RC?
  • Mike GreenMike Green Posts: 23,101
    edited 2007-03-28 22:46
    If you use a small R and a small C then you'll create a terrible DAC.

    I suggest you learn something about RC networks (en.wikipedia.org/wiki/RC_time_constant).

    The PWM statement puts out a pulse train as mentioned. The typical pulse width is related to the instruction time of the processor chip used. I don't know exactly what that is, but it's probably on the order of 1-2us (pulse width that is) for the BS2. The RC network acts as a filter for this and smooths it so that the filter output is very close to the average "on time" of the pulse train. You can't change the pulse width so, if the RC network's time constant is too short, the output voltage will "sag" between pulses and you'll lose accuracy.

    It is possible to create DACs using this technique, but at a faster pulse rate. The Propeller uses this technique to do DAC. The problem is that, as the frequency gets higher, other things interfere. Lead inductance and lead length to the RC components starts to cause problems. Power consumption is related to switching frequency by a power law (square?). If you look at the fastest DACs, they're all resistor ladder. Doing multiple bits at a time is always faster than one bit at a time and, often with ICs, may even be cheaper.
Sign In or Register to comment.