Page 1 of 1

MCP4921 DAC SPI Help Please

Posted: Fri Jul 29, 2011 4:04 pm
by Jordy101091
Hi all,

I need to control this particular part MCP4921 DAC from Microchip.
It uses the SPI protocol.

I have read the datasheet many times to find out what im missing but cant find it.
The datasheet tells me to do as follow:

drive the CS pin Low
send the config bytes and the 12 data bits into the SDI pin on the rising edge of SCK.
CS pin is raised
The LDAC pin is Low all times, because the data is fet directly into the output register.

I also have checked the SPI component settings to be correct and they are (I think)

Hope you can help me.

Thanks,

Jordy

PS the datasheet: http://ww1.microchip.com/downloads/en/D ... 22248a.pdf

Re: MCP4921 DAC SPI Help Please

Posted: Fri Jul 29, 2011 9:51 pm
by Jordy101091
HI, All

I have checked all my connections to and from the device (MCP4921).
I checked the timing diagram from the datasheet and all looks to be correct.

I have changed my flowcode a little because of the Pin LDAC.

Image

Send Upper Half:

0b00101111 (First 4 bytes are config bytes, others are data bytes)

Send Lower Half:

0b11111111

I dont know what im doing wrong here hopefully somebody can figure it out.

Regards Jordy

Re: MCP4921 DAC SPI Help Please

Posted: Sun Jul 31, 2011 7:14 pm
by BChappy
Hello Jordy,

One of the first things I notice is Bit 12. This is SHDN 1 = Output / 0 = No output.

"Send Upper Half:

0b00101111 (First 4 bytes are config bytes, others are data bytes)"

So config. 0b0011xxxx (with BUF/buffer 0b0111xxxx)

Clock settings. The clock I have from your download is set to 19660800MHz. This should be set to the xtal you are using.
My own recommendation for LDAC is to connect it to OV. / ground unless you need to synchronise the output with other functions.

I haven't used the 16F877 for a while so I am not sure of the set up.

(The MCP4921 single, /MCP4922 dual, was the first SPI device I used!)

I hope this helps!

Best regards

Brian

Re: MCP4921 DAC SPI Help Please

Posted: Sun Jul 31, 2011 10:37 pm
by Jordy101091
O man,

You are the best, thanks. I didnt read the datasheet that carefull.
Thanks for youre reply.

Regards Jordy

Re: MCP4921 DAC SPI Help Please

Posted: Sun Jul 31, 2011 11:14 pm
by Jordy101091
This thay I have made some progress on my flowcode program.

The intention of this program is to set the output voltage of my dac using up and down buttons.
up/down steps are 0.1 Volts.

I'm using a integer at starting point from 10 with incremants of 1 (11,12,13,...150) witch then been converterd to a string variable and split in left and right with a decimal point.
So you will get something like this:

(1.0, 1.1, 1.2, 1.3,... 15.0)

Thats only visual.
now comes the tricky part as I think it is good?

I multiply this value (11,12,13,...150) by a 1000
The I will preform a calculation to make 2 8bit words from that integer.
As this information needs to be 16bit.

The calculation goes like this:

Vset_setpoint_DAC = Vset_setpoint * 100
DAC_DATA_lowByte = Vset_setpoint_DAC AND 0xFF
DAC_DATA_HighByte = (Vset_setpoint_DAC >> 8 ) AND 0xFF

There are 2 problems I need to deal with:

1. I need to send the config bits first So that the are located in the DAC_DATA_HighByte. It will look something like this:

16Bit 0b0111xxxx|xxxxxxxx

2. As I prefrom my calculations, the data that i'm sending to the DAC for example 1100 (witch would be 1.1V)
Does not match the value on the display.

Integer = 1100
HighByte = 42
LowByte = 248

From the Datasheet:

Vout = Vref * (Data/4096)
Vout = 5.04 * (1100/4096)
Vout = 1.35V

Witch is an error of 0.25V How can I fix this.
(after some calculations I figured out to use a Vref of 4.096V)

Or is there an other way?

Hope you can help me out.

Regards Jordy

Re: MCP4921 DAC SPI Help Please

Posted: Mon Aug 01, 2011 6:48 pm
by Jordy101091
Hi all,

I have figured out on how to get the config bits first in the MSB byte.
Vset_setpoint_DAC = Vset_setpoint * 100
DAC_DATA_lowByte = Vset_setpoint_DAC AND 0xFF
DAC_DATA_HighByte = (Vset_setpoint_DAC >> 8 ) AND 0xFF
As you can see this is the formule that I have used to make 2 8bit words, but without the config bits.
So what I have done is as follow

added this calculation in: DAC_DATA_highByte = DAC_DATA_highByte OR (0b0111 << 4)

After this calculation I have my config bits always first.

Thanks anyway.

Regards Jordy