Skip to the content
PCBKitNew board
2 layers25.4 × 25.4 mmPIC Timer, the printed circuit board in 3D

Sample code for the PIC 12F1572 interrupt handling

Size
25.4 × 25.4 mm
Copper layers
2
Thickness
1.6 mm
Parts
25
Nets
17
Pads
62
Tracks, vias
106, 7
Pours
1
Routed
Yes
KiCad
KiCad 6 (file 20211014)
Created
28 Mar 2022
Updated
17 Jun 2022

Overview

PIC Timer is an open-source printed circuit board by cnkurzke, from the cnkurzke/HelloPIC_Interrupts repository on GitHub, published under the BSD-2-Clause licence. It is a 2-layer board of 25.4 × 25.4 mm with 25 parts on 17 nets, routed with 106 tracks and 7 vias.

It is built around the PIC12F1572-E/P, HT7550 and CD4148WP, with the BC847 and FQP27P06 among its other parts. Its parts include 9 resistors, 5 connectors, 4 diodes, 3 capacitors and 2 ICs. It belongs with the PIC boards of this library.

Main components

5

README

README.md

About

3D render PCB

This is part of my adventure of learning how to use PIC Microcontrollers in the real world. If you want to learn more about what a PIC is, here are plenty of online resources. E.g. see here:

My intention is to document my learning journey, so others can hopefully find it useful on their own research and learning path. I strongly encourage everyone who finds a mistake, be it an oversight or something out of date, please file a bug, or even better, contribute a fix!

My Setup

I try to do this as cleaply as possible, so that it can be reproduced by everyone.

My primary workstation is a standard PC with Ubuntu (currently version 20.04), and I use the PicKit 3. If you intend to purchase a programmer, be aware that the PicKit 2 is no longer supported by the current (2022) generation of development tools.

As the software environmnet, I am not happy with the Microchip tools, but it is the quickest way to get started. In fact, I installed a Virtual Machine, and run the MPLab IDE inside the VM. But if you have a more "traditional" operating system, you should be fine to run this on your standard computer. Follow the steps here: https://www.microchip.com/en-us/tools-resources/develop/mplab-x-ide

What Does It Do

I started with a very simple problem. For a car I'm currently restoring, I needed something to control the "Transmission Reverse Lock-Out". For a commercial device, look at https://shiftsst.com/tremec-6-speed-reverse-lockout-control-module.html

What's relevant for this level of detail: Low-side vs. high-side

  • The goal is to drive an automotive grade 12 volt Solenoid which is wired to the car in a "High-Side Switch" configuration. What this means:

    • The module we build will have to be able to deliver high current, and it is an "inductive load". Therefore I chose a beefy MOSFET to drive the signal to the transmission.

    • The solenoid is permanently connected to "ground", and we have to close a switch to 12V to activate the solenoid and unlock the reverse gear. This means we have a P-Channel MOSFET in "High Side Switching" configuration. For an example see here: https://www.elektormagazine.com/news/high-side-low-side-switching

    • Open Collector with Clamping Diode The P-Channel MOSFET needs to be driven by a 12V Gate voltage, annd can unfortunately not be driven by the PIC output pin. Even though the Datasheet mentions that PIC outputs are able to work as "open Collector" - this is only thue for voltages within the operating voltage level. The circeled Diode in the diagram shows that the PIC has internal clamping Diodes for protection.
  • The logic implemented by this device is to:

  • Whenever the vehicle is turned on: Activate the solenoid for 30 seconds

  • When the driver pushes a trigger buttom: Activate the solenoid for 30 seconds

This is a fairly simple timer circuit.

Hardware Choices

After a bit of research, I decided the 8-pin PIC 12F1572 is more than capable. It has 6 GPIOs, and holds 2KB memory. See the datasheet here: https://www.microchip.com/en-us/product/PIC12F1572

For the MOSFET I decided to use the: https://www.sparkfun.com/datasheets/Components/General/FQP27P06.pdf It can easily drive 20+ Amp, and most important, it has an integrated "fly back diode" to handle switching the inductive load.

Here's an early sketch of a circuit:

Drawn circuit diagram

It became apparent rather quickly that the biggest challenge would be, how to drive the 12V MOSFET from the 5V PIC output.

MOSFET Drriver

It turns out that the PIC output pins, even though they are "Open Collector" capable, they are protected by a diode, which prevents to pull-up to 12V.

I looked at various MOSFET Drivers, but they are really not needed, for the low (basically DC) switching freqencies. In this case, a simple NPN BJT in Open Collector mode is suficcient.

Prototype

After a bit of breadboarding, I had the first version up and running rather quickly.

Breadboard with components

KiCAD Schematics

I decided to create "REAL" circuit boards. After a bit of research, the free software "KiCAD" cauught my interest. It's everything I need, and way, way more! See: https://www.kicad.org/

After some trial and error and watching tutorials like: https://www.youtube.com/watch?v=ia2n7P3Csac

I created this schematic: Drawn circuit diagram

The source for this is here: https://github.com/cnkurzke/HelloPIC_Interrupts/tree/master/schematics

PCB Layout

With the help of KiCAD, i turned this schematic into a circuit board, and Gerber files: https://github.com/cnkurzke/HelloPIC_Interrupts/tree/master/schematics/KiCAD_project/PIC_Timer/gerbers

The Gerber files describe the PCB and are used to manufacture the final boards: Printed Circuit Board

... stay tuned, the boards will arrive in 5 days

To be continued

SOFTWARE

HelloPIC_Interrupts

Sample code for the PIC 12F1572 interrupt handling.

For a very basic introduction about Interrupts on PIC see: https://picguides.com/beginner/interrupts.php

The Interrupt handler gets registered in main.c, with
IOCAF2_SetInterruptHandler(IOCAF2_CGK_InterruptHandler);

The ISR (IOCAF2_CGK_InterruptHandler()) is called everytime the RA2 is pulled to LOW.

More in detail information about De-Bouncing Switches: http://www.ganssle.com/debouncing-pt2.htm

Parts

25
QtyValueFootprintReferences
810KResistor_SMD:R_0805_2012Metric_Pad1.20x1.40mm_HandSolderR1, R2, R3, R5, R6, R7, R8, R9
3CD4148WDiode_SMD:D_1206_3216Metric_Pad1.42x1.75mm_HandSolderD1, D2, D4
210ufCapacitor_Tantalum_SMD:CP_EIA-3216-10_Kemet-I_Pad1.58x1.35mm_HandSolderC1, C2
110ufCapacitor_SMD:C_1206_3216Metric_Pad1.33x1.80mm_HandSolderC3
112V PowerConnector:JWT_A3963_1x02_P3.96mm_VerticalJ1
11KResistor_SMD:R_0805_2012Metric_Pad1.20x1.40mm_HandSolderR4
1BC847Package_TO_SOT_SMD:SOT-23Q1
1FQP27P06Package_TO_SOT_THT:TO-220-3_VerticalQ2
1HT7550Package_TO_SOT_SMD:SOT-89-3U1
1ICSPConnector_PinHeader_2.54mm:PinHeader_2x03_P2.54mm_VerticalJ3
1LEDLED_SMD:LED_0805_2012Metric_Pad1.15x1.40mm_HandSolderD3
1LoadConnector:JWT_A3963_1x02_P3.96mm_VerticalJ5
1PIC12F1572Package_DIP:DIP-8_W7.62mmU2
1RetriggerConnector_Pin:Pin_D0.7mm_L6.5mm_W1.8mm_FlatForkJ4
1TriggerConnector:JWT_A3963_1x02_P3.96mm_VerticalJ2

Questions

How big is the PIC Timer PCB?

It measures 25.4 × 25.4 mm and has 2 copper layers, 1.6 mm thick.

What parts does the PIC Timer use?

25 parts, built around the PIC12F1572-E/P, HT7550, CD4148WP and BC847. The full list of its parts is on this page, with links to each part's symbol and footprint where PCBKit's library has them.

Where can I download the PIC Timer KiCad files?

From the cnkurzke/HelloPIC_Interrupts repository on GitHub, at the commit this page was made from: the board is schematics/KiCAD_project/PIC_Timer/PIC_Timer.kicad_pcb and its schematic schematics/KiCAD_project/PIC_Timer/PIC_Timer.kicad_sch. PCBKit opens the board in the browser, with nothing to install.

Can I use the PIC Timer design in my own project?

Its repository publishes it under the BSD-2-Clause licence: you may reuse it on that licence's terms (keep the author's notice, and for a copyleft licence share your changes alike).

Similar boards

  • 2 layers60.1 × 77.1 mmLED driver, the printed circuit board in 3D

    LED driver

    jameshanlon/3C-HP-LED-driver

    A three-channel high-power programmable LED driver

    38 parts3MIT
  • 2 layers89 × 35.9 mmRecent IMU, the printed circuit board in 3D

    Recent IMU

    Ndambia-007/IMU

    Inertial measurement unit project

    58 parts
  • 4 layers54.1 × 19.4 mmF405 pill, the printed circuit board in 3D

    F405 pill

    davidmolony/F405_pill

    F405 Pill for running VESC based motor control from a Black/Blue Pill footprint

    50 parts20BSD-3-Clause
  • 2 layers92.1 × 88.9 mmArdCurvTracer, the printed circuit board in 3D

    ArdCurvTracer

    jonsag/ardCurveTracer

    An arduino testing transistors

    64 parts2
  • 2 layers43.6 × 25.5 mmBikeUSBv2, the printed circuit board in 3D

    BikeUSBv2

    H3wastooshort/BikeUSBv2

    Charge your Phone off of your Bike while adapting charging power to available power / riding speed.

    63 parts1GPL-3.0
  • 4 layers51.4 × 61 mmGAMEBOY STM32 CART, the printed circuit board in 3D

    GAMEBOY STM32 CART

    ice-bergtech/Icecart-GB

    A ROM cartridge for the Gameboy

    113 parts1MPL-2.0
  • 2 layersMate car, the printed circuit board in 3D

    Mate car

    cdrfiuba/matecars

    La nueva version de los MbedCars

    30 parts
  • 2 layersTT Clone AY AT, the printed circuit board in 3D

    TT Clone AY AT

    Upcycle-Electronics/AVR-Transistor-Tester

    55 parts47