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
MCP4921 DAC SPI Help Please
Moderator: Benj
- Jordy101091
- Posts: 519
- Joined: Sat Jan 08, 2011 4:02 pm
- Location: The Netherlands
- Has thanked: 25 times
- Been thanked: 188 times
- Contact:
MCP4921 DAC SPI Help Please
- Attachments
-
- Digital Power Supply v1.fcf
- (5 KiB) Downloaded 299 times
the will to learn, should not be stopped by any price
- Jordy101091
- Posts: 519
- Joined: Sat Jan 08, 2011 4:02 pm
- Location: The Netherlands
- Has thanked: 25 times
- Been thanked: 188 times
- Contact:
Re: MCP4921 DAC SPI Help Please
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.

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
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.

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
- Attachments
-
- Digital Power Supply v1.fcf
- edited file
- (5 KiB) Downloaded 342 times
the will to learn, should not be stopped by any price
- BChappy
- Posts: 15
- Joined: Fri Jun 19, 2009 11:03 pm
- Location: Lincoln, UK.
- Has thanked: 13 times
- Been thanked: 7 times
Re: MCP4921 DAC SPI Help Please
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
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
Is your Project Not Working? - Help and General Advice Click here!
Flowcode v8 forum topic - Click here!
Flowcode v8 forum topic - Click here!
- Jordy101091
- Posts: 519
- Joined: Sat Jan 08, 2011 4:02 pm
- Location: The Netherlands
- Has thanked: 25 times
- Been thanked: 188 times
- Contact:
Re: MCP4921 DAC SPI Help Please
O man,
You are the best, thanks. I didnt read the datasheet that carefull.
Thanks for youre reply.
Regards Jordy
You are the best, thanks. I didnt read the datasheet that carefull.
Thanks for youre reply.
Regards Jordy
the will to learn, should not be stopped by any price
- Jordy101091
- Posts: 519
- Joined: Sat Jan 08, 2011 4:02 pm
- Location: The Netherlands
- Has thanked: 25 times
- Been thanked: 188 times
- Contact:
Re: MCP4921 DAC SPI Help Please
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
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
- Attachments
-
- Digital Power Supply v1.fcf
- (18.8 KiB) Downloaded 308 times
the will to learn, should not be stopped by any price
- Jordy101091
- Posts: 519
- Joined: Sat Jan 08, 2011 4:02 pm
- Location: The Netherlands
- Has thanked: 25 times
- Been thanked: 188 times
- Contact:
Re: MCP4921 DAC SPI Help Please
Hi all,
I have figured out on how to get the config bits first in the MSB byte.
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
I have figured out on how to get the config bits first in the MSB byte.
As you can see this is the formule that I have used to make 2 8bit words, but without the config bits.Vset_setpoint_DAC = Vset_setpoint * 100
DAC_DATA_lowByte = Vset_setpoint_DAC AND 0xFF
DAC_DATA_HighByte = (Vset_setpoint_DAC >> 8 ) AND 0xFF
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
the will to learn, should not be stopped by any price