Building a custom PCB using Atmega32A

Go To Last Post
23 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi everyone. I am a newbie with AVR (and also RF like my name says). So far I have been used to using the STK500 board to communicate with an RF module via SPI. I'm on my way to make my own custom PCBs to be a transmitter and a receiver. I have some questions that I couldn't find the answer. Hope you could help. Please excuse me for my English and feel free to ask if I'm not clear at any point.

 

1. I will use JTAG ICE 3 to program my Microcontroller (uC) via SPI (ISP 6 pin). As I have seen in layouts of some Protoboard like this https://www.olimex.com/Products/... , the only connections from the uC we need to make are Vcc, Avcc, GND and the ISP 6pin interface for programming with SPI. Is that all that we need to program with JTAG ICE 3 programmer? (including changing fuses and clocks of the uC). 

 

2. The uC also communicates with my RF module via SPI. When working with the STK500 board, I have seen no difference between unplugging the module or not before programming the uC. However, I just ask for experience. Will the two communication stack with each other? I mean when programming the uC on my custom board, will there be problem with my RF module, because in my board, I have no option to unplug it before transferring the code to the uC. 

 

3. Do you recommend any tutorial/ guide/ reading on building the custom board like in my case? Or suggest me any keywords, because I couldn't find much about this question. Even I don't know how to call the board, but have to use the word "custom PCB using AVR". 

 

These will be my first hardware that I make myself. I greatly appreciate your help. Thank you :D

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well, if you're programming using SPI, you're using ISP, not JTAG.

 

Sharing the ISP pins with the RF module will work fine as long as you have a pullup to be sure the module's CS pin stays high (unselected) while the processor is in reset.

If you don't know my whole story, keep your mouth shut.

If you know my whole story, you're an accomplice. Keep your mouth shut. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

RF_newbie wrote:

2. The uC also communicates with my RF module via SPI. When working with the STK500 board, I have seen no difference between unplugging the module or not before programming the uC. However, I just ask for experience. Will the two communication stack with each other? I mean when programming the uC on my custom board, will there be problem with my RF module, because in my board, I have no option to unplug it before transferring the code to the uC. 

 

Take a look at Atmel AVR042: AVR Hardware Design Considerations,

section 4.1.1 Shared use of SPI programming lines.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

3. Do you recommend any tutorial/ guide/ reading on building the custom board like in my case?

If this is going to be your first PCB you might wish to post bot the schematic and the PCB layout here on AVRFreaks.

That way you will have lots of people looking at it and making suggestions for improvements before you actually get the boards made.

Also, if anyone sees an obvious error in your schematic it is certainly nice to correct it prior to laying out the PCB and getting it made.

 

If you have looked at Olimax schematics you have a pretty good staring point for your own PCB.

 

Some additional comments:

 

Don't forget that EVERY Vcc and the AVcc pin need to be tied to V+.

Likewise EVERY Ground and Aground needs to be tied to Ground.

 

AVcc can have a cap to Ground, or if you are going to use the ADC or AC it would be better to feed it via an LC filter.

 

Every Vcc and AVcc / Ground pair of pins need to have a 0.1 uF cap, (By-Pass Cap), mounted as close to the micro's pins as possible.

 

It is worth laying out pads for an external crystal and tis two caps even if you plan on using the internal RC Osc.

You can always easily add them, later, if needed.

 

Are you going to physically make the PCB's yourself, or have them made, (and you add the parts)?

If you are having the PCB's made, then it is easy to have a couple of "extra" PCB's made.

You can then use them for experimenting on other projects.

 

If your micro has a spare I/O pin bring it out to an extra pad for a resistor and LED.

Nice for debugging, and you don't have to populate the parts if you don't want to.

 

Be sure to put mounting holes in the corners of your PCB, as well as a PCB (Project) label (title) on the PCB, and a Version Number.

If you ever make a second, improved, Version 2, it will be much easier down the road to tell which PCB is which.

 

Be sure to put a small marker on the PCB for Pin #1 of the micro, and for Pin #1 of the Programming Header, (and any other chips or headers on the board).

 

Expresspcb.com has / had a PCB layout tutorial on their web site.

It has some good info for starting out.

You might not wish to actually use them, however, as their service is rather expensive compare to some others.

(They make nice boards, however!)

They also have a free schematic drawing program which might be useful, if you don't already have one you are using.

 

JC

 

 

 

  

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

@Torby, Chuck99: thank you :)

DocJC wrote:

Don't forget that EVERY Vcc and the AVcc pin need to be tied to V+.

Likewise EVERY Ground and Aground needs to be tied to Ground.

 

AVcc can have a cap to Ground, or if you are going to use the ADC or AC it would be better to feed it via an LC filter.

 

Every Vcc and AVcc / Ground pair of pins need to have a 0.1 uF cap, (By-Pass Cap), mounted as close to the micro's pins as possible.

Do I need to connect AVcc, ARef and AGround if I don't use ADC/ AC? So far I didn't connect these pins and it still works in my breadboard.

 

Quote:

Are you going to physically make the PCB's yourself, or have them made, (and you add the parts)?

If you are having the PCB's made, then it is easy to have a couple of "extra" PCB's made.

You can then use them for experimenting on other projects.

The lab in my Uni will help me make the pcb, I just need to solder it. Not sure if they mind when I make more backup boards.

 

Quote:

If this is going to be your first PCB you might wish to post bot the schematic and the PCB layout here on AVRFreaks.

That way you will have lots of people looking at it and making suggestions for improvements before you actually get the boards made.

Also, if anyone sees an obvious error in your schematic it is certainly nice to correct it prior to laying out the PCB and getting it made.

After one week, I tested programming with SPI and the reset button (without the diode).

Here is my schematic. Hope to hear your comments. I don't know if the values are okay.

 

I can think about these questions:

1. Can I group the Vcc and GND pins like in my sketch? 

2. Do you have any idea to temporarily disconnect the RF module from the line when it's in programming mode? The RF module shares Vcc and GND with the AVR, but it's a 3V device. I don't want to use a programming switch, which takes more area on board. 

3. Is there any way to optimize power consumption in my circuit? 

Please also comment about the sketch and the values of components. 

 

Thank you very much guys.

 

Attachment(s): 

Last Edited: Tue. Aug 18, 2015 - 12:58 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Pin 27 (AVcc) is wrong.

 

Ross McKenzie ValuSoft Melbourne Australia

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

valusoft wrote:

Pin 27 (AVcc) is wrong.

 

Can I just leave it unconnected? (I don't use ADC). Could you elaborate? Should I connect it to Vcc?

Last Edited: Tue. Aug 18, 2015 - 02:37 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Can I just leave it? (I don't use ADC). Could you elaborate? Should I connect it to Vcc?

You seem hung up on this.  What did Doc say?

 

Don't forget that EVERY Vcc and the AVcc pin need to be tied to V+.

Likewise EVERY Ground and Aground needs to be tied to Ground.

 

AVcc can have a cap to Ground, or if you are going to use the ADC or AC it would be better to feed it via an LC filter.

 

Every Vcc and AVcc / Ground pair of pins need to have a 0.1 uF cap, (By-Pass Cap), mounted as close to the micro's pins as possible.

 

What does the datasheet say?

2.2.10 AVCC
AVCC is the supply voltage pin for Port A and the A/D Converter. It should be externally connected to V
CC, even if the ADC is not used. If the ADC is used, it should be connected to VCC
through a low-pass filter.

 

What does the Atmel app note say about decoupling? http://www.atmel.com/Images/Atme...

 

What does the datasheet say about AVCC in Electrical Characteristics?  (do you really want to run out of spec?)

AVCC Analog Supply Voltage VCC - 0.3(1) VCC + 0.3(2) V
 

Side question:  Why the '32A vs. the more modern '164 family?

 

Now, are you going to use the brown-out detector BOD in your app?  You should.  And when you do, you will find that it will trip on unconnected/floating AVCC.

 

Are you going to use any pins on port A?  Then you need good AVCC.

 

You have to ask yourself whether you just want a bench app that may exhibit quirks that can be ignored, or a reliable running app on your PCB?

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi, I have some suggestions if you intend to send your PCB to an external fab. If your board is small enough (say below 4 square inch) OSHpark is a must. With their user friendly gerber upload and their impeccable gold finish it's truly something you should try. If your board somewhat exceed the limit at which it would be cost efficient with OSHpark, try pcbshopper.com. You enter all the parameters from your board (size , # of layers, desired quality, # of copies). The site makes a list of all the different fabs and you can sort by price.

OSHpark: 5$/sq. inch for 2 layers ----- 10$/sq. inch for 4 layers

For a minumum functionning board with a Xtal, ISP connector and I/Os breakout you can easily make a 1 sq. inch board at 2 layers. 

If you need some more details just ask!
 

There are 11 types of people in the world. Those who understand binary, those who don't and those who make nerdy pun about it.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:

You seem hung up on this.  What did Doc say?

Side question:  Why the '32A vs. the more modern '164 family?

 

Now, are you going to use the brown-out detector BOD in your app?  You should.  And when you do, you will find that it will trip on unconnected/floating AVCC.

 

Are you going to use any pins on port A?  Then you need good AVCC.

 

You have to ask yourself whether you just want a bench app that may exhibit quirks that can be ignored, or a reliable running app on your PCB?

I'm sorry for my hurry, it's the upcoming deadline that made me so. I dug the datasheet up again and made correction on the AVCC pin as followed. (see attachment)

 

I choose 32A just because it's also the chip in my STK500 board. Besides, I don't have any experience about advantages of 164 family over the 32A. Do you mean the picoPower? 

As my research, BOD will draw some microAmps from the power source, but to make it safe, I will enable it. (one requirement is battery life).

 

Thank you for reminding me about my hurried and careless manner. Of course I wish my project to be fully functional and safe, not just to show off and cause trouble. =P.

 

@All: I fixed the AVCC pin. Please leave any comments that you have on my sketch. Thank you very much!

 

About temporarily disconnecting the RF module while in programming mode (to protect it from VTG > 3.3V if not pre-adjusted), I think of using a DPDT switch that disconnect the VCC line to the RF module the same time when the battery is switched off. Do you guys have any other idea about that? I also read about zener diode, but it draws too much current. 

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I choose 32A just because it's also the chip in my STK500 board.

Indeed, engineering is the art of making what you need from what you have.

 

But just because my STK500 came with an AT90S2313 chip, that doesn't mean we design all of our boards for that.  [And I'll echo earlier comments -- unless the objective of your class is to make your own boards, then for microcontroller exploration there are many inexpensive and ready-made AVR8-based boards nowadays, with assorted AVR sizes.]

 

I don't have any experience about advantages of 164 family over the 32A. Do you mean the picoPower? 

As my research, BOD will draw some microAmps from the power source, but to make it safe, I will enable it. (one requirement is battery life).

Indeed it is sometimes hard to grasp differences from selector charts and datasheet scans.

 

While A variants do use less power than non-A, I'll wager that power charts for the '164 family will show improvement over the '16 family.  I'll also guess that you get more sleep and wakeup options.

 

On the surface, about the same.  '164 will have a second USART, that can also be used as SPI master.  '164 has pin-change interrupts, and they are most useful waking on events when in deep sleep modes.

 

In particular, see the column on BOD Disable?  Read up on the "sleeping BOD"...

 

A quick peek at power draw:

 

'32A is ~8mA at 5V and 8MHz.  '164A about 5mA.

 

 

 

RF apps typically spend nearly all time sleeping.  In general the transmit current will be the big item in the power budget.  (There are threads with power budget and RF discussed in detail--search them out.)

 

Power-down sleep current: 

Again, that is a bit over half of the '32A.  And remember the sleeping BOD?  That drops the '164A to about 200nA at 5V, with the '32A at about 1000nA -- 5x as much.

 

There are a number of other improvements in the '164 family -- clock prescaler; power reduction register; more PWM channels; more ADC channel selection options; faster max clock; wider Vcc range; faster operation at lower Vcc levels ("Speed Grades" chart); and probably more.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

Last Edited: Wed. Aug 19, 2015 - 06:16 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 I think of using a DPDT switch that disconnect the VCC line to the RF module the same time when the battery is switched off.

No.

 

The micro needs to be powered up when it is being programmed...

 

JC 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

DocJC wrote:

 I think of using a DPDT switch that disconnect the VCC line to the RF module the same time when the battery is switched off.

No.

 

The micro needs to be powered up when it is being programmed...

 

JC 

I forgot to mention, I use STK500 as my programmer, it can power the micro when programming. What do you think then about the switch for the RF module?

Last Edited: Wed. Aug 19, 2015 - 10:36 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:

But just because my STK500 came with an AT90S2313 chip, that doesn't mean we design all of our boards for that.  [And I'll echo earlier comments -- unless the objective of your class is to make your own boards, then for microcontroller exploration there are many inexpensive and ready-made AVR8-based boards nowadays, with assorted AVR sizes.]

 

Thank you for your useful information about the 164 family. I'll definitely consider it. Luckily, it has same pin configuration as the 32A.

 

This time I'm required to make my own boards. After this I will try playing with other Atmel chips. It's always fun to explore new things xD.

Last Edited: Wed. Aug 19, 2015 - 10:36 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You will have to post a schematic before anyone can say with certainty whether or not the method you have in mind will work or not.

 

JC

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

DocJC wrote:

You will have to post a schematic before anyone can say with certainty whether or not the method you have in mind will work or not.

 

JC

Here it is. Basically I just change the switch.

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

With regard to your schematic in post #16:

 

First, C1 (0.1uF) is connected from Reset to Gnd.

This will interfere with the ISP programming.

 

Consider adding a solder jumper between C1 and Reset.

 

When you want to ISP the board, remove the solder bridge.

 

When you have finished programming and testing, add solder to bridge the two pads, connecting C1 to Reset.

 

---------------------------------------------------------------------------------------

 

Second, U$2 uses the SPI signals that are also used by ISP.

U$2 has a CE input that is connected to PB1 of U$1, which is high impedance when programming via ISP.

There needs to be a pull-up or pull-down resistor to insure that U$2 is NOT enabled when programming U$1.

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You should make the layout so all unused pins go to something! (1/10" sil or something like that).

 

And I normally make it so there are 4 smd components (603 or 402 pads), one in serial with the IO, from there space for one to GND and VCC, and the last in serial with the connector.

That way it's open for a lot of use . 

 

Add

remember to put GND and VCC on the sil (or dual line)  to open for a more general use.

Last Edited: Thu. Aug 20, 2015 - 10:41 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

With regard to your schematic in post #16:

 

First, C1 (0.1uF) is connected from Reset to Gnd.

This will interfere with the ISP programming.

 

Consider adding a solder jumper between C1 and Reset.

Now, I'm not a board designer.  But we have hundreds of AVR8 production designs in the field over the past 15 years, and probably a million or so pieces.

 

That said, the /RESET circuitry from the post #16 schematic is confusing at best. 

 

-- The diodes are protection diodes?  Protecting from what?  And are 1N4004 appropriate for that?

-- Is S2 an external reset pushbutton?  (We have very few in our designs.)

-- Nearly all of our designs have 4K7 pullup on /RESET.  But I won't argue with 10K.

-- Nearly all of our designs also have a 0.1uF cap on /RESET -- but connected to Vcc and not Gnd.  [Our grizzled board designer with many decades of experience explained the reasoning sometime in the  past but I don't remember ...] 

-- That cap to Vcc does NOT interfere with ISP with STK500 or AVRISP2 or similar.

--  But (and not pertinent in this case) that cap would need to be removed for debugWire use for those applicable AVR8 models.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:

-- The diodes are protection diodes?  Protecting from what?  And are 1N4004 appropriate for that?

Yes, they are. The one from RESET to Vcc is for ESD protection. The other one should be a zener diode "to limit the RESET voltage relative to GND" (from AVR042 appnote - I don't get this line). 1N4004 is just a general purpose model I picked for the diodes, I hope it's suitable. 

Quote:

-- Is S2 an external reset pushbutton?  (We have very few in our designs.)

Yes it is.

Quote:

-- Nearly all of our designs have 4K7 pullup on /RESET.  But I won't argue with 10K.

4k7 or more for STK500. Again, it's the value that I have, and I tested the RESET button. It works well. (also ISP with STK500)

Quote:

-- Nearly all of our designs also have a 0.1uF cap on /RESET -- but connected to Vcc and not Gnd.  [Our grizzled board designer with many decades of experience explained the reasoning sometime in the  past but I don't remember ...]

Maybe the cap is for a more stable pull-up voltage to RESET pin?

Quote:
 

-- That cap to Vcc does NOT interfere with ISP with STK500 or AVRISP2 or similar.

--  But (and not pertinent in this case) that cap would need to be removed for debugWire use for those applicable AVR8 models.

Yeah, Im not going to use debugWire. But after looking up, I decided to remove the cap between RESET and GND. They said their boards work fine without the cap. Now I am thinking if I should add a cap between RESET and Vcc. xD

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Please read my suggestions, in Post #4, in this Thread, once again.

 

Then have a look at This Thread, and at my Post #13, in that Thread, both the text and the schematic.

 

AVcc should have a cap to ground.

 

A Reset Push Button Switch isn't needed at all for a commercial product, but for a relative newbie, and a first PCB / testbed, it might be helpful.

 

Agreed your Reset\ circuit is overly complex.

The presence of the diodes is fine, but is probably overkill for most PCB's.

R3 isn't needed. 

Just tie the PBS to the reset pin on the micro, not going through R3.

 

I suggested you look at Olimex or Arduino circuits.

Have a look at their Reset circuits, and at the one in Post #13 in the schematic in the other Thread.

Keep it simple.

 

See Chuck99's comments on adding a pullup or pulldown resistor, as indicated, to U2, to keep it Not Enabled, when programming the micro.

This is a MUCH better approach that what you are trying to do with the DPDT switch.

Additionally, there are other reasons, not discussed here, for NOT omitting Vcc to the U2 chip while actively having signals present on the other pins.

(Doing that is a generally bad thing to do...)

 

What is the purpose of the DPDT switch?

The micro REQUIRES power both to run the program, AND during programming the micro.

If you power the micro from the STK500, while programming it, that's fine.

BUT the NRF is still going to be powered via its connections to Vcc.

Bottom line, I don't see that the switch does anything useful...

 

If you make a PCB it would be a good idea to bring out the Xtal pins, and extra traces/pads for two caps to ground, just in case you needed to add an external crystal in the future.

 

Last comment:

The STK500 is one of the few, (only ?), Atmel ISP programmers that can power the target board.

That is a nice feature when using it as a testbed.

BUT, when you use it to program an EXTERNALLY attached PCB, that has its own power supply, you can get into trouble very fast!

If you forget to disconnect the PCB's power supply, and have the STK500 connected, BOTH of the power supplies will try to power the PCB, and they will fight each other.

That can damage the power supply one your PCB, the STK500, or both...

Read this paragraph a couple of times and make sure you understand it.

 

You are very close to having a great circuit that should work first time.

Read the last few posts and make one more go at it!

 

JC

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

DocJC wrote:

What is the purpose of the DPDT switch?

The micro REQUIRES power both to run the program, AND during programming the micro.

If you power the micro from the STK500, while programming it, that's fine.

BUT the NRF is still going to be powered via its connections to Vcc.

Bottom line, I don't see that the switch does anything useful...

Thank you very much. I agree with most of your words and will read them very carefully before finishing my board. I just want to answer this question: the switch is for the case that Vtarget from STK500 (if not pre-adjusted) is greater than 3.3V, which will damage my RF module. (e.g someone not me wants to reprogram my board). Like I said before, it's the only way that I could think of. Using a zener diode sounds good, but as I read, it will cause power loss, which is not worth just for protecting the RF module in a very unlucky situation. My requirement is battery life, so I cannot use normal regulator here either.

 

As a newbie, I don't have other ideas for this protection case. If someone has any better idea, I am very glad to hear. To a person with limited experience like me, the switch works as what I wish it to be (theoretically, because I don't have the DPDT switch to test, I can't help but just think about the theory).

 

FYI. My idea for the RF module protection: When running in normal condition, the switch is closed and the voltage from my battery is 3V. Therefore totally safe. When programming with STK500, the switch is open, which also disconnects the Vcc of RF module from the Vtarget line of STK500. Therefore, it can be safe no matter what value the Vtarget is. 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

OK, I understand what you are trying to do.

Your power switching that way will work to switch the power sources, and to disconnect the power supply from the NRF.

 

You could still have a possible problem, however.

I've not used the NRF's, so I've not read their data sheets or worked with them.

As a general rule, however, you do not want live signals connected to a "chip" (NRF module) when it does not have its Vcc connected to power.

You will have live signals on the other lines going to the NRF when you program the micro, and no power going to the NRF.

This could make the NRF act erratically, and possibly cause problems with programming the micro.

 

It may or may not cause you any problems, I don't know.

But I'll mention it as a possibility you might want to think about.

 

I agree the STK500's supply can be not-as-expected at times.

An option is to NOT let the SKT500 power the PCB, always power it from your battery.

And another option is to get a programmer that you can set to 3 V and leave it alone.

 

JC

 

Last Edited: Fri. Aug 21, 2015 - 10:03 PM