Sunday, 12 November 2017

microcontroller - Attaching a LED to PIC's Rx pin


I need some way to know whether the microcontroller (PIC) is receiving (or transmitting) any data. So I thought of keeping a separate LED so that it'll blink when any data transfer occur.


But I need to know how to attach this LED. Is it OK to directly attach an LED to PICs Tx (and Rx) pins? I mean will it affect the transferring data in some way (like by dropping out the voltage etc...).



Answer



(At least some) PICs can't drive much current(*), but also for the RxD pin you better use a transistor to drive the LED, since you'll avoid loading the transmitter at the other end (probably a MAX3232 or similar?).


enter image description here



Connect the input "Q" to the TxD/RxD line. A typical general purpose transistor will have a gain of about 100, then 1 mA base current is enough to get 20 mA collector current.


For a 5 V bus and power supply:
choose \$R_B\$ = 3.9 kΩ, then the base current will be (5 V - 0.7 V)/ 3.9 kΩ = 1.1 mA. To limit the collector current to 20 mA (typical indicator LED) \$R\$ should be (5 V - 2 V)/ 20 mA = 150 Ω.


For a 3.3 V bus and power supply, use the same equations, replacing 5 V by 3.3 V, then your resistor values will be 2.2 kΩ and 47 Ω resp.


A MOSFET like AndrejaKo suggests is a good alternative, but make sure you have a logic level gate type, with a maximum gate threshold voltage somewhat below the bus voltage. (There are logic level gate FETs where that can be as high as 4 V and then you won't get enough drain current with a 3.3 V bus voltage.) The real advantage of the FET is that it needs hardly any drive current, but since we only need a mA for the BJT we won't have any problems with that either.




(*) This random PIC controller specifies a 700 mV drop at only 3 mA output current, that's a 230 Ω output resistance. A 2 V LED directly driven from a 3.3 V output will drop the output by 1 V at only 4 mA. Most indicator LEDs are specified for 20 mA.


No comments:

Post a Comment

arduino - Can I use TI's cc2541 BLE as micro controller to perform operations/ processing instead of ATmega328P AU to save cost?

I am using arduino pro mini (which contains Atmega328p AU ) along with cc2541(HM-10) to process and transfer data over BLE to smartphone. I...