+ Post New Thread
Results 1 to 9 of 9
  1. #1
    Junior Member level 2
    Points: 633, Level: 5

    Join Date
    Mar 2017
    Location
    india
    Posts
    21
    Helped
    0 / 0
    Points
    633
    Level
    5

    problem with coding 123

    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

    •   AltAdvertisement

        
       

  2. #2
    Super Moderator
    Points: 80,159, Level: 69
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    16,268
    Helped
    3690 / 3690
    Points
    80,159
    Level
    69

    Re: problem with coding 123

    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
    Please donīt contact me via PM, because there is no time to respond to them. No friend requests. Thank you.



  3. #3
    Super Moderator
    Points: 82,562, Level: 70
    Achievements:
    7 years registered
    Awards:
    2nd Helpful Member
    betwixt's Avatar
    Join Date
    Jul 2009
    Location
    Aberdyfi, West Wales, UK
    Posts
    13,552
    Helped
    4514 / 4514
    Points
    82,562
    Level
    70

    Re: problem with coding 123

    ... 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.
    PLEASE - no friends requests or private emails, I simply don't have time to reply to them all.
    It's better to share your questions and answers on Edaboard so we can all benefit from each others experiences.



  4. #4
    Super Moderator
    Points: 80,159, Level: 69
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    16,268
    Helped
    3690 / 3690
    Points
    80,159
    Level
    69

    Re: problem with coding 123

    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
    Please donīt contact me via PM, because there is no time to respond to them. No friend requests. Thank you.



    •   AltAdvertisement

        
       

  5. #5
    Super Moderator
    Points: 82,562, Level: 70
    Achievements:
    7 years registered
    Awards:
    2nd Helpful Member
    betwixt's Avatar
    Join Date
    Jul 2009
    Location
    Aberdyfi, West Wales, UK
    Posts
    13,552
    Helped
    4514 / 4514
    Points
    82,562
    Level
    70

    Re: problem with coding 123

    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.
    PLEASE - no friends requests or private emails, I simply don't have time to reply to them all.
    It's better to share your questions and answers on Edaboard so we can all benefit from each others experiences.



  6. #6
    Junior Member level 2
    Points: 633, Level: 5

    Join Date
    Mar 2017
    Location
    india
    Posts
    21
    Helped
    0 / 0
    Points
    633
    Level
    5

    Re: problem with coding 123

    Quote Originally Posted by KlausST View Post
    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/microcontr...ng-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



  7. #7
    Super Moderator
    Points: 80,159, Level: 69
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    16,268
    Helped
    3690 / 3690
    Points
    80,159
    Level
    69

    Re: problem with coding 123

    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
    Please donīt contact me via PM, because there is no time to respond to them. No friend requests. Thank you.



  8. #8
    Junior Member level 2
    Points: 633, Level: 5

    Join Date
    Mar 2017
    Location
    india
    Posts
    21
    Helped
    0 / 0
    Points
    633
    Level
    5

    Re: problem with coding 123

    Quote Originally Posted by KlausST View Post
    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 by marrc; 11th December 2019 at 11:26. Reason: posted in hurry



    •   AltAdvertisement

        
       

  9. #9
    Super Moderator
    Points: 80,159, Level: 69
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    16,268
    Helped
    3690 / 3690
    Points
    80,159
    Level
    69

    Re: problem with coding 123

    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
    Please donīt contact me via PM, because there is no time to respond to them. No friend requests. Thank you.



--[[ ]]--