Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Driving 12V relay with 8051 + opto isolation suggestions for RS485

Status
Not open for further replies.

makjee

Newbie level 6
Joined
Sep 5, 2011
Messages
14
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,425
Hello everyone, its my first post here. I have two separate issues in which I require your input, thanking you in advance. Low powered design is not a priority in this prototype.

1. I have a relay JQC-3F, 12V relay which has an internal resistance of 400 ohms at 12V meaning the drive current required to run the relay is 30mA. I selected a single 2N2222 which has a gain (hFE) of 75 at IC = 10mA and VCE = 10V and considering that I am passing 30mA from the collector I even selected hFE = 50 in calculating the base current which comes out to be 0.6mA. I connected the base of the 2N2222 using 330 Ohms resistor with 8051. Also I noticed that I was getting -1.75volts on the base when the 8051 was not inserted in the socket so I connected the base of 2N2222 with ground via another 330 Ohms resistor. Now the typical problem, if I dont have 8051 in the socket and manually give 5V using a jumper, the current consumption increases by 30mA and relay works. But as soon as I insert 8051 and program it to apply 5 volts to P1 (where 2N2222 is connected), the relay doesnt drive.

1a. What I dont understand is that if the absolute maximum rating for DC current for 8051 is 15mA and I am giving 7.5mA on one pin (5V/(330ohm+330ohm)) then why isnt a single relay being driven comfortably?
1b. Why must I resort to a darlington pair based transistor.
1c. Also please look at the schematic I provided and suggest if I can replace 2n2222 with a single package of transistor/darl. pair which will make me desoldering easy.

2. My second question is related to RS485. I am using SN75176 for receive and transmit, I am using two separate ICs (I want it that way). There is a master RS232-RS485 converter which sends the data to this slave (of which I have attached the schematic). The slaves turns the relays on and send ack back once feedback is achieved. The RS232-RS485 etc is working fine. The problem is... I have to have common ground for both master and slaves. In reality the master and slaves will be around 400 meters apart. I would like a local power supply for both master and slave without having to run the 400meter ground cable. So can you please advise as to how should I connect opto couplers to my RS485 cables to ensure battery/power isolation and complete working. (RS485 termination resistors will be changed to 100 ohms once I start testing on 400m cables ;-))

thank you and sorry for making you read the essay

View attachment rRLYDRV_RMT.pdf
 

330 Ohm to ground is not a good value, try with 4.7k, also 2N2222 is not really for this - will work no question about that, but better try BC547 or other similar general purpose transistor that is rated 100mA or more ... up to 1A, more than that is just waste ... also 330 Ohm to base is a bit low value - I would do it with 1k to the base and 4.7k or 10k to GND, simple calculation example - 5V and 1k is 5mA, most general purpose transistors have gain over 100 for DC current, so with 5mA base current you have 500mA collector - emitter current.

Also RLYxFB - 5V -> 1k -> GND this make no sense at all as your RLYxFB is shorted to GND.

RS-485 is differential and should not need ground reference, just twisted pair :), and take care for good protection circuit at front end.

try and post result :) hope this will solve it.
 
Last edited:
  • Like
Reactions: makjee

    makjee

    Points: 2
    Helpful Answer Positive Rating
thank you Zesto velkov, I will look the IC up, but what velkov is suggesting is that a twisted pair cable is sufficient and I do not need to make the ground common at master and slave. I will definately try that and post the result of running master and slave on separate power supplies with only thing connecting them is the twisted RS485 pair. If that is the case that I do not need the common grounds, it will be great stuff.

@ velkov: Also RLYxFB - 5V -> 1k -> GND this make no sense at all as your RLYxFB is shorted to GND. I should had explained this, actually, the its a 5 vol pull up through 1k. Feedback of relay turning on makes the RLYxFB signal to GND. Its a mistake in schematic, which I fixed in the actual circuit. There is no GND with RLYxFB signal. Sorry about that.

@ velkov: let me try the 1k and 4.7k combo tomorrow without removing 2n2222, if that works, I will be a happy man :)

---------- Post added at 03:12 ---------- Previous post was at 03:05 ----------

and take care for good protection circuit at front end.
I am greatly intrigued by what you mean to say here :), please enlighten
 

ok, I have checked out the suggestions. firstly RS485 handles the communication without the requirement of common ground which is good. So no need for opto isolation required in my opinion. Secondly the npn driver does not work with the combination of 1k and 4k7 resistors. I guess I will have to resort to BC547 or ULN2803 based implementation.. .
 

You can actually do this by calculation. To guarantee that a transistor is saturated you need to drive the base of the transistor with a current that is 10x the base current based on the gain of the transistor. (There is some discussion on whether 10x is overkill, but let's leave that for the moment.) In other words, if you need a collector current of 30mA and the transistor gain (worst case) is 50, in a linear state the base current must be 30/50 = 0.6mA. To guarantee staturation you need to pump 10x this into the base that is 6mA. With a 2.4V output (VOH in the data sheet) this would need a resistor (2.4-0.6)/6=300R. The resistor from base to ground is unecessary. It is only required to speed up the switching of the transistor, and since you are switching a relay, this is unlikely to be a problem.

That would be well and good on any device with an active output. I don't know this variant of the 8051 but the data sheet suggests that it is the same as a vanilla 8051 and the output is basically a pullup resistor of 20K if I remember correctly. (Note the current the 8051 is capable of supplying at the 2.4V is 60uA, dropping to 10uA at 4.5V.(using this as the basis for the calculation, it is a 33K pull up resistor)). In essence connecting this to the base of the transistor will only ever manage 5/20K= 0.25mA at an extreme case and you will never turn the transistor on. You will probably have this problem even if you use a ULN2803. It is possible to add a pullup to 5V in parallel with the output to reduce the overall pullup resistance (increasing the base current) but you have to be sure that the micro can sink the resultant current when there is a zero output. Of course the higher the effective gain of the transistor, the less base current that you need and why the ULN2803 may work.

All in all you would be better off with a logic compatible N-Channel mosfet, where you may not need any resistors. Perhaps a pull up to improve the gate voltage. Sometimes a series resistor to the gate of the mosfet is used to reduce the effect of the gate capacitance on the output. This tends to slow the switching of the transistor, but for a relay this again is not a concern.
 
Last edited:
  • Like
Reactions: makjee

    makjee

    Points: 2
    Helpful Answer Positive Rating
If the current is too low to turn on the transistor to take sufficient current, then you can use a darlington pair. Darlington transistor - Wikipedia, the free encyclopedia

So, if, your transistor has hfe = 75 (worst case scenario), then the overall gain is 75*75 = 5625. So, with 60uA, you can drive 60*5625 = 337500uA = 337.5mA

Hope this helps.
Tahmid.
 
  • Like
Reactions: makjee

    makjee

    Points: 2
    Helpful Answer Positive Rating
So, with 60uA, you can drive 60*5625 = 337500uA = 337.5mA

The whole point of switching transistors is when they are on they should be driven to saturation. Now if I remember correctly, the second transistor
in the darlington pair never saturates, which is why the on voltage is ~1.2V. But what you are suggesting will result in the pair entering the linear region at that sort of collector current.

The o/p suggests using a ULN2803 darlington driver. It has a gain of 1000 (ST data sheet). It calls for an input current of 1.35mA to guarantee it is on (for the 250mA output which I extract from the Vin requirement). By your rationalization the base current should be 250/1000=0.25mA. You can see that it must be overdriven to meet the specs.

In truth, since the o/p only needs 30mA it will probably work, but advice should be based on theory and data in the datasheet. In that way you can guarantee that the product will work under all circumstances and with variations in production lots.
 
  • Like
Reactions: makjee

    makjee

    Points: 2
    Helpful Answer Positive Rating
hi makjee,
actually it should work with 1k and 4.7k, if it works with shorted 5V to 1k resistor - it should work also with the micro controller. if it doesn't - you have to check the microcontroller settings, the port that you are using, etc.
try to measure the voltage on the pin, try to measure the current, make sure that your pin is stable ON or stable OFF and measure both cases
you can try also to replace 4.7k with 10k, when you drive from the micro always drive 0 or 1, never make it input, i.e. hi-z state and it should be OK
 
  • Like
Reactions: makjee

    makjee

    Points: 2
    Helpful Answer Positive Rating
Thank you for the suggestions every one. I did some working over the past days and this is what I have concluded, RS 485 works fine without common ground connection between transmitter and receiver. Secondly, the microcontroller was able to turn the relay on when I applied 2N3906 or a general purpose PNP which was driving the 2N2222 transistors. The base resistance was selected as 4k7 so the microcontroller (AT89C51) was able to sink 1mA on each pin which is good enough since C51 can sink upto 15mA on three of the ports which I am using. So my problems are solved regarding this issue, thanks
 

This is good, except for good engineering design you still have to ensure you are drawing enough current out of the base of the PNP to ensure it in in saturation as well (in all conditions where the design is used). On the assumption that you are pushing 6mA into the base of the NPN, this makes the collector current of the PNP 6mA. At 6mA the gain of the 2N3906 is a minimum of 80. In the linear zone the base current of the PNP would be 6/80=0.075mA. As before, setting the base current to 10 time this is 0.75mA and so your 1mA is perfect!
 
  • Like
Reactions: makjee

    makjee

    Points: 2
    Helpful Answer Positive Rating
Thanks for solving the previous problem, now I want to continue the same hardware with more professional look. I have decided to include opto couplers to avoid relay switching noise and isolate the microcontroller section. I have designed the hardware, with attached schematic. The isolated part has separate bridge+filter cap+ regulators and the digital side will have its own set of bridge+filter+regulators. The input source is single phase AC supply which is same for both the AC to DC converters. Please see if I am on the right track and what considerations I should have
 

Attachments

  • rRLYDRV_RMT_V2.pdf
    319.1 KB · Views: 110

your schematic look ok, but I want to challenge with the following question - why do you need to isolate the noise from relays? your schematics currently consists of micro controller, digital comm, relay drivers and input that is isolated with optocoupler - I don't see any noise sensitive parts that you need to isolate. but this is just a question, otherwise the schematics look OK.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top