(Solved) Atmega16_MCP4922 problem

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
maharadga
Posts: 71
Joined: Mon Dec 01, 2014 1:38 pm
Location: Bulgaria
Contact:

(Solved) Atmega16_MCP4922 problem

Post 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.
Attachments
MCP4922.pdf
(3.62 MiB) Downloaded 72 times
Proteus_Atmega16_MCP4922.rar
(17.49 KiB) Downloaded 77 times
Atmega_16_MCP4922.fcfx
(22.67 KiB) Downloaded 66 times
Last edited by maharadga on Sat Jun 16, 2018 5:00 pm, edited 1 time in total.

User avatar
Benj
Matrix Staff
Posts: 15009
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Contact:

Re: Atmega16_MCP4922 problem

Post 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.

maharadga
Posts: 71
Joined: Mon Dec 01, 2014 1:38 pm
Location: Bulgaria
Contact:

Re: Atmega16_MCP4922 problem

Post by maharadga »

Hello, Benj.
I found out about the connections.
I add brackets, like you say, but result is the same.

User avatar
Benj
Matrix Staff
Posts: 15009
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Contact:

Re: Atmega16_MCP4922 problem

Post by Benj »

Have you wired up the external Latch pin and Enable pin?

maharadga
Posts: 71
Joined: Mon Dec 01, 2014 1:38 pm
Location: Bulgaria
Contact:

Re: Atmega16_MCP4922 problem

Post by maharadga »

Yes, LDAC pin is connected to GND. Output registers are updated immediately.

maharadga
Posts: 71
Joined: Mon Dec 01, 2014 1:38 pm
Location: Bulgaria
Contact:

Re: Atmega16_MCP4922 problem

Post by maharadga »

I changed in Properties "Clock polarity" to Idle High and problem was resolved.
This work in real chip.
Have a nice day.
Attachments
Atmega_16_MCP4922.fcfx
(20.34 KiB) Downloaded 76 times

Post Reply