Last time we noted that the 2.2mH inductor was going to need long pulse-discharge periods to drive the planned 6x LEDs for the next version of #Yapolamp . I thought I would go for a 1mH inductor but plumped for a 680uH one instead. I ordered it a while ago and can't remember why I picked it - probably price!
Dynamic Pulse Calculation & Generation
Now the pulse durations required for the 680uH inductor driving 6x LEDs at the most efficient sawtooth profile (see previous log) vary almost inverse proportionally to the voltage of the supercapacitors that are powering this version. I took the pulse durations calculated by spice at 1.8V, 3.3V and 4.8V, which represent the lower, nominal and upper operating voltages that I expect. I then measured the ADC counts for the 3.3V (actually 3.29V) and 5V (actually 4.82V) rails on the Wemos D1 mini R2 when put through my 2.2K/2.2K Ohm voltage divider. I put them into Excel and used a linear trendline (to start with - we can always improve this) to work out how to calculate a pulse duration for every voltage between 1.8V and 4.8V.
So using this, we can make our pulse calculation code as follows:
pulseOn = 25 - ((analogRead(A0) + 21) / 42);
The / 42 is the equivalent to * 0.024. I add 21 to the ADC read because 21/42 = 0.5 and because integer maths rounds to a floor, rather than normal rounding, adding 0.5 has the effect of implementing normal rounding (both up and down, rather than solely down).
Results
This works! From a fully charged pair of 3F supercapacitors in series at 4.85V, the discharge brightness is pretty even over the full range of voltages down to 1.8V. Here's one of the moments that the pulse duration is increased to maintain the peak sawtooth current (as indicated by the increased duration of the discharge of the inductor in the trace):
I set the ADC-based recalculation of the pulse length at 10Hz and this seems fine for adjusting the pulse (brightness) not only during the discharge but also the MUCH faster charge phase - that's right, this torch can be fully-on with constant brightness during charging of the supercapacitors from the USB battery bank!
This test also now allows us to better estimate the run-time for a given capacitor charge. Bear in mind that we will have to add in the microcontroller current burden to the calculation but from this experiment, our 3F capacitors give us a 4 mins 36 seconds run time from full to 1.8V (and the LEDs are still bright at this point - just can't be sure the microcontroller will keep going below this voltage).
Auto-pulse points to address in future:
- There's a slightly detectable increase in brightness at each increase in pulse duration. Ideally, find a better way than delayMicroseconds() to time the pulse lengths. This will rather depend on the final microcontroller and its configuration (clock etc).
- The discharge duration sits nicely in the 10-12 uS range for voltages above 2.1V but below this, it drops a little low. This could be improved by adopting a non-linear function to calculate pulse durations from ADC counts. Again, because of ADC non-linearity etc, there's little point in optimising this with the ESP8266 (which was never a contender for the final uC but has 3.3V GPIOs for test pulse generation) and I'll wait for the final microcontroller before improving this.
- You will see in the GIF of the oscilloscope trace above, that the point when the next pulse opens the MOSFET is not well-matched to the inductor voltage's lowest point, wasting some energy. This could be improved as an optimisation but I don't think it would make a significant difference to run-time and efficiency. Please disagree with me in the comments and perhaps it will motivate me to compare!
Next steps
So now I have proved we can achieve a constant-ish brightness from a wide range of supply voltages, I'm confident we can now start to design a more compact PCB for a V1.1 beta (oh dear - will we ever leave beta-land?!). However, before that, I need to find a microcontroller that will handle our UI (button), operating mode and pulse calculation and generation. I also need to decide how many Farads we want to pack in with this little torch. Stay patient - this may take me some time...
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.