Thursday, October 29, 2026

0000 0001 0001 0100

Mosfet gives µC joy (and maybe a new µC?) 

In a previous video we looked at retiring the QX5252 workhorse of the candle project in favour of a boost converter (a modified BL8530)

The problem with measuring the light (and hence determining if it is day or night) using a comparator on the PFS154 is that the solar panel voltage dips alarmingly when the BL8530 is drawing current.

Net result? The PFS154 keeps making the wrong decision re nightfall - it mistakes a drop in voltage due to the hungry supercap/boost converter duo for a drop in voltage due to the sun disappearing for the day.

What to do?

Well I went up to the ideas factory with my furry partners, and drew the following possible solution...

...then we went to the lab and tested some switching code...

/*
  MOSFET Bench Test / Blink Example for PFS154
  Drives PA7 HIGH/LOW to switch a low-side N-Channel MOSFET (BS170 or AO3400).

  Connections:
  - PFS154 Pin 2 (PA7) -> MOSFET Gate (Pin 2)
  - MOSFET Drain      -> LED Cathode (-) (LED Anode + goes through 330R to VCC)
  - MOSFET Source     -> System GND
  - 100k Resistor     -> Between PA7 (Gate) and System GND
*/

#include <pdk/device.h>
#include "auto_sysclock.h"
#include "startup.h"
#include "delay.h"

// Hardware bitmask for PA7 (Bit 7 / Pin 2)
#define MOSFET_GATE_BIT 0b10000000

// Helper macros for N-Channel MOSFET control
#define turnMosfetOn()   PA |=  MOSFET_GATE_BIT  // Drive PA7 HIGH -> MOSFET ON
#define turnMosfetOff()  PA &= ~MOSFET_GATE_BIT  // Drive PA7 LOW  -> MOSFET OFF

void mydelay(uint16_t ms) {
    while (ms > 0) {
        _delay_ms(1);
        ms--;
    }
}

void main(void) {
    // Set PA7 as Output Mode
    PAC  |=  MOSFET_GATE_BIT;  
    PAPH &= ~MOSFET_GATE_BIT; // Disable internal pull-up
    turnMosfetOff();          // Ensure MOSFET starts OFF

    while (1) {
        turnMosfetOn();   // PA7 HIGH -> MOSFET ON -> LED ON
        mydelay(4500);

        turnMosfetOff();  // PA7 LOW  -> MOSFET OFF -> LED OFF
        mydelay(4500);
    }
}

unsigned char STARTUP_FUNCTION(void) {
    AUTO_INIT_SYSCLOCK();
    AUTO_CALIBRATE_SYSCLOCK(TARGET_VDD_MV);
    return 0;
}

...and finally we made the following video to explain the possible update to the candle project.

Also, please stay to the end of the video for an announcement of what might be the next iteration in this project.



Wednesday, October 7, 2026

0000 0001 0001 0011

The death of the QX5252?

For years I have been working on the candle project - the idea of an environmentally friendly perpetual "candle", solar powered, that does justice to the gentle flickering of a real candle, including sputtering, has driven a lot of content on this channel!

The only unease I have felt is in using NiMH batteries for solar power storage. Heavy and having a fairly low power cycle count, the main issue was environmental - some nasty chemicals and a not particularly long life meant too many would end up in landfill.

Then in the super capacitor realm we had 120F and 250F LIC capacitors that charged to 3.8V, has a cycle count between 100000 and 1000000 charge/discharge cycles, was light weight and seemed to contain a number of problematic barriers:

1. Making the code so efficient that a super capacitor could drive the project

2. Make the PFS154 better at monitoring the day/night interface to optimise power usage

3. Boost/control the output of the solar panel to charge a 3.8V super capacitor safely

This third hurdle bothered me A LOT because the QX5252 was 80% efficient on a good day and I was using a 3.9V zener clamp on the output which further wasted power.

I needed a good DC-DC boost converter that could step into it's shoes (after all there must be tens of videos on this channel that feature this little soldier).

And so the search began - with some parameters to help me weed out contenders. AI was not much help (a bit too "chicken Little" for my taste)

I am really happy with the TPS6102X family (featured before on this channel), but it is too expensive at the moment, and so with cost in mind I compromised to the BL8530/1N5817 combo.

Please take a look at the video and let me know what you think - especially if you have another contender!