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

Candle Power Flashlight Forum

Help Support CPF:

I'll be honest, with my dog's surgery and needing to watch him almost every minute, I have not even tested ver 2 out yet. My apologies, Jimmy, as I know how anxious you are for feedback. I can sit here on the keyboard with him in my field of vision, but once I go "tinkering," I seem to go into another world for hours at a time.
Lux, Please don't appologize. It's only flashlights, dude. Take care of your dog and get to this when you have time, not before.
 
I'm enjoying your progress and the wonderful things I'm reading about this regulator. I ordered a Kiu socket kit for a D Maglite I don't even have yet, just so I'll be ready when I have a few more spare dollars for this regulator. I'm really looking forward to a sleeper light that will surprise people.

Having said that, and acknowledging that I have a tendency to build brick outhouses, I would like to remind you of Alan's suggestion to define a reasonable feature set and release the code when those features work. There will always be things to tweak. My biggest challenge when programming is to quit when it's good enough. It sounds like you may share that bug. 🙂
I am guilty of the same, but having something work isn't quite enough. It should be done right. This is my first attempt at a microcontroller based design, so I'm trying to build good habits and a solid coding methodology. For example, I know I'm redefining the same variable more than I have to in the loop just to make sure. I want to step through the code and remove superfluous code that just eats up cycles and space.
 
OK. For the multiple level UI How does this sound...
Default values will be 87%, 94%, and 100%, in that order.

Compile time options will allow the setting of low-med-high values as any value you want in 32nds of the squared Vbulb, in any order you want. If you set one to 0, it skips that level and you now have a 2 level light. Set 2 to 0 and you have an ON-OFF interface.
You can set them all to levels < 32 if you want, but that doesn't make a lot of sense.
These percentages are all relative to the Vbulb value set by the pot.

In addition, the Vlow shutdown point is now configurable by the same 32nds values as above as well. If you set it to 0, it reverts to 50% of Vlow, If you set it to 32, it immediately shuts down.
 
EXCELLENT! Jimmy, that is perfect for me. As soon as you get this revision done, I will be ready for my other two regulators.
 
Well, rev3b is ready to go. It can do everything 2a & 2b can do, but includes compile time options for a multi level UI. I just finished testing pretty much every compile time option combination I can, and things work quite nicely.
I'll be posting source code and a new connection diagram. To use the new UI, you need to wire it a little differently.

 
Last edited:
EXCELLENT! Jimmy, that is perfect for me. As soon as you get this revision done, I will be ready for my other two regulators.
Starlight. In the Sale thread, I need to know what options you want.
Vbulb(max):
Level1 Percentage:
Level2 Percentage:
Level3 Percentage:
Soft Start Speed: Slow, Med, Fast
Soft Ramping between levels: Yes/No
Vlow:
Vlow behavior: Pulse or dim
Vlow Timed shutdown: Yes/No, if Yes, how many seconds?
Vlow Undervolt shutdown: Yes/No if Yes, What percent?
Overtemp Warning temp: 50,60,70,80C
Overtemp Shutdown: Yes/No, if Yes, how many seconds
 
Well, rev3b is ready to go. It can do everything 2a & 2b can do, but includes compile time options for a multi level UI. I just finished testing pretty much every compile time option combination I can, and things work quite nicely.
I'll be posting source code and a new connection diagram. To use the new UI, you need to wire it a little differently.


Hi Jimmy

Brilliant

Just one thing :thinking:
If it were possible to use a switched POS for the input to your pad A2 that would make wiring marginally easier - POS is available without rewiring from the newly momentary-modded switch ! To get the NEG you have to isolate the Pos-Slug and solder wire from the battery side of the switch module to the Neg grubscrew . . .

but it's probably not an option ? and it's not much extra work !

Battery Side - Solder and flatten the old contact a bit !
quadp7015switch1.jpg


Tape Isolation - Just in case . . .
quadp7016switch2.jpg


Overall totally brilliant and it's arrived much quicker than I ever thought possible.

Cheers
Pete
 
Last edited:
I hear ya Pete. That would be nice. But unless you only pass 5V to A2, you'll cook it. The exact same way I cooked one yesterday. I accidentally touched the A2 wire to 22V+. I heard a little spark, then it was shot. I have to replace the AVR now. Nice, Jimmy. Real nice.
To isolate the B+ spring cup from the switch internals, I pop the cup out with a screwdriver from the top side. Then place a small disk of plastic I cut out of a soda bottle. Then I pop the cup back in place. A piece of overhead transparency material would work nice too. Any kind of thin hard plastic.
I'll be doing a tutorial document of the process as soon as I can.
 
Compile time options will allow the setting of low-med-high values as any value you want in 32nds of the squared Vbulb, in any order you want. If you set one to 0, it skips that level and you now have a 2 level light. Set 2 to 0 and you have an ON-OFF interface.
You can set them all to levels < 32 if you want, but that doesn't make a lot of sense.
These percentages are all relative to the Vbulb value set by the pot.

In addition, the Vlow shutdown point is now configurable by the same 32nds values as above as well. If you set it to 0, it reverts to 50% of Vlow, If you set it to 32, it immediately shuts down.

Whoah.....Slow down there Bubba-Louie. I'm getting dizzy. I didn't follow that, and would like to. It would probably help if I looked at the code. Can you clarify what you mean by "compile time options" ? Is that the same as making changes in the code, or does it only refer to a specific functional feature?

Also, isn't the stock Mag switch considered momentary? So the control power in this scenario is always connected. Hooking up the new wire to the lug is how AWR did his Hotdriver connection which is pretty easy. Probably good to keep Rev 2 as well as 3 once it is also posted.
To isolate the B+ spring cup from the switch internals, I pop the cup out with a screwdriver from the top side. Then place a small disk of plastic I cut out of a soda bottle. Then I pop the cup back in place.
I'm trying to figure out why you need to isolate the B+ spring/cup, but it will probably be obvious once I look at the new wire layout and your tutorial showing this new setup.

I'm a little concerned that the average user won't be able to keep up with all the changes if they haven't been following this regularly. I can see why AWR did the assembly for people who essentially wanted a drop-in. I would recommend a completely separate Tutorial for each Rev just so people don't get it confused.

Great work again!
 
Whoah.....Slow down there Bubba-Louie. I'm getting dizzy. I didn't follow that, and would like to. It would probably help if I looked at the code. Can you clarify what you mean by "compile time options" ? Is that the same as making changes in the code, or does it only refer to a specific functional feature?
Compile-time options mean that in specific places (instructions given in the code) you can change a value or comment-out/comment-in a line that changes what the compiled code does. This really only affects those users that choose to reprogram their regulators. Just one line changes the regulator from a multi-level UI to the original ON OFF. Once you see the code, it's pretty straight forward. Rev3b supercedes Rev2a in that Rev3B can do everything.
Also, isn't the stock Mag switch considered momentary? So the control power in this scenario is always connected. Hooking up the new wire to the lug is how AWR did his Hotdriver connection which is pretty easy. Probably good to keep Rev 2 as well as 3 once it is also posted.
Nope. The stock mag switch CAN be used as momentary, but once you push it until it clicks it statys either on or off. That won't work for the pushbutton interface. It needs to be normally open and closes when pushed, then opens when released. When NOT using the multi-level UI, the original wiring method is still used. You ONLY have to use the different wiring if you want to use the Multi-level UI. Once you have changed the wiring to the Multi-level UI method, you can use the compile-time options to make the regulator act as though it's just a 1-level on-off regulator if you want. If you have it wired in already by the original method, you just don't use the compile time option for the multi-level UI. The design of this regulator is VERY versatile. You can go simple, like the HotDriver, or more complex like Alan's regulator. Don't even think about rotary encoders yet.:devil:
I'm trying to figure out why you need to isolate the B+ spring/cup, but it will probably be obvious once I look at the new wire layout and your tutorial showing this new setup.
The spring cup no longer connects to the switch. The switch (using the multi-level UI) connects the A2 pad to B-. If you allow the B+ spring cup to touch the switch, BAD things happen. It would be a dead short from B+ to B-.
I'm a little concerned that the average user won't be able to keep up with all the changes if they haven't been following this regularly. I can see why AWR did the assembly for people who essentially wanted a drop-in. I would recommend a completely separate Tutorial for each Rev just so people don't get it confused.

Great work again!
I have to make an update to the sale thread explaining the diferences.
 
EXCELLENT! Jimmy, that is perfect for me. As soon as you get this revision done, I will be ready for my other two regulators.
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.
 
Hi Jimmy

NOTE to Pete : Must not post late at night if any brain input required !

Forgot totally about Logic+ and Batt+ :shakehead

The new Rev3b is just superb.

Love the way that as posted it acts just as Rev2.
Then if you want to do the re-wire, and have multi-level Push-Button UI, you just Un-Comment one line and all the defaults are there . . .
(Ready for Play-Time !)

Wicked
Pete
 
You could use a resistor and zener to protect the micro input, or an opto. Then the m@g switch would not need to be rewired to split off the plus. Just taking the splines off one part would convert to momentary. It would be a lot easier but would require two more parts on the board.
 
You could use a resistor and zener to protect the micro input, or an opto. Then the m@g switch would not need to be rewired to split off the plus. Just taking the splines off one part would convert to momentary. It would be a lot easier but would require two more parts on the board.
That depends on what you mean by "easier". Yes, it would work and allow the use of "switching the positive", but adding components seems more difficult than just running new wires (that you have to add anyway) a little differently. If the only possible use for the A2 connection was the pushbutton interface then I would have designed a little zener/resistor into the board. But that would have limited the use of the A2 pad. Hardware flexibility was the first goal of adding the extra ports to the board. Right now, the B0 and B1 ports are unused except for diagnostic output, but I envision using them for a rotary encoder input at some point. Or they could be used for outputs to LEDs under the switch cover. Lots of flexibility. I suppose I could have added an additional port, closer to the center, as a dedicated Vbat+ input for a pushbutton. But hindsight is 20/20.
 
Hi Jimmy

NOTE to Pete : Must not post late at night if any brain input required !

Forgot totally about Logic+ and Batt+ :shakehead

The new Rev3b is just superb.

Love the way that as posted it acts just as Rev2.
Then if you want to do the re-wire, and have multi-level Push-Button UI, you just Un-Comment one line and all the defaults are there . . .
(Ready for Play-Time !)

Wicked
Pete
Have at it, Pete. I see this as THE version for folks to use if they don't mind the additional wires. Even if you just want ON-OFF, it's just a compile time option away.
 
Have at it, Pete. I see this as THE version for folks to use if they don't mind the additional wires. Even if you just want ON-OFF, it's just a compile time option away.

Yeah - Cool to just have one hardware setup for 1/2/3 levels - only downside is standby drain - 0.1mA vs 1uA (?) still very small either way.

The Latching Single Power Wiring Method also allows for a tail-switch set-up so Mac (etc.) can make super shorty mods regulated too.

Cheers
Pete
 
Yeah - Cool to just have one hardware setup for 1/2/3 levels - only downside is standby drain - 0.1mA vs 1uA (?) still very small either way.

The Latching Single Power Wiring Method also allows for a tail-switch set-up so Mac (etc.) can make super shorty mods regulated too.

Cheers
Pete
Yeah. There's always a tradeoff. But, look at it this way. A 2400 mAh battery will take >24,000 hours to drain. That 1000 days. If you leave your batteries unattended for that long you need to turn in your Flashaholic badge.
 
Yeah. There's always a tradeoff. But, look at it this way. A 2400 mAh battery will take >24,000 hours to drain. That 1000 days. If you leave your batteries unattended for that long you need to turn in your Flashaholic badge.

Oh My God ! Who took my badge ? ? ?

:mecry:
 
That depends on what you mean by "easier". Yes, it would work and allow the use of "switching the positive", but adding components seems more difficult than just running new wires (that you have to add anyway) a little differently. If the only possible use for the A2 connection was the pushbutton interface then I would have designed a little zener/resistor into the board. But that would have limited the use of the A2 pad. Hardware flexibility was the first goal of adding the extra ports to the board. Right now, the B0 and B1 ports are unused except for diagnostic output, but I envision using them for a rotary encoder input at some point. Or they could be used for outputs to LEDs under the switch cover. Lots of flexibility. I suppose I could have added an additional port, closer to the center, as a dedicated Vbat+ input for a pushbutton. But hindsight is 20/20.

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...
 
Back
Top