BS170 Mosfet with PIC Microcontroller

Ask and answer questions, share tips and resources for installing lighting and other electronics in your models.

Moderators: Sparky, Moderators

Post Reply
RossW
Posts: 198
Joined: Wed Oct 02, 2002 1:04 pm
Location: Toronto, ON

BS170 Mosfet with PIC Microcontroller

Post by RossW »

I'm working on a circuit to drive 4 LEDs of various colours (red, green & 2 white) in parallel and I'm pretty sure that the PIC 12f629 micro controller can't drive that much current directly, so someone hear recommended using a BS170 mosfet as a current booster. I've used it successfully in the past but now I can't get it to work; using this circuit diagram as a guide the LEDs stay mostly on but almost blink off (the circuit is for running lights):

http://i188.photobucket.com/albums/z301 ... cuit_2.jpg

Am I wiring up the BS170 incorrectly?
User avatar
Mr. Engineer
Posts: 440
Joined: Mon Dec 10, 2007 6:01 am
Location: Malaysia
Contact:

Post by Mr. Engineer »

I don't have experience with MOSFETs yet but it looks correct to me. When it comes to such arrangement, I always prefer the 2N2222 personally (because I have a lot in my spares).

Anyway, have you used a single LED & resistor to test the output of the PIC? If it lights up as your requirement, then the next stage would be to check on the MOSFET.


Also, this webpage reiforces your circuit.
What can I take apart today?

https://www.facebook.com/PisceanWorks
RossW
Posts: 198
Joined: Wed Oct 02, 2002 1:04 pm
Location: Toronto, ON

Post by RossW »

Yeah, it all works fine without the BS170.

I also used to use the 2N2222 but I've lost my notes on how to use that - do you have an example?
User avatar
Mr. Engineer
Posts: 440
Joined: Mon Dec 10, 2007 6:01 am
Location: Malaysia
Contact:

Post by Mr. Engineer »

Honestly, I don't have the circuit but its being used for my NCC-1701 board, which I am trying to get all the wires done up asap:

http://www.starshipmodeler.net/talk/vie ... hp?t=98739


The closest I can point you to is here:

http://www.phase4c2.com/pic101/interface.htm
where it is on the third circuit, the Q1 NPN.
What can I take apart today?

https://www.facebook.com/PisceanWorks
RossW
Posts: 198
Joined: Wed Oct 02, 2002 1:04 pm
Location: Toronto, ON

Post by RossW »

Thanks!
RossW
Posts: 198
Joined: Wed Oct 02, 2002 1:04 pm
Location: Toronto, ON

Post by RossW »

I've now got the circuit working with the 2N2222 transistor powering up to 4 LEDs, but something doesn't look right with the flashing and it may be a limitation of the design. The code on my PIC microcontroller has instructions to fade in the LED to maximum brightness using a PWM command inside a loop which increases the DUTY from o to 255:

For DUTY = 0 to 255 STEP 2
PWM LED_1, DUTY, 1
Next

(this makes it look more like and old incandescent bulb ala the TOS Enterprise)

If the 2N2222's gate just activates to allow current to pass from the collector to the emitter, how can it vary the LED's brightness - does it just detect the small amount of current starting with the above PWM command and connect C to E? If so, it won't vary the brightness of the LED.

Any ideas?
RossW
Posts: 198
Joined: Wed Oct 02, 2002 1:04 pm
Location: Toronto, ON

Post by RossW »

A new wrinkle using a 2N2222 transistor ... the duty cycle of the flash is different than when driving directly from the output pin of the PIC.

A programmed a 2nd 12f629 chip with the same code as the one hooked up to the 2N2222 (which has a 10k ohm resistor between the output pin and the 2N2222, btw) and hooked up another LED exactly the same as the one with the 2N2222 and put the circuits side-by-side: they start off flashing at the same rate but slowly get out of sync. If I had to guess, it looks like the circuit with the 2N2222 has a slightly longer duty cycle than the one without. Both are using a 20Mhz oscillator, btw.

I'm trying to get exactly 1.5 seconds on, 0.5 seconds off using a PIC but it looks like I'll need to adjust the timings based on the end result, which kind of sucks. Any help here? Would a MOSFET have less of an effect on the overall duty cycle than a 2N2222?
User avatar
Mr. Engineer
Posts: 440
Joined: Mon Dec 10, 2007 6:01 am
Location: Malaysia
Contact:

Post by Mr. Engineer »

Ah, you're using it for PWM. Although the 2N2222 has a 300MHz switching frequency, I have never used this method before.

I did try PWM last year, and it was using a PIC12F629 with an IRF640 MOSFET. However, I did not note the difference in the duty cycle though. I don't have the MOSFET with me now.


Sorry.
What can I take apart today?

https://www.facebook.com/PisceanWorks
RossW
Posts: 198
Joined: Wed Oct 02, 2002 1:04 pm
Location: Toronto, ON

Post by RossW »

Thanks Mr. Engineer. Are you saying that using the IRF640 MOSFET did not produce a noticeable difference or that you didn't check?
User avatar
Mr. Engineer
Posts: 440
Joined: Mon Dec 10, 2007 6:01 am
Location: Malaysia
Contact:

Post by Mr. Engineer »

Yep. Something like that. The circuit worked as it was intended but we did not 'time' it nor do a comparison with just one LED. Once it sort of worked, I gave it to my friend for his Cosplay project.
What can I take apart today?

https://www.facebook.com/PisceanWorks
Doomgiver
Posts: 49
Joined: Tue Oct 27, 2009 9:46 am
Location: Kiel, Germany
Contact:

Post by Doomgiver »

You have forget a very important part for MOSFETS: The Pull-Down-Resistor between Gate and Ground. 100k-1MOhm Resistor is recommendet.
RossW
Posts: 198
Joined: Wed Oct 02, 2002 1:04 pm
Location: Toronto, ON

Post by RossW »

Doomgiver - that did the trick. I put a 350k resistor between the Gate and ground and all works fin with the BS170. Thanks!
Post Reply