Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

dsPIC30f4011 with MCP4922 DAC problem

Status
Not open for further replies.

bassplayer142

Newbie level 5
Joined
May 28, 2006
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,350
I am trying to connect this digital to analog converter to the micro-controller with a small issue. First off, I the MCP4922 has 2 seperate 12 bit channels and the first one I send data to works while the other way stays near 0 volts. I have played with the CKE and CKP values which change whether the clock is active low or high and where on the clock pulse but I can't get the second one to register. I find it strange because if I put a msdelay between sending the first d-2-a (temp1 and temp2) then both don't work. I'm near positive that this is just some kind of timing issue. Any help is appreciated greatly and thanks in advance.

**broken link removed**

Code:
 void initspi(void){        //initialize spi interface
 SPI1STAT = 0x0000;
 SPI1CON  = 0x0038;
 SPI1CONbits.CKE = 0;    //top or bottom clock
 SPI1CONbits.CKP = 0;
 SPI1CONbits.SMP = 0;
 
 SPI1STATbits.SPIEN = 1;        //enable
 CSDAC = 1;
 LDAC = 1;
 msdelay(10);
 }
 
 void updatedac(unsigned int fir, unsigned int sec){
 unsigned char temp1,temp2,temp3,temp4 = 0;
 
 temp1 = (fir >> 8)&0x0F;       
 temp1 = 0x30 | temp1;        
 temp2 = (char)fir;
 
 temp3 = (sec >> 8)&0x0F;       
 temp3 = 0xB0 | temp3;
 temp4 = (char)sec;
 
 CSDAC = 0;
 sendspi(temp1);
 sendspi(temp2);
 CSDAC = 1;
 
 CSDAC = 0;
 sendspi(temp3);
 sendspi(temp4);
 CSDAC = 1;
 LDAC = 0;
 LDAC = 1;
 
 }
 void main(void){
     initspi();
     TRISF = 0x00;
     msdelay(10);
         k2 = 2000;
         while(1){
         k+= 10;
         k2+=10;
         updatedac(k,k2);
         if (k > 4095) k = 0;
         if (k2 > 4095) k2 = 0;
         }
 }
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top