Saturday, November 30, 2019

0000 0000 0001 0111

Your own PCB

So far most of the circuits on this blog have been whipped up on a breadboard or a generic PCB. The solar joule thief showed a PCB which looked a bit more professional, but how does that process actually happen? 

Well, I think I've made most of the mistakes possible and some of my earlier efforts with PCBWAY and JLCPCB were quite comical. It might be worth listing the steps and the gotchas that can crop up along the path to your own PCB.

1. Design your circuit on paper. Use a calculator to check some of the voltages and current in the wires. Later when you look at track widths and separation this might come in handy.


2. Test your circuit using appropriate simulator software if you're up for it - it does take an investment in time. I think it's worthwhile before you fry stuff to have a look at the circuit in a simulator. This is particularly useful if you are experimenting with standard components such as the 555 timer (e.g. as I did here using TinkerCad circuits) or perhaps for checking the flow of logic before wiring the myriad of connections (e.g. as I did here using logic.ly).

3. Breadboard the circuit paying close attention to the voltage and current requirements of your components. In this regard you should at least glance at the datasheets of the components you have chosen! For instance if you are using an LM317 voltage regulator (as I did here), then download and look at the limits shown on the datasheet. Don't ignore decoupling capacitors - these little beauties (generally I use a combination of 47uF and 100nF) smooth out the supply and can make a huge difference to the stability of your circuit. Look carefully at the pinouts - correct orientation of the pins can save you a few fried components. As an example, you may have been making a few projects over the years using the Attiny13 as shown here:


Flushed with success you might then migrate the project to the newer Attiny202 with very different pinouts as follows:


For some reason VCC and GND have moved - which if you're not careful could result in some fried chips!

4. Open up EasyEDA and place your components as required. This blog isn't about how to use this software, and in fact I've used KiCad and Eagle to do the same thing - so choose your weapon! The main consideration is that your software produces what is known as a Gerber file (usually a zip of many files) which describes the PCB in a standard format.

EasyEDA and connecting up your components
EasyEDA placing components on the board
Clicking Gerber, check DRC and head over to manufacturing at JLCPCB
It took me quite a few times to understand what a "ground plane" is and how it can be useful. My advice is to definitely use this feature of PCB design. I learned from watching MickMake and reading a lot of online tutorials. Here is a very quick video showing the addition of a ground plane to a PCB - this was something that I struggled with for a long time.



5. When you are in the JLCPCB site, one definite selection should be to panelise (if you're searching online try "panelize") your board. Before I knew about this feature on JLCPCB, I might spend $18 on 10 boards (which sounds great), instead of panelising and spending $18 on 120 boards - big difference! I learned about panelising from this youtube video which also explains the whole process - what a revelation. If you want a more in-depth explanation, Great Scott has an awesome video here.


To illustrate the whole process I will make a PCB over the next few weeks on this blog. I think I'll use a 555 signal generator as the premise for a few reasons.

Firstly, who doesn't love the 555? It's a good starting point, pretty robust and the central character in a lot of useful circuits. Secondly, from time to time you need a quick reliable clock - for example when making a flashing display - as so many chips rely on a clock signal. Thirdly, there are a lot of example 555 timer circuits out there on the interwebs, so not much time will need to be devoted to actual design and then we can concentrate on the production of the PCB.




Saturday, November 23, 2019

0000 0000 0001 0110

Counting the cost (74HC595 Shift Register...again...)

This week was supposed to be all about the most marvelous CD4026 chip, which I was going to use to count numbers outputting to a 7-segment display. The old favourite 555 timer (of course) was going to be on "clock" duties. But a funny thing happened on the way from China - the CD4026s arrived and had a sudden attack of being completely FAKE!!

To be honest I'm a little shocked because I have enjoyed such success with Chinese companies that it hurts when they send dodgy stuff (hurts them I mean). To rub salt into the wound it was the second lot of fake chips I received this week - the others being LM338 voltage regulators.

I'm getting my money back from AliExpress (hopefully - although they are good with their refund policy), but what I really would like back are the hours and hours of testing and trying to debug circuits which were never going to work in the first instance because of the fakery. Note to self (and anyone else watching) - never buy chips from Si Tai&SH IC accessories Store (CD4026) or shenzhen IC store (LM338). Shame on those guys.

So I've shelved the CD4026 blog for a later date (I have more chips on their way from a different source), and in the meantime and only because I'm so welded to the idea of a 7-segment counter I dragged out an old project which uses the Attiny13a microcontroller and a 74HC595 shift register to "fake" my own version of my own blog (the plot gets real thick about now).

As we've seen before the Attiny13 counts real well, and it also pumps out all the data needed to make the shift register drive not just LEDs but also in this case the patterns required for a 7-segment display (in this case common anode) to count hexidecimally from 0..F.

Here is the circuit:



And of course the Attiny13 needs a little code:


#include <avr/pgmspace.h>     // for reading the progmem values

#define DATA  (1<<PB0)        // pin 5
#define LATCH (1<<PB1)        // pin 6
#define CLOCK (1<<PB2)        // pin 7

// digit patterns for a 7-segment display
const PROGMEM uint8_t digit_pattern[17] =
{
  ~0b00111111,  // 0
  ~0b00000110,  // 1
  ~0b01011011,  // 2
  ~0b01001111,  // 3
  ~0b01100110,  // 4
  ~0b01101101,  // 5
  ~0b01111101,  // 6
  ~0b00000111,  // 7
  ~0b01111111,  // 8
  ~0b01101111,  // 9
  ~0b01110111,  // A
  ~0b01111100,  // b
  ~0b00111001,  // C
  ~0b01011110,  // d
  ~0b01111001,  // E
  ~0b01110001,  // F
  ~0b00000000   // quiet please
  
};

void setup() {

    DDRB = 0b00000111;  // set control pins as output
    PORTB = 0b00000000; // but be quiet to start with
    delay(10);
}

void shiftOut(uint8_t val)
{

    for(uint8_t i=0; i<8; i++) {

        if(val & 0b10000000) {
            PORTB |= DATA;
        }
        else {
            PORTB &= ~DATA;
        }
        // pulse the clock
        PORTB |= CLOCK;
        PORTB &= ~CLOCK;
       val<<=1; // move next bit
    }

    PORTB |= LATCH;
    PORTB &= ~LATCH;

}

void loop() {
        for(uint8_t msg=0; msg<17; msg++) {
            shiftOut(pgm_read_byte(&digit_pattern[msg]));
            _delay_ms(500);
        }
            _delay_ms(500); // extra delay before repeating cycle
}


Which just leaves us to breadboard the whole thing up and turn it on:





Saturday, November 16, 2019

0000 0000 0001 0101

Putting some bits and pieces together

So what's the point of a voltage regulator, a police light at 12V, a one touch switch at 6V, an isolating optocoupler, a Darlington Transistor and a police siren (also at 6V)?

Well, you could put them all together in one symphonic circuit to simulate a regular Saturday night in town. You see the flashing lights first - you think they're for someone else - then the siren starts!

I had an idea to use only a single power source for the whole circuit. The maximum voltage needed is 12V (makes sense - it's police car voltage!) but the one touch switch and the siren both need only 6V. Hence I used the LM317 regulator with a 220Ω resistor and a 1kΩ potentiometer set at 836Ω to give the required voltage.

https://circuitdigest.com/calculators/lm317-resistor-voltage-calculator

From the little breadboard with the LM317 the power splits off with 12V going to the police light board and 6V travelling to the one touch switch. The switch output does not have the power to drive the siren which seems to need anywhere from about 160mA to 240mA depending on the frequency of the output. I tried some transistor options but they weren't initially cooperating and instead of creating a new paradigm I thought why not use an optocoupler instead of the LED from the original switch circuit? It would make sense to have the optocoupler on a whole new circuit, isolated from the switch, but I thought seeing as how the whole circuit was based on a simulation, why not simulate the isolation! Er...and laziness.

Sadly the output from the optocoupler (50mA) wasn't sufficient to drive the siren, so I popped in a BC547 (110mA and hFE 200) which allowed a few stuttering pops and splutters from the siren, but not enough to scare any potential perps! 

Then the trusty favourite SS8050 (1.5A and hFE 200) swung into action forthwith which allowed a recognisable but slightly anaemic siren. Finally I remembered the wonders of Darlington Transistors and referred back to the ULN2083 Darlington Array from an earlier blog. Using a whole array on a tiny breadboard seemed a bit over the top so I settled on a TIP120 single Darlington transistor which allows 5A at a hFE of around 2500. Presto we have lights and a switchable siren. Pay no attention to the rogue transistor on the latching switch breadboard with the single blue jumper lead attached to ground - clearly I was trying a few options and forgot to "switch" it out again!





Saturday, November 9, 2019

0000 0000 0001 0100

Two NE555 timers - Police Siren

Inspired by the law enforcement circuit from last week (and with a truckload of 555s available), I looked about for a Police Siren to match the Police Lights. There are seven trillion such circuits out there, but I loved the simplicity and the wonderfully simple instructions found in this video (screenshot below).


https://youtu.be/zDMOsEDxPOc
So off to TinkerCad to make and test the circuit.



Then I built it on a breadboard and here is the siren in all it's screaming glory.





Saturday, November 2, 2019

0000 0000 0001 0011

Two NE555 timers - Police Lights

What could possibly be better than one NE555 timer? Well, maybe you could hook up two of them working together and get some law enforcement action!

Yep, I went looking for a "Police Light" simulator and as usual found many great circuit examples. I liked that this version only contained the 555 (albeit two of) and also it seemed to be a good simulation of the real thing.



The circuit was very simple to make firstly by simulating the lights using Tinkercad Circuits.



Then I made the real thing - works a treat!