1
\$\begingroup\$

How can I control voltage level on a specific pin in PIC18F? Let's say then I want to send about 0.6V to transistor base. But I cannot use a voltage divider. I need to control output voltage by my PIC18F (PIC18F2525).

\$\endgroup\$
  • 1
    \$\begingroup\$ Is this a programming problem? It sounds like you just need a resistor, which is clearly a hardware issue. \$\endgroup\$ – Gabe Mar 13 '11 at 7:40
  • \$\begingroup\$ It is programming issue. I know that I can use PWM in some way. Let's say that I want to achieve a fading LED effect via change the output voltage level (using timer modlue). \$\endgroup\$ – sennin Mar 13 '11 at 7:45
  • 1
    \$\begingroup\$ So you need software control over the voltage output. Are you asking how to do PWM? Or do you know how to do PWM and are asking for other solutions? \$\endgroup\$ – Gabe Mar 13 '11 at 7:49
4
\$\begingroup\$

You don't actually want to send 0.6V to the transistor base. $V_{BE}$ will vary a good deal between various transistors, so you won't get a well defined current through the transistor if you set it to 0.6V.

The standard way to bias a transistor is by sending a small amount of current through it. Let's assume you're working with a MMBT3904, and want to send 30mA through it. Get the datasheet, and find the graph which relates $h_{FE}$* and $I_C$ (Line 2 is at $25^{\circ}{\rm C}$):

Ic vs hFE

$h_{FE}$ is about 140, so you need to send $214\mbox{ }{\mu}A$ through the base:

$$\frac{I_C}{h_{FE}}=\frac{30\mbox{ mA}}{140}=214\mbox{ }{\mu}A$$

Note that this parameter isn't precisely defined (that's why they used a graph), is temperature dependent (that's why there are three lines in this figure), and varies with $V_{CE} (as indicated by Figure 3). However, it varies a lot less than $V_{BE}$.

There are many circuits to perform the task of sending a small current through the base. Basically, every way you can connect resistors to $V_{CC}$, GND, and $V_{EE} (if a negative supply is used) has a name. Wikipedia has a good article, but my college course spent a good two weeks talking about these different modes, so don't be discouraged if you don't get it in the first pass. I'll explain the simplest circuit (fixed bias) here.

The schematic looks like this:

fixed base with microcontroller driving base

$R_L$ is your load; if you need to connect your load to ground, use a PNP and invert everything.

When you drive pin 5 into a low or high-impedance state, only a leakage current will flow through the collector. According to the datasheet, this value is $I_{CBO}=50\mbox{ }nA$ with $V_{CB} = 30\mbox{ }V$. When you drive it high (say, $3.3\rm V$), there is a voltage established across $R_B$ and the base-emitter junction of the transistor. This is an N-P silicon junction, very similar to a diode. It has a similar voltage characteristic - According to Figure 4 of the datasheet, it will be about $790\rm mV$, but that will vary as we've said before. But $800\mbox{ }mV$ is close enough for our purposes. We need to find the value of $R_B$ that gives a current of $30\mbox{ }mA$:

$$ I_C = h_{FE} * I_B = 140 * \frac{ 3.3\mbox{ }V - 0.8\mbox{ }V }{R_B} $$
$$ R_B = \frac{140 * ( 3.3\mbox{ }V - 0.8\mbox{ }V ) }{I_C} $$
$$ R_B = \frac{350}{I_C} \rightarrow 11.66\mbox{ }k\Omega $$

An $11\mbox{ }k\Omega$ 5%, 2%, or 1% resistor should do nicely!

* - $h_{FE}$ is roughly synonymous with $\beta$, so you may see both values in datasheets. $h_{FE}$ usually refers to the quiescent/DC state of the transistor, while $\beta$ is used when working with small-signal/AC currents. They both denote the ratio of base current to collector current.

|improve this answer|||||
\$\endgroup\$
1
\$\begingroup\$

Some PICs have built in low resolution DACs that you can use. Check the datasheet!

|improve this answer|||||
\$\endgroup\$
1
\$\begingroup\$

If you need to supply a digital signal to a transistor base of 0v or 0.6v, use a resistor.

If you want to provide an analogue output, you need to use an external DAC (Digital to Analogue Converter) (some PICs may provide these internally). You can make a simple DAC with a resistor ladder and several digital output pins. The more pins you use, the more bits of resolution you'll get.

If you want to control the brightness of an LED you can rapidly toggle a digital signal and modulate the width of your pulses. This is called PWM, Pulse Width Modulation. Because we humans cannot see the rapid pulses, we perceive them as a continuous analogue output.

|improve this answer|||||
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.