Mega328P circuit clarification

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

Hi,

 

I'm making a circuit for push button where I've connected 100 nF capacitor on pin PC3 in Mega328P device.

 

I'm attaching the circuit diagram.

 

 

Do I need to connect any pull up or pull down to this pin? If yes, can you please help me to calculate  this value?

 

 

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

Not enough info, what is the purpose of the circuit, in other words, what are you trying to do?

 

 

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

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

I'm just making a simple circuit where PORTC3 as input and I'm connecting it to a push button.

 

PORTD0  as output which is connected to LED.  So, If push button is pressed, LED has to glow.

 

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

Configure the pin as an input.

You can connect an external pull up resistor, perhaps 10K, from the pin to Vcc,

OR

You can enable the internal pull up resistor.

 

The pull up resistor, internal or external, holds the pin high until the push button switch pulls it low.

 

JC

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

You also want a resistor in series with the switch.  Otherwise the inrush current from the charged cap will eventually destroy the switch.  Not until many thousands of cycles, but for the cost of resistor...

 

Select a resistor which is less than half the pull-up value but sill limits the current to a reasonable maximum.  For a 10K pullup, a 1K series resistor is OK.  For the internal pull-up which has a minimum value of about 20K, don't use more than about a 10K series resistor.  1K would still be OK.

 

 

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

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

Thank you all for your reply.

 

I've enabled internal pull up for that pin. Do I still need to connect an external resistor?

 

If I didn't connect connect an external resistor, does it affect this pin or port?

Last Edited: Sat. Jun 13, 2015 - 01:49 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The purpose of connecting capacitor is mainly for switch debounce.

 

Shall I disconnect this capacitor and connect the switch directly to pin and handle the debounce through software?

 

Switch debounce through software:

 

Test a key, wait a while and re-test - if the switch state is same, then it is a valid key. 

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

You can connect an external pull up resistor, perhaps 10K, from the pin to Vcc,

OR

You can enable the internal pull up resistor.

 

As you noted, you can debounce push button switches in hardware, in software, or both.

The choice is yours.

 

JC 

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

The internal pull-up is sufficient pull-up.  You don't need and external pull-up.

 

The series (between switch and ground) resistor is to protect the switch from repeated high inrush current from the cap.  If you have the cap, you should have the series resistor.  It is not necessary for the circuit to work, but it is advisable for the circuit to work reliably for the life of the gadget.

 

As for software debouncing, there are uncountable threads here at AVR Freaks on the subject.  Search.

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]