Page 1 of 1

(Solved) Atmega16_MCP4922 problem

Posted: Tue Jun 12, 2018 4:42 pm
by maharadga
Hello.
I have problem with SPI. Maybe mistake is my, maybe it's a bug.
I want produced DAC volt and DAC current with MCP4922. It's a 2 channel SPI DAC from Microchip.
But I found something strange.

Vol toutput is 2,5V and Current output is 0V with dac_Volt and dac_Current = 0.

With dac_Current I can adjust only Volt Output.
If I decrease dac_Current by one, output Volt is jump to 5V. If increase dac_Current, output is increase too.

With dac_Volt can't adjust anything.

I connect PIC MOSI with MOSI on MCP4922. Otherwise I lost comunication. And should not I connect MISO with MOSI and vice versa? Same problem with connection exist and with MCP3202.
This is real design.
I post Flowcode project, datasheet MCP4922 and Proteus project.

Re: Atmega16_MCP4922 problem

Posted: Wed Jun 13, 2018 10:31 am
by Benj
Hello,
I connect PIC MOSI with MOSI on MCP4922.
MOSI should go to MOSI and MISO should go to MISO.

MOSI = Master Out (SDO) Slave In (SDI)
MISO = Master In (SDI) Slave Out (SDO)

So the cross connection is done for you using the MOSI / MISO naming convention.

Looks like you are very close to a solution. This line of code may be the problem.

Code: Select all

send_Volt = dac_Volt | 0x7 << 12
Try adding brackets to ensure the maths is correct.

Code: Select all

send_Volt = dac_Volt | (0x7 << 12)
Same for the Current channel.

Let us know how you get on.

Re: Atmega16_MCP4922 problem

Posted: Wed Jun 13, 2018 4:33 pm
by maharadga
Hello, Benj.
I found out about the connections.
I add brackets, like you say, but result is the same.

Re: Atmega16_MCP4922 problem

Posted: Wed Jun 13, 2018 4:41 pm
by Benj
Have you wired up the external Latch pin and Enable pin?

Re: Atmega16_MCP4922 problem

Posted: Thu Jun 14, 2018 5:16 am
by maharadga
Yes, LDAC pin is connected to GND. Output registers are updated immediately.

Re: Atmega16_MCP4922 problem

Posted: Sat Jun 16, 2018 4:59 pm
by maharadga
I changed in Properties "Clock polarity" to Idle High and problem was resolved.
This work in real chip.
Have a nice day.