Go Down

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

thejoker-1s

Jul 25, 2016, 01:06 pm Last 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 arduino
v_pin = 'A0';
value = 1;
dac = i2cdev(a,'0x62');                              % Connect to mcp4725 using I2C protocol
write(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

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

Thank you for your quick reply, I greatly appreciate it.

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

Since this appears to be strictly a Matlab issue, you would be better off asking the Matlab community for help.

thejoker-1s

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.

Thanks for your suggestion though.

ieee488

#5
Jul 25, 2016, 04:21 pm Last 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.

Thanks for your suggestion though.
You are wrong.

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

Use your brain for thinking.   :smiley-roll:



PaulS

Quote
Matlab is software on my computer and I am having issues with the communication/interface-aspect.
Fine. So, post your Arduino code and we'll help you with that part of it.

thejoker-1s

Fine. So, post your Arduino code and we'll help you with that part of it.
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

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.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy