Go Down

### Topic: Matlab MCP4725 I2C communication problem (Read 884 times)previous topic - next topic

#### thejoker-1s

##### Jul 25, 2016, 01:06 pmLast Edit: Jul 25, 2016, 01:14 pm by thejoker-1s Reason: changed code slightly
Hi,

I purchased the MC4725 Digital-to-Analog-Converter (datasheet over here) to get my arduino Mega 2560 to output an analog voltage.

The MCP 4725 has a 12-bit digital to analog converter, so I figured that the resolution is high and precise. Right now I tell the MCP 4725 to output a certain voltage by using the following code:

Code: [Select]
`a = arduino('com3','Mega2560');        % Connect to arduinov_pin = 'A0';value = 1;dac = i2cdev(a,'0x62');                              % Connect to mcp4725 using I2C protocolwrite(dac,value,'uint16') readVoltage(a, v_pin)`

My problem is that 'value' has to be an integer in the range of 0 ~ 15. This means that my voltage output is discrete, starts at 0 [V] and 'jumps' by roughly 0.29 [V] per integer increase.

Does anybody know how to communicate to the MCP 4725 such that I can give it a 12-bit string which is then converted to a voltage? I want to have a higher resolution and be able to control the voltage on the order of [mV]'s.

Kind regards

#### PaulS

#1
##### Jul 25, 2016, 01:14 pm
Quote
Right now I tell the MCP 4725 to output a certain voltage by using the following code:
That code will NOT work on an Arduino.

Matlab can NOT directly tell the MCP4725 to output a voltage. It must tell the Arduino to tell the MCP4725 to output a voltage.

So, what code IS running on the Arduino?

Quote
I can give it a 12-bit string
A 12 bit value and a string are two completely different things. A 12 bit string does not make sense.

Quote
My problem is that 'value' has to be an integer in the range of 0 ~ 15.
Why?

#### thejoker-1s

#2
##### Jul 25, 2016, 01:25 pm

That code will NOT work on an Arduino.

Matlab can NOT directly tell the MCP4725 to output a voltage. It must tell the Arduino to tell the MCP4725 to output a voltage.

So, what code IS running on the Arduino?
I have no idea what code is running on the Arduino; I am using the arduino-matlab-support-package (webpage over here) to communicate to my arduino and DAC. The matlab doc page (see here) has a few commands/functions which can be called but the help page is not very informative on which kind of data types can/must be used.

A 12 bit value and a string are two completely different things. A 12 bit string does not make sense
I guess I used the wrong terminology here, I mean a 12-bit value (examples: 000000000001, or 111111111111)
Why?
I honestly have no idea but I suppose it has something to do with the 'uint16' setting.

All in all my question is: how can I use matlab to communicate with the MCP 4725 in such a way that the output voltage can be controlled precisely.

#### PaulS

#3
##### Jul 25, 2016, 01:57 pm
Since this appears to be strictly a Matlab issue, you would be better off asking the Matlab community for help.

#### thejoker-1s

#4
##### Jul 25, 2016, 02:35 pm
Since this appears to be strictly a Matlab issue, you would be better off asking the Matlab community for help.
I will try that as well, but I disagree with you that it is strictly a Matlab issue.
This forum is intended for 'interfacing with software on the computer'. Matlab is software on my computer and I am having issues with the communication/interface-aspect.

#### ieee488

#5
##### Jul 25, 2016, 04:21 pmLast Edit: Jul 25, 2016, 04:21 pm by ieee488
I will try that as well, but I disagree with you that it is strictly a Matlab issue.
This forum is intended for 'interfacing with software on the computer'. Matlab is software on my computer and I am having issues with the communication/interface-aspect.

You are wrong.

This forum is intended for interfacing with software on a computer as it relates to the Arduino.

#### PaulS

#6
##### Jul 25, 2016, 04:29 pm
Quote
Matlab is software on my computer and I am having issues with the communication/interface-aspect.

#### thejoker-1s

#7
##### Jul 25, 2016, 05:21 pm
As I have stated before, I am using the matlab-arduino-support-package and therefore I code with matlab. No arduino code I am afraid.

So, can you help me with the matlab-arduino-interfacing problem, or do you insist that I use arduino code and delete the matlab-arduino-support-package?

#### PaulS

#8
##### Jul 25, 2016, 05:46 pm
Quote
So, can you help me with the matlab-arduino-interfacing problem, or do you insist that I use arduino code and delete the matlab-arduino-support-package?
I don't insist on anything. Well code tags, but that's all.

There is a community dedicated to the matlab program you are using. It seems logical to ask them for help, when you have NO control over what the Arduino is doing.

The write documentation does bear reading, though - especially the part about precision.