MCP3301 A/D converter SPI reading


Closed Thread
Results 1 to 15 of 15

Hybrid View

  1. #1
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,115


    Did you find this post helpful? Yes | No

    Default Re: MCP3301 A/D converter SPI reading

    Your ADC is differential one. So, that means it can convert positive and also negative (in relation to the two inputs + and -) voltages.

    If the + input is more positive than the - input of the converter then the output will be a plain 12 bit binary number.

    But if the - input is more positive than the + input, then as you can understand the result of the ADC should be negative. This is shown in binary with the most significant bit (MSB) of the value being 1. That is the sign bit.

    But the rest of the 12 bits follow a specific rule then. All bits are reversed and also -1.

    For example, 1 1111 1111 1111 means negative number and this number is the reverse of 1111 1111 1111 plus one, or just 1. So in total -1.

    Or, 1 0000 1111 0000 is also negative and the value is -3856

    Hope this clear a bit of the mud!

    Ioannis

    More here https://www.cs.cornell.edu/~tomf/not.../twoscomp.html

  2. #2
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    938


    Did you find this post helpful? Yes | No

    Default MCP3301 A/D converter SPI reading

    Thanks Ioannis and sorry for the late reply,

    So, if I would connect GND to the "-" input and measure i.e. a + signal from 0 to 5 Volts, I should have as 12 bits result, right?



    Or, 1 0000 1111 0000 is also negative and the value is -3856
    This is confusing to me. I get the positive and negative thing but I can't figure out how you come to this 3856 number?

    Name:  Bit-view.jpg
Views: 902
Size:  10.4 KB
    Roger

  3. #3
    Join Date
    May 2013
    Location
    australia
    Posts
    2,631


    Did you find this post helpful? Yes | No

    Default Re: MCP3301 A/D converter SPI reading

    to expand a 13 bit negative two's complement number to a 16 bit number bits 13,14 an 15 need to be set accordingly
    in general the "sign bit" needs to be extended to the new width
    so 1 0000 1111 0000 becomes 1111 0000 1111 0000 qed -3856
    Name:  r3.jpg
Views: 925
Size:  38.0 KB
    Warning I'm not a teacher

  4. #4
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,115


    Did you find this post helpful? Yes | No

    Default Re: MCP3301 A/D converter SPI reading

    Yes, Richard is correct. I forgot to mention you have to adjust the value to the byte, word or whatever width you have.

    So the sign is the left most bit but the rest should also be 1. Remember we reverse the bits to get the absolute value disregarding the left most, sign bit.

    Seems confusing at first, but has its logic.

    Ioannis
    Last edited by Ioannis; - 9th February 2024 at 11:11.

  5. #5
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    938


    Did you find this post helpful? Yes | No

    Thumbs up MCP3301 A/D converter SPI reading

    Got it now!

    Thanks a lot
    Roger

  6. #6
    Join Date
    Aug 2011
    Posts
    453


    Did you find this post helpful? Yes | No

    Default Re: MCP3301 A/D converter SPI reading

    Remember we reverse the bits to get the absolute value disregarding the left most, sign bit
    To convert a 2's compliment negative value to a positive number, invert all the bits (NOT) and add 1.

    For example 2's compliment -1 = FFFF
    invert = 0000, add 1 = 0001

  7. #7
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,115


    Did you find this post helpful? Yes | No

    Default Re: MCP3301 A/D converter SPI reading

    I was reffering to the left most bits but yes. Absolutely correct, to convert a positive to negative after reversing all bits you add one.

    Ioannis

Similar Threads

  1. Reading DS1620 (SPI Temperature) from 18F46k22 Micro at 16MHz
    By JimAvanti in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 13th June 2015, 00:24
  2. Need to use SPI but I'm already using the SPI port
    By Christopher4187 in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 30th December 2012, 09:52
  3. SPI on a pic without hardware SPI?
    By modifyit in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 26th April 2006, 13:29
  4. Isolated A/D converter, SPI I/F
    By srob in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 3rd November 2004, 07:18
  5. help D/A converter
    By matelda in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 8th September 2004, 17:25

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts