Coder Social home page Coder Social logo

Why if (t >= 32768) t = 65536l - t about mcp342x HOT 4 OPEN

keestux avatar keestux commented on August 30, 2024
Why if (t >= 32768) t = 65536l - t

from mcp342x.

Comments (4)

kerrydwong avatar kerrydwong commented on August 30, 2024

That's calculating 2's complement.
On Dec 16, 2015 5:21 PM, "Kees Bakker" [email protected] wrote:

Hi,

Why is there this piece of code in MCP342X.cpp? What is it trying to do?

if (t >= 32768) t = 65536l - t;


Reply to this email directly or view it on GitHub
#1.

from mcp342x.

keestux avatar keestux commented on August 30, 2024

Hmm, I assumed you were trying to do that, but are you sure it is working correctly?
Take a look at a few examples of input (16 bits resolution).

value h value l value t
0 1 1
127 255 32767
128 0 32768
128 1 32767
255 255 1

That can't be right. It will never give a negative value, which is required when the MSB is 1.

For 14 bits and 12 bits it is not working either. The values never get over 8191 (14 bits), and 2047 (12 bits).

from mcp342x.

kerrydwong avatar kerrydwong commented on August 30, 2024

Looks like it should be t - 65536. I think the code provided was only for
16 bit resolution if I remember correctly.
On Dec 17, 2015 2:23 PM, "Kees Bakker" [email protected] wrote:

Hmm, I assumed you were trying to do that, but are you sure it is working
correctly?
Take a look at a few examples of input (16 bits resolution).
value h value l value t 0 1 1 127 255 32767 128 0 32768 128 1 32767 255
255 1

That can't be right. It will never give a negative value, which is
required when the MSB is 1.

For 14 bits and 12 bits it is not working either. The values never get
over 8191 (14 bits), and 2047 (12 bits).


Reply to this email directly or view it on GitHub
#1 (comment).

from mcp342x.

skyice78 avatar skyice78 commented on August 30, 2024

try to use the library with particle photon and have no luck with it. I like this library because it is much simpler. Anyone got it to work on particle photon?

from mcp342x.

Related Issues (1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.