Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] problem with coding 123

Status
Not open for further replies.

marrc

Junior Member level 2
Joined
Mar 1, 2017
Messages
23
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Location
india
Activity points
219
hi guys!

i recently purchased dac mcp 4725 and just tried connecting it to arduino

so i am giving 0-5 v at A0 pin of arduino
problem is Mcp4725 is always op 2v only irrespective of voltage at A0 pin

i think its a coding error

my code is as follows:
# include<Wire.h>
# define MCP4725 0x61 //MCP4725 address as 0x61 Change yours accordingly

unsigned int c;
byte buffer[3];

void setup() {
// put your setup code here, to run once:
Wire.begin();
Serial.begin(9600);
}

void loop() {
// put your main code here, to run repeatedly:

c= analogRead(A0)*4; // 0-1023 convert to 0-4096 ie 10 bits to 12 bits
Serial.println(c);
buffer[0]= 0b01000000;
buffer[1]= c>>4; // sending msb values
Serial.println(buffer[1]);
buffer[2]= c<<4; // sending lsb values
Wire.beginTransmission(MCP4725); //Joins I2C bus with MCP4725 with 0x61 address

Wire.write(buffer[0]); //Sends the control byte to I2C
Wire.write(buffer[1]); //Sends the MSB to I2C
Wire.write(buffer[2]); //Sends the LSB to I2C

Wire.endTransmission(); //Ends the transmission

}

A0 pin is connected to center of pot and its other 2 ends to 5v and gnd
A4 to SDA
A5 to SCL
Gnds of arduino and DAc tied

if u need any other info please ping me

cheers,
marrc
 

Hi,

I don´t think that 0x61 is the correct device address. How did you decide it?

The wiring is unclear. Draw a sketch.

Klaus

Added:
buffer[1]= c>>4
buffer[2]= c<<4;
Also this is not right... at least I think so.
Please take a sheet of paper and verify if this is correct.

And check datasheet Figure 6-1 ... is this what you try to do?

Klaus
 

... and what is the point in multiplying the result by 4? It is still a 10-bit value with zeroes at the end. It may be stored with extra bits but the precision isn't increased to 12-bits.

Brian.
 

Hi,

and what is the point in multiplying the result by 4?
to adjust to DAC digital input range --> and thus it´s analog output range to full scale...

Klaus
 

I understand that Klaus but it doesn't increase 10 bits to 12 bits, it just multiplies the result by 4, the LSB will always be zero. The ADC is still 10 bits.
Some Arduino device can use 12-bit resolution natively but I think they require some register configuration.

Brian.
 

Hi,

I don´t think that 0x61 is the correct device address. How did you decide it?

The wiring is unclear. Draw a sketch.

Klaus

Added:


Also this is not right... at least I think so.
Please take a sheet of paper and verify if this is correct.

And check datasheet Figure 6-1 ... is this what you try to do?

Klaus

Hello Klaus!

I am a newbie to arduino and am just trying to check if my recently purchased mcp4725 is working fine.

i thought that a simple way to do that would be to read an analog voltage to arduino and make it convert it to digital form and send it to the dac. the dac would then convert it bak to analog form. this way we can also check accuracy of dac!

i got the idea and built the circuit/code from here : https://circuitdigest.com/microcontroller-projects/arduino-dac-tutorial-interfacing-mcp4725-dac

the only connections on my arduino are on A0, A4 and A5 which are connected to centre of Pot ,SDA on dac and SCL on dac respectively.
rest is software.

further inputs from you experienced guys will be greatly appreciated.

cheers,
Marrc
 

Hi,

I am a newbie to arduino and am just trying to check if my recently purchased mcp4725 is working fine.

i thought that a simple way to do that would be to read an analog voltage to arduino and make it convert it to digital form and send it to the dac. the dac would then convert it bak to analog form.
There's nothing wrong with it.

this way we can also check accuracy of dac!
No. This is a more complicated way to check if it operates....but it's no way to check accuracy, because the error (inaccuracy) of your analog value as well as the error of your ADC will be higher than the error of the DAC.

A more simple way is to send a known digital value to the DAC. This digital value also does not have any errors (analog value, ADC) and thus it's more suitable to check DAC accuracy.

I'm neither experienced with Arduino nor with your DAC.
So to find the problem I need to read Arduino documentation, library documentation, DAC documentation ... and use a paper and a pencil.
You can and should do the same.

Example:
In the DAC datasheet there is a section where you can see an example of how to communicate. Bit by bit, byte by byte...
Compare this with your software.

Another hint:
Use reliable sources of information. Informations from IC manufacturers are way more reliable than some internet document from amateurs. Many amateur document are full of mistakes.
I don't know if your internet document is correct or not.

Klaus
 

Hi,


There's nothing wrong with it.


No. This is a more complicated way to check if it operates....but it's no way to check accuracy, because the error (inaccuracy) of your analog value as well as the error of your ADC will be higher than the error of the DAC.

A more simple way is to send a known digital value to the DAC. This digital value also does not have any errors (analog value, ADC) and thus it's more suitable to check DAC accuracy.

I'm neither experienced with Arduino nor with your DAC.
So to find the problem I need to read Arduino documentation, library documentation, DAC documentation ... and use a paper and a pencil.
You can and should do the same.

Example:
In the DAC datasheet there is a section where you can see an example of how to communicate. Bit by bit, byte by byte...
Compare this with your software.

Another hint:
Use reliable sources of information. Informations from IC manufacturers are way more reliable than some internet document from amateurs. Many amateur document are full of mistakes.
I don't know if your internet document is correct or not.

Klaus

Hi Klaus!

thanks so much for your comments.
someone has told same thing to me earlier about referring to datasheets, but i know i might sound stupid but i find them a bit boring!

P.S:by the way the online document worked this time ,some tweaking in hardware was needed

Cheers,
Marrc
 
Last edited:

Hi,

referring to datasheets, but frankly i find them a bit boring!
Do you think you find a single person in this forum who does not think reading documents is boring?

There´s no way around.

Klaus
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top