(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

maharadga
Posts: 56
Joined: Mon Dec 01, 2014 1:38 pm
Location: Bulgaria
Has thanked: 12 times
Been thanked: 11 times
Contact:

(Solved) Atmega16_MCP4922 problem

Postby maharadga » Tue Jun 12, 2018 4:42 pm

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 3 times
Proteus_Atmega16_MCP4922.rar
(17.49 KiB) Downloaded 1 time
Atmega_16_MCP4922.fcfx
(22.67 KiB) Downloaded 2 times
Last edited by maharadga on Sat Jun 16, 2018 5:00 pm, edited 1 time in total.

User avatar
Benj
Matrix Staff
Posts: 12847
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 3637 times
Been thanked: 3499 times
Contact:

Re: Atmega16_MCP4922 problem

Postby Benj » Wed Jun 13, 2018 10:31 am

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.
These users thanked the author Benj for the post:
maharadga (Sun Jun 17, 2018 6:11 am)
Rating: 5.88%
 

maharadga
Posts: 56
Joined: Mon Dec 01, 2014 1:38 pm
Location: Bulgaria
Has thanked: 12 times
Been thanked: 11 times
Contact:

Re: Atmega16_MCP4922 problem

Postby maharadga » Wed Jun 13, 2018 4:33 pm

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: 12847
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 3637 times
Been thanked: 3499 times
Contact:

Re: Atmega16_MCP4922 problem

Postby Benj » Wed Jun 13, 2018 4:41 pm

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

maharadga
Posts: 56
Joined: Mon Dec 01, 2014 1:38 pm
Location: Bulgaria
Has thanked: 12 times
Been thanked: 11 times
Contact:

Re: Atmega16_MCP4922 problem

Postby maharadga » Thu Jun 14, 2018 5:16 am

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

maharadga
Posts: 56
Joined: Mon Dec 01, 2014 1:38 pm
Location: Bulgaria
Has thanked: 12 times
Been thanked: 11 times
Contact:

Re: Atmega16_MCP4922 problem

Postby maharadga » Sat Jun 16, 2018 4:59 pm

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) Not downloaded yet
These users thanked the author maharadga for the post:
Benj (Sat Jun 16, 2018 8:40 pm)
Rating: 5.88%