go away spammer

Author Topic: ATMEGA 328 Pin map  (Read 6061 times)

0 Members and 1 Guest are viewing this topic.

Offline XyverTopic starter

  • Robot Overlord
  • ****
  • Posts: 125
  • Helpful? 0
ATMEGA 328 Pin map
« on: August 03, 2011, 02:42:48 AM »
Hello, I'm working on my project, and I have all the code worked out and prototyped on a arduino, and now I just have to build the circuit board around an Atmega.  I bought a bunch of 328's and am trying to figure out what pin does what.  Im going off the 50$ robot tutorial, and thats helping me lots, but the one(two part) question I have still is this:

It said that the 328 has 23 programmable I/O pins.  What pins are those, and how do I program them?  I need 15 digital outputs, 6 digital input, and one analogue input.

Fast help would be greatly appreciated, I need these working in about 24 hours. (less preferably. It is now 1:40 AM, so I'm going to bed soon, and these need to be done and given to my friends before 2 AM tomorrow morning.  So... I'll be working on them pretty much all day, and I'll be here on the forum as well.  So if you'd like to stick around and help me out a bit, that'd be greatly appreciated :D)

Offline corrado33

  • Supreme Robot
  • *****
  • Posts: 611
  • Helpful? 11
Re: ATMEGA 328 Pin map
« Reply #1 on: August 03, 2011, 04:10:24 AM »
http://www.atmel.com/dyn/resources/prod_documents/8271S.pdf

The datasheet contains all the information (and much more) than you'd ever need (or want) to know.

Almost any pin can be used as a digital out/in.  The ACD pins are the analogue in pins, you just need to tell it that in software. 

« Last Edit: August 03, 2011, 04:11:38 AM by corrado33 »

Offline joe61

  • Supreme Robot
  • *****
  • Posts: 417
  • Helpful? 16
Re: ATMEGA 328 Pin map
« Reply #2 on: August 03, 2011, 06:08:05 AM »
You probably also need the mapping between the datasheet and the Arduino pins.

http://www.arduino.cc/en/Hacking/PinMapping168

Joe

Offline XyverTopic starter

  • Robot Overlord
  • ****
  • Posts: 125
  • Helpful? 0
Re: ATMEGA 328 Pin map
« Reply #3 on: August 03, 2011, 11:14:11 AM »
Yes, I've looked at the datasheet, but I don't know what 90% of the pin's labels mean.

@ Joe That is really good, but on top of that, what other pins can I use as I/O?  I need more then the arduino provides.

Heres what I got now:
1) Reset
2-6) Digital I/O Pins
7) Vcc (input voltage at 5 volts? Correct me if I'm wrong)
8 ) Ground
9+10) More I/O pins?
11-19) More Digital I/O pins
20) Vcc (More 5 voltage input?)
21) analogue reference?  What does that do? (I'll google it)
22) Another ground
23-28) Analogue input (they can be used as digital I/o, right?)

So that gives me 15 digital I/O pins (2-6, 11-19), and 6 Analogue inputs (I need 6 digital Inputs and one analogue)

So what is another pin that I can use as an analogue input?
And how do I program what each in does?  Do I just do it in the software, and say something like pinMode (23, INPUT); ?

Also, what cable do I need to connect it to the computer for programming?
« Last Edit: August 03, 2011, 11:23:31 AM by Xyver »

Offline corrado33

  • Supreme Robot
  • *****
  • Posts: 611
  • Helpful? 11
Re: ATMEGA 328 Pin map
« Reply #4 on: August 03, 2011, 02:24:24 PM »
Yes, I've looked at the datasheet, but I don't know what 90% of the pin's labels mean.

@ Joe That is really good, but on top of that, what other pins can I use as I/O?  I need more then the arduino provides.

Heres what I got now:
1) Reset
2-6) Digital I/O Pins
7) Vcc (input voltage at 5 volts? Correct me if I'm wrong)

You are right.

Quote

20) Vcc (More 5 voltage input?)
21) analogue reference?  What does that do? (I'll google it)
23-28) Analogue input (they can be used as digital I/o, right?)

Yes

Basically, it is what the microcontroller compares your analogue input to.  So if you provide it with 5V, and your sensor (which is connected to one of the analogue input ports) outputs 0-5V, you'll be good.  You will see all values 0-255 on an 8 bit ADC (theoretically) But, if your sensor only outputs 0-3V, you will only ever see 0-153 on an 8 bit ADC.  So, in that case it would make sense to provide 3V to your analogue reference pin so that you will get 0-255 out of your 3V sensor.  Make sense?

Yes, they can also be used as digital IO.  

Quote
So that gives me 15 digital I/O pins (2-6, 11-19), and 6 Analogue inputs (I need 6 digital Inputs and one analogue)

So what is another pin that I can use as an analogue input?

You can't.  According to the pin mapping the DIP version of the chip only has 6 ADC (analogue input) pins.  You can, however, use a couple of transistors to switch between two things on the same port.  I have no idea how well that would work out, and it would require 1 extra digital i/o port.  

Quote
And how do I program what each in does?  Do I just do it in the software, and say something like pinMode (23, INPUT); ?

It depends, how do you plan on programming it?  What language?  I have no idea how arduinos are usually programmed.  

Quote
Also, what cable do I need to connect it to the computer for programming?

Unless there is a bootloader installed on the chip, you usually need an actual programmer to program the chip.  One like the USBTinyISP, or any of the official ones from atmel.  

Offline XyverTopic starter

  • Robot Overlord
  • ****
  • Posts: 125
  • Helpful? 0
Re: ATMEGA 328 Pin map
« Reply #5 on: August 03, 2011, 02:50:55 PM »
Programming in C, and I don't have a programmer, I'm trying to replicate the 50$ robot tutorial programmer with a serial cable, since no store I went to had the ISCP/serial cable.

Offline joe61

  • Supreme Robot
  • *****
  • Posts: 417
  • Helpful? 16
Re: ATMEGA 328 Pin map
« Reply #6 on: August 03, 2011, 04:51:11 PM »

Heres what I got now:
1) Reset
2-6) Digital I/O Pins
7) Vcc (input voltage at 5 volts? Correct me if I'm wrong)
8 ) Ground
9+10) More I/O pins?
11-19) More Digital I/O pins
20) Vcc (More 5 voltage input?)
21) analogue reference?  What does that do? (I'll google it)
22) Another ground
23-28) Analogue input (they can be used as digital I/o, right?)

So that gives me 15 digital I/O pins (2-6, 11-19), and 6 Analogue inputs (I need 6 digital Inputs and one analogue)

So what is another pin that I can use as an analogue input?
I'm a little confused here. If you need 1 ADC input, and you have 6, why do you need another one?

Quote
And how do I program what each in does?  Do I just do it in the software, and say something like pinMode (23, INPUT); ?
The data sheet has a section called I/O Ports (section 13) that gives technical details, but that might be a little abstract if you're just starting out.

There is a register for each port that determines whether a pin is input our output. For example, if you want to set PB0 to output, you'd say

DDRB |= (1 << PB0);

Which means to set the bit corresponding to pin PB0. If you want it to be input you don't have to do anything, or if you're being careful you can explicitly clear the bit with

DDRB &= ~(1 << PB0);

There are also pullup resistors that can be set if the pin is set to input mode, or you can set the pin to high impedance. Basically you just set or clear bits in the required registers. The data sheet tells you what the required registers are and how to set them up. It took me a while to get to where I could read data sheets without throwing things, but I don't know any other way to do it.

There are a number of tutorials about programming Atmel chips on the web that might be a better starting point. For example

http://www.societyofrobots.com/programming_robot.shtml the admin here has a lot of good information in these pages.

http://www.ladyada.net/learn/avr/ This gives a very general intro, and shows how to make a target board that you can use to program a chip.

http://www.nongnu.org/avr-libc/user-manual/ This gives a lot of good information about how the library used with avr-gcc works.

http://electrons.psychogenic.com/modules/arms/art/3/AVRGCCProgrammingGuide.php I haven't really looked at this much, but it might help too.

I highly recommend looking at the tutorials both on this site, and avrfreaks.net. http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewforum&f=11&sid=228a248b7842e20eb27991c6c5809fbe

Quote
Also, what cable do I need to connect it to the computer for programming?

There are a number of possibilities, I generally use the usbtiny programmer from www.adafruit.com, but I also have a Pololu avrisp2 clone which works well too. You'll need to get something like this, and you should be able to get a good one without spending a lot.

Joe
« Last Edit: August 03, 2011, 05:17:36 PM by joe61 »

 


Get Your Ad Here

data_list