PDA

View Full Version : MCP4922 Dual DAC



J_Brittian
- 21st October 2005, 19:15
I've been trying to talk with a MCP4922 chip using the 16f877. I basically just modified code that I know works for an LTC1257. In addition to the code posted below I have the LDAC pin grounded and the SHDN pin tied to 5V. Right now I'm just trying to get this chip to work at all. I would expect output B to step up to 5V, drop to zero and start all over. I can watch the variable value change on the LCD screen but I get no output from the DAC.
Suggestions??

Define OSC 4

ADCON1 = %10001100 ' Make PORTA and PORTE digital
TrisC = %11101000
' Define LCD connections
Define LCD_DREG PORTD
Define LCD_DBIT 4
Define LCD_RSREG PORTE
Define LCD_RSBIT 0
Define LCD_EREG PORTE
Define LCD_EBIT 1

HighVref var word
alldata var portc.5
daccs var portc.6
clk var portc.3

PAUSE 100
HighVref = 0

main:
pause 100
Lcdout $fe, 1, "HIGHVREF: ", dec HighVref
HighVref = HighVref + 1
PAUSE 100

'___DAC output__________
DAC1out:
low alldata
Low DACCS ' Enable the mcp4922
Shiftout alldata,CLK,1,[%1011\4, HighVref\12]' Shift out the 16-bit word
High DACCS ' Now disable the chip
Goto main

J_Brittian
- 24th October 2005, 14:17
The two things most likely to be wrong are the wiring to the chip and the configuration bits in the Shiftout command. The first four bits tell the DAC which output to use, if the Dac's Vref should be buffered or unbuffered, set the gain to x1 or x2, and enable/disable the output.

(Datasheet pg. 18)
I'm definitely trying to use output B. So the first bit should be 1.

I can't see why I care about the buffering on Vref. I have Vref connected to Vdd right now. My 2nd bit is 0.

I'm going for a x1 gain making the 3rd bit 1.

This last bit could be a problem, but I've changed it with no effect. It's the Output Power Down Control Bit. 1 = Output Power Down Control Bit. 0 = Output Buffer Disabled, Output is High Impedance. I have this bit set to 1.

So if I've done this right my configuration should be 1011. Did I format the Shiftout command right? Is there a better way to format the command?

As for the wiring:
pins 1 = Vdd = 5V
2 = NC = no connection
3 = CS = portc.6
4 = CLK = portc.3
5 = SDI = portc.5
6 = NC
7 = NC
8 = LDAC "If desired this input can be tied low to reduce the required connections from 4 to 3."(pg. 20) = GND
9 = SHDN This could also be a problem. "The device will remain in shutdown mode until the SHDN pin is brought high and a write command with SHDN = 1 is latched."(pg. 20) = 5V
10 = VoutB =
11 = VrefB = 5V
12 = AVss = GND
13 = VrefA = 5V
14 = VoutA =

If anyone needs more information I will be more than happy to provide. Is there some reason I can't use portc?

http://ww1.microchip.com/downloads/en/DeviceDoc/21897a.pdf
(link to datasheet)

dmairspotter
- 24th October 2005, 15:02
Try mode 5?

DEFINE SHIFT_PAUSEUS xx?

J_Brittian
- 24th October 2005, 16:23
Originally I used mode 5 because that was the way my code ran for the 1257 DAC. I took another look at the MCP4922 datasheet though and on pg. 19 it shows the clock idles low and somewhere I think I read that the data gets latched on a low to high clock pulse. What would DEFINE SHIFT_PAUSEUS xx do ? I'm more concerned about the way I tacked the configuration bits on to the front of my variable. I have to send the DAC 16 bits. The first four are the configuration bits the next twelve bits are the output. Should I add/or a 16 bit configuration value with my output variable and then only Shiftout a single 16 bit number? Or should it work the way I've got it?

dmairspotter
- 24th October 2005, 17:36
DEFINE SHIFT_PAUSEUS xx where xx is some number will slow down the SDI transmission. Looking at the data sheet, it shouldn't be necessary but maybe worth a try? No harm in trying to make up one 16 bit word for transmission either, maybe that would help.

Like I said, I'm pretty new to PICs but I've found if I thrash around and change enough stuff I can mostly get stuff to work....mostly.

As far as I can see, your connections and logic look good. Sorry I can't find you a magic bullet.

J_Brittian
- 24th October 2005, 21:58
I tried DEFINE SHIFT_PAUSEUS 100. Still no output.

I used a logic probe to verify activity on the serial and clock pins. I can watch the CS pin go low. Activity on the LCD screen verifies the program is running. The PIC seems to be doing what it's supposed to. I changed the Shiftout command to:

Shiftout alldata,CLK,1,[%1111111111111111\16]' Shift out the 16-bit word

This should output 5V on output B.
Still no output.

The differences between this chip and the LTC1257 are: Configuration bits, hardware and program shutdowns, LDAC signal. I think I've addressed all of these. Using essentially the same code as below, just without configuration bits, I verified the PIC16F877 I'm using will drive the LTC1257. I've exhausted all my ideas for now. Any thoughts at all are welcome.

Ruben Pena
- 24th October 2005, 22:50
J.Britain:
Do you can live with 8 bits.?
Last week I tried the MAX520, with 4 DAC channels.
It uses I2C and worked in the first try. It is more expensive than the
Microchip part,but with 4 channels. I got them at Digikey.
I hope this helps...
Greetings...
Ruben de la Pena

J_Brittian
- 25th October 2005, 00:47
Ruben,
You want me to give up? I have ten of things sitting on my desk.

-Josh

arniepj
- 25th October 2005, 12:45
I have had problem with the shiftin/shiftout commands depending on the device being used.The clock pulses are too fast and using the define shift_pauseus doesn't seem to help.Writing your own works best as you can control the clock pulses.This example sends out the control bits,then reads in the data bits.


DataAcquisition:
for Indexer = 12 to 0 step -1 ' Output data,13 clock pulses
portc.2 = SerialDataOut.0[Indexer] ' Output data port
gosub Clockout ' Output clock pulse
next Indexer ' Next data bit,next clock pulse
for Indexer = 1 to 12 ' Read data,12 clock pulses
SerialDataIn = SerialDataIn * 2 ' Shift each bit to the left
SerialDataIn = SerialDataIn + portc.3 ' Data in port
gosub Clockout ' Output clock pulse
next Indexer ' Next data bit,next clock pulse
Clockout: ' Clock pulse
pulsout portc.0,5 ' Clock pulse port, 1 msec
return

J_Brittian
- 25th October 2005, 18:39
Thank you, I replaced my Shiftout command with your For....Next Loop example and everything works great.