BS170 Mosfet with PIC Microcontroller
Moderators: Sparky, Moderators
BS170 Mosfet with PIC Microcontroller
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?
http://i188.photobucket.com/albums/z301 ... cuit_2.jpg
Am I wiring up the BS170 incorrectly?
- Mr. Engineer
- Posts: 440
- Joined: Mon Dec 10, 2007 6:01 am
- Location: Malaysia
- Contact:
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.
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.
- Mr. Engineer
- Posts: 440
- Joined: Mon Dec 10, 2007 6:01 am
- Location: Malaysia
- Contact:
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.
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.
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?
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?
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?
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?
- Mr. Engineer
- Posts: 440
- Joined: Mon Dec 10, 2007 6:01 am
- Location: Malaysia
- Contact:
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.
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.
- Mr. Engineer
- Posts: 440
- Joined: Mon Dec 10, 2007 6:01 am
- Location: Malaysia
- Contact: