Risk of injury. You do everything at your own risk - I don't take any responsibility for any property damage, injuries or other harm caused by applying any of the information here.
This is a digitally controlled high voltage power supply. The output voltage range is 500 V-5 kV. An isolation test function is also planned.
The device is powered from a 12 V, ≥2 A power supply through the connector J6. The power input is fused (F1) and protected against reverse polarity (D3) and filtered with C7. The basic input circuitry is followed by an LCR filter (L1, R19, C11) and voltage regulator (U3 - 7805 and capacitors C14, C18, C22).
The control logic part is based on the ATmega328p microcontroller (U1), which is clocked by the crystal Y1 (16 MHz). Its AVCC input is filtered using FB1, C9. Button inputs are filtered and debounced using RC networks (R20-22, C10, C12, C13). Voltage feedback is connected to J9 through an external 120 MΩ resistor, the internal ADC is used to sense the voltage. The lower part of the divider consists of resistor R25 and C20. Current measurement for isolation measurement (input J1) is implemented using a selectable shunt (resistors R1-R3). This input is protected by the varistor MOV1 and a fast clamp circuit (R4, R6, Q1 - B-E junction in "Zener-like" mode). Output current sensing is implemented by transistors Q7, Q8 and parts around them. The circuit gets activated at around 5 mA (safety feature), the current can be lowered to 2-3 mA by changing R26 and C21 to around 10 kΩ and 100 pF. The ~OCD node is also connected to a circuit that senses the primary/MOSFET current. Parts C21 and R26 reduce noise on this node (the pull-up in U1 isn't enough by itself).
The power part is driven by a PWM signal at around 30 kHz. It consists of a level shifter (Q2, Q3 and nearby parts, 5 V to 12 V), current strenghtening circuit (Q4, Q5) to drive the gate of the switching transistor (MOSFET Q6), the power MOSFET itself, which drives the primary of a small high voltage transformer (J3, J4) and an over-current detection circuit. The switching speed of Q2 is enhanced using capacitor C1 (providing a current pulse when changing state). Turn-off of Q3 is made faster using a Schottky diode (D1), which prevents saturation. The collector of Q3 goes to the bases of Q4, Q5, which work as followers (current amplifiers) and drive the main MOSFET gate through R9. The MOSFET current is sensed using R10 (0.22 Ω) between its source and ground, if a certain voltage drop is present, then the comparator U2A connects the ~OCD node to ground, this goes to the MCU and activates an interrupt routine handling over-current protection. Fast spikes are removed using R12, C2. Maximum current can be set between approx. 1.5 to 4 A (the trimpot RV1 sets the voltage level necessary to activate the comparator). The second comparator in U2 is used for +12V rail undervoltage detection. The MOSFET is heatsinked (the heatsink is placed directly on board, connected to J2 and isolated from the FET with a sil-pad).
A small HV transformer from a photocopy machine is used here. It operates in flyback mode (careful with phasing, the high voltage output pulse polarity is reversed relative to "charging" - Q6 on). The primary is connected to J3, J4. The transformer has a built-in diode. Its output goes to a 5 nF, 5 kV capacitor. A high voltage resistor (1-5 kΩ) should be connected between the HV output and load to prevent a huge current spike/EMI due to discharge of the 5 kV capacitor. The negative pole of the load is connected to GND as close as possible to J5, D2, C5. In insulation resistance measurement mode, the load is connected between HV +OUT and J1 (MEASURE). An external protection network must be placed between J1 and the load. The resistance measurement feature isn't implemented yet.
A character LCD (16x2, HD44780, lines VCC, contrast, E, RS, D4-D7, others are tied to ground) and buttons (BTN1-3, switching to ground) are connected to the connector J8. The microcontroller is programmed through J7.
The program is written in Arduino IDE. Speed-critical parts use direct port/register manipulation. Regulation is done using a PID loop, coefficients are set in the program using #define. The PID loop runs at some kHz, which isn't too much of a problem here due to the fairly large output capacitance. The built in AD converter has quite a lot of noise, which causes PWM jitter and thus increases output ripple. The PID coefficients should be tuned for minimal overshoot and maximum speed, accuracy and stability.
A single sided-board is used (with wire jumpers). It was made by photo transfer and persulfate etching. Both SMD and THT parts are used. Be careful with design (EMI susceptibility). Capacitors C4, C6, C8, C9, C11, C14, C15, C22 must be placed as close as possible to corresponding circuits.