Author Topic: Problem with Digispark/mosfet LED flasher  (Read 8087 times)

Woodsplinter

  • Newbie
  • *
  • Posts: 8
Problem with Digispark/mosfet LED flasher
« on: January 24, 2017, 12:06:11 pm »
I'm not sure if this is the best place to post this so mods feel free to move if necessary.

The project: LED flasher that alternately flashes 2 LED's.

The equipment: Digispark, 2 N-channel mosfets (FQP30N06L), 2 small DC-DC buck voltage regulators, 2 hi-power LED's.

How it should work: Power is supplied from a drone battery via a 30 pin mezzanine connector mounted on a PCB I made along with the other components except for the LED's. Only 5 pins are used. +5V power is supplied to the digispark, and +15 volts to the voltage regulators. Ground is common, although I chose to use a separate pin for each mosfet and the digispark.

Pins 0 and 2 of the digispark are connected to the gates of each mosfet. The drains are connected to the (-) input of the regulators, and the sources are connected to ground.

The regulators are set to output 2.2V to a red LED and 6V to a white one. (Yes, I'm aware that led's should be driven by current controlled regulators which these are not. Because the LED's are only on for 50 ms, I felt this was OK, as there is no build up of heat.)

A sketch tells the circuit to execute a double flash on pin 0, pause, then the same on pin 2. A very simple alternating double flash.

I built a prototype and it works perfectly. I built another, but moved the components around on the PCB to save space. All the connections are identical but prototype #2 doesn't work properly. The red led comes on immediately with power but it should not until the sketch is executed after a 5 second delay built into the digispark. It does not flash nor does the white led.
I can remove all the components from the PCB and hook them up using a bread board and they work fine. I then put only the digispark,  one mosfet, and one regulator (connected to the white led) back on the PCB, and the white led comes on immediately, then begins flashing after 5 seconds.
I checked the digispark and verified it is putting out 5.4V on pins 0 and 2 after the sketch begins.

Because the digispark and voltage regulators all have holes for connections, I connect them to the PCB using pins. The mosfets are soldered in using their leads and do not touch each other in any way, nor do they touch anything else.

I am completely stumped why prototype #1 works and #2 doesn't. The other oddities are also confusing.

NOTE: I have used this configuration in the past using the digispark, 1 mosfet, and 1 regulator driving a 10W LED and it always works perfectly.

Any help will be GREATLY appreciated!

PeterF

  • Hero Member
  • *****
  • Posts: 881
Re: Problem with Digispark/mosfet LED flasher
« Reply #1 on: January 24, 2017, 04:31:30 pm »
If the digisparks you are using on each PCB are exhibiting the same/correct behaviour, then the error must be in the modification to the second PCB.

With the red LED coming on whilst the bootloader is active (the five second delay), have you got pulldown resistors on the mosfet gates? I'm not sure what state the digispark pins are in whilst the bootloader is active, so it is probably best to have a pulldown resistor so the mosfet gates are not left floating/indeterminate state.

As to why it's not working... its hard to tell without being able to see or test the board physically. As I said before, of the digisparks are doing what they are supposed to do, the difference is obviously in the PCB. Have you checked the gate of the mosfet... is it being pulled high instead of low? is it being pulled high even when the digispark is not connected? What happens when you use a connect 5v/GND to its gate i.e. test the circuit without the digispark.

btw, using the voltage regulators shouldn't be an issue... as long as they are set to the forward voltage of the LEDs, or a smidgen below, they shouldn't overtax them.

Woodsplinter

  • Newbie
  • *
  • Posts: 8
Re: Problem with Digispark/mosfet LED flasher
« Reply #2 on: January 24, 2017, 05:53:41 pm »
Peter, thanks for the reply. I agree the error must be in the 2nd PCB but I cant find it. The connections are identical, only the physical layout changed but I cant imagine how that would affect anything.

I don't have pulldown resistors on the mosfet gates. Since the 1st prototype works fine without them, I didn't think they would be needed. My limited reading on the subject indicates they they would be in the 5-10K range? Don't know how to properly size them though.

I don't know how to check if the mosfet gate is being pulled high or low but will read up on the subject. Is current supposed to flow when it is pulled high?
If it is being pulled high without the digispark connected, what does that indicate?

I didn't think to check the circuit without the digispark but will do so. I presume connecting 5V to the gate will turn the led on as this is what the digispark does. If it does not come on, what might that be an indication of? Im really baffled because all of the components work fine when tested on a breadboard.
Can the mosfet work ok on a breadboard but not in a circuit? Ive read a little about testing them but haven't seen a really definitive or foolproof way to test.

I'll work on this and report back. I'll try to attach the PCB layout which I created in PCB Artist.

Also, I forgot to mention their is a 3rd voltage regulator which supplies 5.4V to a constant current regulator which feeds a red and a green led which remain on all the time. (No flashing, not connected to the digispark or a mosfet). The problems persist whether these 2 components are installed or not.

PeterF

  • Hero Member
  • *****
  • Posts: 881
Re: Problem with Digispark/mosfet LED flasher
« Reply #3 on: January 24, 2017, 10:52:02 pm »
From the looks of the diagrams, it seems fine... I can't see anything that is wired wrong in the digispark -> mosfet -> voltage regulator path.

Since these are N channel mosfets (so ground or -ve switching), they are enabled/turned on when the gate is high, and disabled/off when the gate is low. So pulling the gate high and low manually should make the LED go on and off. Without a resistor pulling the gate high or low as needed, it is then susceptible to static and can fail or just do any random thing. If you apply 5v to the mosfet, and it doesn't work... it unfortunately most likely means it is dead (assuming correct wring, etc).

There are issues with capacitance, inductance, resistance when doing stuff on breadboards, but that shouldn't cause any dramas. For the downs (or pullups when using P-channel FETs), I usually use 10K. All it needs to do is bias/keep the gate voltage high or low, without making the Digispark/MCU have to fight it when it wants to control it.

Nothing is jumping out as to why the second board isn't working... Are pins 28/29 linked together on both boards? It looks they are simply both ground pins? Double check the mosfets are the right way around... on your second PCB the gates are on the same side, so they should both be facing the same direction (i.e. back to the digispark).

Navigations lights for a quad or plane? Looks like something I was working on a few years back... used a bare Attiny85 and a couple of mosfets instead, as I had 12v power and used three leds from 12v tape... looked pretty good at night!

Woodsplinter

  • Newbie
  • *
  • Posts: 8
Re: Problem with Digispark/mosfet LED flasher
« Reply #4 on: January 24, 2017, 11:16:45 pm »
Thanks for checking Peter. Pins 28 & 29 are grounds. Verified mosfets are wired correctly on both boards.

Tomorrow I will get some resistors and try a 10K pull-up to see what happens. I think it makes sense that one or both of the mosfets is staying on when the circuit is powered off. That would explain why one or the other led comes on as soon as power is applied to the circuit. Once the Digispark starts running, they begin to flash.

Why the 1st board is free of any problems will probably remain a mystery.

Yes, lighting for a drone. Red /grn Nav lights up front, strobing white & red in the back. The Nav lights are 3 watts, the others are 5 watts for good daytime visibility. At night, they're visable from the space station.. almost.

I'll report back what I learn tomorrow..well, now it's today here. 8)

PeterF

  • Hero Member
  • *****
  • Posts: 881
Re: Problem with Digispark/mosfet LED flasher
« Reply #5 on: January 25, 2017, 02:12:18 am »
Nice. I had three lights on mine... right and white navigation lights, and the white strobe. I seem to remember making so the strobe/tail light do a double heartbeat pulse, and the navigation lights to a periodic left to right chase blink. Plus it was plugged into the receiver so I could have multiple patterns, but never finished programming that bit.Need to dig it out again and fix it up (quad had an unfortunate incidence with loss of power and gravity...).

Hope to hear some good news tomorrow then... ;)

Woodsplinter

  • Newbie
  • *
  • Posts: 8
Re: Problem with Digispark/mosfet LED flasher
« Reply #6 on: January 25, 2017, 04:25:02 pm »
Partial success.' :(
Put a 10K resistor across each mosfet and the circuit worked perfectly- for a short time. After a few on-off cycles it was back to the original problem.

Tried 5K and 20K no help. Oddly, only the white led circuit which actually has 2 led's connected in series, is coming on prematurely. It is set at 12.5V and the led's are drawing about 1.4A when flashing.

The red led never comes on early. Tried using several mosfets, no help.

I then swapped out the 5W white led's for 3W which draw 650 mA at 6V. Worked perfectly for about 2 on-off cycles, then back to original problem.

I'm completely stumped and at my wits end.

Woodsplinter

  • Newbie
  • *
  • Posts: 8
Re: Problem with Digispark/mosfet LED flasher
« Reply #7 on: January 25, 2017, 07:25:38 pm »
UPDATE: I discovered the Digispark is sending out about 1.8 volts on pin 2 during the 5 second "warmup" period. The white led's are connected to pin 2.

Pin 0 has no voltage during that time period. (The red led is connected here).

I suspect this voltage is causing the mosfet to turn on despite the 10K pull-up resistor.

I'm wondering if a different mosfet might work better for this but I don't know what specs to look for to determine if I need to switch.

If not, any ideas how to deal with this initial voltage?

PeterF

  • Hero Member
  • *****
  • Posts: 881
Re: Problem with Digispark/mosfet LED flasher
« Reply #8 on: January 26, 2017, 01:04:55 am »
Ok, that's interesting.

So can I just confirm then that

1) whilst the digispark is 'loading/waiting' that the white led comes one (or more specifically, is random)
2) once the bootloader has given control to your program, that the LED is controlled properly?

If so, two things spring to mind:
1) I hope when you were saying pullups you meant pulldowns... the 10k resistors should have been pulling the mosfet gates to ground (i.e. off). Else you'd actually be making it so the default state is on. ;)
2) Are you able to replace the bootloader on the digispark with a new one? you could then use one of the jumper variant bootloaders in which the digispark immediately runs the user program unless a jumper/pin is closed/GND'd at poweron. I'll just go look for the link to it...

This of course assumes that when you apply 5v and GND to the mosfet gate that it indeed turns the led(s) on and off consistently, hence indicating it is indeed the Digispark to blame here.

Edit: Ok, that really didn't want me to find it then! :-O So, here is the forum thread talking about how to do install the 'jumper' bootloader... it looks like micronucleus can load it itself, which will make it pretty painless. However, the link to the firmware file is broken, so use this one instead.

https://github.com/micronucleus/micronucleus/blob/v1.11/upgrade/releases/micronucleus-1.05-jumper-upgrade.hex

If you want the use the latest version of micronucleus instead, or want to use a I/O pin other than P5, let me know, and I can compile and attach one for you.

« Last Edit: January 26, 2017, 01:18:16 am by PeterF »

Woodsplinter

  • Newbie
  • *
  • Posts: 8
Re: Problem with Digispark/mosfet LED flasher
« Reply #9 on: January 26, 2017, 07:08:35 am »
Peter,
1 & 2 are correct and yes I meant pull down. :-[ You are correct that the Digispark is to blame.
I will try the different boot loader- I don't know anything about them.

This was supposed to be an easy, no brainer project- no massive research required as I have had no problem when using 1 led with Digispark in the past.

Side note: I finally discovered the difference between prototype 1&2- the Digispark in #1 (which works) is a knockoff (counterfeit) I bought off eBay before I knew they were "not authorized".

#2 uses the authentic Digispark I bought directly from digistump.

Don't know if that is the actual cause- it shouldn't matter.

Thanks again Peter- I'll post results as soon as I can.

Woodsplinter

  • Newbie
  • *
  • Posts: 8
Re: Problem with Digispark/mosfet LED flasher
« Reply #10 on: January 26, 2017, 03:41:38 pm »
SOLVED: Erik, owner of digistump, provided the answer in response to an email I sent him.

He said try a 1K resistor. I thought it would be a waste of money but I bought some anyway.

BLOODY HELL- IT WORKED! So far, despite many on/off cycles, the led's do not come on prematurely.

PeterF- thanks! You got me on the right track. If your ever in the neighborhood, look me up & I'll buy you a pint. :D

PeterF

  • Hero Member
  • *****
  • Posts: 881
Re: Problem with Digispark/mosfet LED flasher
« Reply #11 on: January 27, 2017, 05:12:35 am »
So that's 1K pulldowns instead of 10K (or the 5Ks?)? Or is it a 1K resistor in series? I'm suspecting pulldown, and it's just being more affirmative in the pulldown, which is good to know.

Anyway, it's working, so at least you can get on with your project now! ;)

Woodsplinter

  • Newbie
  • *
  • Posts: 8
Re: Problem with Digispark/mosfet LED flasher
« Reply #12 on: January 27, 2017, 07:46:34 am »
Yes, 1K pull down between gate and source. I just soldered them directly to the mosfet leads.
5, 10 and 20k didn't work.

Thanks again.
« Last Edit: January 27, 2017, 07:51:00 am by Woodsplinter »