Sinking Current

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

Hi,

 

I am trying to sink current on an I/O pin on an ATmega324P, to turn a P FET on.  After reading the datasheet I note I can only sink 40mA max.  

 

* When I set the I/O pins to sink mode,  DDxn = 1, and PORTxn = 0, my usart stops working, but the FET works.  Page 74.

 

* When I set the I/O pins to input pull-up, DDxn = 0, and PORTxn = 1, my usart works, but my FET does not work.  Page 74.

 

my question is, other than setting DDxn, and PORTxn, do I need to set up any other registers to enable sinking.  It seem odd why the usart stops working?

 

Thanks,

 

Tuurbo46

 

 

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

Why do you need to sink 40mA? If you are driving the gate of a FET, the sink current should be VERY small?

 

What pin are you trying to do this on? Expressions DDxn and PORTxn do not tell us anything about the pin which is where likely UART conflict might be.

 

Jim

 

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

 

 

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

ka7ehk wrote:
If you are driving the gate of a FET, the sink current should be VERY small?

Agree, and sort of calls for a schematic from the OP.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

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

Tuurbo46 wrote:

...to enable sinking...

 

You don't 'enable sinking'. Unlike the 8051 the AVR outputs are always driven active-high/active low. As Jim says, more info on what pins we are talking about and some info on how your UART is connected. Also, how is your power connected?

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

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

Micro is a ATmega324P TQFP

 

I have selected a NX2301P FET configured as VSG

 

I am trying to switch 3.8V 1.5A from a battery to my device.

 

FET wiring

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

 

* pin 1, Gate, this connects to PD5 I/O pin (this has a 1k resistor in series)

 

* pin 2, Source, this connects to a 3.8V battery (connected to pin 1 with a 100k)

 

* pin 3, Drain, this connects to the device I am trying to power.

 

* MCU supply voltage 3.3V

 

Test 1) MCU I/O set as input and internal pull-up, S = 3.8V, D = 2.16V, G = 3.48V // why does D not equal 0

 

           This test the usart works, the commands are out putted cleanly to terminal. 

 

Test 2) I/O set as output, logic 0, sink mode,        S = 3.8V, d = 3.8V, G = 18mV

 

             This test the usart partly works, the commands stop mid sentence.

 

USART pins

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

 

* TX PD1

 

* RX PD2

 

The Usart uses an external RS232 breakout board, so my Tx and Rx wires go to the edge of the board and use a header.

 

 

My conclusion is either I am configuring the FET wrong or I have blown my device chip.

 

Oh and I have charged both of my batteries to full capacity, to confirm that is not the problem. 

 

look forward to your input.

 

Tuurbo46

 

 

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

Can you show the smallest example code which demonstrates the problem? It *feels* like you're not controlling the port properly.

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

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

Hi Brian,

 

In short this is how I am turning the FET on and off.  I understand it can only sink on an output, and not an input.  In my code I want to be able to turn the FET ON and OFF.  Are the below examples correct.

 

Thanks Tuurbo46.

 

* Turn FET ON - PD5 I/O Pin:

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

 

DDRD =  0b00100010; // (0, 0, FET_ON, 0, 0, 0, TXD0_OUT, RXD0_IN)

PORTD = 0b00000000; // (0, 0, FET_LOW, 0, 0, 0, 0, 0) 

 

 

* Turn FET OFF - PD5 I/O Pin:

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

 

DDRD =  0b00100010; // (0, 0, FET_OFF, 0, 0, 0, TXD0_OUT, RXD0_IN)

PORTD = 0b00100000; // (0, 0, FET_HIGH, 0, 0, 0, 0, 0) 

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

Why not leave the pin as an output and just make it high or low by changing the bit in PORTD. You don't have to change the pin direction! How about a bit of real schematic?

 

Jim

 

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

 

 

Last Edited: Sat. Mar 12, 2016 - 10:50 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ka7ehk wrote:
You don't have to change the pin direction!

According to the code snippets in #7, he's not.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

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

Ugh, the OP has two different constants, FET_OFF and FET_ON while the bit pattern for DDRD does not change. 

 

Jim

 

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

 

 

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

I'd be interested to know the answer... On paper, driving a small MOSFET should be easy, you set an output pin high or low as required. The gate looks rather like a capacitor to the MCU, on large MOSFETs there can be significant current required to charge/discharge it, but in this case with a small MOSFET there should not be a problem. The 1k series resistor on the gate should limit the current to a few mA.

 

I can't see how driving the MOSFET would affect the UART - it should be unrelated. I am assuming the MOSFET is switched on once and not PWMed, that might cause some effects. It seems more logical that there is something else in the circuit, or maybe the software, that is causing weird behaviour with the UART.

Bob. Engineer and trainee Rocket Scientist.

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

A few thoughts...

 

1) Have you got all 4 GND pins of the AVR connected to your 0v rail?

 

2) Have you got all 4 VCC pins of the AVR connected to your 3v3 rail?

 

3) Is the 0v rail for your load connected to your 0v rail for your AVR?

 

4) Do your really want to use TX on one USART and RX on the other?

 

5) Have you got at least 2 100nF capacitors and a 100uF capacitor connected somewhere close to your AVR?

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

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

OP

 

Test 1) MCU I/O set as input and internal pull-up, S = 3.8V, D = 2.16V, G = 3.48V // why does D not equal 0

 

The FET is somewhat 'on' due to the 3.8 V on the source vs the 3.3 volts on the gate. (And if it is a battery, might be >3.8V and unless you have a way cool uC, <3.3V on the gate.) Looking at the data sheet, the Vgs(th) could be as low as .5V. So, basiclly the FET is never 'off'.

 

Common design is to pull the gate of the FET to the source voltage with a high resistor and then use a transistor to pull the gate low.