Pages: [1]   Go Down
Author Topic: ATmega2560 Analogue inputs  (Read 563 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 19
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi
I am trying to use A0-7 as digital inputs and have set PORT F accordingly but A7 constantly returns 1 even when pin A7 is forced to ground.
Is the that channel used by Arduino software or have I just got a duff chip on my board?
Thanks
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17294
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi
I am trying to use A0-7 as digital inputs and have set PORT F accordingly but A7 constantly returns 1 even when pin A7 is forced to ground.
Is the that channel used by Arduino software or have I just got a duff chip on my board?
Thanks

Should work, but without seeing your code that doesn't work it's hard to say why you are having problems.

Lefty
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 19
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi
I am trying to use A0-7 as digital inputs and have set PORT F accordingly but A7 constantly returns 1 even when pin A7 is forced to ground.
Is the that channel used by Arduino software or have I just got a duff chip on my board?
Thanks

Should work, but without seeing your code that doesn't work it's hard to say why you are having problems.

Lefty


Looks like the problem is the Arduiono software....using Serial.println(variable,BIN)  this routine doesn't write the MSBit to the monitor if it is logic 0

i.e. HEX fffff   = BIN display  1111111111111111 but HEX 7fff = BIN display 111111111111111 instead of 0111111111111111
same problem for byte, char or int conversions......the HEX OCT and DEC work fine



Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 108
Posts: 5150
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The Print class prints the values binary using this method:

Code:
size_t Print::printNumber(unsigned long n, uint8_t base) {
  char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte.
  char *str = &buf[sizeof(buf) - 1];

  *str = '\0';

  // prevent crash if called with base == 1
  if (base < 2) base = 10;

  do {
    unsigned long m = n;
    n /= base;
    char c = m - base * n;
    *--str = c < 10 ? c + '0' : c + 'A' - 10;
  } while(n);

  return write(str);
}

As you can see, it stops adding characters as soon as there are only zeros left, so leading zeros are omitted. Count the ones, in the first case you get 16, in the second case you get 15.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 19
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes I noticed that. Not very helpfull having the output length changing when you are trying to watch specific bits changing.
Guess I'll just have to write my own routine that outputs the condition of ALL bits.

Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 108
Posts: 5150
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

A binary number is not the same as a bit display. The binary number is usually written without leading zeros as you do with decimal numbers.
Logged

Pages: [1]   Go Up
Jump to: