PWM Regulator-Mag D, JM-PhD-D1, UPDATE

Candle Power Flashlight Forum

Help Support CPF:

Starlight, I need to know what options you want. Unless you want to program your own. I haven't posted the new formware on Alan's site yet, but I can email it to you if you want.

Jimmy, I can't program my own yet, because I ordered the equipment from AlanB and I don't have it. What I would like to do is return one of my first 3 regulators for you to convert to Rev3 code. Then you could send it back with the last 2 that I ordered. If that is okay, just send me an email with your address.
 
Edit in
#define BUTTONUI

32 100% (L3 Default)
31 99%
30 97%
29 95%
28 94% (L2 Default)
27 92%
26 90%
25 88%
24 87% (L1 Default)
23 85%
22 83%

#define LEVEL1 24
#define LEVEL2 28
#define LEVEL3 32

. . .

All - Defaults

BUILD

Program: 1576 bytes (38.5% Full) (32.8% for Single Level)

Not much room left then ! ! ! for LEDs / Rotary etc. :devil:

FLASH - Rev3b One Level (Rev2 Emulation) Works :thumbsup:

FLASH - Rev3b - Default 3 Levels Works too :thumbsup: :thumbsup: :thumbsup:

Ha Ha Found an extra feature already.

Based on
2-Clicks from OFF straight to Level2
3-Clicks from OFF straight to Level3

2-Clicks from Level1 jumps to Level3
2-Clicks from Level3 jumps to Level2 (down 1)
2-Clicks from Level2 jumps to Level1 (down 1)

Round and round we go . . .

Perfect

Works for me

Cheers
Pete
 
Last edited:
Hi Jimmy

COOOOOL

L1 - Low Default is too bright for indoor daytime use with a 633 so I expect I can go lower and get extra runtime with a very usable (if slightly off-white) Low level

😀

Can't wait for darkness to fall

Cheers
Pete
 
Modding the M@g switch is a chore with all the drilling, cutting, grounding the switch, etc. There is a lot of potential for a short with the tight clearances. Reducing this to just making it momentary but still positive going is a lot less fuss. I would put the resistor/zener on the board for that, it is such a common situation. Even if the pads for the parts are on the board they don't have to be loaded. But the boards are already etched, so it is something for a future board.

Back to work...
See, but the thing is, for those who don't like the actual building of the light. Your regulator is the better solution. It's just a drop in. For those of us that enjoy the building part, it's no worse than installing a KIU on a Mag switch base. To each his own, I suppose. For those who like the building part, mine are much cheaper option for the Do-It-Yourselfer. Excatly the folks that I targeted with this design.
I'll consider the additional Bat+ button pad for a furure design.
 
Program: 1576 bytes (38.5% Full) (32.8% for Single Level)

Not much room left then ! ! ! for LEDs / Rotary etc. :devil:

Pete
Kidding, right? There's a TON of room left. Most of that code space is taken up with the 32-bit math required to get full 10-bit ADC readings and 12-bit PWM. I'm actually stepping the pwm in steps of 2 to keep response to falling voltage tighter. But I could use single steps. So in effect I'm only using 11-bit PWM. But the frequencies and everything else worked out nicely. Alan has a S**T load more bells and whistles but slightly smaller code size, because his design only requires 16-bit math. He uses 8-bit ADC and 8-bit PWM. So the resulting code required for regulation is much smaller.
The UI features don't require as much space. So in the remaining 60% I could make this thing flash the star spangled banner. Or, in your case, God Save the Queen.:grin2:
If you want to try using the full 12-bit PWM, edit the source code.
Towards the very bottom is a section like below...
---------
else
{
if ((vbatsqpwm < (vbulbsq - fastband)) || (vbatsqpwm > (vbulbsq + fastband)))

{
pwmstep = fastadj;
}
else
{
pwmstep = 2;
}
}
----------

Change "pwmstep = 2;" to "pwmstep = 1;" Happy hacking. :devil:
 
Oh My God ! Who took my badge ? ? ?

:mecry:
I just converted a 2xD-Lion Mag275 from an AWR HotDriver (personal comments witheld) to the JM-PhD-D1 using the Multi-Level UI. It took me a little while to figure out the best way, but I've figured it out. So when I do the tutorial document everything will work out nicely.:grin2:
 
Just Kidding 😀

Shed loads of room - amazing !

Thanks for the hack - Still playing with levels at the moment

Just converted my Rev2 to a Rev3 - no problem.

My tunnel for the BIG Pos was quite big enough for a little extra wire and a couple of little grooves in the top for the extra Pos and the wire to A2 were all that was needed for the body.

Cut off the lower splines from the latching mech with a craft knife and did the NEG switch mod as shown above in my photos. #268

Not much effort at all . . .

Cheers
Pete
 
Hi Jimmy

Having JM-PhD fun over here . . .

I have set my 633 to L1=20, L2=32, L3=12

This gives me MED : HIGH : Xtra.LOW
but I can get High with a Double BLIP
or Single BLIP for on MED or Triple BLIP for on X.LOW

Double BLIP for a 2 level HIGH:MED:HIGH: etc.

I have also found that when the OverTEMP kicks in I still get 3 levels at the reduced level - Neat.
But my counter seems not to work as OTShutdown doesnt happen after 30sec as set in default ? left for 60 seconds and still no shutdown !!
No biggy for me but just wondering why it wasn't shutting down ?

One time I got the LOW-Batt warning and then soon after got the OverTEMP so it went into OT-DIM mode this didn't time out - the LOW-Batt may have stopped with the bounce from the reduced power output ? ? Not sure how your nested (?) multiple (?) logic works ! ! !

Yep - I am having FUN 😀

Cheers
Pete
 
Hi Jimmy

Having JM-PhD fun over here . . .

I have set my 633 to L1=20, L2=32, L3=12

This gives me MED : HIGH : Xtra.LOW
but I can get High with a Double BLIP
or Single BLIP for on MED or Triple BLIP for on X.LOW

Double BLIP for a 2 level HIGH:MED:HIGH: etc.

I have also found that when the OverTEMP kicks in I still get 3 levels at the reduced level - Neat.
But my counter seems not to work as OTShutdown doesnt happen after 30sec as set in default ? left for 60 seconds and still no shutdown !!
No biggy for me but just wondering why it wasn't shutting down ?

One time I got the LOW-Batt warning and then soon after got the OverTEMP so it went into OT-DIM mode this didn't time out - the LOW-Batt may have stopped with the bounce from the reduced power output ? ? Not sure how your nested (?) multiple (?) logic works ! ! !

Yep - I am having FUN 😀

Cheers
Pete
Nice catch Pete. I was using the over temp event counter as the over temp timer as well. However it was only an 8-bit variable, so it could never count high enough. I also made a couple of other changes to "clean things up" when it comes out of a power-down condition.
I'll email you the code and forward the Rev3c version to Alan.

Once the over temp mode is triggered, it no longer looks for low voltage. The light can't be in low-voltage and over-temp conditions at the same time. Over-temp mode supercedes low-voltage mode. Once in over-temp mode, it will dim then, if desired, shutdown. However, in normal mode or low voltage mode it still checks for an over temp condition. Once in over-temp mode, the only way to get it out is to shut off the light and turn it back on. This is by design. However, in low-voltage mode it will go back into normal mode if the battery voltage recovers.
 
Last edited:
Nice catch Pete. I was using the over temp event counter as the over temp timer as well. However it was only an 8-bit variable, so it could never count high enough. I also made a couple of other changes to "clean things up" when it comes out of a power-down condition.
I'll email you the code and forward the Rev3c version to Alan.

Once the over temp mode is triggered, it no longer looks for low voltage. The light can't be in low-voltage and over-temp conditions at the same time. Over-temp mode supercedes low-voltage mode. Once in over-temp mode, it will dim then, if desired, shutdown. However, in normal mode or low voltage mode it still checks for an over temp condition. Once in over-temp mode, the only way to get it out is to shut off the light and turn it back on. This is by design. However, in low-voltage mode it will go back into normal mode if the battery voltage recovers.
The order sounds illogical to me. I believe that low voltage mode should do its work wether at the same time in overtemp mode or not.
 
The order sounds illogical to me. I believe that low voltage mode should do its work wether at the same time in overtemp mode or not.
OK. Sounds like an opportunity here.
Once in Over temp mode, I can make it still scan for low voltage, but what should it do if the condition is detected? It's already dimmed to 35% of Vbulb.
What behavior should it exibit if a low voltage condition is detected while in Over Temp mode?
Perhaps this...
If it's already dimmed by Over temp, it could blink off every few seconds if low voltage is detected. Then it would be a race to see what shuts it down first... Over Temp shutdown timer, Low voltage warning shutdown Timer, or the Under Voltage % trigger...
 
OK. Sounds like an opportunity here.
Once in Over temp mode, I can make it still scan for low voltage, but what should it do if the condition is detected? It's already dimmed to 35% of Vbulb.
What behavior should it exibit if a low voltage condition is detected while in Over Temp mode?
Perhaps this...
If it's already dimmed by Over temp, it could blink off every few seconds if low voltage is detected. Then it would be a race to see what shuts it down first... Over Temp shutdown timer, Low voltage warning shutdown Timer, or the Under Voltage % trigger...

Hi Jimmy

Blinking Off sounds good to me. :thumbsup:

I will probably not use the OTemp timer so to protect the batteries I think continuing to monitor for LowBatt is a good idea and use the same as normal - LVTimer/UV%Trigger/Both

Cheers
Pete
 
I'm going to leave the behavior the same for over-temp (dimming), but just implement the shutdown timer/voltage limitations for the low voltage warning selected as options..
The over-temp behavior (dimming) will supercede the low voltage warning bahavior (dimming or pulsing), but it will still keep monitoring for low voltage. If the low voltage level is tripped during over-temp mode it will start the low voltage timer and monitor for the undervolt %. If the conditions are met for shutdown under low voltage conditions while in over-temp mode (even if overtemp shutdown is not selected) the light will shutdown.
If you are already in low-voltage mode when over-temp is triggered, the low voltage timer is reset to 0 and the count begins again.
If, while in over-temp mode, the batteries recover, the low voltage timer is reset.
 
Last edited:
So guys? How does that sound? I've written the code and tested it using my hot air rework station to "over heat" the chip in my test setup. I set the code to under 50C for testing purposes. I didn't want to heat it to 80C just for testing.

I uploaded the new code to my own Mag5761 and left it running. It went into over temp mode while the head of the light was still only very warm to the touch. So I added insulation between the bulb and KIU base. Now the head gets very hot (not 80C hot) and the regulator doesntt shut down in over temp.
 
In an effort to screw around and possibly learn more AVR programming techniques I've been messing with the Rev3d code. In multi-level mode I have to declare some global variables which eats up code space. But several of them are simple things like 1 or 0 for startup mode.
So I figured why not try out the General Purpose I/O registers (GPIOR). In the process I've also split the "mode" (normal, low voltage, and over temp) into 2 parts. LVMODE 1/0, and OTMODE 1/0. So now, the regulator CAN be in both low voltage mode and over temperature mode. This allows me to carry over the low voltage timer if the regulator goes into over temp mode while in low voltage mode. So once in low voltage mode the low voltage timer just keeps running until shutdown even if it does into over temp mode 1 second before the low voltage timer is up.
The results of the above are both good and bad. In multi-level mode my memory usage has dropped a little, but the standard mode has risen a little.
Any way. I still want to keep messing around and testing with this before I call it good (functionally), so it's not an official release. There's still one more GPIO register to tinker with.
 
I keep replying to myself. Oh well.
With some more tinkering... I've kept the low voltage timer carryover, gotten rid of the global variables, not used the GPIO registers, I've made the number of available levels 5 instead of 3, Just don't use the ones you don't want.
AND shrunk the code more.
 
I keep replying to myself. Oh well.

And we're still reading! :wave: Clichéd as this may sound... more great work, Jimmy. :hitit:

OK, enough bologna from my end... I'm ready to order (freakin' finally! :ohgeez:).

Sending PM tomorrow to ask a final question or two, then bombs away!
 
I keep replying to myself. Oh well.
With some more tinkering... I've kept the low voltage timer carryover, gotten rid of the global variables, not used the GPIO registers, I've made the number of available levels 5 instead of 3, Just don't use the ones you don't want.
AND shrunk the code more.



Well just to let you know I'm also still reading...and keep hovering over the PP button, but you keep improving things.....(+ I have been too busy to follow closely)...but i'm still at least good for two ( maybee more) when you stop fiddling 😀

I think you have all the stuff I wanted (and more), but may look to swap things about, like have one set up for a fast-straight to high for a "tactical type bump in the night light" with the option of going down modes for runtime, and one regular for torch type duties.....So many posibilities...Great Work :popcorn:
 
Back
Top