
LED driver
jameshanlon/3C-HP-LED-driver
A three-channel high-power programmable LED driver

Sample code for the PIC 12F1572 interrupt handling
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.
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!
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
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:

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
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.
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:
It became apparent rather quickly that the biggest challenge would be, how to drive the 12V MOSFET from the 5V PIC output.
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.
After a bit of breadboarding, I had the first version up and running rather quickly.
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:

The source for this is here: https://github.com/cnkurzke/HelloPIC_Interrupts/tree/master/schematics
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:

... stay tuned, the boards will arrive in 5 days
To be continued
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
| Qty | Value | Footprint | References |
|---|---|---|---|
| 8 | 10K | Resistor_SMD:R_0805_2012Metric_Pad1.20x1.40mm_HandSolder | R1, R2, R3, R5, R6, R7, R8, R9 |
| 3 | CD4148W | Diode_SMD:D_1206_3216Metric_Pad1.42x1.75mm_HandSolder | D1, D2, D4 |
| 2 | 10uf | Capacitor_Tantalum_SMD:CP_EIA-3216-10_Kemet-I_Pad1.58x1.35mm_HandSolder | C1, C2 |
| 1 | 10uf | Capacitor_SMD:C_1206_3216Metric_Pad1.33x1.80mm_HandSolder | C3 |
| 1 | 12V Power | Connector:JWT_A3963_1x02_P3.96mm_Vertical | J1 |
| 1 | 1K | Resistor_SMD:R_0805_2012Metric_Pad1.20x1.40mm_HandSolder | R4 |
| 1 | BC847 | Package_TO_SOT_SMD:SOT-23 | Q1 |
| 1 | FQP27P06 | Package_TO_SOT_THT:TO-220-3_Vertical | Q2 |
| 1 | HT7550 | Package_TO_SOT_SMD:SOT-89-3 | U1 |
| 1 | ICSP | Connector_PinHeader_2.54mm:PinHeader_2x03_P2.54mm_Vertical | J3 |
| 1 | LED | LED_SMD:LED_0805_2012Metric_Pad1.15x1.40mm_HandSolder | D3 |
| 1 | Load | Connector:JWT_A3963_1x02_P3.96mm_Vertical | J5 |
| 1 | PIC12F1572 | Package_DIP:DIP-8_W7.62mm | U2 |
| 1 | Retrigger | Connector_Pin:Pin_D0.7mm_L6.5mm_W1.8mm_FlatFork | J4 |
| 1 | Trigger | Connector:JWT_A3963_1x02_P3.96mm_Vertical | J2 |
It measures 25.4 × 25.4 mm and has 2 copper layers, 1.6 mm thick.
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.
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.
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).

jameshanlon/3C-HP-LED-driver
A three-channel high-power programmable LED driver


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


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


