I’m trying to keep going and have some bench time every day to keep things going. So far, so good.
I figured the next bit to sort was how to move the decorative flashy LED feature over to the 12V rail. As mentioned before, I want to keep the 5V side exclusively for the clock and digital logic so it keeps its time when I unplug it (provided I have a 9V battery in it of course).
What I had done
Strangely, at least at first re-glancing at the schematic posted here, I seem to have used a TIP122 darlington transistor to do the switching. It wasn’t apparent as to why I did that until I noted the lack of current limiting resistors for the LEDs and realized that I was using it to do the switching and the current limiting as well. Okay, makes sense so far, but how to rebalance it for a 12V rail? How did I come up with those value resistors in the first place? I hadn’t a bloody clue. I knew I’d have to bias the transistor just right, and the amount of current it let through was a function of the current I used to drive the base.
So I whacked it up on the breadboard to try it out as is, and not to too much surprise it rather failed to function properly. I tried a few values of resistors to not much effect and realized I’d have to do some learning and number crunching to remember how to bias a transistor again (I’ll have to review that anyway, it is very important).
Then I thought “hang on, why am I using this rubbish? I could just use a MOSFET to do the switching” and so I did. I rummaged about in my bins, confident I knew how to use a MOSFET way better than a transistor and it would accept a logic level pulse just fine. I looked in there and found some rather high power ones but decided to use the low power BS170 N-Channel MOSFET. Marvy.
I did my due diligence, consulted the datasheet, noted the pinout, ensured the maximum ratings were in no danger of being violated – seemed perfectly suited. I dashed together the following schematic the old fashioned way (as I still have yet to renew my circuitlab subscription) and went off to the bench.
I wired it up all nice and neat and held my breath hoping I didn’t make some damn fool mistake. I powered it up and… nothing. Sigh. Double sigh. Electronics as a hobby will do this! Dave Jones famously says “I hope you build it and it doesn’t work” and he’s right, that’s how we learn things, but sometimes – I just want the damn thing to work.
I went over my schematic, I checked all my wiring, everything seemed great. I double checked the datasheet … everything. Scratching my head, I pull the thing out to do a diode test and did not get the expected results. Thinking I somehow fried the thing, I tried another BS170 but the same result. There were no shorts between the gate and source or any of the other pins, everything pointed to it was just fine. What on earth was the trouble?
In a fit of pique, I reversed the package in the breadboard and the lights came on. I mean, they were supposed to be pulsing at 0.25Hz at 50% duty cycle… but they were steady on. What on earth is with this MOSFET!?
Throwing caution to the wind I tried rewiring it. In one instance, I got the expected flashing, but inverse of what it should be. It turned on if i connected the gate (or I thought it was the gate) to ground. Trying out various wiring permutations, I finally found it. If you can believe it – the datasheet was wrong about the pinout.
Don’t believe everything you read
Quite simply, the datasheet gave me wrong information. This had never happened to me before. Quite infuriating.
Transistor and other active part pinouts are given with the package facing you, and the pins numbered left to right. In this case 1, 2, and 3. The datasheet said that Pin 1 was Drain, Pin 2 was Gate, and Pin 3 was Source. That is how I wired it when nothing worked. What I had discovered, through random experimentation, was that Pin 1 was gate, Pin 2 was drain, Pin 3 was source. This is actually more usual for MOSFETS, but definitely not was on several datasheets I had looked up. Even Wikipedia makes mention of the pins being DGS, noting a similar part, the 2N2700 was reversed – SGD. No matter what, the parts I had were definitely GDS.
Okay, so I sorted that and I have my flashy LEDs back. It works just marvy and I’m quite sure this is what I’ll end up whacking on the board. The only caveat would be that the flashing is more abrupt than before. I was using a 1500µF capacitor with a resistor to make a an RC charging circuit to provide a more gentle fade-in-fade out effect. This is purely cosmetic for the clock and will simply illuminate the tubes from below and give some indication that the clock is indeed ticking. I will have to mess with the capacitor and/or resistor values to provide a decent smooth long fade in without using a whacking giant cap. Ideally, i’d like a slow smooth fade that almost covers the 4 second wavelength. A simple matter, usually. I’ve used RC tanks in other circuits before, but I need to balance it with another resistor to ground which provides the pull down for the gate, to ensure it actually switches off.
Once I have this nailed to my liking, it will be time to whack that on the board and then turn my attention to the first two decade counters which will count the seconds for me from the 1Hz pulse. Then on to board two.
So I hopped back to play with some cap values for that fade effect. I noted something interesting in that the cap seemed to be happily draining back through the CD4521 which is not something I wished to do! Those wiley electrons will get everywhere. The easiest solution is of course to put a diode leading in, just a regular 1N4148 signal diode, making a nice check valve and prevent any back feeding from naughty discharging caps. I played with many resistor/cap combinations. Generally speaking the charge/discharge time will be roughly 5*R*C and that would work fine normally but it’s kind of constrained by the MOSFET which has a specific voltage threshold to turn on, namely 2.1V (typical) for the BS170. Meaning anything above ~2.1V will be pretty much fully on and anything bellow fully off.
That was one advantage to using the darlington transistor before is I could neatly fade the LEDs from zero to full brightness by using it to control the current. In this case with the MOSFET, I have a very narrow region where it will turn on, then it will charge the cap giving a fade-in effect before coming to full brightness, then when the signal goes LO it will discharge giving the fade out. Through some bench experimentation (i.e. whacking in different resistor and cap values), I concluded that it is roughly R*C or a bit less. I settled on using a 1.5kΩ resistor with the 1500µF cap and that give a steady fade in/fade out, blanking just before the next cycle begins.
I made adjust it a bit more to make it smoother, but overall I’m pretty happy with that. If I chose a higher value resistor (or cap but much easier with a resistor) I would have to find a sweet butter zone where the cap just completely discharges before charging again. Otherwise, I’d end up with a scenario where the cap never gets to 0V and the lowest brightness keeps getting brighter and brighter until it just stays on. There might be a sweet spot in there, maybe I’ll try and find it tomorrow.
I also switched the paragraph font from quicksand to arial… the former didn’t have the micro µ sign in its character set. I kinda need that! In looking at it, I can see why Arial is one of the most popular fonts. It is immensely readable!