Size of external pull-up resistor

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

Hi,

 

I'm using the PB1 on an Attiny24 as an output and controlling an external system with this output. Sometimes I want to force the PB1 pin high (no matter what the code must say) and to do so I've added a push button and an external 4.7k pull-up resistor to 3v3. 

 

But here's the issue. When the Attiny drives the PB1 low, my external pull-up resistor isn't able to force the voltage high on the pin. I'm figuring that its because the resistor is too big and it thereby limits the flow of current through it.

 

So, how do I determine the right value of the resistor to make sure I'm always able to force the pin high?

 

Appriciate any feedback I can get.

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

What?? If the pin is an output and you force it high you blow up the pin, if it's an input then 4K7, 100K or even higher will do depending on what's attached to the pin.

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

lovepie wrote:

Sometimes I want to force the PB1 pin high (no matter what the code must say) and to do so I've added a push button and an external 4.7k pull-up resistor to 3v3. 

....

But here's the issue. When the Attiny drives the PB1 low, my external pull-up resistor isn't able to force the voltage high on the pin. 

No.  No!  NO NO NO!  For the love of humanity, no!

What you are asking for is to drive enough current through a fully-turned-on output transistor to raise the voltage across it to a '1' level.  This is insanity.  You will burn out that output, and quite possibly a whole lot more.  Your trash bin will fill up with AVRs that you have murdered.

I kind of doubt you need to do what you say, but if you must, simply use a SPDT switch.  Connect the switch center to the output (the circuitry that PB1 is driving).  Connect one throw to 3v3 (through a 1k to 10k R would be best).  Connect the other throw to the AVR output pin.  Now you have your "Emergency 1" capability, and your AVRs will live to run another day.

Last Edited: Sat. Nov 25, 2017 - 07:42 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

\Thats not the way MCU pins are supposed to work.

 

If you want the state of a pin to be controlled by something external, then configure it as an input. Period. 

 

To qualify this slightly, some MCUs have open drain outputs. Few, if any Mega/Tiny MCUs have this. In this configuration, the low level is defined by the  internal pull-down transistor being turned on. The other state is determined by external circuitry. Tiny24 does not have this, so forget about it.

 

What you describe is a very strange requirement. Perhaps if you describe what you are trying to achieve, one of us can help you figure out a better way.

 

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

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

For exact spec's look at the specific datasheet, but let's assume your uC pin can deliver 10mA safely.

3V3 / 10mA = 330 Ohm.

If you lower the resistance (or pull it op to a higher voltage) you will have an over current situation (possibly bad).

But with a 330 Ohm resistor the output will of course stay low. Do not make short circuits on purpose.

 

If you want to know if the output is being pulled up then:

1). Save the state of the output pin.

2). Turn output to input.

3). Maybe wait a us or so (a few "nop's " will do).

4). Turn the pin to ouput again.

5). Restore the saved pin state from 1.

 

Notes:

This might introduce glitches every time you check the state of the pin. (Maybe add a capacitor).

Depending on the external circuit and if you use interrupts, you might want to make these 5 steps "atomic".

 

That said.

Above is a direct answer to you question.

I usually want to look a level deeper (Like Jim).

What kind of circuit are you controlling?

Why not use a separate i/o pin?

If you tell us what your master plan is (schematic?), maybe we can come up with better ideas.

 

Doing magic with a USD 7 Logic Analyser: https://www.avrfreaks.net/comment/2421756#comment-2421756

Bunch of old projects with AVR's: http://www.hoevendesign.com

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

kk6gm wrote:
I kind of doubt you need to do what you say,

Sounds like a classic case of: http://www.catb.org/~esr/faqs/sm...

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I assume that there is a circuit on PB1 that must be brought to 3.3v in order to ensure its correct configuration, initialization, and/or operation.

  I would isolate this from PB1 with a hex switch such as a 74HC125 or 74HC126 buffer.   This is a three-terminal gate switch that allows the output side to see the logic on the input side when the enable pin is in activated mode.  Activated mode is logic low on the HC125 and logic high on the HC126 (confirm on the data sheet).  When not activated, the output side sees a high-impedance "wall" and will always allow the external resistor to pull the circuitry to logic high.  There are four of these gates in each HC chip package. 

 

I use the 74HC125 on the Arduino serial line when using MIDI. It functions as an alternative to a softwareSerial UART.  At power up, the AVR port pins go to logic high (no pull-up) mode.  This ensures that the gate is not activated (the input logic is not reflected on the output) and that the Arduino can utilize the boot-loader without being disrupted by any signal on the MIDI IN port (which is sharing the AVR RX line with the bootloader).
 

Last Edited: Sun. Nov 26, 2017 - 12:22 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for all the feedback guys. Really appriciate it. 

 

This is a true case of stupidity from my side. I'm going to add an OR gate to make sure I get the right result. 

 

Thanks again. 

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

If you don't want to add aditional component to the design and you still have a free pin you can use it.

For example use PB1 for output (DDRB is 1 for PB1) - switching it high/low in the main code. Then use PB0 for input (DDRB is 0 for PB0):

 

if PB0==1 (internal pull-up active and button/switch is driving it to GND)

   then normal operation

elseif PB0==0

   PB1 = 1 (force output to high state)

   and ignore rest of the main procedure

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

@lovepie

 

You could achieve what you need with one diode and one resistor in addition to your push button switch.

 

Connect the diode anode to your PB1. The cathode goes to one side of your switch and to the external circuit and to one side of a grounded resistor (eg 10K). The other side of the switch goes to your 3.3 volt  Vcc. When the switch is open, the external circuit's input is pulled low by the resistor except when PB1 is high.

Ross McKenzie, Melbourne Australia

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

In other words, an OR gate using diode logic, but you don't need the diode on the push button input (doesn't hurt either).

 

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

If you post a schematic of your project, and a description of your goals, there might well be multiple options.

 

JC

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

just place a 100k pull down resistor to PB1.

and use the DDR register to control the level.

as output it should be high.

as input it will be low (make sure of that the internal pull up is disabled).

if you push the button it will be high.