PIC and NPN transistors

Hello,
This will probably be one more of my newbie questions, but I'm stuck and don't know where to go. Here's my problem:
What I'm trying to do: Control the flow of an R/C servo signal. There is one connector in my board (CN1) where the PWM signal and GND comes from the R/C RF receiver and goes straight to CN2, which is connected to the actual R/C servo motor. Sometimes I want the signal to go straight from CN1 to CN2, and some other times I want to cut that path using a transistor and feed CN2 with a PWM signal generated by the PIC.
What I'm using: PIC 18F452 and MMBT123S NPN transistor (and other components not relevant to this problem). Port D4 is connected to the base pin of the NPN (link below). CN1 PWM signal is connected to the collector pin of the NPN transistor, and the emiter pin is connected to the CN2 output connector. In an earlier test I had a 2.2K in series between PORTD.4 and the transistor base, but results were the same.
What happens: When I set D4 low, I see the PWM signal on NPN collector (0V to 5V), 0V on NPN base and 0V on NPN emiter (as expected). When I set D4 high, things get weird. The PWM signal from the R/C receiver turns into a 1.2V to 1.3V signal (I can still see some PWM in there), the NPN base (PORTD.4) follows the same 1.2/1.3V signal that is in the collector, and the emiter has the same signal shape, but 0.8V to 0.9V instead.
Assume: That I'm setting TRISC to 1 and PIC is working fine (at least for other things).
http://www.diodes.com/datasheets/ds30292.pdf I read the transistor datasheet 10 times already, but there are some terms in there that I cannot comprehend.
Am I experiencing another impedance mismatching problem? I thought that transistors were exactly to solve that. Any alternative solution for what I'm trying to do?
Cheers and TIA
Padu
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Sorry for the top post, but I read what you wrote and I'm still not sure I know what you are doing and why.
(This discussion covers bipolar transistors, not MOSFETs, and depending on NPN or PNP, the current flows in different directions.)
First, a bipolar transistor is not a switch, it is a current amplifier. The beta characteristics of the transistor define the amount of current flowing from the emitter to the base allows current to flow from the emitter to collector.
For a bipolar transistor to work, a forward bias has to exist between emitter and base. It is typically about 0.6 volts minimum. The emitter and base form a diode. Once current flows from emitter to base, the forward bias also allows current to flow to the collector.
Is your PWM signal powered high, low, or both?
Padu wrote:

Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
"mlw"

I understand now...

The PWM signal is a regular R/C servo signal that goes from 0V to 5V. By reading Dan Michaels post, yours and a few other posts from the piclist, I realized that a NPN transistor is definitely not appropriate for this application. I'll test how it works out with an AND gate... and I'll go back to the basic electronics books.
Cheers
Padu
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Padu wrote:

I've been following the conversation a bit. Just out of curiosity, what kind of drive current do you want? Sourcing and sinking current? Sort of like 1/2 of an h-bridge?
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
"mlw"

Since we're talking about the signal line of an RC servo, a few miliamps. The drive current for the servo is on another wire. I've sourced the signal line for RC servos with a PIC and it works fine. I've just finished a few more tests, see the results on the bottom of this thread.
Cheers,
Padu
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Hi Padu. From what I can follow, you have essentially built an emitter follower, with CN2 following D4 [which is not what you want], and which is not operating properly due to CN1 going to 0v bobbling up the operation.
What you want is a switch instead. Replace the NPN with a PNP transistor [2N3906], and tie the base to D4 through a 1-5K resistor. Connect the "emitter" [not the collector] to the input side CN1, and the collector to the output side CN2. Now, when D4=hi, the switch will be off. When D4=low, the CN1 signal should pass through to CN2.
Since the signals are digital, you can also simply use a TTL or HC And-gate.
A very simple means, which would probably also work, would be to just use a 1K resistor from CN1 -> CN2. Then connect D4 directly to CN2. When D4 = hi-Z, CN1 passes through. When D4 is configured to output, then CN2 will follow D4 directly, and the signal coming in from CN1 will be overridden by D4.
The downside to this route is that you are loading down the CN1 pin out of the receiver with an effective 1K load. You cannot use a much larger R than 1K since the input impedance of the typical servo is about 10K.
- dan michaels www.oricomtech.com ==================== Padu wrote:

Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
"dan michaels"

Thanks for the complete explanation and all the pertinent suggestions. I think in my case, the AND gate makes sense. Is there any disadvantage on using it? Can it switch fast enough to let a servo PWM pass through?
Since I already have the pads for the NPN, it may be possible that I can find an AND gate in the same package and simply replace the component without having to redesign my board or using a dead bug...
Cheers
Padu
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Padu wrote:

'HC And gates will switch at Mhz rates. Will be at least a 14 or 16-pin DIP package.
However, you can stick the PNP transistor into the NPN pads, just get the emitter and collector pins correct. Emitter towards CN1 input side. Be sure to include the base series R.
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Padu wrote:

R/C servo PWM is extremely slow. Even vacuum tubes can keep up with it.

Is the board made yet? If so, I have a feeling some rework will be needed any way you go. You could make an AND gate out of two NPN transistors and some resistors, but Dan's method (which I've never tried) sounds good, too, though it may mean turning some leads.
Perhaps you could just make a daughter board using a standard 14-pin AND gate package (SMC would be smaller), and solder it into the pads you have for the transistor? Gateway in Clairmont Mesa sells surface mount adapters, or you can get them from Mouser, which is local to you as well.
If the board's not made yet, you could probably sneak in an 8-pin SSOP AND gate package in about the space of a standard signal transistor.
-- Gordon
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
From: "Gordon McComb"

I got a 14 pin AND gate here in the office and I'll try it tonight and test the concept. (yes, the board is done.... I know I know... prototype first). If it works and there's enough room to dead bug it, (it's a DIP), then I'll do it. Otherwise I'll get a dual gate (I'm "gateing" two PWM signals) in a SOIC8 package and dead bug it. It won't be pretty I know. If I have to redo the board some day....
Thank you guys for all the hints!
Padu
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Padu wrote:

If you're gonna try an And-gate chip, 'HC is better than TTL, unless the TTL gate has a totem-pole output. You'll get better rail-to-rail output transitions with HC.
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
"dan michaels"

Yes, the one I'll test is marked CD74HCT08E. I'll let you guys know after I test it tonight. Now, from the discussions, I assume it is ok for the AND gate to have voltage on its Y pin when the output is low, right?
Cheers
Padu
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Padu wrote:

Maybe not. You might want to look at the Phillips (etc.) datasheets for the 74HC family. Some folks use a diode on the output to prevent possible problems.
-- Gordon
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
"Gordon McComb"

Ok, just finished soldering the AND gate to my board. It works, but I can see that there's still something wrong with it and perhaps it is related with the interaction of the AND output (y) and the PIC output pin.
So now when I set the control leg of the AND gate low and output the pwm signal from the PIC to the servo, the waveform is correct and voltages are correct (0-5V). When I set the control leg of my AND gate high and stop generating the pwm signal from the PIC (the pin is still defined as output and I leave it low), the PWM signal coming from the RF receiver to the other leg of the AND is fine (both waveform and voltage), but the AND output is not completely fine. The waveform is correct, but the amplitude drops to 0V to 1V. Amazingly the servo still works fine, except that I feel it a little jittery when moving the joystick up and down, and it doesn't hold torque as it used to.
Do you think that since the PIC output pin and the AND output are connected without restrictions, it may be sunking the voltage out of the AND gate?
Cheers
Padu
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Padu wrote:

Generally it's not a good idea to tie two outputs together if they don't have hi-Z states, or you aren't steering their logic. Since you have control over the state of the pin on your PIC, I think the most straightforward thing is to make the pin an input during those times.
-- Gordon
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Padu wrote:

This is a bad idea, you should OR them together, you might be able to use two diodes.

Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
"mlw"

Thanks mlw and Gordon. Yesterday I realized that. Setting the PIC output pin to input solved one side of the problem, and when the pwm signal is being sourced by the RF receiver (and going through the AND gate), signal is perfect (both waveform and amplitude). Now when I closed the AND gate and started making the pwm signal from the PIC, I guess the AND gate loaded the signal, since the amplitude dropped to 0-1V. Next thing I did was to include a diode on the AND output. That solved the problem for the PIC output, but screwed the AND output. Now the AND output amplitude goes from 4V (low) to 5V (high), and the falling edge of the square wave is rounded.
My next step is to do what mlw suggested and OR the signals together... I feel that I'm getting closer.
Cheers
Padu
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
It's getting more complicated, but here is a suggestion if you have either a couple free I/O lines to use as enables, or 1 free I/O line and an inverter. Just and the PIC and enable 1 and and the RC and enable 2 Then use a couple diodes to connect the 2 and a pullup resistor.
_____ /_\ PIC_PWM-------------| \ | / | / | AND |----------| |-------------| \ 10k pullup Enable1----------------|_____/ |\ | | / | \ out to servo _____ |---------------------------- RC _PWM-------------| \ | / | | | AND |----------| |-------------| Enable1----------------|_____/ |\ |
If you have an inverter (make one using a transistor then enable1 can also be Not_enable2
Ringo
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
looks like my beautiful ansi artwork got mangled. There is a diode following each AND gate. Those are connected together and then a pullup to Vcc. Ringo
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Here is an even better idea (I think). Use a NAND gate _____ PIC-------------------| | |NAND |---- en1------NAND_INV-----|_____| | ____ | ---| | | ____ |NAND|------------out ----| | |---|____| |NAND|----- RC--------------------|____|
This way you use 1 enable and all 4 gates from a NAND chip and no diodes or pullups. Just tie the 2 inputs together on a nand gate to make a NAND inverter. Ringo
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

Polytechforum.com is a website by engineers for engineers. It is not affiliated with any of manufacturers or vendors discussed here. All logos and trade names are the property of their respective owners.