PT8211 has a DC DAC

Status
Not open for further replies.

manatee

Active member
Hello!

I'm trying to use the PT8211 has a DC DAC with relative success, but my limited coding knowledge is getting me nowhere...

I know the PT8211 is not the best DAC for this application but is understanding is that since the PT8211 is an R-2R ladder DAC this project should be doable for non precision applications, like LFOs etc.

I've tried to modify this code: https://gist.github.com/dilshan/9044b895dcc8aa05d9df0cac1e928f8e

So far i've simply modified the void loop to do a simple Potentiometer follower. But has is, i've stumbled in to some problems:

- i'm having problems to scale the pot value to the full resolution of the DAC, seems like the dac is bias at half the voltage reference and i can only write to one half or the other.
(if i do: int val = map(pot, 0, 4096, 0, 65536); it writes to the top half of the DAC
if i do: int val = map(pot, 0, 4096, 65536, 0); it writes to the bottom half of the DAC)

-can't understand how to select and write to individual DAC channels, the pot value is always updated to both DACs.

Other than this, seems like it works smoothly as a DC DAC and could be a nice/cheap alternative for the more expensive DACs.

What would be needed to modify in order to use it as a simple DC DAC?

Here is where i am so far:

Code:
//#include <limits.h>

#ifndef PIN_BCK
#define PIN_BCK   21
#endif

#ifndef PIN_WS
#define PIN_WS    20
#endif

#ifndef PIN_DIN
#define PIN_DIN   7
#endif

#define NOP __asm__ __volatile__ ("nop\n\t")

void writeDACChannel(short waveData)
{
  unsigned char pos = 16;

  // Send data into PT8211 in least significant bit justified (LSBJ) format.
  while(pos > 0)
  {
    pos--;
    digitalWrite(PIN_BCK, LOW);
    // Write next bit in stream into DIN.
    digitalWrite(PIN_DIN, (waveData & (1 << pos)) ? HIGH : LOW);
    NOP;
    // Toggle BCK.
    digitalWrite(PIN_BCK, HIGH);
    NOP;
  }
}

void writeDAC(short waveData)
{
  digitalWrite(PIN_WS, LOW);
  digitalWrite(PIN_BCK, LOW);
  // Write data into right channel of DAC.
  writeDACChannel(waveData);
  digitalWrite(PIN_WS, HIGH);
  // Write data into left channel of DAC.
  writeDACChannel(waveData);
}

void setup() 
{
  pinMode(PIN_BCK, OUTPUT);
  pinMode(PIN_WS, OUTPUT);
  pinMode(PIN_DIN, OUTPUT);
  analogWriteResolution(12);
}

void loop() 
{
 
    int pot = analogRead(A0);
    int  val = map(pot, 0, 4096, 0, 65536);
    writeDAC(val);


}

Thanks in advance!
 
Last edited by a moderator:
Thanks Paul!
oh, silly me...that fixed the scaling problem :)

Any simple solution to select channels and write different values to them?
 
Any simple solution to select channels and write different values to them?

Maybe just write different values, sorta like this?

Code:
void writeDAC(short waveData1, short waveData2)
{
  digitalWrite(PIN_WS, LOW);
  digitalWrite(PIN_BCK, LOW);
  // Write data into right channel of DAC.
  writeDACChannel(waveData1);
  digitalWrite(PIN_WS, HIGH);
  // Write data into left channel of DAC.
  writeDACChannel(waveData2);
}
 
Status
Not open for further replies.
Back
Top