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

Searching for DAC

T ChapT Chap Posts: 4,223
edited 2007-01-07 06:38 in Propeller 1
Is there a DAC object for using a Prop pin and no external hardware? I looked everywhere and don't see one. Searching Propeller + DAC didn't produce much. Here is the closest thing I can find using a recommended 10k and .1.

PUB ADC_start(pin)
  dira := |< pin
  frqa := 0
  ctra := %00111 << 26 + pin
 
PUB ADC(value)
  frqa := value




PBaker said...
ADC_start initializes the ADC to output on pin and sets the inital value to 0V, ADC changes the output voltage to 3.3x(value/2^32).

I need to set a voltage between 0 and 3 volts and change it as needed.

Thanks

Post Edited (originator) : 1/2/2007 6:46:44 AM GMT

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-01-02 07:18
    What you've found is pretty much all you need. You have to have the resistor and capacitor to smooth the output of the circuit. The maximum voltage is 3.3V set by the power supply voltage of the Propeller. The value you need for FRQA is v/3.3/2^32 where v is a voltage between 0 and 3.3. You need to compute this using integer arithmetic. The question for you is: What precision do you want? Do you want this to the nearest millivolt? Do you want it to the nearest tenth of a volt? Do you want it to some more convenient fraction like 1/1024 volt? That will determine how you pre-scale the number for the division by 3.3, then the shift that effectively divides it by 2^32.

    Look at the schematic for the Propeller Demo Board for an example (for the audio output) of this kind of DAC. There are some programs in the object library included with the Propeller Tool that copy sound from the microphone to the headphone output. This uses the DAC to produce the sound signal.
  • T ChapT Chap Posts: 4,223
    edited 2007-01-02 07:25
    Thanks Mike, that is a big help. The nearest 10th is fine for this app of setting a REF input for current regulation on a stepper driver. I want to change the level depending on the condition, motor at rest needs lowest current to keep things cool. If a step shows up, then it bumps to the higher voltage.

    I'll check out the schematic mentioned.
  • T ChapT Chap Posts: 4,223
    edited 2007-01-02 09:01
    Are you saying that I can't just type in a value between 0 and 3.3 including decimal points in PUB ADC(value)

    i.e. PUB ADC(1.9)

    I will test this myself tomorrow.

    Is ADC universally accepted for both A to D or D to A? I'm puzzled why ADC is used in Pauls explanation when it is D to A.
  • Ym2413aYm2413a Posts: 630
    edited 2007-01-02 18:02
    originator said...

    Is ADC universally accepted for both A to D or D to A? I'm puzzled why ADC is used in Pauls explanation when it is D to A.

    I'm puzzled as well on that one.

    Anyway the value would be from 0 to (2^32)-1.

    (0) being 0 volts.
    (4,294,967,295) being 3.3 volts.
    (2,147,483,648) would be 1.65.

    You might want to scale this to something else.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-01-02 18:23
    ADC is used for A to D. I don't know why the name ADC was used except that sometimes a D to A converter is used with a comparator for A to D conversion and the Sigma-Delta A to D converter setup for the Propeller works somewhat this way.

    For scaling, if you use a number between 0 and 29 to represent voltages between 0.0 and 2.9, you could approximate the scaling by the following:
    PRI scale(v)
      return ((v << 26) / 33) << 6
    
    


    What this does is to position the 0-29 value in the upper 6 bits of a 32 bit signed long,
    divide it by 33 to get a quotient that's a fraction of 33 with the binary point between the upper 6 bits and the lower 26 bits, then shift that fraction left to put the binary point all the way to the "left" end of the long word. This makes it a fraction of 2^32-1 which is what you want for the D-A process.· The reason for doing is this way is to get as accurate a fractional value as possible, yet to adjust for the fact that the division may be signed.

    Post Edited (Mike Green) : 1/2/2007 6:27:43 PM GMT
  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-01-02 18:50
    I likely just misnamed it, I believe I cooked it up in < 1 hour for a customer that asked for it. The Propeller Counter Ap note explains DAC under the duty cycle mode of operation.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • T ChapT Chap Posts: 4,223
    edited 2007-01-02 19:52
    Thanks for the clarification fellows. One last question about the example posted above. Is the method to be put in a repeat loop to keep it alive, or is the freqa and ctra features something that will stay running on it's own unless some other command cancels it? I am asuuming that the freqa and ctra are associated with the current cog it is running on, and if the code is on a cog by itself, it hits the bottom the cog is cleared right cancleing all counters as well? If the method is located in a cog with other methods looping, does the DAC operate automonously once set in a non-repeating PUB INIT for example. I printed the new counter documents and will study it to start getting an understanding as well.
  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-01-02 20:02
    Whenever a cog dies, all counter registers are reset to 0.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • T ChapT Chap Posts: 4,223
    edited 2007-01-05 04:43
    CON
      _clkmode  = xtal1 + pll16x 
      _xinfreq  = 5_000_000
    VAR
    OBJ
    PUB START
       
       DAC_START(0)
       WAITCNT(CNT + 800000)
       DAC(2147483648)   'Tried 0 - 3.3   , pin is always 3.3v
       REPEAT  
    
    PUB DAC_START(PIN)
       DIRA := |< PIN
       FRQA := 0
       ctra := %00111 << 26 +  PIN
    
       
    PUB DAC(Value)
      frqa := value
    
    



    Can someone tell me where the error is? I get 3.3v on pin no matter what Value is from 0 - 3.3 equiv. I tried .1 and .01 with 10k.


    Thanks
    417 x 229 - 8K
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2007-01-05 05:43
    For troubleshooting, it might help to simplify.

    PUB
      DIRA[noparse][[/noparse]0..1]~~    ' p0  and p1 are output
      FRQA := $8000_0000   ' 50% duty
      CTRA := %00110 << 26 +  0   ' pin p0 single ended duty
      REPEAT       ' stay alive
          !outa[noparse][[/noparse]1 ]    ' also observe toggling on pin p1, 50% duty cycle
    



    Then reverse the roles of p0 and p1.
    Either one should give 50% duty cycle, but the one from the counter module will be much much faster (40mhz switching).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com

    Post Edited (Tracy Allen) : 1/5/2007 9:19:05 AM GMT
  • T ChapT Chap Posts: 4,223
    edited 2007-01-05 05:59
    Thanks Tracy, I borrowed a small portion of your code and it started working:

    Sub'd %00110 for %00111

    I had no idea you could set and forget counters like this, it's like having another set of semi-limited cogs to put to use. Pretty exciting discovery.
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2007-01-05 06:25
    It's pretty cool, a team of helpers.

    %00111 is the differential mode, where you have the true output on Apin and the complement of that on Bpin. You had originally set up pin p0 to be the output for both, by default. On the surface that is a conflict, because in differential mode that pin will want to be both high and low at the same time. Nonetheless, the propeller arbitrates the conflict and the final state of the pin is always high, 3.3 volts, as you observed.

    The propeller i/o logic is wired OR for both DIRS and OUTS.

    Paul, I see the same thing in the listing on page 13 of AN001, the counter doc. The counter mode is set to differential with both apin=0 and bpin=0, although the comment at the end of the line mentions bpin=1.

    Post Edited By Moderator (Paul Baker (Parallax)) : 1/5/2007 9:48:36 PM GMT
  • T ChapT Chap Posts: 4,223
    edited 2007-01-05 06:33
    Without knowing an application yet for using the compliment, should there be a parameter in Paul's original for the Not pin?
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2007-01-05 06:44
    Given what the code in AN001 is trying to illustrate, I think the mode should probably be %00110, single ended, in which case the bpin value doesn't matter. On the other hand, by using differential mode with bpin := 1, then the same code could generate a rising sawtooth on p0 and at the same time a falling sawtooth on p1. What do you want to do?!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • T ChapT Chap Posts: 4,223
    edited 2007-01-05 06:48
    I just want to set a voltage, and change it as needed. I was just curious on the use of the bpin, I don't have a use in mind.
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2007-01-05 21:10
    Just as a reminder, here is the diagram from the Prop manual, showing how the counter outputs are OR'd together with the other possible sources of output. The diagram does not explicitly show that the separate apin and bpin outputs from each counter are OR'd like that, but I'm guessing that is how it _must_ be. Huh?

    That should be classified as a trap, to use any of the differential modes (pll, nco or duty) when you really need single ended. It won't work as expected if both apin and bpin are the same.

    attachment.php?attachmentid=44883

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com

    Post Edited (Tracy Allen) : 1/5/2007 9:20:29 PM GMT
    433 x 317 - 15K
  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-01-05 21:49
    Tracy Allen said...

    Paul, I see the same thing in the listing on page 13 of AN001, the counter doc. The counter mode is set to differential with both apin=0 and bpin=0, although the comment at the end of the line mentions bpin=1.

    I'll take a look at it and add changes to the errata list. I did alot of code carryover and may have left an artifact from another example in there.

    Sorry about editing the post I just quoted from, I accidently hit the edit post button instead of the quote post button. I restored your post to it's orginal form.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • T ChapT Chap Posts: 4,223
    edited 2007-01-06 22:11
    Tracy

    Thanks for pointing out the OR'ing of both counters and the clarofication. It appears that both counters could be used simultaneously on different pins in single ended mode, giving a total of 32 pins of DA as a real possibility, not for a specific application in mind.
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2007-01-07 06:38
    I should have put it like this--The diagram in the manual is incomplete. There should really be two outputs from each counter, one for apin and one for bpin, so in each cog there are 7 possible inputs to the OR gate, not just 5.

    It is confusing because both counter A and counter B each have an Apin and a Bpin.

    There are a total of 16 counters in the 8 cogs. So they could affect 16 pins in single ended mode, or up to 32 pins in differential mode.

    Paul, I know what you mean about code carryover! The bane of copy and paste. I added a little note to the "tricks and traps" sticky about that one.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
Sign In or Register to comment.