1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

Twos compliment in Oshonsoft

Discussion in 'Oshonsoft' started by camerart, Feb 24, 2018.

  1. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,827
    Likes:
    11
    Location:
    Dorset UK.
    Hi J,
    I follow.
    My point is that, when receiving 2's complement, I would only be able to alter it after it has been gleaned by Oshonsoft, so would it have been corrupted in any way before applying (msg#12)?
    C.
     
  2. jjw

    jjw Member

    Joined:
    Apr 16, 2012
    Messages:
    389
    Likes:
    18
    Location:
    Helsinki, Finland
    ONLINE
    I don't quite understand what you mean.
    If the data is corrupted, how can you know it?
    Or do you want to make some filtering / averaging?
     
  3. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,827
    Likes:
    11
    Location:
    Dorset UK.
    Hi J,
    I think the penny has dropped.
    Thanks for your patience.
    C.
     
    Last edited: Feb 25, 2018
  4. dave miyares

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    2
    Likes:
    -10
  5. Ian Rogers

    Ian Rogers User Extraordinaire Forum Supporter Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,806
    Likes:
    958
    Location:
    Rochdale UK
    ONLINE
    You are reading too much into this 2's complement thing.... The output of the chip is a word... The number will be 0 to 65535 IF!! the number is bigger than 32767 then its negative!! Is as simple as that!! Your output is apparently
    4095 to -4096 where 0 is flat!! If the value is bigger than 32767 then subtract it from 65536 and you will get the correct number!!
     
  6. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,827
    Likes:
    11
    Location:
    Dorset UK.
    Hi I,
    Again! the penny has dropped, thank you all for your patience.
    I'll let you know, how I get on.
    C.
     
  7. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,827
    Likes:
    11
    Location:
    Dorset UK.
    DELETED
     
    Last edited: Apr 3, 2018
  8. dave miyares

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    2
    Likes:
    -10
  9. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,723
    Likes:
    422
    Location:
    Brisbane Australia
    Think of what happens when you decrement or subtract 1 from a number. It will eventually go to zero and on the next decrement it will be 0xffff or minus 1 - the same as in decimal. It's just a convenient way to represent negative numbers.

    Mike.
     
  10. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,827
    Likes:
    11
    Location:
    Dorset UK.
    Hi M,
    I had to experiment for some time to figure out that, although I thought I was dealing with BITs BYTEs and WORDs, I needed to use LONG to accommodate the suggested subtract from 65536. No wonder Oshonsoft rejected it:) Using BINARY allowed me to visualise better.
    C.
     
  11. jjw

    jjw Member

    Joined:
    Apr 16, 2012
    Messages:
    389
    Likes:
    18
    Location:
    Helsinki, Finland
    ONLINE
    Subtract from 65536 was suggested, when the data was first converted to floating point.
    With 16 bit words you can subtract from 65535 and then add one.
    I think floating point is needed, when calculating angles from x,y
    ( arctan ( x/y ) )
     
  12. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,827
    Likes:
    11
    Location:
    Dorset UK.
    Hi J,
    True, I'm sure I'll need it, but just couldn't visualise it as a number, until, I changed it to BINARY.
    C.
     
  13. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,827
    Likes:
    11
    Location:
    Dorset UK.
    DELETED
     
    Last edited: Apr 3, 2018
  14. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,827
    Likes:
    11
    Location:
    Dorset UK.
    Hi,

    Because I appear to be getting errors in the results, I have set the program to show X and Y in separate BYTES and each WORD on the output screen.

    The LB appears ok and shows 0 to 255
    The HB only shows 0 or 254 or 255.

    I understand the high BIT of the HB is the + - indicator, but I can't see which of the other BITs combine with the LB to give 12BITS.

    Is there an error?

    C.
     
  15. jjw

    jjw Member

    Joined:
    Apr 16, 2012
    Messages:
    389
    Likes:
    18
    Location:
    Helsinki, Finland
    ONLINE
    What is the gain setting?
    It might be too low.
    According the d/s the values can be from 0xF800 to 0x7FF
     
  16. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,827
    Likes:
    11
    Location:
    Dorset UK.
    Hi J,
    It was the default 0x20
    I turned it up to max %11100000 and now the HB is always 0 or 255.

    From your reply, I can now see that it is the lower 3xBITs in the HB that makes up the 12BIT together with the LB. (Remembering that the HB high bit is the +- indicator:))

    EDIT:
    I tried all of the gain settings, and at the lowest setting, if the module is moved in all directions, and tilts, then X and Y give 0, 1, 2, 253, 254, 255
    Y occasionally gives 252.

    This looks promising, so I'll try it in the program, which has the XY calculation. If it works, I'll then try to include the Z correction.
    C.
     
    Last edited: Apr 4, 2018

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice