[SOLVED]8bit DAC

Hello,
i'm using R-R2 ladder to make 8bit DAC, using this schematic:

Since on mega8/168/328p/etc... PB6 and PB7 is used for crystal, free ports are from PB0..PB5 and PC0..PC5.
So i'm using the first 6 bits on PB0-5 and last two bits - PC5 and PC4.

And to get outputs from it using bitwise operators(value is 0-255 byte):

PORTB = (PORTB & 0xC0) | ((value & 0xFC) >> 2);
PORTC = (PORTC & 0x0F) | ((value & 0x03) << 4);

Tested via serial, i'm getting the right bits, however, testing with multimeter on output (Vout in sch) voltage drops from 0V to 4V for like 1V:

if value is 0, output is 0V, if value is 5, output is 1V, if value is 20, output is 4V, if value is 25, output goes again to 0V or 1V and this goes till value is 255.

Since i tested it via serial, it could be wiring problem...? Dunno... Or i missing somewhere else maybe?

P.S i know, there is PORTD available, but actually i need 2x 8bit DAC's, and yes, im already using one on PORTD.

I've never used the port commands.

It should be easy enough to check the digital output pins with your voltmeter to get the actual binary output. And that's most easily done with a "walking ones" test. i.e. Write the following binary sequence:

0000 0001 (decimal 1)
0000 0010 (decimal 2)
0000 0100 (decimal 4)... etc.

That should help to diagnose the problem.

Since you are not really using the ports B & C as 8-bit ports, I'd suggest using the bitRead() command to get the bit values from your DAC variable and digitalWrite() to write one pin at a time.

Yeah, it was wiring problem. Had to attach LED's and check between two DAC's, using same value for both.