AnsweredAssumed Answered

declaration misunderstanding

Question asked by MarcZ on Apr 29, 2013
Latest reply on Apr 30, 2013 by CraigG

Hi,

 

We are working on a SARC ASDP-21489 Ez-kit board.

 

1) We have a 16-bit A/D connected to the AMI bus. This A/D delivers 16-bit, signed data. We have declared the pointer to this as being a pointer to an signed short, which we assume would tell the compiler that there is a 16-bit peripheral out there. However, when we read the data from this A/D, negative values show up as very-high-valued positive values. The compiler is thus, ignoring the fact that we told it that it was a signed port connected to the AMI bus and thus, after we read the data, we need to do C code such as this to correct it:

 

    if(Value>32767) Value=Value-65536;

 

2) After we discovered the situation above, we tried a few things. For example, we did:

    short int Bob;

    Bob = 300000000;

 

The compiler seems perfectly happy to assign a short integer a value of 300 billion, which of course won't even fit into a 32-bit integer let alone a 16-bit one.

 

We also tried putting 300 billion and even higher values into a "char", which with most compilers would generate errors with numbers greater than 127.

 

Questions based on the tests from above:

 

a) From experiments 1 and 2 above, are we to conclude that the compiler really assigns all variables to 32-bit floating point variables?

 

b) Is there any better (i.e. faster) was of recovering signed information from our A/D other than the code provided above?

 

c) In the Linker Description File, we see that we are able to create 16-bit sections. Would such a thing help here or what?

 

Please provide some insights as to what is going on here...

Thank you,

Marc

Outcomes