STM32F103 C8T6 PWM Timer and NE555 redundancy Part 002

Latest iteration of the Neon supply 170 - 240 Volt generator.

The original circuit sported a "NE555" to drive the "Fly-Back" inductor N-Channel MOSFET, then after a hour sitting in its cosy socket (and an elvish brainwave later) it has been made redundant in preference to some"PWM Code..."

The PWM Timer4 is capable of driving (albeit for me via 2N2222 transistor) the gate of the IRF840 MosFet  @ a sweet spot frequency of 30khz.

The IRF840 was all I had to hand (Gate switching is 10 volts...however driving it at 6 volts worked perfectly fine as circuit draws low current) ... a better choice would be an IRF540 (Gate switch voltage 2 to 4 volts) and drive it direct from 3.3v mcu logic.

It enables a great way to dim the Neons through software control.

STM32F103 C8T6 PWM code for HighVolt generator
int prescaler=25;
int f_pwm=30000; // frequency (Hz)
double pwmval;

void setup() {
    pinMode(PB7, PWM); // GPIO for PWM signal to Gate of Mosfet
    Timer4.setPrescaleFactor(prescaler);
    pwmval=(72000000/prescaler)/f_pwm;  // STM32 is running at 72 000 000 Hz
    Timer4.setOverflow(pwmval);
    pwmWrite(PB7,50);  // Start the service ASAP DutyCycle 50%
}

void loop() {
   for (int i=5; i <= 95; i++)    // Duty cycle
   {  pwmWrite(PB7,i); delay(10); } // Ramp the voltage up and down
}

No Elves were electrocuted during the making of this update......