PortD with R-2R as fast 8 bit DAC

To my project to a TACAN-similator I need a fast DAC. After some test I find out, that the build-in DAC is to slow, and tryed to use PortD and R-2R ladder-network.

It work fine, a conversion with lookup in a table use ~ 160nS.

The laddernetwork use 24 pc. 2k2 resistors.

The code:
int SinDots = 360; // Point in the Tab1 sinustable.
// If you change this, you shall also change the "ii<360;" in line 36.
byte Tab1[360];
byte trigger = 13;
byte x = 0;

//-------------------------------------------------------------------------------------------
void setup() {
Serial.begin(250000);
PIOD->PIO_PER = 0x00FF; // Configure PORTD to PIO controller
PIOD->PIO_OER = 0x00FF; // Enable PORTD as output
pinMode(trigger, OUTPUT);

for(int degree=0; degree<SinDots; degree++)
{
// float radian = ((degree * 71)/4068.0); //For 360 points sinustable
float radian = ((degree * 71)/(11.30*SinDots));
int Value = (sin(radian)*127)+128;
Tab1[degree] = Value;
// Serial.print(Value); // Output thr table to use anywhere
// Serial.print(", ");
// if(degree % 20 == 19) {Serial.println();}
}
}
//-------------------------------------------------------------------------------------------
void loop()
{
PIOB->PIO_SODR=1<<27; //trigger. Use 24nS
for(int ii=0; ii<20; ii++) {PIOD->PIO_ODSR = 0;} // Delay to show tre trigger on the scope.
PIOB->PIO_CODR=1<<27; //trigger. Use 24nS
for(int i=0; i<256; i++)
{
PIOD->PIO_ODSR = i; //Make linear ramp
}
for(int ii=0; ii<30; ii++) {PIOD->PIO_ODSR = Tab1[0]; } //Short hor. line before sinus
for(int ii=0; ii<360; ii++)
{
PIOD->PIO_ODSR = Tab1[ii]; // Make sinus
}
for(int ii=0; ii<4; ii++) {PIOD->PIO_ODSR = Tab1[SinDots-1]; } //Short hor. line after sinus
}

For an 8-bit DAC a R-2R ladder is certainly faster, although the Embedded DACs are 12-bit DACs.

The maximum speed you can expect from these DACs is 84MHz/2/25 = 1.68 MHz (for 2 conversions if you select both DAC0 and DAC1).

It is possible to use a 12-bit R-2R ladder, but the resistors has to better then 1 oo/o. And the output voltage tolerance from the outputpin is to bad.
In my case 8 bit is more then precise enough.

Even an 8bit R/2R ladder requires 1% (or closer to 0.5%) resistors. :frowning: Matching is probably more important than exact value, and "there are ways" to select a batch of resistors that match to better than their nominal specification...
(One easy way is probably to use "resistor networks" instead of individual resistors, like https://www.digikey.com/product-detail/en/bourns-inc/4610X-R2R-103LF/4610X-R2R-103LF-ND/3787967

Yes, the nominal resistance is'nt important.
My resistors are all SMD 1%.
Another important thing is the outputimpedance from the portpin.
I have measured it to be ~30 Ohm. It is in fact more then 1% of 2.2 kOhm, so the accuracy of my ladder is not good. But the speed is more important then the accuracy for my project.

I'm curious as to why you used 2k2 resistors and not values that have convenient doubles (eg 10k & 20k or 1k and 2k even) and save yourself a load of parts and work. The accuracy thing with modern components is no better if you use the same values or mix and match the convenient doubles.
If you lose the bet though and do actually get a 1% resistor value error then potentially the bottom two bits of your 8 become meaningless and would probably just make your sinewave look a bit fuzzy.
Thanks for sharing this as well. If I want to use the Due DACs this kind of information from you and the replies from others can be pure gold!

PE.

I used 2k2 because I have them and don't want to buy new.
I couldn't use DAC0 or DAC1 because I need the voltage to go to 0V, and because they are to slow.
And, as I say before, the speed are important, I has to make a sin^2 pulse with a width of 3.5uS.

You can see the pulses TACAN pulse 1

KG_DK:
I used 2k2 because I have them and don't want to buy new.
I couldn't use DAC0 or DAC1 because I need the voltage to go to 0V, and because they are to slow.
And, as I say before, the speed are important, I has to make a sin^2 pulse with a width of 3.5uS.

You can see the pulses TACAN pulse 1

I think you might have to buy new anyway. As you already know the 30 Ohm output resistance of the logic pins more than doubles the error of 1% tolerance of your resistors. Digikey carry the Panasonic ERJ series for US0.24c ea (one off) or 10 for U$2.04 which are 0.1% and 50ppm. Your signal also has some serious bandwidth requirements. Have you considered the capacitance of the resistor network and in particular the capacitance of the resistor pads? I'm wondering if the R-2R resistance is increased to reduce the impact of the output R of the logic pins will you have also created a low pass filter that will then have an impact on your band of interest?

To get 30 Ohm to be only 0.5% error (in R), R needs to be 6k. If you went the route of 0.1% resistors you'd need 60k which is pushing the envelope I would think. A single pad of a few pF and 60k has a -3dB around 1MHz so the whole network might be a problem with R in the order of 60k. I haven't crunched any numbers for the 6k range but I think you will have to be careful that your band of interest gets through it all ok.

I am also still making the assumption that the accuracy is an issue for you which may not be the case. If so, please ignore my ramblings. :wink:

PE

There has to be a LP-filter behind the 'DAC', and I suppose a 0.5Mhz bandwidth is OK.

The nominal width af the sin^2 pulse is 3.5uS and pulsespacing is 12uS.
I now has used 10k 1% in the ladder whitch with the inputcapitance of a PicoScope give pulse as seen on: TACAN pulse 1.