Society of Robots - Robot Forum
Software => Software => Topic started by: spizzak on August 04, 2009, 07:04:53 AM
-
I'm trying to use 5 analog sensors for input by using this statement:
sensorx=a2dConvert8bit(5);
It works for (5) and (4) but not (3) or (0). I haven't tried 1 & 2. Do I have to do it a different way for those ports? Any one have any ideas? Thanks.
Edit: When I plug any device in 5 or 4 it shows proper values. The same device plugged into 0 or 3 shows consistent 0.
-
what board are you using?
no clue if ports behave differently without knowing the kind of board ;)
-
Sorry forgot to mention its an AtMega8 :P
-
I think it may have something to do with not having the right ports set up for input/output. Is there a guide on how to configure each port individually for input/output.
I'm working off the commented $50 robot code but i cant quite figure out how to configure all ports from that:
//configure ports for input or output - specific to ATmega8
void configure_ports(void)
{
DDRC = 0x00; //configure all C ports for input
PORTC = 0x00; //make sure pull-up resistors are turned off
DDRD = 0xFF; //configure all D ports for output
DDRB = 0xC7; //configure B ports 0, 1, 2, 6, 7 for output (google search '0b11000111 to hex')
I'm not really sure how to configure individual ports or how to change between input/output
-
i dont know off the top of my head, you could always look at the avrlib manual:
http://www.nongnu.org/avr-libc/user-manual/index.html
-
actually, this looks like it could be more useful:
http://code.google.com/p/arduino/source/browse/trunk/hardware/cores/atmega8/pins_atmega8.c
http://code.google.com/p/arduino/source/browse/trunk/hardware/cores/arduino/wiring_analog.c
Really, i'm not all that sure about programmign the atmega8 in winavr
sorry