You are on page 1of 3

microBuilder.

eu

Login
Register

Open Hardware and Micro-Manufacturing Made Easy(er)

Home

Tutorials

Components

Projects

Blog

Forums

Store

Search

Tutorials > LPC2148 QuickStart Guide > Lesson 2 - Basic Input and Output (GPIO) > Example: Safely Toggle >4mA Devices

Example: Safely Toggle >4mA Devices with GPIO


Using a MOSFET to safely work with devices that draw more than 4mA of current

Looking at the datasheet for the LPC2148, w e can see that the GPIO pins on the LPC2148 -- in fact the entire LPC2000

LPC2148 QuickStart Guide


Getting Started
Basic Input and Output (GPIO)

fam ily -- can only safely supply or sink (pull to GND) a m axim um of 4m A each (see "HIGH-level output current" and

Example: Softw are Debouncing GPIO

"LOW-level output current" on page 27), and the MCU itself is limited to a total of 300m A (100mA "supply current per pin" x 3

Example: Safely Toggle >4mA Devices

available supply pins). Since even something as basic as an LED typically draw s around 20mA, this 4mA upper limit is much
too low to safely hook up most devices directly to a GPIO pin ... especially if w e are using several such devices on our board.

Analog Input (ADC)


Example: LV-MaxSonar-EZ4 Range Finder
Example: Nintendo DS Touch Screen

While you can almost certainly get aw ay w ith hooking one or tw o 20mA LEDs directly to a GPIO pin --

PINSEL: Selecting Pin Functions

many people do exactly this -- it isn't recommended, and you may w ant to search for an LED that draw s

PCONP: Pow er Control for Peripherals

less current (2ma, 5mA and 10mA varieties also exist).

How do you safely connect a >4mA device to GPIO?


One of the easiest w ays to stay below the 4mA limit on GPIO (and the 300mA limit on the 2148) is by using something called a
MOSFET -- short for metaloxidesemiconductor field-effect transistor (see MOSFET on Wikipedia for all the dull technical
details). While the name sounds complicated, the device essentially acts like a programmable on/off or opened/closed
sw itch: If the 'gate' is open, electrical current enters on one end, and flow s through the MOSFET out the other end causing a
'complete' circuit (and turning your LED or connected device on). If the gate is closed, the electrical current is interrupted and
the device w ill be turned off. The advantage of using a MOSFET is that the current flow s through the MOSFET and not
through the LPC2148. This means that you can safely use GPIO to turn on or off devices that require fairly large amounts of

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

electrical current, w ithout overheating or risking damage to your MCU. (The 'gate' on the MOSFET is exceptionally sensitive
and requires almost no electical current to 'open' or 'close' it.)
While there are tw o main types of MOSFETs -- N-Channel and P-Channel -- the type that you need to turn something like an
LED on or off is an N-Channel MOSFET. To see how you w ould hook up an LED using an N-Channel MOSFET and a GPIO pin,
take a look at the follow ing schematic:

You should be able to understand fairly easily how the MOSFET w orks in this case. The current is coming from an external
3.3V source (external meaning simply that it isn't coming directly from the LPC2148), it flow s through a current-limiting resistor
(R1, used to protect the LED from burning out), through the LED, and into the MOSFET (Q1). If the 'gate' on the MOSFET is open
(using the GPIO pin that it is connected to on your MCU), the current w ill continue to flow through the device to GND and the
LED w ill turn on. If the 'gate' on the MOSFET is closed, the LED w ill remain off since there is no connection to GND available.

The 2N7002 (surface-mount SOT23 package) or 2N7000 (breadboard-friendly TO-92 package) used in this
example is a common and inexpensive N-Channel MOSFET that serve as good general-purpose device.
They can easily be found online or in any self-respecting electronics store.

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

And that's it. Your code w ill be exactly the same as if you had the LED hooked up directly to the GPIO Pin -- you set the GPIO
pin to output w ith IODIR, using IOSET and IOCLR to turn the LED on or off) -- but you now have a much safer w ay to w ork
w ith high current devices w ithout any risk of damaging your MCU!

Components Used in this Example


While all of the components mentionned above are easy to find, here is a list of the specific models w e used in this example
(simply because it's w hat w e had laying around):

1. LED1 - RED 15mcd 20mA 1206 LED


2. R1 - Current-Limiting 150 Ohm Resistor
3. Q1 - 2N7002E N-Channel MOSFET

Comments

About microBuilder | Contact Us | Privacy Policy | Legal Information and Disclaimers

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

Content 2010 MicroBuilder SARL

pdfcrowd.com

You might also like