Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Can I use the PIC 18F2550 with a DAC 12bits (MCP4822)

Status
Not open for further replies.

macmmt

New Member
Hello,

I found a circuit that sends data from pic dsPIC30f2012 (that pic has a resolution of 16 bits) to a DAC 12 bits (MCP4822) . My question is if I can use the SPI Module of a pic 18f2550 of 8 bits to send data to the DAC 12 bits. Can I do that or I just have to have the other PIC.


Thanks for your help.
 
Hello,

I found a circuit that sends data from pic dsPIC30f2012 (that pic has a resolution of 16 bits) to a DAC 12 bits (MCP4822) . My question is if I can use the SPI Module of a pic 18f2550 of 8 bits to send data to the DAC 12 bits. Can I do that or I just have to have the other PIC.


Thanks for your help.

You send the data in 2 8bit words.

Code:
REGISTER 5-1:    WRITE COMMAND REGISTER FOR MCP4822 (12-BIT DAC)
  W-x   W-x W-x  W-0  W-x W-x W-x  W-x  W-x  W-x W-x    W-x  W-x W-x W-x W-x
        —   GA  SHDN  D11 D10 D9   D8   D7   D6   D5    D4    D3 D2  D1  D0
  A/B
 bit 15                                                                  bit 0
REGISTER 5-2:   WRITE COMMAND REGISTER FOR MCP4812 (10-BIT DAC)
  W-x   W-x W-x  W-0  W-x W-x W-x  W-x  W-x  W-x W-x    W-x  W-x W-x W-x W-x
  A/B   —   GA  SHDN  D9  D8  D7   D6   D5   D4   D3    D2    D1 D0   x   x
 bit 15                                                                  bit 0
REGISTER 5-3:   WRITE COMMAND REGISTER FOR MCP4802 (8-BIT DAC)
  W-x   W-x W-x  W-0  W-x W-x W-x  W-x  W-x  W-x W-x    W-x  W-x W-x W-x W-x
        —   GA  SHDN  D7  D6  D5   D4   D3   D2   D1    D0     x  x   x   x
  A/B
 bit 15

https://www.electro-tech-online.com/custompdfs/2010/05/22249A.pdf
 
Thanks for your reply. As far as I know, the SPI Module of the PIC 16F877A can just send one 8bit word per time. How would you send two words of 8 bits together?

Thanks.
 
Thanks for your reply. As far as I know, the SPI Module of the PIC 16F877A can just send one 8bit word per time. How would you send two words of 8 bits together?

Thanks.

16 bits register, send the high 8 bits first, low 8 bits second (or whatever way the device wants).

Code:
unsigned char CMD[2],ctrl; // bits 7-4 control bits in ctrl
unsigned int data; // 12 bit data
/* set ctrl config bits */
CMD[0] = (unsigned char) (((data & 0x0F00) >> 8)|ctrl);
CMD[1] = (unsigned char) (data & 0x00F0); // lose the last four bits for 8 bit ADC

You could also use pointers.
 
Last edited:
The MCP4822 does not use dual byte mode so above mentioned suggestion will not work. When you send to the MCP4822 simply truncate the 4 LSB's. In other words, send 12 bits ignoring the last 4 LSB.
 
Thanks Mikebits,

I need to send the 16 bits, the one of 4 bits of control will allow me to select OutA or OutB. The question is how would u send the 16 bits. The SPI module wont work since it just have 8 bits. Could u explain how would the PIC C code be?
 
The MCP4822 does not use dual byte mode so above mentioned suggestion will not work. When you send to the MCP4822 simply truncate the 4 LSB's. In other words, send 12 bits ignoring the last 4 LSB.

My bad, It takes 16 bit transfers.
Fixed above code.
 
Last edited:
Thanks Mikebits,

I need to send the 16 bits, the one of 4 bits of control will allow me to select OutA or OutB. The question is how would u send the 16 bits. The SPI module wont work since it just have 8 bits. Could u explain how would the PIC C code be?

Assert the chip Enable.
put byte 1 in the SSP register.
wait for the byte to leave.
put byte 2 in the SSP register.
wait for the byte to leave.
De-assert the Chip Enable.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top