go away spammer

Author Topic: Analog to Digital Convert  (Read 1662 times)

0 Members and 1 Guest are viewing this topic.

Offline spizzakTopic starter

  • Full Member
  • ***
  • Posts: 102
  • Helpful? 1
Analog to Digital Convert
« 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.

Offline wil.hamilton

  • Robot Overlord
  • ****
  • Posts: 207
  • Helpful? 6
  • rtfm
Re: Analog to Digital Convert
« Reply #1 on: August 04, 2009, 07:58:06 AM »
what board are you using?

no clue if ports behave differently without knowing the kind of board ;)
use the google.  it's your friend.

Offline spizzakTopic starter

  • Full Member
  • ***
  • Posts: 102
  • Helpful? 1
Re: Analog to Digital Convert
« Reply #2 on: August 04, 2009, 08:54:02 AM »
Sorry forgot to mention its an AtMega8  :P

Offline spizzakTopic starter

  • Full Member
  • ***
  • Posts: 102
  • Helpful? 1
Re: Analog to Digital Convert
« Reply #3 on: August 04, 2009, 10:59:00 AM »
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:

Code: [Select]
//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
« Last Edit: August 04, 2009, 12:29:50 PM by spizzak »

Offline wil.hamilton

  • Robot Overlord
  • ****
  • Posts: 207
  • Helpful? 6
  • rtfm
Re: Analog to Digital Convert
« Reply #4 on: August 04, 2009, 04:39:41 PM »
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
use the google.  it's your friend.

Offline wil.hamilton

  • Robot Overlord
  • ****
  • Posts: 207
  • Helpful? 6
  • rtfm
Re: Analog to Digital Convert
« Reply #5 on: August 04, 2009, 04:50:12 PM »
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
use the google.  it's your friend.

 


Get Your Ad Here

data_list