Shop OBEX P1 Docs P2 Docs Learn Events
WORD moving with << (left) command — Parallax Forums

WORD moving with << (left) command

ArchiverArchiver Posts: 46,084
edited 2003-04-21 19:45 in General Discussion
Hi!

I've a word looking like this:

1111 1111 1111 1100

This is data read via I2C from an A/D converter (input pin hooked up to
VDD, just for testing). By some reason, the data is not as it should be.
It's shifted 2 postions right. It should look like:

1111 1111 1111 00 00, eg remove the first "11", shift left 2 positions.
Then my value from the A/D should be alright.

So I tried to use the << command, like this:

ad_result = ad_in << 2

ad_result then looks like this:

1111 1100 1111 0011

What I don't understand, is why the first byte (1111 1100) doesn't get
the value 1111 1111?

Or cant the << command work with words?

Any solution to this?

I want to shift the word 2 steps to the left and then replace the ending
"0011" with "0000".



Thanks.


Regards, Johan

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2003-04-21 18:50
    Not sure about the AFC you are using, but with the Atmel AVR's that have a
    10-bit ADC, you can specify whether or not the result is left or right
    justified. Maybe this is the same for the chip you are using?

    Original Message

    > I've a word looking like this:
    >
    > 1111 1111 1111 1100
    >
    > This is data read via I2C from an A/D converter (input pin hooked up to
    > VDD, just for testing). By some reason, the data is not as it should be.
    > It's shifted 2 postions right. It should look like:
    >
    > 1111 1111 1111 00 00, eg remove the first "11", shift left 2 positions.
    > Then my value from the A/D should be alright.
    >
    > So I tried to use the << command, like this:
    >
    > ad_result = ad_in << 2
    >
    > ad_result then looks like this:
    >
    > 1111 1100 1111 0011
    >
    > What I don't understand, is why the first byte (1111 1100) doesn't get
    > the value 1111 1111?
    >
    > Or cant the << command work with words?
    >
    > Any solution to this?
    >
    > I want to shift the word 2 steps to the left and then replace the ending
    > "0011" with "0000".
  • ArchiverArchiver Posts: 46,084
    edited 2003-04-21 19:45
    I'm using the Maxim 127 I2C AD.

    Solved the problem now... My fault.. A missing zero can cause a lot of
    trouble. =)




    Rodent wrote:

    >Not sure about the AFC you are using, but with the Atmel AVR's that have a
    >10-bit ADC, you can specify whether or not the result is left or right
    >justified. Maybe this is the same for the chip you are using?
    >
    >
    Original Message
    >
    >
    >
    >>I've a word looking like this:
    >>
    >>1111 1111 1111 1100
    >>
    >>This is data read via I2C from an A/D converter (input pin hooked up to
    >>VDD, just for testing). By some reason, the data is not as it should be.
    >>It's shifted 2 postions right. It should look like:
    >>
    >>1111 1111 1111 00 00, eg remove the first "11", shift left 2 positions.
    >>Then my value from the A/D should be alright.
    >>
    >>So I tried to use the << command, like this:
    >>
    >>ad_result = ad_in << 2
    >>
    >>ad_result then looks like this:
    >>
    >>1111 1100 1111 0011
    >>
    >>What I don't understand, is why the first byte (1111 1100) doesn't get
    >>the value 1111 1111?
    >>
    >>Or cant the << command work with words?
    >>
    >>Any solution to this?
    >>
    >>I want to shift the word 2 steps to the left and then replace the ending
    >>"0011" with "0000".
    >>
    >>
    >
    >
    >
    >
    >To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    >from the same email address that you subscribed. Text in the Subject and Body
    of the message will be ignored.
    >
    >
    >Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
    >
    >
    >
    >



    [noparse][[/noparse]Non-text portions of this message have been removed]
Sign In or Register to comment.