CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

MCP4922 D/A question

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
mike holeton
Guest







MCP4922 D/A question
PostPosted: Sat Mar 26, 2005 2:48 pm     Reply with quote

I am trying to us the MCP4922 (SPI mode) to communicate with a 16F876A. I was wondering if there are any drivers out there for this in C, not ASM.

Thanks

Mike
bluetooth



Joined: 08 Jan 2005
Posts: 74

View user's profile Send private message

PostPosted: Sat Mar 26, 2005 5:55 pm     Reply with quote

This chip is nice and simple, hardly needs a "driver".

All you need to do is:

Code:

// SPI MODE 0,0 is set up earlier

DAC_CS = 0; // Drop chip select
            
spi_write(dac_ms_byte);
spi_write(dac_ls_byte);
            
DAC_CS = 1; // Raise chip select


dac_ms_byte holds bits 15-8, dac_ls_byte holds bits 7-0. From the data sheet, you can decide how to fill them in. Basically, there are four configuration bits and 12 data bits. You can select the DAC you want to write to, whether or not you use the Vref buffer, set the Vref gain (handy!), and to put it in shutdown mode. It's important to set the Output Power Control Bit (SHDN) bit or you won't see any output.

From the data sheet:

Quote:

bit 15 A/B: DACA or DACB Select bit
1 = Write to DACB
0 = Write to DACA

bit 14 BUF: VREF Input Buffer Control bit
1 = Buffered
0 = Unbuffered

bit 13 GA: Output Gain Select bit
1 = 1x (VOUT = VREF * D/4096)
0 = 2x (VOUT = 2 * VREF * D/4096)

bit 12 SHDN: Output Power Down Control bit
1 = Output Power Down Control bit
0 = Output buffer disabled, Output is high impedance

bit 11-0 D11:D0: DAC Data bits
12 bit number “D” which sets the output value. Contains a value between 0 and 4095.


Have used this part - works well.

Hope this helps....
mike holeton
Guest







PostPosted: Sat Mar 26, 2005 7:57 pm     Reply with quote

Thank You.

I obviously have not used the chip before and getting some basic input is always welcome. I will be ussing the chip for 0-5 volt sensor output.

Thanks again
Mike
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group