# Hotwire Regulator Design Collaboration Project



## Alan B (Jan 13, 2008)

Now that I've built a [email protected] I can see the value of a soft starting regulator for incan. But I don't see much availability. I see JimmyM and AW planning to do something soon. I see old stuff but not currently available. Did I miss any? Soft starting with a thermistor is nice, but not enough.

Being the electronics and software engineer that I am makes me think of how to build a simple regulator. With today's microprocessors having PWM, ADCs, temperature detection and just about everything else (memory, clock, ram, etc) built in, it would seem to me that very few parts are required. I have done projects with AVR and PIC microprocessors. It is amazing what can be done with a single small low lead-count chip. (The design developed here uses only about a dozen parts).

Requirements that I would like to see:

Primary Features:

1) soft start
2) regulated RMS bulb voltage by PWM for high efficiency
3) provide battery overdischarge protection
4) provide overtemperature protection for the electronics
5) provide selectable voltage levels (programmable Vbulb)

(9/3/08, above items are coded and mostly tested, the FET power driver is not yet tested, though it has been analyzed)

6) have a lock off sequence for safety - secret unlock sequence to prevent accidental turnon (or provide a 'normal' flashlight Vbulb mode that would run the bulb at a lower setting that is very safe, and keep the turbo mode for expert access)
7) provide a 'timeout' feature to dim and shutdown to limit runtimes when desired
8) make it user reprogrammable, with free software tools and simple/inexpensive PC interface
9) have some public open sourcecode so folks could play with the user interface and make customized versions
10) have a public pcb layout available so folks could roll their own small batch if needed
11) one or more folks can make the hardware (and sell it), over time if they become unavailable someone new can step in and make hardware that will work with the same or slightly modified software
12) be a simple enough design to allow a builder to make one without a pcb (DIY dead-bug style, etc)

Secondary Features (possibly developed later):

1) provide one button reprogramming in the field for voltage settings, etc
2) provide a minimum off timer to reduce bulb wear from over clicking friends
3) auto-detect battery type and set voltage protection
4) other ideas??

It seems to me that it would not take a lot of parts to do this. A good Power FET directly driven from an AVR or PIC micro PWM output, and a way to measure the actual voltage across the filament, plus some calculations to determine the effective (RMS) voltage and adjust smoothly to the desired value. Possibly a second ADC channel on the battery side to keep track of the battery voltage (if needed). Approximately three processor I/O pins are required:

1) pushbutton input
2) pwm out
3) battery voltage (loaded battery V is bulb peak V)
bulb RMS voltage (calculate from bulb peak V and duty cycle of PWM)

This would place square wave current pulses into the filament, but the frequency can be selected to be high enough to avoid problems, but low enough to manage losses in the switching FET. The thermal inertia of the filament provides the filtering, so pulses must be short enough for the temperature to be essentially constant from pulse to pulse.

I don't know if any of the existing available designs work precisely this way. JimmyM's soft start is not a micro. AW's is but I don't know much about the design. Most others I find (AWR et al) are no longer available.

Anyone interested in something like this? I don't have the time to do the whole project, but I may be able to do some part of it. Perhaps it could be some kind of group project?

Any interest? Any important requirements or concerns about this simple approach?? Anyone want to work on this???

If you have any links to similar projects (past or present), post them in this thread so we can review them and give them credit.

If you have done similar work or have ideas, chime in and let us know!

-- Alan

*Project Status: (9/13/2008)*

We have a preliminary schematic. See the directory linked below. We have a sketch of a "Regulator Sled" that would slide into a D mag and replace the switch with the regulator PCB and a tactile momentary switch. There can be other electrical and mechanical designs, but this is what we have thus far.

*We have Code Running:*







The above is a scope capture of the output of the CPU outputting PWM to an LED on the STK500 development test board. It ramps smoothly between different voltage levels. It is not driving the FET in this test setup.

*Next Step:*

We need to prototype the hardware. At this point (9/13/2008) we are waiting for Jimmy, Will and Alan's prototypes to be constructed and tested. Alan built and tested a USBtinyISP programmer. This is a $22 kit for programming the micro in the flashlight. This will be useful for loading the software, changing the parameters, and trying out different versions of the software.

Alan has developed software using the Atmel STK500 board. This board has the programming capability, a socket for the CPU, and an LED and switch that can be jumpered to the chip. Using this Alan has developed software that does most of the basic functions - variable levels, voltage regulation, temperature and low battery cutout, etc. This is still in work, but it is doing most of the important functions required for this project.

Prototypes of the hardware are not yet complete. JimmyM and Alan are both working on some pc boards, but it may be a couple more weeks before this happens.

*Signup Sheet:*

Send me a pm if you want to be added to this list:

Hardware Design: mostly done, here on the forum, by Alan B, JimmyM and That_Guy; with lots of helpful input and encouragement by folks like LuxLuthor, and others.

Hardware Prototyping: Alan B, JimmyM and wquiles working on.

Software Development: The software is pretty far along at this point. Based on AVR-GCC in WinAVR and AVR Studio for this. All Free software tools. 


*Test Programs: (these are done)*

* DLY: Delay Test Program
*
* FP1: Toggle the FET Gate Output Test Program
* FP2: Electronic Pushbutton Switch Test Program
* FP3: PWM Test Program
* FP4: Ramped PWM with Soft Start Test Program
* FP5: Ramped Regulated Calibrated with Soft Start Test Program

More Later.


*Design Files: (schematics and code)*

http://akbeng.com/flash/hwreg/ 

*References:*

The Lightbrain 2002 DIY regulator is very similar to the design goals for this project:
http://lasertagparts.com/lightbrain/free_regulator.htm 

AWR HotDriver (soft start, linear):
http://www.cpfmarketplace.com/mp/showthread.php?t=107783

PIR1 PWM Regulator Thread:
https://www.candlepowerforums.com/threads/107211

PIR1 Regulator Manual:
http://greenengineering.se/PIR1/PIRmanual.pdf 

Willie Hunt Light Bulb Regulator: 
http://www.cs.indiana.edu/~willie/lvr.html 

That_Guy Regulator (similar to LightBrain):
http://img169.imageshack.us/img169/5875/pwmregulatorff7.png
http://rapidshare.com/files/87979929/PWM_Regulator.zip.html

JimmyM JM-SST Soft Start:
https://www.candlepowerforums.com/threads/181866

AW Soft Start:
http://candlepowerforums.com/vb/showthread.php?t=166223

Kiu Bipin Socket:
https://www.candlepowerforums.com/threads/171607

(Destructive) Bulb Testing - lots of bulb data:
https://www.candlepowerforums.com/threads/179748

Atmel Tiny85 Microprocessor Info:
http://www.atmel.com/dyn/products/product_card.asp?part_id=3612

Atmel AVR ISP USB Programming Adapter:
http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail?name=ATAVRISP2-ND

AvrFreaks on the Tiny85:
http://www.avrfreaks.net/index.php?module=Freaks Devices&func=displayDev&objectid=102

Low Cost USB programmer (tested, works):
http://www.ladyada.net/make/usbtinyisp/

AvrDude Programming Software (included in WinAVR):
http://www.ladyada.net/make/usbtinyisp/avrdude.html


----------



## DonShock (Jan 13, 2008)

*Re: Hotwire Regulators*

Winny's PIR1 had a lot of these features. Soft start with programmable delay time, three regulated and programmable voltage levels, programmable low battery voltage warning and cutoff. You can program it with either a sequence of button presses or using a USB programmer and custom software. The bad news is that they are no longer in production but they occasionally come up for sale. That's how I picked one up a while back.


----------



## Alan B (Jan 13, 2008)

*Re: Hotwire Regulators*

Thanks for the tip. Here is the sales/info thread for Winny's PIR1:

https://www.candlepowerforums.com/threads/107211

This is possibly more complex than I was considering. Boil it down to really minimal. But much of the same idea.

Also mentioned was the LightBrain. It has a homebrew version here:

http://lasertagparts.com/lightbrain/free_regulator.htm

They seem to have quit making product in 2005.

I think something in between these two examples is what I'm thinking of.

-- Alan


----------



## pertinax (Jan 14, 2008)

*Re: Hotwire Regulators*

No offense to Winny, but I blew all three of my PIRs-- and I'm not clear how. One minute they're working, then suddenly they weren't. When they worked, they had the features you describe. They were freakin' AWESOME when they worked.

But back to your design: you do NOT want to "filter" the PWM. This isn't audio-- you can't see 1KHz blinking, assuming a filament could heat up and cool down that quickly, which of course it cannot.

The trick is the SW. You need to measure the input voltage, Then figure the right duty cycle to give an RMS equivalent voltage to the desired output. Repeat every second or so.

Unless someone wants to go crazy and take voltage drop during the "on" phase into account, that's pretty much it.

Pertinax

P.S. If anyone would like to try resurrecting some dead PIRs, make me an offer.


----------



## DonShock (Jan 14, 2008)

*Re: Hotwire Regulators*



pertinax said:


> No offense to Winny, but I blew all three of my PIRs-- and I'm not clear how. One minute they're working, then suddenly they weren't. When they worked, they had the features you describe. They were freakin' AWESOME when they worked.......


Yeah, mine's got a glitch too. It works fine until you tell it to turn off fully. Then it goes off and won't come back on until you cycle the power to the driver, then it works fine again. Winny gave me a possible cause, but it doesn't look like that's it. I've been meaning to disassemble it to check it more fully, but haven't done it yet. In the meantime, I'm just using a second tailcap switch to reset the driver.


----------



## Mr Happy (Jan 14, 2008)

*Re: Hotwire Regulators*



pertinax said:


> But back to your design: you do NOT want to "filter" the PWM. This isn't audio-- you can't see 1KHz blinking, assuming a filament could heat up and cool down that quickly, which of course it cannot.


The human eye may not see 1 kHz, but electronic circuitry certainly can. When you have a 1 kHz PWM drive to the load, the voltage is jumping up and down at 1 kHz. I think you have to filter that to provide a smooth feedback reference to measure when controlling the PWM duty cycle.


----------



## Alan B (Jan 14, 2008)

*Re: Hotwire Regulators*



Mr Happy said:


> The human eye may not see 1 kHz, but electronic circuitry certainly can. When you have a 1 kHz PWM drive to the load, the voltage is jumping up and down at 1 kHz. I think you have to filter that to provide a smooth feedback reference to measure when controlling the PWM duty cycle.


 
You are both right. We don't want to filter the power to the filament. We do want to get a measurement of the effective voltage to the filament. In thinking about this further, I can think of several ways to do this, but one thing to understand first is that the effective filament voltage is not the same as the average filament voltage. Power is E squared over R, so averaging the loaded supply voltage over the duty cycle does not give the effective voltage. For example, doubling the voltage and halving the duty cycle will keep average voltage the same, but power will double due to the E squared term of the power equation.

Measuring E under load could be done, but this would require synchronization between the voltage sampling and the PWM. Since there is a sag in the voltage under load, this could lead to sample timing issues, in addition to the complexity. So to keep it simple we want to use some kind of averaging, which is like the process that develops power in the filament.

I did a quick bit of algebra and came up with a correction factor for the average voltage to get to the effective voltage. I define the effective voltage as that DC voltage equivalent to the filament that would produce the same power in the filament as the average voltage we would read under PWM with a simple RC filter. It is the voltage we want to control to.

This correction factor turns out to be one over the square root of the duty cycle. So if we average the filament with a filter, ADC convert that value, and multiply by this correction factor we get an effective voltage value that we can feed back on. So the PWM duty cycle is adjusted upward during soft starting until this effective voltage reaches the user set desired filament voltage.

Do these other hotwire regulators work this way? Am I reinventing the PWM incan regulator here?? 

-- Alan


----------



## Mr Happy (Jan 14, 2008)

*Re: Hotwire Regulators*



Alan B said:


> the effective filament voltage is not the same as the average filament voltage. Power is E squared over R, so averaging the loaded supply voltage over the duty cycle does not give the effective voltage


The term that presents itself here of course, is RMS or root-mean-square voltage. This is the DC voltage that delivers the same power into a resistive load as an AC waveform. 

One over the square root of the duty cycle, huh? That's a neat result. Could provide a use for an op-amp analog square root extractor, or maybe the idea of using a programmable micro-controller is not as off the wall as I originally thought it might be... :devil:

From my internet browsing, there are quite a few examples of analog PWM regulation circuits out there. Unfortunately, I have not understood exactly how they get the voltage/current feedback control part to work out.


----------



## JimmyM (Jan 14, 2008)

*Re: Hotwire Regulators*



Mr Happy said:


> The human eye may not see 1 kHz, but electronic circuitry certainly can. When you have a 1 kHz PWM drive to the load, the voltage is jumping up and down at 1 kHz. I think you have to filter that to provide a smooth feedback reference to measure when controlling the PWM duty cycle.


 
That's precicely it. The square wave output needs to be sampled and filtered. You can't sample the entire current path like a SMPS. That would lead to large inductors and capacitors with associated resistance.
The PIR has problems measuring the battery voltage and calculating the required duty cycle. That's why he had to incorporate a couple of calibration factors. The battery voltage sags under load and the rapid switching introduces noise into the signal as well. You mentioned increasing the frequency. That would help reduce the size of the sampling components and ripple. But it increases heat. You really need to measure a filtered sample of the output voltage. I love the microcontroller idea. I just don't have the programming knowledge to implement your ideas.
I've just received some new components to begin regulator experimentation. However, the L14K softstarter is next in line for building.


----------



## Alan B (Jan 14, 2008)

*Re: Hotwire Regulators*



Mr Happy said:


> The term that presents itself here of course, is RMS or root-mean-square voltage. This is the DC voltage that delivers the same power into a resistive load as an AC waveform.
> 
> One over the square root of the duty cycle, huh? That's a neat result. Could provide a use for an op-amp analog square root extractor, or maybe the idea of using a programmable micro-controller is not as off the wall as I originally thought it might be... :devil:
> 
> From my internet browsing, there are quite a few examples of analog PWM regulation circuits out there. Unfortunately, I have not understood exactly how they get the voltage/current feedback control part to work out.


 
RMS precisely. Forgot to mention that. Excellent observation!

Using a micro seems overkill, but when an 8 pin micro costs $2 in small quantities and reduces the system parts count and gives capabilities not otherwise practical, they're worth it. It makes the thing smaller, and reduces the number of parts and wiring. I would rather write software than wire up a bunch of op amps, myself. Especially if to build 100 of them. PCBs make the wiring easy but there is still the procurement, soldering, testing, alignment, troubleshooting, etc.

Another thought is to have a public PCB layout. Free software is available for PCB layout from at least one company, and they make PCBs quickly via internet upload of the design file. They aren't the cheapest place on the net, but they are quick and good quality and with a public PCB layout anyone can have a few boards made, and even customize them a bit if needed. For about $60 you get three boards, each 2.5 by 3.8 inches. Depending on the side of the actual regulator board, up to about six could be laid out on each of these three boards, so up to about 18 boards could be made in less than a week for under $60 (expresspcb.com). That's just over $3 each. Not bad for quick turnaround, small quantity, and free PCB software that anyone can play with. Alternately one person could do the PCB and hardware, and make a few bucks selling the basic hardware modules. Maybe a small donation per board sold to the forums here would be appropriate as the enabling technology to facilitate the collaboration.

I'm hoping here we can combine efforts of a few folks to get something that no one has time/skill combinations to do alone. Glad to see JimmyM posting here. If we can get one person doing hardware, and one or more doing software we can spread out the effort and perhaps get this thing off the ground. We can start out with simple software and basic hardware and get something useful. Then later it can be improved as needed, and the software re-loaded into the chip. Unlike some of the earlier parts the current parts that are reprogrammable are readily available inexpensively. So new "firmware" for your flashlight is possible. (And since they are off-net they are not subject to viri et al).

-- Alan


----------



## JimmyM (Jan 14, 2008)

*Re: Hotwire Regulators*

I'd be happy to do some schematic to PCB design work. I can also prototype a few for proving. I use "PCB Artist" and winQcad. PCB artist's files can be uploaded to their site for Gerber file creation. WinQcad can generate the Gerber files locally.

The biggest hurdle here is converting a measured sample of a square wave to a DC voltage in a linear fasion. There are RMS converters, but the ones I've found are expensive. Something like $30+ volts.


----------



## Alan B (Jan 14, 2008)

*Re: Hotwire Regulators*

Just adding a uP to your existing soft start switch might be a good start. I've not looked at the soft start schematic, but it does not take many parts, perhaps fewer than the soft start already has. Actually, the LightBrain schematic is very close to what is needed. Links above.

What I'm proposing is to use an RC 'averaging' filter and the correction coefficient from the PWM duty cycle to calculate RMS voltage. Since the filament voltage is too high for the on-chip ADC the filter needs to both divide the voltage and provide enough averaging for a few cycles of PWM. This can be accomplished with two resistors and one capacitor from the filament voltage to the ADC input. The rest is software. No RMS chip needed.

Then multiply the measured average voltage by one over the square root of the duty cycle to get RMS. The PWM correction factor can probably be a table lookup, I don't think much precision is required, if the CPU is not well suited to doing that calculation directly.

I have used both PIC and AVR micros, lately I have been preferring AVRs. A quick look shows the Atmel ATTiny13 8 pin chip might be suitable. 6 I/O pins, PWM, onboard clock, 1K program flash mem, etc, etc. Here is the summary sheet:

http://www.atmel.com/dyn/resources/prod_documents/2535S.pdf

These microprocessor systems on a chip are about $1.29 at Digikey in ones, and about 0.81 in quantity 25!! 

-- Alan


----------



## Mr Happy (Jan 14, 2008)

*Re: Hotwire Regulators*



Alan B said:


> I don't think much precision is required, if the CPU is not well suited to doing that calculation directly


There's a very fast approximate method for 1/sqrt(x) used by the games programming fraternity, that uses some bit twiddling followed by a single Newton update, that might be portable to a micro. I can find the reference if anyone's interested.


> These microprocessor systems on a chip are about $1.29 at Digikey in ones, and about 0.81 in quantity 25!!


What do you need to program them, though? Might that not be the more expensive bit?


----------



## JimmyM (Jan 14, 2008)

*Re: Hotwire Regulators*

The PWM design I have uses low-side switching to avoid using a charge pump/mosfet driver that would be required to use an N-channel mosfet on the high side. P channel MOSFETs don't have the low Rds(on) that N channel fets have. I have a PWM controller picked out that drives a P-channel FET, but I need to do some testing at high power. Heat sinking is at a premium unside a KIU base.

The RC network would just convert the squarewave to a sawtooth. As long as the sawtooths peak-to-peak voltage is within the tolerances of the ADC in the MC, then it should read a pseudo DC voltage. The sample circuit I'm thinking of using is more like the output stage of an SMPS. It should result in a more DC-like waveform. I'm looking into the ripple tolerance of the controller.


----------



## Alan B (Jan 14, 2008)

*Re: Hotwire Regulators*



Mr Happy said:


> There's a very fast approximate method for 1/sqrt(x) used by the games programming fraternity, that uses some bit twiddling followed by a single Newton update, that might be portable to a micro. I can find the reference if anyone's interested.
> What do you need to program them, though? Might that not be the more expensive bit?


 
Programming software is free. That's one reason I prefer AVR to PIC, but there is now free software for both. On the larger parts GCC (the free GNU C Compiler) will work with the AVR, but on the smaller parts assembly is usually required. 

The programming hardware is pretty simple and can be homebrewed, or a nice USB version purchased for $35:

http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail?name=ATAVRISP2-ND

-- Alan


----------



## JimmyM (Jan 14, 2008)

*Re: Hotwire Regulators*

It JUST hit me. The PWM controller's error amplifier's output is brought out at one if the pins (compensation). There's no transient response to deal with. The load is constant. A sawtooth wave at the feedback pin might not be an issue, if the error amplifier has a RC load on it with a time constant several times the switching frequency.
This is good for my design, not necessarily good for the microcontroller design. Unless you want to consider using an external opamp and voltage reference.


----------



## Alan B (Jan 15, 2008)

*Re: Hotwire Regulators*

JimmyM, Good that you figured out something useful from this brainstorming. Lots of good ideas.

Earlier this evening I had a long response to your earlier post typed up and my computer video went away. Looks serious, so I'll have to work on that.

I counted 10 parts in the CPU design by LightBrain. That is a good target. I'm aiming for that neighborhood. 

N channel FET is good for parts count and cost/performance, though the P channel devices are more reliable (tougher, have more safety factor for equal performance). N channel is easier to drive, so cost/parts count comes down. It does create a problem measuring average bulb voltage however.

I'm looking into the details of the micro to see if the ADC can be synchronized easily with the PWM. Then the voltage under load can be properly measured and RMS calculated. This will mean the RC filter won't be needed or wanted. Reduces the parts count to 9. I would add a gate drain resistor however as the micro comes up tri-state, and we wouldn't want that gate to float up and the FET go linear. That would likely blow the FET. Wonder if that's what's happening to the PIR1's. If this was happening I would expect they might come on partially bright and then either go full on (shorted FET) or off (open FET).

-- Alan


----------



## LuxLuthor (Jan 15, 2008)

*Re: Hotwire Regulators*

I didn't see any mention of AWR's Hotdriver which has some other useful contributions to the project.


----------



## JimmyM (Jan 15, 2008)

*Re: Hotwire Regulators*



Alan B said:


> N channel FET is good for parts count and cost/performance, though the P channel devices are more reliable (tougher, have more safety factor for equal performance). N channel is easier to drive, so cost/parts count comes down. It does create a problem measuring average bulb voltage however.


Please explain further. I'm not sure how you mean N-channel fets are easier to drive. For a regulator, we'd have to use it in the "high side". That requires a mosfet driver or some sort of gate drive charge pump to fully enhance the gate. In high side switching the P channel is easiest. Pull the gate to B+ to turn off, pull it to B- to turn on.
I thought the N channel MOSFETs were the more robust chips. Is there some info you could point me to so that I can learn.
And "Yes" a tri state gate spells doom for the FET.

Lux,
You too. Please explain further with regards to AWRs HD. It is a fantastic piece that has served the group very well. But what in his design can we use in a PWM design. Hey, why re-invent the wheel right?
Thanks.


----------



## Alan B (Jan 15, 2008)

*Re: Hotwire Regulators*



JimmyM said:


> Please explain further. I'm not sure how you mean N-channel fets are easier to drive. For a regulator, we'd have to use it in the "high side". That requires a mosfet driver or some sort of gate drive charge pump to fully enhance the gate. In high side switching the P channel is easiest. Pull the gate to B+ to turn off, pull it to B- to turn on.
> I thought the N channel MOSFETs were the more robust chips. Is there some info you could point me to so that I can learn.
> And "Yes" a tri state gate spells doom for the FET.
> 
> ...


 
I'm not sure why a regulator has to use the 'high side' switch. Perhaps you are thinking that way because detecting the filament voltage in a low side configuration is harder, but if the ADC is synchronized with the PWM the low side driver is not a problem, we can still measure bulb voltage under load and use PWM duty cycle to calculate RMS.

On P vs N channel devices I have a thick handbook. It is old, but I think a lot of the info is still good. The P channel devices have a lower density of current carriers, so they have to use a lot more semiconductor material to get the same impedance as the N channel devices. This makes P channel devics cost more (for the same low on-resistance) but they then have more thermal mass and are more robust. For a given amount of semiconductor material, the N channel devices have lower impedance and higher current capability, but for a given impedance level the P channel devices (with more semiconductor material) have more thermal mass. That's what I recall from that source, unless device physics have changed since it was printed.

I think we are saying the same thing regarding driving the FETs.

The N channel logic level devices can be connected directly to the microprocessor in a low side switching configuration, so the drive is easy and low in parts count, as in one resistor to drain the gate when the micro goes tristate. The P channel devices in a high side configuration have to be pulled down to drive them, which requires a driver since the micro pins cannot handle the high voltage, and you have to protect the P channel device gate from overvoltage. So it takes a few more parts. In the solar controllers I have designed it took three resistors, a zener, and another small FET to drive them. So the parts count would go up by 4 and be about 14 instead of 10 parts. Then the averaging circuit on the filament voltage would work so another cap would be needed so 15 parts. Five extra parts plus the higher cost of the P chanel devices would increase costs a bit.

Driving the N channel device in a high side configuration, as you are indicating, is difficult, requiring a higher voltage.

The other problem with P channel devices is they require 10 volts to saturate, while logic level N channel devices will saturate with 5 volts of gate drive. There may be similar P channel devices available but I have not seen them.

Hi LuxLuthor. I have not seen a schematic or technical details on the AWR driver, I did look, but the links have been broken. I was referring to it in the class of "unavailable" drivers mentioned in the first post. So I am not very aware of what might be useful there. If you can help with links that would be useful.

-- Alan


----------



## That_Guy (Jan 15, 2008)

*Re: Hotwire Regulators*

I've already built such a device. Currently it only regulates and doesn't have any flashy features like you listed, but they can be added in software. I'm using an ATtiny13, but can easily port it to any AVR. The Tiny13 is the best choice for DIY, it is the smallest available through-hole AVR at 8 pins, and is the second cheapest/simplest (the cheapest AVR, the Tiny11, cannot be used because it doesn't have an ADC or PWM channel).

It is extremely simple. Basically all you need is the micro and two resistors (and the MOSFET of course). In fact you don't even need the resistors if Vin is less than 5V! Of course the final design is a bit more complicated, but it is still very simple! You just need a few more support components: a capacitor on the input of the micro, a voltage regulator, a capacitor on the input of the regulator, and a diode on the input for reverse polarity protection. Thats it!

The way you a trying to do it is reinventing the wheel, and vastly over complicates things. The best way to do it is slightly unorthodox as it doesn't involve any feedback or measuring the voltage across the bulb, but it dead simple and works well. Pertinax has already said it. All you have to do is measure the input voltage and use the micro to mathematically determine the correct duty cycle for a given RMS output voltage.

The formula is a simple division, and is as follows:
Duty cycle (as a ratio) = (Vout^2) / (Vin^2)

Right now I'm tired and can't think straight. I'll go into more detail of how it all works tomorrow after I've got some sleep.


----------



## Alan B (Jan 15, 2008)

*Re: Hotwire Regulators*



JimmyM said:


> It JUST hit me. The PWM controller's error amplifier's output is brought out at one if the pins (compensation). There's no transient response to deal with. The load is constant. A sawtooth wave at the feedback pin might not be an issue, if the error amplifier has a RC load on it with a time constant several times the switching frequency.
> This is good for my design, not necessarily good for the microcontroller design. Unless you want to consider using an external opamp and voltage reference.


 
The nature of this load as it increases in impedance, and the battery voltage drops make it an easier design than a normal power supply. Things tend in the right direction, and as you mention, transient response is not really an issue. That is one reason a microprocessor can work nicely here in the feedback path, as they might not be as suitable for a general purpose switching supply. This approach really cuts the parts count down. That's why I like these micros. 

Ten electronic parts sounds pretty good to me. Add a programming connector and a PC board, and it still is only a dozen parts. To get an idea of the schematic, look at the LightBrain DIY link above. It is similar to that, though the micro will be different, and remove the filter cap on the ADC input plus add a gate bias resistor on the FET and the programing connector.

If we want temperature detection another part would be required (or more). Is temperature detection useful? Seems like it might be a nice option but not part of the basic package. A Mag85 or ROP level device probably doesn't need that.

-- Alan


----------



## Alan B (Jan 15, 2008)

*Re: Hotwire Regulators*



That_Guy said:


> I've already built such a device. Currently it only regulates and doesn't have any flashy features like you listed, but they can be added in software. I'm using an ATtiny13, but can easily port it to any AVR. The Tiny13 is the best choice for DIY, it is the smallest available through-hole AVR at 8 pins, and is the second cheapest/simplest (the cheapest AVR, the Tiny11, cannot be used because it doesn't have an ADC or PWM channel).
> 
> It is extremely simple. Basically all you need is the micro and two resistors (and the MOSFET of course). In fact you don't even need the resistors if Vin is less than 5V! Of course the final design is a bit more complicated, but it is still very simple! You just need a few more support components: a capacitor on the input of the micro, a voltage regulator, a capacitor on the input of the regulator, and a diode on the input for reverse polarity protection. Thats it!
> 
> ...


 
Just waking up here. Welcome to the thread. Love to see your design, sounds exactly like what I have in mind. If you look at the LightBrain schematic linked above you'll find pretty much what you are talking about, and that was published in 2002. Just needs an update.

Not sure what you mean 'vastly overcomplicating', hard to imaging 10 parts being vastly overcomplicated. I think we are on the same wavelength, actually. If you mean the square root, that would not be needed with the designs we are looking at now anyway. I didn't go through the algebra, but the ratio of squares sounds about right, and a simpler algorithm. Did you synchronize the ADC with the PWM to get loaded supply voltage?

The Tiny13 is the one I mentioned above and appears to be a good choice. I have some others here that would work also (15,22), but they are probably discontinued models so the 13 would be a better design at this time.

Looking forward to see more of your design,

-- Alan


----------



## Alan B (Jan 15, 2008)

*Re: Hotwire Regulators*

Hmmm. Found a better microprocessor. The AtTiny85. Still 8 pins, either through-hole or surface mount. Has onboard temperature measurement, and 8K of program space, and costs under $2 in 25 qty. This one should be compatible with the free GCC (Gnu C Compiler), so it will be much easier to make code for it... The on-chip temperature measurement might come in handy as well.

-- Alan


----------



## JimmyM (Jan 15, 2008)

*Re: Hotwire Regulators*

Good explanation on the P vs N. Moving holes IS harder than moving electrons.
IF you can work out measuring Vbulb in a low side switch configuration, that's great.


----------



## Alan B (Jan 15, 2008)

*Re: Hotwire Regulators*



JimmyM said:


> Good explanation on the P vs N. Moving holes IS harder than moving electrons.
> IF you can work out measuring Vbulb in a low side switch configuration, that's great.


 
A couple of choices. One is to measure Vbulb when the FET is closed, synchronous with the PWM.

Another is to use the differential ADC inputs on the Tiny85, and measure an RC filter that is across the bulb differentially.

I think the synchronous measurement would be advantageous due to the reduced parts count. It can be averaged to give some additional filtering. Some review of the CPU specs to insure this is practical to do, and some testing are probably in order to insure it works well enough.

Measuring the average voltage across the filament is likely more accurate since it ignores other losses (resistances) in the system. Measuring Vbattery when the FET is closed is not taking into account losses in the FET switch. However these should be small enough to safely ignore them in most lights.

That_Guy may have some experience with these measurements, though it wasn't completely clear. It sounded as though his design might be measuring average supply voltage rather than loaded supply voltage. This would tend to give a higher value, and the amount of error would depend on the impedances in the system and cells and the duty cycle. Still, it probably works pretty well.

Another tact might be to measure the minimum supply voltage. This can be done by mathematically processing randomly timed (unsynchronized to the PWM) measurements for the minimum value, or by using a diode/capacitor filter to the ADC. The minimum voltage corresponds to the loaded voltage, so this is a way to get that without requiring precise ADC timing synchronization with the PWM.

-- Alan


----------



## JimmyM (Jan 15, 2008)

*Re: Hotwire Regulators*

So, Alan. When can we expect a prototype? 
If you do the schematic design, I can build a board for it.


----------



## Alan B (Jan 15, 2008)

*Re: Hotwire Regulators*

I will work on a schematic. I need to review the CPU docs pretty carefully. With all that is on my calendar it will probably take a week or so to review all the design details. I am preparing to go to Quartzfest in Arizona next week, so probably after I return would be about right. I will work on it while we are there, should have some time available. I may have internet while we are there (we are camping in the desert there), but it may be hit or miss. RV'ers often have satellite to WiFi setups, so if I can get permission to access one we'll be on the net.

Do you have a favorite N channel logic level drive powerFET or do we need to pick one? Also a low current 5V regulator. 

We need to choose a voltage range so the dividers can be selected.

-- Alan


----------



## JimmyM (Jan 15, 2008)

*Re: Hotwire Regulators*

I don't normally use logic-level mosfets. I'd have to look into that.
As far as regulators go, I like the Linear LT3010-5. SOT-23-5 package, LDO, fixed 5V out, 80V max Vin, 50 mA.


----------



## LuxLuthor (Jan 15, 2008)

*Re: Hotwire Regulators*

Jimmy & Alan, here is the link to his thread with photos. Given the animosity towards AWR, I don't really want to get into presenting specifics of his design....but you can follow the links of his first post to more specifics such as this. He has since incorporated various Inrush Current Limiters (i.e. NTC) to prevent the high watts from blowing his FET.


----------



## Alan B (Jan 15, 2008)

*Re: Hotwire Regulators*



LuxLuthor said:


> Jimmy & Alan, here is the link to his thread with photos. Given the animosity towards AWR, I don't really want to get into presenting specifics of his design....but you can follow the links of his first post to more specifics such as this. He has since incorporated various Inrush Current Limiters (i.e. NTC) to prevent the high watts from blowing his FET.


 
Thanks for the links. I have read some of it. Not too much there that will directly apply to this design, but may be somewhat useful in understanding the operating environment. 

I like the idea of adding the NTC but if the driver is PWM at low duty cycle I wonder if it is needed?

What should the low and high voltage limits be to be useful for folks?

-- Alan


----------



## That_Guy (Jan 16, 2008)

*Re: Hotwire Regulators*

I'm not to sure where to start. Before I go into more detail of my design and how it differs from yours, I first want to make sure I understand what you're trying to do. From what I can tell you are thinking of two different methods:

First method:
The first method is to filter the square wave across the lamp with an RC filter, which gives you the average voltage. You then use the micro to calculate the RMS voltage from the average voltage and duty cycle using the formula you stated earlier. You then modify the duty cycle to make the measured RMS output voltage match the desired output voltage. Correct? How do you modify the duty cycle? Do you compare the measured RMS voltage to the desired voltage and increment the duty cycle by one if it is lower, decrement it if it is higher, and leave it the same if they match? Or is the process different / more complicated than this?

Second method:
The second method is to measure the lamp voltage during the “on” cycle of the square wave by timing the ADC conversion with the PWM wave. You then calculate the RMS voltage. Correct? What I don’t understand here is how do plan on calculating the RMS voltage?



The Light Brain regulator is interesting. I’d never heard of it until now. I knew of Willie Hunt’s LVR, which as far as I know is the original PWM light bulb regulator, and Winny’s PIR, which is based off the same idea as the LVR only more advanced. The Light Brain regulator is pretty much identical to mine. It’s actually quite disheartening to see something so similar to mine after all the work I’ve put in. The circuit is identical to mine, the only difference is that he uses a momentary switch connected to a PIC pin as a software switch, while I use a toggle switch connected to the positive input as a hardware switch.

Apart from the added functionality (soft start, dimmable levels, warning flashes) the software is similar. He uses the exact same method / formula as me to calculate the duty cycle. The two differences are that he uses a lookup table to find the correct value rather than calculating it in real time and he does the PWM in software. Doing the PWM in software allows the use of a cheaper micro without hardware PWM, but they are so cheap anyway it isn’t really worth the added software complexity unless you’re making thousands of them.

Calculating the duty cycle in real time is easy on the AVR because it’s so fast. Even at around 300 cycles per calculation it is so fast that with the appropriate components it could probably be hooked up directly to the 120VAC mains with nothing more than a full wave rectifier and do a decent job of powering a 12V halogen down light.

Calculating the duty cycle in real time has a few advantages. It’s much simpler because to change the desired output voltage all you need to do is change a single 8-bit constant at the top of the code. To change the voltage with a lookup table a whole new table needs to be generated and pasted into the source code. It also has the advantage that the output voltage can be changed during runtime. This allows a pot to be used to change the voltage as it’s running similar to the AWR Hotdriver.

I'll go into detail about how mine works next post once I know how yours works.


----------



## Alan B (Jan 16, 2008)

*Re: Hotwire Regulators*



That_Guy said:


> I'm not to sure where to start. Before I go into more detail of my design and how it differs from yours, I first want to make sure I understand what you're trying to do. From what I can tell you are thinking of two different methods:
> 
> First method:
> The first method is to filter the square wave across the lamp with an RC filter, which gives you the average voltage. You then use the micro to calculate the RMS voltage from the average voltage and duty cycle using the formula you stated earlier. You then modify the duty cycle to make the measured RMS output voltage match the desired output voltage. Correct? How do you modify the duty cycle? Do you compare the measured RMS voltage to the desired voltage and increment the duty cycle by one if it is lower, decrement it if it is higher, and leave it the same if they match? Or is the process different / more complicated than this?
> ...


 
Works isn't quite the right term since this design has not yet been constructed.

When I found the LightBrain I was surprised how similar it was to what I was starting to put together. Optimized designs do tend to the same schematic.

At this point my design looks like the LightBrain except less the filtering capacitor on the ADC input, and add a gate drain resistor on the FET.

The ADC is used to measure the loaded supply voltage. This is used to calculate the desired PWM. I have not gone through the algebra here but it is likely the ratio of the squares that you mentioned (and apparently also used by the LightBrain). Since we want smooth ramping of the voltage this desired PWM would not be used directly but subtracted or compared to develop an error, and a change applied to the control ramp value. The change amount would be a parameter to control the ramp rate. Or a proportional gain can be used, so a percentage of the error is applied at each control cycle, which is the usual way proportional integral feedback loops work.

The LightBrain design uses an "average" voltage rather than the "loaded" supply voltage. This won't matter much for low impedance supply situations, but will yield a high result for higher impedance ones. This will tend to lower the RMS bulb voltage when the source impedance is high. It is safe, but is a bit less "regulated".

I would rather calculate in real time than use a lookup table, if a lookup table is used it would be generic and not changed for each voltage. Having field programmability somewhat like the PIR1 is a longer term goal, but should be possible with the design hardware.

The PWM is developed by the AVR hardware rather than software.

This newer tiny85 has lots of memory so features can be added later on. It also has a temperature detector so a safety shutdown can be built in.

The circuit design needs to be compatible with the programming plug, as we want to change the firmware in-situ for development and possibly later in the target system. Perhaps a small connector next to the control switch under the rubber boot..

The input operating voltage range is going to be 5 plus the low dropout regulator headroom, to at least 16V. 

I don't know how you feel about putting design and code into the open. My goal here is to make this open and available, and give credit to all sources. Perhaps this can become the "Linux" of PWM Hotwire Regulators..

-- Alan


----------



## KingSmono (Jan 16, 2008)

*Re: Hotwire Regulators*

I just want to say that I'm extremely excited to read of this "collaboration" that may bring a regulated incan driver to the market! This is why I love CPF. I can't wait until I can say !!!


----------



## Alan B (Jan 17, 2008)

*Re: Hotwire Regulators*

Thanks for the encouragement.

I did a draft schematic. I need to review the pin choices carefully again but it is close to adequate for a prototype. Hope to publish that within the next day or so.

-- Alan


----------



## NextLight (Jan 17, 2008)

*Re: Hotwire Regulators*

If this project needs some micro SMT assembly done: Right now I have time, plus formal HP-Agilent training & certification in hand solder & inspection, and about $30K of Metcal soldering towers, tips, fixtures, tools, and a Zeiss Stereo Microscope in my lab, looking for something fun to do. 

PM for further.

Keep up the good work(s)!


----------



## That_Guy (Jan 17, 2008)

Ok, now I understand. You're pretty much doing the same thing I am (and what the Light Brain does). The only difference is that I calculate the duty cycle directly, while you want to do it in a more complex round about sort of way by using a method similar to guess-and-check. Why don't you want to calculate the duty cycle directly? Your method isn't any more accurate, but much slower. Doing it directly has a much faster transient response. You said you want a smooth ramping of the voltage, I presume by this you mean a soft start? Soft start is easy with my method. This is where being able to change the output voltage during runtime comes in. All you need to do is start off with the output voltage set to 0, and go around a loop incrementing the output voltage by one each time until it reaches the desired value. The rate can be changed by adding a delay between each increment of the output voltage. No doubt there are many other, possibly simpler methods, but this is fairly simple and has the advantage of providing a true linear voltage ramp.

To be honest, however, I'm yet to be convinced of the value of a soft start. Most of CPF seems pretty keen on it, in many cases even more so than regulation, but in my opinion regulation is far more important than soft start. Apart from the constant output and increased efficiency regulation also extends bulb life because it cuts off the initial voltage peak that batteries have during the first seconds after the light is turned on. Any benefit attributed to soft start may in fact come from it “burning off” this extra voltage and the extra resistance it adds. 

Now, onto how mine works in more detail. The ADC is used to measure the input voltage. It should be noted that the input voltage and lamp voltage (referenced to ground, not the negative lamp terminal) are the same since they are connected together. Initially the ADC was being used in free running mode so it only measured the average input voltage, but now I have it synchronized with the PWM so it measures the input voltage under load.

The micro then uses the input voltage to calculate the duty cycle to give the desired RMS output voltage. The formula is what I said above:

Duty cycle (as a ratio) = (Vout^2) / (Vin^2)

Since it is a ratio the result is between 0 – 1. This then needs to be multiplied by 0xFF before it can be written to the 8 bit output compare register. So the formula now becomes:

Duty cycle (ready to be written to output compare register) = [(Vout^2) / (Vin^2)] * 0xFF

You can see that the result of the division is a floating point number. This is easy enough to do in C, the entire formula could simply be written in one line as is and work, but I’m programming in assembler which makes things much more difficult. Apart from being difficult to do in assembler the floating point division is also slow, so I simplified the equation to eliminate any floating point operations. It’s easy enough, all that needs to be done is move the 0xFF to the top line. The equation now becomes:

Duty cycle = (Vout * Vout * 0xFF) / (Vin * Vin)

That’s a 24 bit integer division, no floating point required (I’m only using 8 bits of the ADC). It is still quite complicated to do in assembler from scratch, but there are 24 bit division routines on the internet which make it easy. All I needed to do was download one and paste it into my code. 

Calculating the denominator is easy since it is just an 8 x 8 multiplication. That can be done on a Mega as just “mul Vin,Vin” since it has a hardware multiplier. It’s a bit harder (and slower) on the Tiny because it has to be done in software, but is still easy because there are plenty of 8 x 8 routines on the internet.

The numerator is a bit more complicated since it’s an 8 x 8 x 8 multiplication, which works out to an 8 x 8 followed by a 16 x 16. However since Vout is a constant the entire numerator can be calculated during compile time, no multiplication required. This of course makes it impossible to change the output voltage during runtime which means that you can’t do soft start or change the voltage with a pot, so I’ve also included a 16 x 16 division routine and code to calculate it in real time. However this is quite slow on the Tiny, so I would rather use a Mega if I want to go this route. The Megas also have a few other advantages (over the Tiny13 at least) such as 16 bit timers for higher resolution PWM which allows accuracy to be maintained at higher input to output voltage ratios.

I’m happy to give out my source code, but on one condition: I want first shot at selling it. I’m happy for people to build their own or modify my code, just no selling. I know this sounds mean and selfish, but I’ve put a lot of effort into this, over 100 hours and over $100 (over $500 if you include the tools I had to get such as an oscilloscope). Being an unemployed student it would be nice to be able to get something back. I’m happy for other people to take over and sell them once I stop making them, or if I never start (if say I don’t have one on the market within the next three months). This way the CPF community won’t be left in the dark once I stop, like what happened when winny stopped selling his PIR. It’s just for as long as I’m selling them myself that I don’t want any one else to do the same. However since I’ve already given away the “secret formula” it would be trivial for you or anyone else to make something similar in C since it is nothing more than a simple one line formula.

I really am pretty dumb for waiting this long to sell it. I initially made this as the assessment project for my microcontroller class back at the start of 2007 since I wanted a PWM regulator for myself and winny had stopped selling his PIR and there was no one else on the horizon with any plans . I wasn’t confident of my success in making a functional regulator so the idea of selling it didn’t cross my mind until after I had finished. I didn’t want to step on anyone’s toes so it was only because no one else had any plans for making one that I even considered it at all. However I then got bogged down with work and didn’t have any time to work on it. It’s only now during the end of year holidays that I’ve had time. Now there are three other individuals that I know of with plans for a home-made PWM regulator: you, JimmyM, and Atomic_Chicken (for the M6-R). I still don’t want to step on any toes but now that’s pretty much unavoidable and I really don’t feel like abandoning it now after all the work I’ve put into it. It’s like my baby. However all of us DIYers will soon be made obsolete anyway with AW planning on releasing his commercial regulator in the form of a beautiful, simple, easy to install, user friendly and professionally made Mag drop-in.


----------



## Alan B (Jan 17, 2008)

*Re: Hotwire Regulators*



NextLight said:


> If this project needs some micro SMT assembly done: Right now I have time, plus formal HP-Agilent training & certification in hand solder & inspection, and about $30K of Metcal soldering towers, tips, fixtures, tools, and a Zeiss Stereo Microscope in my lab, looking for something fun to do.
> 
> PM for further.
> 
> Keep up the good work(s)!


 
Thanks for the offer. Sounds like a terrific setup. We'll have to see how this develops.

-- Alan


----------



## radellaf (Jan 17, 2008)

*Re: Hotwire Regulators*

Don't the ADCs on these devices sample fast enough that you could just sample the whole out or in waveform and average a few seconds worth of samples in software?

Could these micros run low enough to regulate a 2 cell light? There's got to be a way to drive a FET off 2-3 volts otherwise how would a 1 cell boost LED driver work?


----------



## Alan B (Jan 17, 2008)

*Re: Hotwire Regulators*



radellaf said:


> Don't the ADCs on these devices sample fast enough that you could just sample the whole out or in waveform and average a few seconds worth of samples in software?
> 
> Could these micros run low enough to regulate a 2 cell light? There's got to be a way to drive a FET off 2-3 volts otherwise how would a 1 cell boost LED driver work?


 
Averaging is definitely possible.

What kind of cells? A 3V system is possible, but the design is quite different, and not as simple. I suspect the minimum for the present design is about 6V. So 2 Li-Ion cells would be ok, if the regulator behaves reasonably when the input voltage gets low. I have not reviewed the regulator that JimmyM proposed.

-- Alan


----------



## Alan B (Jan 17, 2008)

That_Guy said:


> ...
> I’m happy to give out my source code, but on one condition: I want first shot at selling it. I’m happy for people to build their own or modify my code, just no selling. ...


 
Thanks for the offer. Unfortunately, the conditions are incompatible with the goals for this collaboration, so I cannot accept. I wish you the best of luck on your project, and I hope you do proceed. I look forward to seeing your product on the market, and I believe that having a couple of products in this area would be good.


----------



## radellaf (Jan 17, 2008)

*Re: Hotwire Regulators*

1.2 or 2.4V. 2xAA is just my favorite size (and running price).


----------



## cy (Jan 17, 2008)

*Re: Hotwire Regulators*

AWR has some well earned animosity from a load of folks. besides taking thousand of folks hard earned $$$ and not delivering. 

his activities had a chilling effect on other budding hotwire regulator mods. 

instead of delivering product, AWR was all time announcing some new latest greatest product.... and of course collecting more $$$ from gullible folks. 

the list of regulated hotwire projects, killed by AWR's announcements was complete. almost all competition was killed off, resulting in shortage of regulated hotwire boards that exist today. 

correct me if I'm wrong, but willie hunt's PWM hotwire board as used in JS's M6R addressed all issues mentioned so far. problem is willie hunt is not interested in selling individual boards 

willie hunt's design might be a good place to revisit. 



LuxLuthor said:


> Jimmy & Alan, here is the link to his thread with photos. Given the animosity towards AWR, I don't really want to get into presenting specifics of his design....but you can follow the links of his first post to more specifics such as this. He has since incorporated various Inrush Current Limiters (i.e. NTC) to prevent the high watts from blowing his FET.


----------



## Alan B (Jan 17, 2008)

*Re: Hotwire Regulators*



cy said:


> ...
> correct me if I'm wrong, but willie hunt's PWM hotwire board as used in JS's M6R addressed all issues mentioned so far. problem is willie hunt is not interested in selling individual boards
> 
> willie hunt's design might be a good place to revisit.


 
I have read the entire threads that you have quoted, and that was AWR's linear regulator.

Thus far I have not found Willie's threads. I did some searching for them but did not find them. Any links would be appreciated. Is Willie still around??

-- Alan


----------



## cy (Jan 17, 2008)

*Re: Hotwire Regulators*

do a google search for willie hunt , he's a designer for surefire. his home page should pop up. willie hunt has no threads on cpf. 

black diamond headlamps has used his boards. 

also do a search on CPF for M6R by JS 

willie hunt will do custom batches of boards to customer's spec's. 
that is if you can get him to return your phone call. 



Alan B said:


> I have read the entire threads that you have quoted, and that was AWR's linear regulator.
> 
> Thus far I have not found Willie's threads. I did some searching for them but did not find them. Any links would be appreciated. Is Willie still around??
> 
> -- Alan


----------



## Ctechlite (Jan 17, 2008)

*Re: Hotwire Regulators*

I've got a few of Willie Hunts LVR (3D variety) if you want to have a look at them to see if you can figure out how they work. I am working on incorporating them in a torch but have stalled due to lack of readily available parts. Custom for me right now is an obstacle so they are just waiting on my work bench.

Some Willie info...


----------



## That_Guy (Jan 17, 2008)

Alan B said:


> Thanks for the offer. Unfortunately, the conditions are incompatible with the goals for this collaboration, so I cannot accept. I wish you the best of luck on your project, and I hope you do proceed. I look forward to seeing your product on the market, and I believe that having a couple of products in this area would be good.



In what way are my conditions incompatible? It is still an open collaboration, and people can still build their own, the only difference is that instead of you getting to sell it it would be me. I'm just kind of annoyed that I've given everything away which will allow you to get a product to market faster than I can, making all my efforts amount to nothing.

What sort of time frame are you looking at? Even though I have already designed, built and tested my regulator it will take at least two months before I can go into production. This is because my design is currently all through-hole using a vero stripboard which is fine for personal use, but not really something I can sell to others. For that I need a professionally made surface mount PCB which, living in Australia, will take a month to get here for the prototype (from batchpcb), and assuming it all works another month for the production run to arrive. In reality it will probably take more like three months once construction and testing is taken into account. If you can get something up and running earlier than that then there is little point in me continuing.


----------



## Alan B (Jan 17, 2008)

That_Guy said:


> In what way are my conditions incompatible? It is still an open collaboration, and people can still build their own, the only difference is that instead of you getting to sell it it would be me...
> 
> What sort of time frame are you looking at? Even though I have already designed, built and tested my regulator it will take at least two months before I can go into production. This is because my design is currently all through-hole using a vero stripboard which is fine for personal use, but not really something I can sell to others. For that I need a professionally made surface mount PCB which, living in Australia, will take a month to get here for the prototype...


 
By the way, what is your name? You don't sign your posts. It is nice to have at least a first name.

I don't intend to sell anything. My intent, which I tried to state in post #1 (which I have updated slightly a couple of times), is to facilitate an open design and software. I expect that one or more persons will build these and make some profit in doing so, and hopefully contribute a little something to CPF from those sales (perhaps 5%?), and I will be able to buy them for my own use. You are welcome to be one of the builders of our group design. I hope JimmyM will also be interested in building them. If no one at all builds them I might consider building them myself, but I don't have the time at this point and don't expect to anytime soon. If I have to do my own, I would probably put the PCB layout files on the web and folks could use the layout.

You could sell hardware of our design and put your secret sourcecode on it. You are way ahead of us there.

One thing I'm trying to end here is the exclusivity of making regulators that has resulted in limited or no availability. I also want something that is user programmable so it can be tailored for different applications. As far as I can tell, zero products on the market or promised will do that. 

The timeframe is not really up to me. I plan to publish a schematic within a week or so, and then we'll see what happens. I don't know what the situation is in Australia, but here in California I could layout a PCB and have prototypes in my hands in under a week for something with so few parts.

In terms of the design, I'm not planning to change it from what was stated. I did the algebra and came up with duty cycle = Vrms^2 / Vbat^2, as you had pointed out. No getting around the algebra. I still plan to use a feedback loop as described. I won't worry about the details of the calculation until I get farther along. I'm familiar with integer / floating point calculations and tradeoffs in microprocessors, I've been working with them since 1974 (and boy were they primitive). What I'll do there is see what the compiler generates and decide if I need to improve it or not. With the 8k program space it may not be necessary to work as hard as you did to get the algorithm in. Later, as the software is improved and more features are desired it will likely be required to drop more code into asm, or tweaked C code optimized for the environment.

As I plan to put the software into the public domain as well, I expect others will take it up and make improvements. Perhaps I won't end up writing the code at all - perhaps someone will volunteer to do that. We'll have to see how it plays out.

-- Alan


----------



## Mr Happy (Jan 18, 2008)

That_Guy said:


> If you can get something up and running earlier than that then there is little point in me continuing.



I really don't see this. This is a kind of enthusiast/hobby environment where people will buy stuff for the enjoyment of it. It can't hurt to have choices out there. If there is more than one offering available, people may well buy samples of all of them to compare.

It is not a business enterprise that is going to make anyone a millionaire. We are talking about a bit of pocket money to help defray the cost of parts and development and make it a less expensive hobby.

You should also realise that it's a big bad world out there. If you publish any of your designs, you really have no legal way to stop anyone manufacturing them and selling them as their own work. I'm not saying anyone here would do that, but once published anyone with access to Google can find the information. If you really want to keep things for your own benefit, you will have to keep them confidential. I'm afraid that's just the way the world is.



Alan B said:


> One thing I'm trying to end here is the exclusivity of making regulators that has resulted in limited or no availability. I also want something that is user programmable so it can be tailored for different applications. As far as I can tell, zero products on the market or promised will do that.



From what I read, this is true. I don't think there is anything secret about the kind of design and technology involved here. There should be options available for the people who aren't in a position to design and build their own, and if there are competing designs out there rather than none at all it can only be a good thing.

Every time someone says "X is doing it, so I won't bother," the world loses a bit of richness.


----------



## That_Guy (Jan 18, 2008)

While there is no reason why I can’t continue to develop and sell my design alongside this collaboration I really can’t see the point. Choice and competition is great in the commercial world, but for hobbyists on a small budget it isn’t so good. There is little incentive to spend any significant amount of money developing or improving something if there are no guarantees of being able to recoup the costs because there is already something similar or the same on the market.

In my case if I were to continue the only costs would be transitioning from a through-hole design to surface-mount. It might not sound too costly but the reason I’ve stuck with through-hole this whole time is that surface-mount is expensive in Australia. With through-hole I can order all the parts locally and use vero stripboard instead of a PCB. With surface-mount I need a proper PCB. Using batchPCB, which as far as I know is the cheapest for single prototypes, I’m looking at around $20 and a one month wait. There are faster options, but they are even more expensive. The most costly thing is the parts. Most need to be ordered from overseas, and Digikey charge a minimum of $30 to ship internationally, so it can get expensive quickly, especially if you realise you need another part after you’ve placed your order which almost always ends up happening. So to sell my design I’ll probably be looking at spending a minimum of $100 on top of what I’ve already spent. Since my costs are much higher I would also have to sell my design at a much higher price. Since it isn’t really any different to what’s going to be designed here I doubt many people would be interested so it is unlikely I would be able to recoup my costs.

While talk of profit always sounds evil next to talk of open source projects, it really is necessary to drive innovation, even amongst hobbyists who aren’t in it for the money. The money made from projects goes beyond just recouping the costs spent developing it. The money I was planning on making was going to be reinvested back into the design to make it better. One of the first things I would have done would be to purchase a True RMS multimeter to allow me to properly measure the output voltage which would allow me to improve the accuracy of the regulator.

Open collaborations like this are good because they allow people to contribute and make improvements without having to bear the costs of doing such things themselves, and there’s nothing stopping me from contributing. In fact I would be happy to because it doesn’t cost me a cent. However there are limits to this. With open source software the only investment needed from the developers is time. But this is hardware, and hardware costs money. Sooner or later someone is going to have to pony up the cash and that person is going to be less willing to spend much money if they can’t get any of it back. They may be happy to spend a little bit, but to make more dramatic improvements in a design it often takes a lot of money and the only place that money is going to come from is profit. The fact is profit drives innovation, without it things will stagnate. 

Despite seemingly being motivated by profit it doesn’t mean that I want to keep everything a secret. I like the idea of an open source regulator. My plan all along had been to do something similar to what you hope to achieve. I was going to announce my regulator, with the source code, schematic and PCB layout all freely available, along with a detailed description of how it all works and instructions on how to build your own and modify the code, hardware and PCB layout to your own requirements. The only difference was that I wanted exclusive rights to sell it so that I would be guaranteed of making a profit to both recoup my costs and fund further development. This restriction was only going to be for as long as I sold it, so that when I stopped other people could take over and CPF wouldn’t be left without a regulator.

I was really hoping that since our goals were so similar that I would be able to convince you to settle for what I had already designed and let me make some money selling it, but it looks like that’s not going to happen.

Since the only point of restricting the sale of my design was to prevent any competition, it doesn’t make any difference to me if someone else sells a regulator based on my design or your’s. I am therefore willing to give out my source code with no restrictions. However there probably isn’t much point since you want to do it in C. The only reason I used assembler is because I don’t know how to program microcontrollers in C. You could probably write a program in C in less than 15 minutes which would be easier than trying to understand what I’ve done.

Despite the impression I may have given you there really isn’t anything at all special about my source code. It really is quite simple. It’s only 226 bytes long, doesn’t use any RAM and isn’t at all optimized. What’s special is the equation. That’s the beauty of a microcontroller based PWM regulator – its elegance. All it is is that one little equation. Very simple yet very powerful. My main piece of advice would be to drop your idea of using a feedback loop and just calculate the duty cycle directly. As far as I can see there is absolutely no benefit to doing it your way. Apart from slowing down the response it ruins the elegance. As far as I know my method is the same used by everyone else: Willie’s LVR, winny’s PIR and the Lightbrain. I’m still a novice when it comes to electronics so if there is an advantage to your method I’d be interested to hear it but at the moment I just can’t see any point.

To design the regulator in C all you need to do is configure the timer for PWM on one channel, and then configure the ADC to be triggered by the timer on the other channel. You then use the ADC interrupt to calculate the duty cycle. You use an if statement to check if Vin < Vout, in which case the duty cycle is 100%, and if it isn’t you then use the formula to calculate the duty cycle. Simple as that. Are you still interested in my code?

Regards,
Tim


----------



## Akarusa (Jan 18, 2008)

That_Guy said:


> There is little incentive to spend any significant amount of money developing or improving something if there are no guarantees of being able to recoup the costs because there is already something similar or the same on the market.


Tim,
While I can understand wanting a reasonable probability of profit before investing, nobody in a free market gets a guarantee that they'll recoup their costs. Profit and risk go hand-in-hand, and there is no practical way to close this market for regulators in order to break that rule.

I really can't see what you expect to gain from getting some kind of exclusivity agreement. Even if someone were to agree to your terms, once your code is publicized, any 3rd party who wasn't part of the agreement could do whatever they want with it. Short of copyright or patent protection (and their attendant costs), that's just the reality of things.

And if, as you contend, your simpler design is more elegant and efficient than the one discussed here, wouldn't that alone create a separate market niche for your product and partially insulate it from competition?


----------



## Alan B (Jan 18, 2008)

Here is a pencil draft of the design so far. Sorry I have not had time to make a pretty schematic. In essence, it is not much different from the LightBrain linked above. I included a capacitor on the ADC input but that may not be required or even desirable, but it can be left unloaded. Many details regarding i/o and programming pins are different for this CPU. About 12 parts including PCB and programming connector.

http://akbeng.com/flash/hwreg/attic/20080118 loside.pdf

Jimmy proposed a regulator, I did not investigate to see if it requires the support parts shown. The FET needs to be selected, a logic level gate N channel in the 30V, 30A, 5 milliOhm region.

Form factor would seem to be circular to fit on a KIU socket. The FET might heatsink on the socket adapter, perhaps. Some access to the programming jack should be provided for development and future software or parameter changes. Of course a prototype does not have to fit, but with this few parts I might go for a fitting prototype...

-- Alan


----------



## JimmyM (Jan 18, 2008)

That's nice and simple. I see the voltage divider you have there would be sensing battery voltage. Be careful of that capacitor though. When the mosfet turns on, it's going to dump when the battery voltage sags. The resistors will have to be pretty large value. 1M on the high side, and 100K on the low side. I like the simplicity. I'll do some looking around for logic level mosfets.

OK. IRLR6635 Int Rectifier, 30V, 32A, 2.4 mOhm @ 4.5V. DirectFET MX, 6.4mm x 5.1mm footprint. Odd package though. It would require oven reflow soldering.
or
IRLR7843 Int Rectifier, 30V, 100A, 3.9 mOhm @ 4.5V, DPak package. 6.7mm x 10.4mm footprint. Slightly higher gate charge would slow down switching speed, but not very much.


----------



## That_Guy (Jan 18, 2008)

While under normal circumstances I would love this project it's just disheartening for me because I had already gone so far down the path of designing something so similar myself, and now I'm going to lose my baby. Despite seemingly being motivated by profit it was never meant to be a commercial venture to make me rich and I never wanted to compete with anyone. I was just wanting to fill the void left by winny, the same as this project, and hopefully make a bit of money to fund further development and buy better equipment. If I had announced my idea earlier I doubt this thread would exist, it’s just that I wanted to wait until I had finished before announcing annoying. Of coarse it's my fault for waiting so long in the first place. If I had built it once I had finished designing it 8 months ago instead of sitting on it there wouldn’t be any need for this project. Sure others would eventually have made commercial units and gone into competition with me, such as AW with his commercial Mag regulator, but it wouldn’t matter because I would have already made enough money off the initial period of exclusivity that I could either drop my prices or stop production and let someone else take over with my design.

The fact that my design is simpler and more elegant won’t make the slightest bit of difference because consumers won’t be able notice and won’t care. It’s really just an intellectual nicety. But as I’ve said I don’t want to compete.

I’m happy to contribute as much as I can to this project. At least that way all my efforts go completely to waste and I won’t feel as bad.

Does anyone know of any good guides on the internet for programming AVRs in C? I shouldn’t have any problems making the program myself once I know how to manipulate the registers.

Regarding hardware the first thing that should be decided is what are the requirements with regards to size and power handling? A small low power regulator could be made to fit inside a C Mag, or a large high power regulator could be built for powering monster bulbs like the 36V 400W 64663 used in the Ken 5 or the 28V 600W Q4559X used in “The Sleeper” and the Larryk14. Something to fit a D sized Mag would probably be the most popular, but since AW is already coming out with a regulator to fit a D sized Mag with the added convenience of a professionally designed drop-in including switch and socket there isn’t much point. Of course there can be a number of different versions, but something should be settled on initially.

You also need to decide if it’s going to be surface-mount or through-hole. The Tinys are the best choice for through hole because at 28 pins the smallest Megas are too large. However for surface mount this isn’t a problem. The 8 pin Tinys are only available as SOICs while the Megas are available as TQFPs so despite the greater number of pins they aren’t really any bigger. Both are also available as the tiny 4 x 4mm QFNs but they are much more difficult to solder. I would recommend using the AtMega48 since it isn’t much bigger or more expensive, but has a hardware multiplier, more timers including a 16 bit for higher resolution PWM, an AREF pin for reducing the noise on the ADC and more IO pins allowing the option of things like LEDs to indicate battery voltage.

Regarding the choice of MOSFET I’ve found switching losses to be far more important than a low Ron. Even when switching at only 294Hz with a MOSFET driver and a mediocre MOSFET with a Ron of 5.3mOhms I’ve found switching losses to dominate at higher input voltages.

The resistors used for the voltage divider can’t be very high, the ADC requires an input impedance of less than 10k for good accuracy.


----------



## Mr Happy (Jan 18, 2008)

That_Guy said:


> While under normal circumstances I would love this project it's just disheartening for me because I had already gone so far down the path of designing something so similar myself, and now I'm going to lose my baby.


I think it's a shame you are disheartened so readily. With no disrespect to Alan, whatever is discussed in this thread so far is vaporware. It may come to nothing. There have been any number of threads like this in the history of discussion forums that have gone nowhere.

I'm sure everyone would welcome your input if you choose to join in and add more of your contributions here, but there is some realism to face up to as well. From what you have said, Australia is not such a kind place to innovate in as the USA. I find that resonates a little since I have met Australians who have emigrated in order to find a more stimulating high technology environment than their home country. If it's as costly as you say to work from your home base, you do face some obstacles that set you back from the start. Is there really no domestic Australian equivalent to Digikey?

If you have built a working prototype already, then I think you have achieved two of the most important things, namely (1) your own personal education and edification, and (2) the satisfaction of designing and building something that works. I think your dismay here arises from building a future vision in your mind and then knocking it down. Remember that right now you have not lost anything except a future of your own imagination. Keep imagining and don't be disheartened! I'm sure you have a long career ahead of you.


----------



## That_Guy (Jan 19, 2008)

Mr Happy said:


> Is there really no domestic Australian equivalent to Digikey?


There's Farnell which has a huge range, but they still don't have the more exotic parts, and despite being in Australia shipping is still pricey at $10. They can also be very expensive, making Digikey cheaper in some cases even with the excessive overseas shipping charges. Despite this I'm actually quite lucky because there's a brick and mortar chain called Jaycar which caters to the hobbyist and has a surprisingly good range. It's great being able to walk in and buy individual components and even though they are very expensive it doesn't matter when most parts are no more than a couple of dollars anyway. The only problem is that they cater a little bit too much to hobbyists - they hardly sell any surface-mount stuff. 



Mr Happy said:


> I think it's a shame you are disheartened so readily.


 It's probably because this is the first time I've ever attempted anything like this. After I had realised that I could actually sell something I had designed I got really enthusiastic about the whole idea and went getting my hopes up.



> I think your dismay here arises from building a future vision in your mind and then knocking it down.


 Yep, that's pretty much it. Next time I design something or have an idea I need to go out and do it, rather than waiting around for months and then whinging when someone else decides to do something similar.


I'm happy to contribute, it will make me feel useful and better about this whole thing. Is this project going to be done in C or assembly? I would really like to learn how to program micro controllers in C. I can already write basic C programs for DOS, it's just C for AVRs specifically that I need help with. I've been trying to find some guides on the internet about it but I haven't found any simple and clear guides yet. It's so confusing with all the different compilers and linkers and makefiles and things. Assembler seems so much easier, it is nice and simple and straight forward.


----------



## Alan B (Jan 19, 2008)

I like to use a mix of C and assembler, but if we have a standard hardware platform there can be different codes for it, and some could be C and some assembler.

AVRFreaks website is the place to get the info on the gccavr compiler. I have not used it recently, but there is a package to download and install. It is confusing to get it working at first, once going it is really a snap. There are a few special C idioms that are specific to I/O that need to be learned. And one has to be very careful. For example, doing a floating point anything brings in a lot of library code, so on a small chip it can overflow it. Once in it can be used without much further code growth. 8K parts have quite a bit of space, but can be filled up. A 2k part can be overflowed with a single formula, so no floating point there.

On the processor, my tendency for the first go-round is to stay with an 8 pin part. If we want to make it simple enough that someone can dead-bug it, the megas are probably too fine pitch in the smaller packages. They probably don't have a temperature sensor either, though I didn't verify that. 

Good points about the FET specs. If we choose a generic enough package the FET can be easily substituted. I would expect that any logic level gate FET would be potentially suitable. Look in Digikey and suggest something. We're wide open on this.

Another issue is off-current. If we have to make the divider too low in impedance it will draw some current. Also the 5V regulator we use should have very low idle current, or we may have to turn it off. I'd like to keep the parts count low. We should choose an off-current maximum spec. Something like 2500 mAH divided by six months??

In terms of a space requirement, my own needs at this time are for D Mag, which would be into a KIU socket base. Perhaps fitting in a KIU C socket base would be more universal, however. I have neither at this time, so someone could help here by putting the available size of those two environments. Are there other packages that we should consider?

On the AW regulator, I don't know for certain what it will do, or when it will be released. It looks very nice physically (the non regulated version). I think the differentiating factor that makes me interested in this collaboration's version is that it will be more flexible than one from any vendor with closed hardware/software. 

If you look at LED regulators, there seems to be plenty of market space for many units. Even a single vendor offers almost a dozen variations. This market is possibly smaller, but don't forget there are many cavers, etc who really prefer incans and not necessarily the super power models, but more practical long running stuff. At least one designer will only answer the phone for 10,000 units per order!

I am interested in a fairly basic hardware design, but perhaps a phase II would be much more sophisticated. How about a zigbee RF interface, so you could control your flashlight and set its parameters as well as read out battery status, etc from a distance. Save that for later.

I am going to Quartsite Quartzfest tomorrow and I need to get the RV packed. Any CPF'ers going should look me up. We'll be with the Ham Radio group at mile marker 99. I may have internet, or not.

See you folks in a week. Play nice!!

-- Alan, WB6ZQZ


----------



## JimmyM (Jan 19, 2008)

That Guy,
There's nothing wrong with having more people at the party. AW has a fancy soft starter with 3 levels in a custom switch body. I have my JM-SST. It's just the board and sells for 1/3 the price. They're both soft starters and both are selling.
I'm happy to help this project in what ever way I can, but it won't stop my development on a PWM regulator of my own. I can't do PICs or AVRs, so I'm going with what I know. A PWM controller and a P-channel MOSFET. If your design is better and you want to release it on your own. Please do. It will have it fans and detractors as everything does. But it will be your design and your baby.
I kind of felt the way you do when AW brought out his soft starter before I announced mine was ready to go. My mine still sells well for a couple of reasons, it's cheaper and super durable.
Keep at it!

For my part, I'm still in the hunt for the "perfect" PWM controller.


----------



## petrev (Jan 23, 2008)

Hi All,

No help in design terms here I'm afraid - just a bodger.

Had a PIR (or 2) - Loved it but it broke . . . Winny Off-Line.

AWR-HD broke the fragile little trim pot and never got it back from AWR.

I tend to buy multiple different things to try them so . . .

Make mine nice and robust with provision for an external volume pot - love the JM-SST for that and looking forward to Jimmy's regulated version soon.

Have to keep my eye on this one - looking forward to the results . . .

Cheers 
Pete



ps. Kiu C-Adapter space is really quite small 17.9mm Dia. by 6.9mm deep

D-Adapter 30.4mm Dia by 7.0mm deep

there are quite a few places where a bit of Dremeling can be done to make extra room for odd components . . .


----------



## JimmyM (Jan 23, 2008)

petrev said:


> Hi All,
> 
> No help in design terms here I'm afraid - just a bodger.
> 
> ...


I have a design that kind of works off the JM-SST design basics but does regulation. Now I'm in the process of trying to find chips that do more than one thing at a time. I found a chip that is an oscillator, comparator, error amplifier, and a high-side NFET driver. I think it's been discontinued though. AAARRRRRRGGGGGGHHHHH. I'll be breadboarding this weekend.


----------



## Alan B (Jan 29, 2008)

Back from vacation. Spent some time working on this, have some new designs. At this time the variation I like best is to drive a high side N channel 4.5V gate FET using a capacitor, resistor and diode from the PWM pin of the IC. Not sure this will work, need to do some calculations, but it appears to be sound. Anyone want to breadboard and test that? Apply a 5V square wave to the circuit and see if the FET stays cool??

The high side driver allows the voltage divider chain to be lower impedance since it is on the bulb side and not energized when the light is off. This is important to keep the off-current from draining the batteries. The lower impedance divider chain is required to get good accuracy from the on-chip ADC and still keep the parts count low.

Based on the small size of the C KIU socket I would propose that the first design be made for M*G D size. The design should be set up to work with the KIU socket without drilling a bunch of new holes in the KIU unit.

I received my KIU socket but have not found the instructions. I presume the Mag tower must be milled off and the KIU screwed to it. How is the assembly located in the M*G tube?

I have read pretty much the entire PIR1 thread. I can see a couple of common issues that need to be dealt with.

Calibration is one. I am considering calibration schemes that make it much easier for the end user to calibrate it without complicating the design.

-- Alan


----------



## That_Guy (Jan 29, 2008)

Alan B said:


> The high side driver allows the voltage divider chain to be lower impedance since it is on the bulb side and not energized when the light is off.


Wouldn't it be easier to just use a FET to disconnect the voltage divider?


I've finished tidying up my source code, so if you're interested I can release it. All I need is somewhere to host it. There's sites like Rapidshare, but being forced to wait 5 minutes in a queue to download a 2kB file is rather stupid, the page telling you to wait in a queue is larger than the file itself! Since it's just text I could post it directly in this thread, but that would be rather messy.


----------



## JimmyM (Jan 29, 2008)

One of the lowest Rds(on) MOSFETs I've found at 4.5V is the IRLR7843, but that is 5V ABOVE the MOSFET source pin. You can't do that without a high side driver.
My suggestion would increase the parts count by 3, but would properly enhance the gate of a power MOSFET.
Use a dual channel LDO (5V for the microcontroller, 12V for MOSFET driver) instead of a single channel to just drive the controller.
The Infineon 
TLE4484 is an SOT-223 package that outputs 5V & 15V, If the pack voltage is under 15V, the 15V side is in LDO mode and just passes pack voltage to the LTC4440 (high side gate driver in an SOT-23 package). It will boost the gate voltage by that amount.
The maximum Vcc of the LTC4440 is 15V so it would be close.
This will fully enhance the gate of ANY N channel mosfet resulting in lower Rds(on) and faster switching times, both reduce heat and increase power handling.
I know it increases component count, but I think it results is a better, more flexible design. Input voltages can be as high as 45V with the TLE4484, and choice of MOSFET is wide open. The IRLR7843 for 6-30V operation with moderate to high current or the IRF2804 for very high current up to 40V or the IRF3206 for up to 60V operation.
A variety of "standard" boards could be possible.
Version "A" is smallest with a single SOT-23 regulator on board with the IRLR7843 good up to the maximum input voltage of the LTC4440 (15V).
Version "B" is a D size KIU only, with dual regulator good up to 45V with the IRLR7843 (30V) or IRF2804(40V).
Version "C" is a larger square board with dual LT3014B regulators and any 1 or 2 MOSFETs up to 80V.
If I'm given schematics I can build the PCB designs for "A" smallest possible, "B" 30mm OD, "C" smallest possible rectangular with provision for 2 MOSFETs.

Just my 2 cents.


----------



## Alan B (Jan 29, 2008)

Jimmy, sounds like good suggestions. Have to look into drivers, though I'm not sure we need them for our low frequency switching. How much power do these LDO regulators draw. They are powered all the time, even if the micro goes to sleep. Are they low enough to leave on?

Here is a schematic showing a low parts count hi-side N channel driver variant.

http://www.akbeng.com/flash/hwreg/attic/20080129 hiside 0.0.pdfhttp://akbeng.com/flash/hwreg/2008_01_29_16_58_45 hwreg hiside driver.pdf

The above schematic is not fully detailed, but shows a low parts count approach to driving an N channel FET using capacitive coupling and a simple DC offsetting circuit. The upside is simplicity. The downside is it cannot be driven at DC, the duty cycle must be slightly less than 100%. I have not tried this technique, but with the proper component values it should work. One upside is that the ADC divider is not drawing power from the battery all the time, only during bulb on pulses.

Perhaps someone else has tried this technique and can comment on it, we would like to hear that.

Tim, I'm wondering if the best way to share your design is for you to start a separate thread or web page for that. We can link to it from this thread to tie it together. That is how other external designs are referenced, and it would keep your design separate from this thread and give you direct credit for it. It is a bit early for sourcecode in this thread, and this design may not work with your stock code. It would really be neat if your code was the first to work on the collaboration's hardware, but it would require some modifications depending on how the hardware goes.

One thing I learned from reading the PIR1 thread was the difficulty of calibrating the setup was a stumbling block. I have been thinking about a calibration design for the past week. There are three things to calibrate. One is the voltage divider. The other two are the ADC gain and offset. They can be combined into a gain and offset pair. My current thinking is to select two calibration voltages. One should be near the nominal battery voltage. This one is used to determine overall gain. The second calibration voltage should be significantly less - half the first or thereabouts. It is used to determine offset. Calibration is generally done once when the board is new. 

Required Equipment:

Variable DC power supply
DC meter of sufficient accuracy
Programming cable and software (not required if the calibration voltages are already set)
Calibration jumper
LED/resistor load

The procedure might then be:

1) remove regulator from flashlight (if necessary)
2) connect to programmer
3) program the two calibration voltages into the nonvolatile parameter memory (the code and parameter memory should already have been programmed)
4) remove power (and the programmer) from the board and install the calibration jumper and install the resistor/LED into the bulb output
5) set the power supply to the first calibration voltage and apply power to the board
6) observe the LED which will be partially on. When the LED goes off the first part of the calibration is done, and the overall gain value will have been saved into parameter memory
7) (optional, go to step 9 if offset is not to be changed) set the power supply to the second calibration value and apply power to the board
8) observe the LED as in step 6, this time the ADC offset will be measured and saved into parameter memory
9) remove the calibration jumper
10) reinstall the board

-- Alan


----------



## That_Guy (Jan 30, 2008)

I'll say it again: why not just use a FET to disconnect the voltage divider? I can't see any problem with it, and it's much simpler than using a high side MOSFET.

The quiescent current of the regulator JimmyM suggested is 500uA, although in reality it would be lower because it is spec'd at a 1mA load. Not great, but not high enough to be much of a problem with most setups. There are LDO regulators designed specifically to have a low quiescent current (<50uA) if such a thing is really needed.

Why do you want to use a software on off button? While it has the advantage of being able to use a momentary switch to convey extra information for things like dimming, it significantly complicates both the design and operation. For the first version at least a hard switch is more suitable: zero standby current, minimum parts count and can be used with standard toggle switches.

The biggest problem that I can see with winny's PIR was that it was too complicated. It required a momentary switch which meant modding or replacing the stock switch and it was difficult to adjust the voltage. One button programming is very inconvenient, and plugging it into a computer isn't much better and requires an expensive programmer.

Despite being vastly inferior and having a fixed low voltage cut-off AWR's Hotdriver was much more popular. It could be used with standard toggle switches, no modifications required, and the output voltage could easily be adjusted with a pot. Its popularity can't all be attributed to its simplicity, his name and his slick BS sales pitch also had a lot to do it (this really annoyed me, and I do feel for winny who didn't enjoy the success that he deserved, but that’s a story for another time), but its simplicity was certainly a big factor. So the aim for my design, for the first version at least, was to keep it as simple as possible. Standard toggle switch, a pot to adjust the voltage, and a pre-programmed low voltage cut-out. Similar to the Hotdriver, but with the advantages of higher efficiency and the high input output differential that goes with it, user chosen LVC instead of the fixed 80% of Vin, and the ability to plug it into a computer to change things like the LVC for the more advanced users.

So if you want to make something that will benefit the greatest number of CPFers my advice would be to initially make something simple and straight forward like the Hotdriver, not something as advanced and feature packed as possible. That can come later.

Regarding calibration, the biggest source of error isn't the ADC itself but the internal reference voltage which has an accuracy of +/- 10%. So all you need to do is measure the actual voltage on the Aref pin and use that in all the calculations. The ADC itself is quite accurate, I can't really see any need to calibrate it unless the specs given in the data sheet are overly optimistic.

I can't really see much point starting a new thread for my code, I doubt anyone outside this thread would be interested. This is meant to be a collaboration, not a number of different designs, so I don't see why it should be kept separate. The software is by far the most important part, so a significant chunk of the work is already done. I don't see how it is too early for source code. The hardware is trivial, there really is nothing to it. The hardware should be built around the software, doing it the other way round doesn't make much sense, although since it’s so simple it doesn't really make much difference in this case. The only challenge is selecting the best MOSFET, taking into account both switching and resistive losses, and selecting the best MOSFET driver to go along with it for higher power versions.

I'll post my code tomorrow with an explanation of how to use it. This should accomplish the core aims of this project: a DIY regulator with open source code. All that is left after that is designing the production surface-mount PCB to sell since most people aren't interested in DIY, and the more advanced features such as one button programming.


----------



## Alan B (Jan 30, 2008)

Tim raises some good points here. Can we get some input and comments from others?

How many folks want on/off with a single output voltage using a hard power switch. This would require disassembly of the flashlight and removal/reprogramming with a computer to make any parameter changes. 

How many would be willing to set up a soft switch (mod the M*g switch) and get more possible features, with a greater upgrade path?

My feeling is that we design the hardware to handle the simple case as well as the more complex case, and the user can decide when they install the PCB. Then software and installation can choose. The soft switch input pin can be left open, and the software configured to regulate whenever power is applied. Then we can make a different configuration of the software that uses the soft switch input for more features.

(One quick thought here is that disconnecting power "hot" to the high side design may need to be analyzed to insure that the gate-source voltage limit is not exceeded).

FET disconnect of the ADC divider - not easy. Low side would allow high voltage to the micro, and would not break the current drain, high side is not low in component count.

Using a low quiescent current regulator - I am in favor of this. I don't like electronics that is always discharged when you need it. I might put a tailcap switch in anyway for full off, but would prefer that to be optional.

Calibration - I don't believe Vref is readily available to measure externally on an 8 pin part (I would like to stay with an 8 pin part to make the smaller size boards more feasible), and this would not take the voltage divider component values into account, so it does not really meet the requirements. If you read the PIR1 thread they seemed to have significant problems with adequate calibration, perhaps because folks are pushing some of these bulbs hard to the edge. I would like a simple calibration procedure that gets gain and offset and takes into account the components on the board, and something that anyone with minimal equipment can do. Suggestions?

-- Alan


----------



## petrev (Jan 30, 2008)

Hi

Non expert input !

Power-on regulated system is good for both traditional Mag switch and also tail switch designs (SF-M6 etc. and Mag Mods). That's why I liked Willie Hunts design (but it's not re-programable! ) and the JM-SST. However the famous PIR was also great for easy(ish) re-programming.

How about Power-On regulation and a two-pin push-button programming option so that a push switch could be added (or optionally fitted with an acces hole in the Kiu say) for reprogramming or greater features ? Could be active if a jumper were fitted to make the board a Constant-On version with Blip-Switch functionality or if no jumper then programming only function and Power-on regulation ? Just an idea ! Does this make sense to people who know.

On the "little pot" front . . . AWR's were useless as they kept breaking when actually used ! (mine did on the HD anyway). JM-SST much better and useful. Personally don't mind the regulation setting being by programming (as long as it is fairly easy to redo somehow - see above) but an external 20% to 100% pot can be a real boon to some of the bigger Mods as I have found with the JM-SST(special) and adds great functionallity to those "BIG" ones eg. Larry12K, Blitz, Sleepers etc. (not made any yet just hoping . . .)

Hope this helps (?)
Pete


----------



## cnjl3 (Jan 30, 2008)

Mod the MAG switch is my vote.
Removing and reprogramming with disassembly sounds ugly.
One button programming or "durable/reliable" adjustment trim pots would be my choice.


----------



## JimmyM (Jan 30, 2008)

My vote is to use 1 pot for voltage adjustment, and another for low voltage cut off. Use the stock switch to turn control power on/off. Batteries would be connected directly to the PCB/Bulb.
Let's get a working design schema before we start getting fancy and asking for the moon.

Use the stock switch to control power to the onboard regulator or some enable/disable pin that pulls low to shut off. Having an automatic LVC based on a percentage of battery voltage is useless. It would have to know what a full pack voltage is. Just use 1 1M pot across the battery to sample voltage as an input to the processor. Don't forget to put a 5V zener on the wiper to prevent it from blowing the processor and a small cap to even things out as the voltage shifts because of switching. Program it to disable output if voltage falls below 2.8V and re-enable above 3V. That's a ~7% off/on hysteresis.

This is getting too complicated and will never get built if we're looking for a regulator that will do everything.

By the way, my PWM regulation design is working pretty well on the bench. 300Hz. I just need to work on the linearity of the sample circuit.
If I set Vbulb to 7.2VRMS it starts at 7.2V at Vin=7.2V then falls to 6.6VRMS as I increase voltage to 15V. The output is a super sharp square wave with nearly un-detectable ramp unless I really crank down the sec/Div.


----------



## Alan B (Jan 30, 2008)

Great comments, folks! Keep them coming. I'm not going to reply on the comments at this time.

Here is an update of my draft schematic.

http://www.akbeng.com/flash/hwreg/attic/20080130 hiside 1.0.pdf

I refined things a bit in the draft schematic from yesterday, specified a few parts and pinouts. 5.2 - 40V range, 6.5 milliOhms FET, about a dozen parts. About 50 uA standby current drain. Protection for the FET gate. Programming connector. Control input (which can be used or ignored, depending on software). There are a couple possible ways to use jumpers on the programming connector to communicate with the software, which can be used for calibration or operation mode selection.

This design measures bulb voltage. The ADC is synchronized with the PWM so this will be loaded battery voltage, so battery protection can be monitored. 

The simplest way to program this design is to set nonvolatile parameters in the chip using the programming cable. This inexpensive USB programmer plugs on to a six pin connector on the board (Atmel AVR-ISP mkII). Install firmware and set parameters like battery cutoff voltage and bulb output RMS voltage(s) in the chip. Do a calibration to determine the ADC versus DC voltage levels. Install in the flashlight and go.

This hardware is pretty simple and can still meet the design requirements, and has a lot of code space for improvement. It can be operated on simple code, and more advanced software can be done later.

-- Alan


----------



## JimmyM (Jan 30, 2008)

Nice and simple. What is the duty cycle limit? 95%? 99%? What is the switching frequency?
Is there any way to get me a simply programmed chip to breadboard the design?
I found a nice N-FET from Fairchild: FDD8444L, 40V, 50A continuous, Rds(on)=3.8mOhm @ 5V Vgs. Perhaps an alternative


----------



## Alan B (Jan 30, 2008)

Jimmy,

If you have a 5V square wave generator the output stage can be breadboarded. That will give a pretty good idea if the FET drive circuit is going to work. If you can vary the duty cycle, even better, but if not still it would show if the capacitor coupling is going to work.

For the initial test microprocessor, I think we should follow in your pattern. Program a chip to sweep from 0% to full% in say 10 seconds, a soft start chip. Make the ramp slow so the behavior of the circuit can be examined. Check the FET for heating, try different loads, etc. Perhaps the zero-eth version of the production software should be a soft-start setup, that would be a useful setup to wring out the system in real flashlights before the regulated software. Just a few parameters to set in the nonvolatile memory such as PWM start, PWM end, PWM rate of change.

As to your questions. I have not programmed this chip's PWM system, so Tim may be able to speak from his experience with his similar chip. The frequency is programmable, there are some limits, but we should be able to do 300 hz or somewhere near there.

The max duty cycle is theoretically 255/256. This needs to be tested to verify that there is no issue. A narrow off-time could possibly heat the FET depending on how things switch, but it should be okay. There are things we can do if needed to improve it.

The Fairchild FET sounds good. We should collect a candidate FET list and check availability/pricing at some point. One spec we need to watch on the FET is input capacitance. If it gets too high it may affect the drive circuit. The FETs I looked at were under 5kPF, and the drive cap is 200x that, so it is not likely a problem.

I have not tried to calculate the effect of this drive setup on the output of the micro. I should look at that a bit. I doubt it is a problem.

-- Alan


----------



## That_Guy (Jan 30, 2008)

JimmyM said:


> Let's get a working design schema before we start getting fancy and asking for the moon.


My thoughts exactly. Start with something simple, get it working, then build on it from there. The most important part of a regulator is the regulation, the rest is just icing on the cake!



Alan B said:


> FET disconnect of the ADC divider - not easy. Low side would allow high voltage to the micro


Didn't think of that. What about putting the FET in the middle, after the first resistor, but before the micro? With a 1.1V ADC reference and 5V input to the micro Vgs would be 3.9V at maximum input voltage, enough to fully turn it on. If a 2.56V reference is used Vgs will only be 2.44V - are there FETs out there designed to operate that low?



Alan B said:


> Calibration - I don't believe Vref is readily available to measure externally on an 8 pin part.


That's a nice thing about the Tiny85 - one of the pins can be configured as Aref. After looking at the data sheet it is quite a nice chip you've found. It also has a second timer which should come in handy for the more advanced features, and differential inputs and programmable gain on the ADC. Really the only thing it is lacking compared to the bigger chips is the multiply instruction.

In my case the actual output voltage is 8% lower than what I programmed - it'll be interesting to see how much of this is due to Vref, and if calibration of the ADC will still be needed.



My code is here and a simple schematic for breadboarding or DIY using strip board or whatever is here.

It is set up to use the AtTiny13 with pin 3 as the ADC input and pin 5 as the PWM output. It is very bare bones - it only regulates and has no LVC or soft start. Feel free to edit or add to it. All the different things that are likely to be changed are at the top of the code for easy access. The variable names for the math routines are very long because I have difficulty remembering the abbreviated names. The code is designed for ease of use so it isn't the most compact or efficient, but this shouldn't matter since it is so small anyway.

Accuracy of the regulation itself is decent. Output is highest when Vin = Vout, and steadily drops as Vin increases. On the bench with Vout set to 10V and a Vin of 30V light output drops by around 5 - 10% according to my budget light meter. That works out to a RMS voltage drop of around 1.6 - 3.2% with a Vin to Vout range of 3 to 1.

My first priority is to add a low voltage cut-out, it should only take a few lines of code so it shouldn't take much more than an hour if I stop being slack and get to work, assuming no one else wants to give it a try. After that is the soft start, which is a bit more difficult but should still be fairly easy if it works as planned. After that there is porting the code to the Tiny85, and adding the ability to change the output voltage with an external pot.

I can't be bothered going through the code and how to use it right now, I've written enough already, I'll go into more detail next post.


----------



## Alan B (Jan 30, 2008)

Tim, very elegant small design and low parts count, and the source file looks pretty small and clean, too, though I didn't try to grok the code at all.

One possibility for Jimmy to breadboard the driver is to use one of your programmed chips to generate the PWM.

-- Alan


----------



## JimmyM (Jan 31, 2008)

I do have a PWM source running at 300Hz. I can at least breadboard the output stage. I have IRLR7843's to test.


----------



## Alan B (Jan 31, 2008)

JimmyM said:


> I do have a PWM source running at 300Hz. I can at least breadboard the output stage. I have IRLR7843's to test.


 
Excellent.

Another thing occurred to me this morning. We can have a POT input option, or a switch input, or possibly even both inputs at once, or of course neither for those DC switch only designs. I will look into that, and other configurations of the I/O pins such as an LED output. That would allow a lot of flexibility.

NOTE - I have updated the first post in this thread to include reference links to a lot of stuff. Please post suggestions to expand this so we can use this as a central repository of links for this project.

EDIT - added new schematic with POT interface option, as well as two more I/O lines useable for serial, jumpers, or boolean I/O.

http://www.akbeng.com/flash/hwreg/attic/20080131 hiside 1.3.pdf


-- Alan


----------



## That_Guy (Feb 1, 2008)

I've added a low voltage cutout. Here is the latest version of the software. Rather than triggering as soon as the input drops below the minimum it increments a counter and only triggers after a certain number of low readings to prevent transients from triggering it. When the LVC is triggered the micro goes to sleep, but this can easily be changed.

I also made an Excel spreadsheet for calculating the values for Vout and LVC from the resistors used for the voltage divider and the voltage of the ADC reference. It is included in the zip file containing the code.


----------



## JimmyM (Feb 9, 2008)

I've had some success in my own, non-microcontroller design.
I've got a design breadboarded that will maintain 7.5V to a bulb as the input is swept from 8-13 volts. It uses a 40kHz PWM controller that is 100% duty cycle capable and has softstart built in.

I am noticing something odd however. Perhaps because the bulb I'm using is a 12V automotive bulb and is really underdriven in testing.
My fluke 189 measures 7.5V and 1.8 amps the during the whole sweep. I mean it doesn't vary by more than a few hundredths. But the bulb increases in brightness as I increase input voltage. Not a lot, but you notice it. I'll be redesigning the wiring to reduce resistance and make sure everything is wired properly.

My next step is to purchase slightly different parts that have a better voltage range.

Do you guys/gals have any idea what may be causing this brightness variation?


----------



## Mr Happy (Feb 9, 2008)

JimmyM said:


> My fluke 189


Wow, nice multimeter! :wow:



> Do you guys/gals have any idea what may be causing this brightness variation?


Yes, I have an idea. What about the difference between average voltage and RMS voltage? Which one are you controlling to and measuring with the meter?

The bulb will only remain at constant brightness if you provide a constant 7.5 V RMS to it. If you provide a constant average voltage of 7.5 V, the power supplied to the bulb will change with the duty cycle of the PWM wave.

You do have a true RMS meter, so I'm wondering if you are using a true RMS mode when reading the voltage?


----------



## Alan B (Feb 9, 2008)

Hi Jimmy.

To maintain constant RMS voltage on the bulb requires a feedback circuit that is sensitive to RMS, not average voltage. There is a difference (related to the square root of the duty cycle, as I recall). I did the math earlier in this thread, and I later noted it in the PIR1 thread.

The microprocessor can compensate for this, but doing it without a micro would require a square law circuit.

Did you ever get a chance to try a capacitive FET driver?

-- Alan


----------



## Alan B (Feb 9, 2008)

True RMS meters have a crest factor limitation, as I recall, and a square wave probably exceeds it.

-- Alan


----------



## Mr Happy (Feb 9, 2008)

Jimmy,

What happens if you put a smoothing capacitor across the output of the PWM regulator?


----------



## Alan B (Feb 9, 2008)

I would be careful about putting a capacitor across the PWM output. It would tend to make VERY LARGE current surges in the switch, possibly exceeding ratings.

-- Alan


----------



## Mr Happy (Feb 9, 2008)

Alan B said:


> True RMS meters have a crest factor limitation, as I recall, and a square wave probably exceeds it.


 

For the kind of money that meter costs, I would expect perfection!


----------



## AMD64Blondie (Feb 9, 2008)

A hotwire regulator would be wonderful,as I love my Mag85..but hate the rapidly dimming light output. (How would the regulator be intergrated?)


----------



## Alan B (Feb 9, 2008)

Received my 1000 lumen 15 watt Ostar in a Maglite from Mac today. Wow. But back to topic...

I don't know for certain what the capability is of a modern meter to measure RMS accurately, I just recall there were limits in the past. Perhaps they have been reduced. It is suspcious that it reads a constant value, hinting that it may be reading average instead of RMS, which may be a function of the range setting of the meter. Perhaps the correct way to measure these regulators is by measuring average light level, and forget about measuring the RMS. Instead measure the duty cycle and peak voltage and calculate the RMS. Jimmy do you have a scope?

-- Alan


----------



## Alan B (Feb 9, 2008)

AMD64Blondie said:


> A hotwire regulator would be wonderful,as I love my Mag85..but hate the rapidly dimming light output. (How would the regulator be intergrated?)


 
The circuits we are looking at are PWM circuits that chop, or interrupt current flow to the filament, so they require extra voltage to have regulation (they allow using much higher voltage than required, and efficiently use the extra energy). The thermal inertia of the filament averages the chopped power, so the light does not pulse. The physical installation would be a small circuit board generally located between the battery pack and the light, near the switch in a M*g. The KIU type bulb socket has some room for that in D diameter M*gs, whereas C type M*gs are more challenging. Other bulb configurations might require modification to make room for the circuit board.

-- Alan


----------



## JimmyM (Feb 9, 2008)

Alan B said:


> Received my 1000 lumen 15 watt Ostar in a Maglite from Mac today. Wow. But back to topic...
> 
> I don't know for certain what the capability is of a modern meter to measure RMS accurately, I just recall there were limits in the past. Perhaps they have been reduced. It is suspcious that it reads a constant value, hinting that it may be reading average instead of RMS, which may be a function of the range setting of the meter. Perhaps the correct way to measure these regulators is by measuring average light level, and forget about measuring the RMS. Instead measure the duty cycle and peak voltage and calculate the RMS. Jimmy do you have a scope?
> 
> -- Alan


 Yes. A scope. Check.
I'll take some more measurements. My 189 can tolerate crest factors of 3 at full range and 6 at half range. I'm reading 7.5V on the 50V range. So It is accurate for at least a crest factor of 6. What is the crest factor of a square wave?
How do I build a square law circuit?


----------



## JimmyM (Feb 9, 2008)

Mr Happy said:


> Jimmy,
> 
> What happens if you put a smoothing capacitor across the output of the PWM regulator?


I tried that. Cooked the MOSFET. Just before that, it drove the error amp completely berzerk. But I'm not sure it cooked the FET because of current or because its gate voltage was all over the place causing too much heat.
I was thinking of connecting a second small mosfet in parallel with the main one just to feed the voltage feedback divider. Then I could have a capacitor filtered output to the bulb without the odd wave form messing up the error amp.


----------



## Mr Happy (Feb 9, 2008)

JimmyM said:


> I tried that. Cooked the MOSFET.


Ah. Oops. 

Sorry about that. I hope you read Alan's warning before you tried it...


----------



## JimmyM (Feb 9, 2008)

Mr Happy said:


> Ah. Oops.
> 
> Sorry about that. I hope you read Alan's warning before you tried it...


I'll just thow it on the pile with 2 FET drivers that I cooked by wiring the output and Vin pins backwards. Yeah. TWICE. Oh well.


----------



## Alan B (Feb 9, 2008)

The costs of education (burning out parts). In a sense, my flashlight investment can be chalked up to similar goals  And Ham Radios, and ...

I had a little mishap with one of my solar controllers (my design and PCB), and blew the center of the FET right out. Made a hole in it. Not much smoke at all. Did that with an IC driver chip once, under program control. Never had software go bang before or since.

If you look at the circuit, you have a battery, FET and capacitor, which looks like a short until the voltage equals the battery. So the capacitor pulls some amazing current pulses, tempered only by the impedance and inductance which are both low. That's why they use inductors for storing energy in switching power supplies and not capacitors.

Making a circuit that is sensitive to the square, and having enough bandwidth is a problem. That's why the RMS meters have limits. Diodes have square law behavior in low current regimes, and other analog chips take advantage of this for that kind of response. They have range and bandwidth limits.

Another way to do this feedback is to use a light sensor picking up light from the filament, and regulate based on that. Shield it from outside light, and make it an IR sensitive pickup to minimize other light. External light will turn down the power, so it will be safe anyhow.

The crest factor is the ratio of peak voltage to RMS voltage, so you can estimate it if you have the duty cycle. Your meter should be okay down to a duty cycle of 1/6th, but if it reads constant it sounds like it is in an averaging mode instead of RMS.

The micro sounds more appealing all the time.

-- Alan


----------



## JimmyM (Feb 9, 2008)

It reads constant as the voltage rises and duty drops. I'll check the meter settings and see what I can come up with.


----------



## Mr Happy (Feb 9, 2008)

In an effort to learn more about this stuff, I am reading this paper (PDF warning). I'm only part way through it, but it looks somewhat topical.


----------



## JimmyM (Feb 10, 2008)

Doing some more research myself and some more reading with the 189 proves that this is the case. The regulator is maintaining Average voltage. The bulb. of course, is reacting to RMS voltage. My DMM clearly shows, now that's on the proper setting, that the voltage rises as the duty cycle decreases.


----------



## That_Guy (Feb 11, 2008)

I've added a soft start, latest version here.

It starts the output voltage at 0 and increments it by one unit (not one volt) every PWM cycle until it reaches the preset output voltage. This makes it a linear voltage ramp, rather than just a linear duty cycle ramp. Only drawback is that the soft start time is dependent on both the output voltage (as a binary value in the code, not the absolute output voltage) and the PWM frequency. The is also a counter which can be used to extend the soft start time by making it increment the output voltage every x cycles. At the standard frequency of 294Hz a value of 0 is fine and probably doesn't need to be raised above 1 or 2 for low output voltages, it is mainly for the higher PWM frequencies that it is needed.

So is anyone going to build a regulator or not?


----------



## Alan B (Feb 12, 2008)

Tim, nice improvements.

Jimmy, great job. This really shows why a micro is the way to do this project. Any chance to check out a capacitive FET driver soon?

Thanks,

-- Alan


----------



## JimmyM (Feb 12, 2008)

That_Guy said:


> I've added a soft start, latest version here.
> 
> It starts the output voltage at 0 and increments it by one unit (not one volt) every PWM cycle until it reaches the preset output voltage. This makes it a linear voltage ramp, rather than just a linear duty cycle ramp. Only drawback is that the soft start time is dependent on both the output voltage (as a binary value in the code, not the absolute output voltage) and the PWM frequency. The is also a counter which can be used to extend the soft start time by making it increment the output voltage every x cycles. At the standard frequency of 294Hz a value of 0 is fine and probably doesn't need to be raised above 1 or 2 for low output voltages, it is mainly for the higher PWM frequencies that it is needed.
> 
> So is anyone going to build a regulator or not?


 
Send me a programmed controller and the schematic you want to use. I'll see what I can put together.

AlanB, No, sorry. I haven't had a chance yet to test the capacitive drive.


----------



## That_Guy (Feb 12, 2008)

JimmyM said:


> Send me a programmed controller and the schematic you want to use. I'll see what I can put together.



There isn't much point in a preprogrammed chip because you won't be able to change anything. Sparkfun electronics sell serial and parallel port programmers for $12.95, and if you have the time you can make one yourself for even less. All you need is a parallel port cable and a 74LS245 or similar. There are a number of circuits for DIY parallel port programmers on the internet, I used this one.


----------



## JimmyM (Feb 12, 2008)

That_Guy said:


> There isn't much point in a preprogrammed chip because you won't be able to change anything. Sparkfun electronics sell serial and parallel port programmers for $12.95, and if you have the time you can make one yourself for even less. All you need is a parallel port cable and a 74LS245 or similar. There are a number of circuits for DIY parallel port programmers on the internet, I used this one.


 
Once I have my bench cleared a bit, I might be able to get into what you're suggesting. But I'm barely able to spend time on the projects I have now. I've got one regulator design breadboarded and have a lead on an average to RMS compenation fix. After that I have to integrate low voltage protection. After that, I need to scale it to a high power design.
I'd like to be more "on board" with the microcontroller design, but I'm more apt to have success using the techniques I understand. Plus I think the approach that is being persued is too simplistic. Personally, I don't think the capacitive gate drive will work to fully enhance a big n-channel FET. If this design is to be truely flexible you can't use a logic level FET to carry the power level that will be required. Also, 100% duty cycle is necessary for LDO operation.


----------



## That_Guy (Feb 13, 2008)

JimmyM said:


> Plus I think the approach that is being persued is too simplistic. Personally, I don't think the capacitive gate drive will work to fully enhance a big n-channel FET. If this design is to be truely flexible you can't use a logic level FET to carry the power level that will be required. Also, 100% duty cycle is necessary for LDO operation.


The capacitive gate drive is just one possible method of overcoming the problem of the voltage divider drawing power when off when a "soft" on/off switch is used, it isn’t an integral part of the design. At the moment my design doesn’t use this at all, it is just a low side MOSFET driven by an optional MOSFET driver. A high side MOSFET driver is probably the best way to go for driving a high side MOSFET rather than the capacitive gate drive if it is decided to go down the route of using a high side MOSFET. A MOSFET driver it isn't much more complicated or expensive than the capacitive gate drive, but has the advantage of lower resistive losses due to the higher gate voltage in addition to the reduced switching losses and 100% duty cycle.



Is anyone reading this interested in building their own regulator? All you need is a soldering iron and basic soldering skills, some time and a bit of money (no more than $50, probably around $25), although some basic electronic knowledge would help (able to understand simple circuit diagrams and construct a circuit from it). The main limitation is that, being through-hole, it will be quite large so it won’t be very suitable for going into a Maglite. I can write a step-by-step guide explaining how to do everything if someone does want to DIY.


----------



## JimmyM (Feb 13, 2008)

Sorry if my previous post came across as being snippy. I had a stressful day. Sorry to all.
OK. On to constructive things.

Most thru-hole components can be found in surface mount packages as well.
My thoughts (personal preferences) regarding the drive of the FET are such that the design can be used for rather high power incans. Folks are going to want to regulate their 64458s, and 64655s. To reloably carry 20 amps (Room for safety). You're going to have to use a sturdy FET. Remember, all those ratings are based on proper heat sinking which is at a premium inside a flashlight. Some of the folks here are about a billion times more savvy with microcontrollers than I am. I submit that they should build a prototype. If I can help out the person who decides to do that. I'd like to.


----------



## Ctechlite (Feb 13, 2008)

That_Guy said:


> Is anyone reading this interested in building their own regulator? All you need is a soldering iron and basic soldering skills, some time and a bit of money (no more than $50, probably around $25), although some basic electronic knowledge would help (able to understand simple circuit diagrams and construct a circuit from it). The main limitation is that, being through-hole, it will be quite large so it won’t be very suitable for going into a Maglite. I can write a step-by-step guide explaining how to do everything if someone does want to DIY.



I am very interested. I lack advanced elec circuit knowledge, but I can read a basic circuit diagram. If you provide part numbers for components I would be glad to order the parts and put it together myself and test it out. Size is not a concern really at this point, I could just use it in one of those 10 million candlepower spotlights. 

I have been watching this thread with great interest but have nothing to input atm due to my lack of expert knowledge.


----------



## That_Guy (Feb 13, 2008)

Ctechlite said:


> I am very interested. I lack advanced elec circuit knowledge, but I can read a basic circuit diagram. If you provide part numbers for components I would be glad to order the parts and put it together myself and test it out. Size is not a concern really at this point, I could just use it in one of those 10 million candlepower spotlights.



Great! What sort of input voltage, output voltage and output current are you looking at? This is important for choosing the MOSFET. At low powers it doesn't matter much, but at high powers things get interesting.


----------



## Ctechlite (Feb 14, 2008)

Can this regulator design boost voltage?

For the power requirements, I was going to start low but could possible go up to 40V for a LarryK14 light. I was looking at this lamp for one of the spotlight hosts that are cheap to buy. I would want to start off slow tho I'd think.

I also have in mind 24V lamp that could be powered from 3 lead acid bat's so 36v supply.


----------



## JimmyM (Feb 14, 2008)

So far, no. The desings that have been discussed thus far, are buck only. The designs for a boost regulator are much more complicated.


----------



## Ctechlite (Feb 14, 2008)

Ok, I thought so but just wanted to make sure.

Let's say I'll run it on a bench then, no light housing at all. I will use 2 serial 12v lead acid batteries for a starting voltage of a max of 28v. Bulbs I have on hand to test are WA1185, osram xx623, xx611, 64458-s, 64655. The 1185 is like a 10v bulb, the 623, 611 and also the 458-s (I think IIRC) 12v rated and the 655 is 24v.

PM me if it will make it easier too, or email.


----------



## JimmyM (Feb 14, 2008)

Ctechlite said:


> Ok, I thought so but just wanted to make sure.
> 
> Let's say I'll run it on a bench then, no light housing at all. I will use 2 serial 12v lead acid batteries for a starting voltage of a max of 28v. Bulbs I have on hand to test are WA1185, osram xx623, xx611, 64458-s, 64655. The 1185 is like a 10v bulb, the 623, 611 and also the 458-s (I think IIRC) 12v rated and the 655 is 24v.
> 
> PM me if it will make it easier too, or email.


I'm not quite sure what you're asking.


----------



## Ctechlite (Feb 15, 2008)

JimmyM said:


> I'm not quite sure what you're asking.



My last post was regarding ThatGuys request for information from me on what I would use a regulator for that he was going to instruct me how to build....


----------



## JimmyM (Feb 15, 2008)

Ctechlite said:


> My last post was regarding ThatGuys request for information from me on what I would use a regulator for that he was going to instruct me how to build....


Ahh. OK.


----------



## petrev (Feb 15, 2008)

Ctechlite said:


> Can this regulator design boost voltage?
> 
> For the power requirements, I was going to start low but could possible go up to 40V for a LarryK14 light. I was looking at this lamp for one of the spotlight hosts that are cheap to buy. I would want to start off slow tho I'd think.
> 
> . . . . .


 
Hi Ctechlite

If you are doing the 1000W build a bit like my thread here then I just added a note on the variants I can find including the 4557 dual filament lamp.



> Note: Q4559*X* (MBCP 765,000)with halogen capsule is brighter than standard Q4559 (MBCP 600,000)
> 
> Note: 4556 not listed in current GE/Silvania/Ushio literature
> Alternate. . . 4555 Shown as lower (MBCP 600,000) than Q4559X
> Alternate. . . 4557 Dual filament version 400/1000 but some also list as lower MBCP ?


 
Literature I have found is inconclusive on whether the 4557 is brighter than the Q4559X or not !
It would make an interesting mod though with dual power capability.

Cheers
Pete


----------



## That_Guy (Feb 15, 2008)

The 1000W lamp is the worst possible case. High current (40 amps!) AND high voltage. The simple single MOSFET design can't handle these power requirements without significant heat sinking. Running something of that power without a heat sink is one of the ultimate goals of this project, but we're not at that stage yet. JimmyM has the most experience when it comes to this.

It would probably require four MOSFETs in parallel driven by a good MOSFET driver, or possibly even four individual MOSFET drivers. It would be possible to use a single MOSFET if it is mounted externally on either a large passive heat sink or a small HSF used for older computer CPUs.

The other lamps are much easier, but the higher current lamps like the 64655 will still be a bit of a challenge. The limitation is heat. If the MOSFET stays cool enough to touch for a few seconds then it's fine. If it gets burning hot then it is potentially too hot, but it is difficult to know without actually measuring the temperature.

A maximum input voltage of 28V rules out the IRF1324 so the next best is the 40V IRF2804. It is available in both a through-hole TO-220 package and a surface-mount 7-lead D2-Pak. The 7-lead D2-Pak is better, but more inconvenient than the TO-220 package.

I'll start writing the guide over the weekend, but I'm rather lazy so it may take a while. The basics are already scattered throughout this thread. I posted a circuit diagram a while back. For the 5V voltage regulator the extremely common 7805 is fine, the MOSFET I've already mentioned and the chip can be either the Tiny13 or Tiny85. For the voltage divider the resistors I'm using for my prototype are suitable. I'm using 8.2k and 270 ohms which gives a Vmax of around 34V. I mentioned possibilities for the programmer to Jimmy a few posts back, and the software is AVR Studio and can be downloaded from the Atmel website.


----------



## JimmyM (Feb 15, 2008)

To make that 1000W build with a regulator design from this thread. You're definitely going to need dual MOSFETs like Pete's and some heat sinking. That means a MOSFET driver. I've seen frequencies here mentioned in the 260-280Hz range. That means a little more heat. Also, Pete said his gives a very industrial buzz. That's the 175Hz switching of the JM-SST. At 260-280Hz, you'll hear a bit more of a low pitch whine, than a buzz.
You'll need 2 onboard regulators. One 5V for the microcontroller and a 12V one for the MOSFET driver. If the design you have uses "High side switching" you need a high side gate drive like the Linear LTC4440.
If you use low side switching, you can get away with a TI TPS2829.
Don't skimp on the gate driver. You'll be sorry. In the 30+ amp range, you can make a lot of heat very quickly if the gate is not driven hard enough.
Don't think that a 5V logic level mosfet will do the job.
If you need any help, please feel free to ask. I'll help in any way I can.


----------



## JimmyM (Feb 15, 2008)

That_Guy said:


> A maximum input voltage of 28V rules out the IRF1324 so the next best is the 40V IRF2804. It is available in both a through-hole TO-220 package and a surface-mount 7-lead D2-Pak. The 7-lead D2-Pak is better, but more inconvenient than the TO-220 package.
> 
> the chip can be either the Tiny13 or Tiny85. For the voltage divider the resistors I'm using for my prototype are suitable. I'm using 8.2k and 270 ohms which gives a Vmax of around 34V. I mentioned possibilities for the programmer to Jimmy a few posts back, and the software is AVR Studio and can be downloaded from the Atmel website.


IR makes the IRF2804S which is a 3 lead surface mount version.
Perhaps I should download that AVR software and have a look. Maybe it's easier than I thought.


----------



## JimmyM (Feb 15, 2008)

OK. I downloaded the software. I'm going to try my hand at AVR programming.
Is there a good place on line to download code, a discussion forum?
Has anyone coded anything this far for this regulator project?


----------



## Mr Happy (Feb 15, 2008)

As to AVR software and programming, I noticed that Atmel have a free AVR Studio developer environment for download along with loads of docs and application notes.

Has anyone looked at downloading AVR Studio as a private individual? (I'm curious since Atmel's site has a registration form that seems set up for businesses and commercial users and doesn't seem to say much about personal and/or non-commercial use).


----------



## JimmyM (Feb 15, 2008)

Mr Happy said:


> As to AVR software and programming, I noticed that Atmel have a free AVR Studio developer environment for download along with loads of docs and application notes.
> 
> Has anyone looked at downloading AVR Studio as a private individual? (I'm curious since Atmel's site has a registration form that seems set up for businesses and commercial users and doesn't seem to say much about personal and/or non-commercial use).


No sweat. I just registered and downloaded the software and service packs. I need to get some programs to look at. Preferably ones that do the regulation thing.


----------



## Alan B (Feb 15, 2008)

Tim had posted his code earlier (That_Guy), so you might start with that.

Which programmer are you going to get?

The Atmel AVRISP mkII is more future proof that some of the others out there.

-- Alan


----------



## Alan B (Feb 15, 2008)

JimmyM said:


> .. Plus I think the approach that is being persued is too simplistic. Personally, I don't think the capacitive gate drive will work to fully enhance a big n-channel FET. If this design is to be truely flexible you can't use a logic level FET to carry the power level that will be required. Also, 100% duty cycle is necessary for LDO operation.


 
Jimmy, sorry somehow I missed the email about updates to this thread so didn't see all the activity and your response.

I understand your concerns, but I think this design can be the core of a family of designs that use different drivers. For a Mag85 level it appears to me, if I did the calculations right, that there is no difficulty capacitively driving the FET. Now I did not build a spice model, haven't used spice in a long time so that would take awhile, but a simple breadboard will tell us quite a bit. If we can build a simple version that is low in cost and meets 80% of the needs, that seems interesting. The high power folks will need a bigger driver, but the micro and software can be essentially identical. Throwing more parts at the design is easy, making a really elegant capable design with minimum parts count is the challenge, but the value is high.

I don't understand the comment about 100% duty cycle required. 99.6% isn't enough? Most users of these designs will add a cell or two to the pack to get more runtime, and 100% will not ever be required as the low voltage cutout won't allow ever getting there.

We can put software options in so the user can choose the max duty cycle, and if the driver permits 100% that can be allowed, so the same software can work in either case.

-- Alan


----------



## JimmyM (Feb 15, 2008)

Alan B said:


> Jimmy, sorry somehow I missed the email about updates to this thread so didn't see all the activity and your response.
> 
> I understand your concerns, but I think this design can be the core of a family of designs that use different drivers. For a Mag85 level it appears to me, if I did the calculations right, that there is no difficulty capacitively driving the FET. Now I did not build a spice model, haven't used spice in a long time so that would take awhile, but a simple breadboard will tell us quite a bit. If we can build a simple version that is low in cost and meets 80% of the needs, that seems interesting. The high power folks will need a bigger driver, but the micro and software can be essentially identical. Throwing more parts at the design is easy, making a really elegant capable design with minimum parts count is the challenge, but the value is high.
> 
> ...


All good points. I think there is value is the ability to go to 100% (LDO mode). Driving a MOSFET well takes a little bit of doing to stay out of the linear range as much as possible. That's what kills an FET.
I'll grab Tim's code to take a look.
I was looking at the same programmer as mentioned above. I'd rather just stick to what I know will work and leave the steep learning curve to the actual programming.
I've been doing some brainstorming and sketching designs. Too little time to actually do development. That pesky job I've got. They actually demand that I work to get paid.


----------



## Alan B (Feb 15, 2008)

Jimmy,

Don't worry about making the capacitive driver test. To really be meaningful it has to be done with the micro's output driver. Using a different source will change the results. I will do a more thorough analyses when I have some time.

Getting set up to program the chips is more useful. We (the group) can exchange code on the net and do development.

-- Alan


----------



## Alan B (Feb 18, 2008)

OK, I did some quick calculations on driving a power FET. These are rough, and perhaps I missed something, but it does not look difficult at all to drive these FETS at these LOW frequencies:

The Facts:

FET gates 5kPF or less (5x10e-9 F)
Tiny85 output impedance is 25 ohms (0.5V at 20ma at 85 deg)
The series capacitor is 200x the gate capacitance, so we can ignore that
This calculation also valid for low side direct driven N channel FETs, the same issues apply.

Thus we have a series RC circuit. The time constant is 25 x 5e-9 or 125e-9 or about 1e-7 seconds

The most time power would be dissipated (as the gate voltage swings across the linear region) is about twice the time constant, or 2e-7 S.

How much power can we dissipate in this period? A worst case estimate might be the voltage difference battery to bulb times the current. So how much voltage is reasonable? Let's assume a battery voltage double the bulb voltage, so the drop would be the same as bulb voltage. To get specific, on a Mag85 let's assume 12V and 4A just for conservatism. If the FET has 12V and 4A across it, that's 48W. If we operate at 300 hz and the transition occurs twice per cycle, the power would be:

2e-7 * 48 * 300 * 2 which comes to 6 milliwatts of dynamic power.

The steady state drop at full on is I * I * R, where the current is 4A and the FET resistance is 6.5 milli-ohms worst case, or 4 * 4 * 6.5e-3 equals 100 milliwatts. To this add the dynamic power.

As pointed out a few posts later (by Tim) in this thread, there was an error here at 50% duty cycle, which is what "average voltage" rather than "RMS voltage" might indicate. The correct duty cycle for equal load power at double voltage is 25% since the load would dissipate four times the power if we did not switch it... Corrected below:

The steady state drop at 25% duty cycle and 4A RMS current is:
8 * 8 * 6.5e-3 equals 400 milliwatts but this only occurs a quarter of the time, so 100 milliwatts. To this add the dynamic power.

I think FET drivers are required for higher frequencies, but 300 hz just isn't very demanding. At this frequency the static dissipation appears to be more important than the dynamic.

Did I miss something here??

-- Alan


----------



## JimmyM (Feb 18, 2008)

Alan B said:


> OK, I did some quick calculations on driving a power FET. These are rough, and perhaps I missed something, but it does not look difficult at all to drive these FETS at these LOW frequencies:
> 
> The Facts:
> 
> ...


That's good to see the numbers all laid out. The driver I was takling about was one for high-side driving the N-FET HARD. Using a built in boost circuit liek the LTC4440. So it always sees the supply voltage at the gate pin when on to fully enhance the gate. If you're going to use the capacitive drive on a logic level FET, without going completely to 100% duty, that math looks fine. It's really just that current spike at turn-on and turn-off that's critical. You also need to make sure that there's a fail-safe pulldown of the gate. If you allow the gate to float there's no telling what it will do. Lock full on, full off, or half way which would burn it up.


----------



## That_Guy (Feb 20, 2008)

Your maths for the resistive losses is wrong. If Vin in twice Vout the duty cycle would be 25%, not 50% so losses would only be 100mW, not 200mW. It all works out quite nicely actually. Resistive losses are independent of Vin, all that matters is the RMS current which makes it very easy to calculate. It's just IRMS^2 * R.

Your calculations for switching losses I'm not sure about. At first I thought your results were far too low, but after testing my circuit again at 2.4kHz you may be close after all. There's definitely something dodgy going on with my circuit. I know that when I last had it running at 2.4kHz a few months ago switching losses were significant at high input voltages, but when I tested it just before there was no noticeable difference at high Vins. The only change in my circuit is that I am no longer using a MOSFET driver, but that is meant to reduce switching losses, not increase them.

If switching losses really are as low as you've calculated then it's good news because all that matters when selecting a MOSFET is finding one with the lowest Ron rather than having to take into account gate charge and find the right balance between switching and resistive losses.


----------



## Alan B (Feb 20, 2008)

Tim, glad that you caught that. I spent most of my thinking on the dynamic power, tossed in the static at the last minute and got caught in the average voltage trap. 

I have edited my post above to indicate the corrections.

In any case, it looks like these approaches all should work pretty well, and the drive requirements are not that difficult.

-- Alan


----------



## Alan B (Mar 3, 2008)

Any progress here? What is on the list?

1) Need to analyze what happens with the capacitive coupled driver if the drive sticks high (goes to 100% full on) and the gate drive decays through the active region of the FET, under what conditions will the FET and/or bulb be overstressed, and what, if anything can be done to reduce this effect. This should be rare but could be encountered during development.. I plan to work on that analysis. Hopefully soon. This should not hold up testing.

2) Need to have someone build a test setup. Could use Tim's software with a small mod to prevent going to 100% duty cycle. Like some verification that the whole package works.

3) Need to lay out a board for a small batch of production prototypes, get parts, and get some units in the field.

Anything else?

-- Alan


----------



## That_Guy (Mar 4, 2008)

I haven't done anything lately. Classes have started again, so I don't have much free time. I want to get an AtTiny85, but since I have to order one online I'm waiting until I want some other parts as well to justify the shipping cost. Since I'm not doing much that may take a while. Maybe I should just bite the bullet and order one now.

One more difference with the high side MOSFET is that there is also a minimum duty cycle in addition to a maximum. This could be an issue if for some reason we want to sample the input voltage while keeping power consumption to a minimum (fuel gauge?).


----------



## JimmyM (Mar 4, 2008)

That_Guy said:


> One more difference with the high side MOSFET is that there is also a minimum duty cycle in addition to a maximum. This could be an issue if for some reason we want to sample the input voltage while keeping power consumption to a minimum (fuel gauge?).


Oh yeah. That's right. Could a pull down resistor be used to hold the gate low once it's been shut off? A 100K resistor can easily hold the gate low once it's already low. It may affect switching speed or necessitate the use of a larger capacitor for use in high duty cycle conditions.


----------



## Lips (Mar 4, 2008)

Alan B said:


> Any progress here? What is on the list?
> 
> 
> 2) Need to have someone build a test setup. Could use Tim's software with a small mod to prevent going to 100% duty cycle. Like some verification that the whole package works.
> ...





Hello Alan


I believe member *KOALA* may could handle this...




He is taking on the *Aviatrix Project* but may be interested in this one also...

https://www.candlepowerforums.com/posts/2383522#post2383522

May be worth a PM to him pointing this thread out?



Cheers and nice work guys!



.


----------



## Alan B (Mar 4, 2008)

There is a pulldown resistor in the present design schematic, as I recall. One cannot leave floating gates in CMOS. The value may need further analysis, that is what I referred to earlier. So there is no minimum duty cycle requirement. 

I have the same problem on ordering some parts, I keep waiting for more stuff to go on the order, probably should just go ahead and do it. Maybe I'll have some time this weekend to detail an order. Perhaps I can get the STK500 development board fired up and get the development software working.

-- Alan


----------



## koala (Mar 5, 2008)

Actually... I am learning a lot by reading Alan B, JimmyM and That_Guy posts- they are a lot more experienced in terms of high current power switching. If the AVR code goes nasty I might be able to help a bit, in assembly language please.





Lips said:


> Hello Alan
> I believe member *KOALA* may could handle this...


----------



## That_Guy (Mar 5, 2008)

The reason for minimum duty cycle requirement isn't because of the capacitive gate drive but because the voltage divider is disconnected when the duty cycle is zero. The MOSFET/lamp has to be on for a short time each cycle to measure the input voltage.


----------



## Alan B (Mar 6, 2008)

Welcome, Koala. Tim has an assembly program you can try out.

Tim, the voltage doesn't need to be measured until the light needs to be on, then it can ramp up from an initial duty cycle, or use a narrow duty cycle to make a measurement. Either way, not a big problem.

-- Alan


----------



## LuxLuthor (Mar 7, 2008)

This is great to keep following progress. Thanks to all of you working on this.


----------



## cnjl3 (Mar 27, 2008)

Did this project


----------



## Alan B (Mar 27, 2008)

cnjl3 said:


> Did this project


 
I hope not.

I think folks are busy, so progress is slow. In my case orders have piled up and are keeping me quite busy...

Any progress out there to report?

-- Alan
-- www.AntennaLaunchers.com


----------



## JimmyM (Jun 30, 2008)

A little progress here.
My 40kHz PWM chip is stable with an RMS converter for feedback.
Soft start to 7.2V (adjustable) sweeping the input from 7.2 to 14V nets a change of only a few 0.01 volts. There's so much switching noise under heavy load (5761), however, that without a ton of bypass capacitor on the FET driver, it lets the smoke out. But the concept works. 40kHz is just crazy.
I'm *NOW* working out a lower frequency design.
And get this. The RMS converter has differential inputs. So I might be able to get away with low side switching.

Edit: I am NOW (instead of NOT) working on a low frequency design. WOW what a difference one letter makes.


----------



## BVH (Jun 30, 2008)

Any of you electronics experts give me a hand here?

https://www.candlepowerforums.com/threads/201544


----------



## Alan B (Jul 5, 2008)

JimmyM said:


> A little progress here.
> My 40kHz PWM chip is stable with an RMS converter for feedback.
> Soft start to 7.2V (adjustable) sweeping the input from 7.2 to 14V nets a change of only a few 0.01 volts. There's so much switching noise under heavy load (5761), however, that without a ton of bypass capacitor on the FET driver, it lets the smoke out. But the concept works. 40kHz is just crazy.
> I'm not working out a lower frequency design.
> And get this. The RMS converter has differential inputs. So I might be able to get away with low side switching.


 
Hi, Jimmy - great progress. The capacitors make it bulky, though? 

Do the differential inputs have enough common mode voltage compliance?

Is it a practical design (cost, size, etc.)?

Things have been busy here. Haven't been working on flashlights for awhile. Use them every day, though. 

-- Alan


----------



## JimmyM (Jul 5, 2008)

Alan B said:


> Hi, Jimmy - great progress. The capacitors make it bulky, though?
> 
> Do the differential inputs have enough common mode voltage compliance?
> 
> ...


It needs at least 10uF of bypass or  I have a new design based on the same principles, but using some separate components. They're all smaller than the PWM controller, but I can tune the frequency. 40kHz is just too damned high to switch large current levels without prohibitively large bypassing and other protections. Also, the RMS chip has the capability to measure voltage across the bulb in a low side configuration. It has 1.2 MOhm (100 Mohm common mode) input impedance but documentation shows that it won't attenuate a signal from a high impedance source. Calculations show that resistor dividers from before and after the bulb to ground will "waste" about 3 mA when the circuit is off. A pitfall of low-side switching. Experimentation will prove out if higher resistor values can me used to reduce "waste" current. However, components I've looked at so far will enable a 40V maximum input voltage.
So the overall range will be about 6-40V.
But, since there is no output filtering, the bulb will get the full Vbatt during "On" cycles. So it would be inadvisable to try to run a 5761 with a 40V pack. Using a pack voltage no more than 2X the regulated output voltage should be OK.
Using low frequency will cause switching noise especially of it's in the human hearing sensitive range, 300-3000Hz. It may not be noticable from the outside of a Mag light body, but Larry14Ks, and Petrev's monsters will hum.
The FET driver I've chosen has a peak output current of 2A, so it should be able to drive 2 or more large FETs quite easily.
It's just going to be a problem fitting all that crap under a KIU base.


----------



## Alan B (Aug 17, 2008)

I just updated the first posting of this project. The new material is below.

I also cleaned up the filenames in the design area.

...

*Project Status:*

We have a proposed design with about a dozen parts. See the version 1.3 file (the last one) in the design file link just below.

*Next Step:*

We need someone to prototype the proposed hardware. This can be a big ugly breadboard, or a circuit board designed to fit into a flashlight. Either way, one prototype to start with and test the basic circuit. After that we need several prototypes for software developers. 

*Signup Sheet:*

Send me a pm if you want to be added to this list:

Hardware Design: mostly done, here on the forum
Hardware Prototyping: need volunteer
Software Development: need several volunteers

*Design Files:*

http://akbeng.com/flash/hwreg/ 

-- Alan


----------



## LuxLuthor (Aug 18, 2008)

I don't think I'm knowledgeable enough in what you need to be of much support, but those are some great links on your first post. So I'll just say thanks and cheer you on! :thumbsup:


----------



## JimmyM (Aug 18, 2008)

Alan B said:


> *Signup Sheet:*
> 
> Send me a pm if you want to be added to this list:
> 
> ...


I'd li*K*e to volunteer for the hardware prototyping, but things are busy at work and in "the shop".

Arrrrgh: damn fat fingers.


----------



## Alan B (Aug 20, 2008)

JimmyM said:


> I'd lie to volunteer for the hardware prototyping, but things are busy at work and in "the shop".


 
You would lie? Jimmy, you must be tired.  (I see Jimmy fixed his typo  )

I understand. I see you're keeping busy.

I am drawing a proper schematic, and if I get a few minutes I will lay out a "Software Development Test Board". This will not fit in a flashlight, but will be suitable for testing and software development. If that goes well, I will have three boards cut and build up one. It may take a few weeks or more, but it seems that no one else has time time/motivation. If we can get a prototype going perhaps we can get more interest. The other two boards will probably be available for other programmers.

I have made a few minor changes to the design, but it is basically the same. Added a couple of diodes to protect the PWM output, and an LED indicator on the output. Changed the connector pinouts a bit. I'm planning to use through-hole parts for the prototype.

The off-current looks to be about 15 micro-amps for the regulator, which would take more than 7 years to consume one amp-hour. This depends on the software putting the micro to sleep most of the time when off, so the initial software may not be this miserly but it can be improved. Those micros don't draw much.

This design requires a 5V gate N channel mosfet, the one I'm looking at presently is 4 milliohms, 40 volts and 160 amps rated. That seems pretty capable, hopefully that will handle most hotwire requirements. What are the requirements for the higher power lights? Might be nice to collect a table of the typical applications in this thread. What do folks want to do??

-- Alan


----------



## Alan B (Aug 20, 2008)

The schematic has been properly drawn using ExpressPCB.com schematic capture software for a test board. This board has a few features and parts for test purposes that won't be required in a flashlight. The board layout has not been completed yet.

(this version had a problem that JimmyM noticed, so fixed version is referenced below)

-- Alan


----------



## Alan B (Aug 20, 2008)

LuxLuthor said:


> I don't think I'm knowledgeable enough in what you need to be of much support, but those are some great links on your first post. So I'll just say thanks and cheer you on! :thumbsup:


 
Your encouragement is welcome! Those are impressive bulb tests that you have done. Perhaps you might comment on the most useful voltage and current specifications for a regulator such as this.

-- Alan


----------



## JimmyM (Aug 20, 2008)

Not to nit pick, but isn't your FET backwards.


----------



## koala (Aug 20, 2008)

How big is the code? I have a few spare tiny45 here, half the flashsize of 85.


----------



## Alan B (Aug 20, 2008)

JimmyM said:


> Not to nit pick, but isn't your FET backwards.


 
Jimmy:

Glad you pointed that out! I'm so used to using the P channel devices, I didn't look closely enough at those connections. Reversing it raises some issues with the capacitive drive, though. Have to review that... One solution is to use the capacitive drive with a P channel device. Have to look at them again.

Koala:

Not sure about the Tiny45, but I think Tim did it with a Tiny15, with efficient code it is possible. These processors are so cheap it may not be worthwhile to use smaller chips, if it causes any other issues.

Turning the device around to get the current in the proper direction will interfere with the way the gate is driven, so I'm going to have to make some changes.

-- Alan


----------



## Alan B (Aug 20, 2008)

Alan B said:


> The schematic has been properly drawn using ExpressPCB.com schematic capture software for a test board. This board has a few features and parts for test purposes that won't be required in a flashlight. The board layout has not been completed yet.
> 
> (this version had a problem that JimmyM noticed, so fixed version is referenced below)
> 
> -- Alan


 
OK, I went back to Plan "A", a P channel FET high-side switch. This method is direct drive and does not have the capacitive coupling limitation and so can run at any duty cycle.

http://akbeng.com/flash/hwreg/20080821 test board.bmp

-- Alan


----------



## Alan B (Aug 20, 2008)

Alan B said:


> ... Those are impressive bulb tests that [LuxLuthor] has done. Perhaps he might comment on the most useful voltage and current specifications for a regulator such as this.


 
I just took a quick look through LuxLuthor's bulb testing and it looks to me like 35V at 15A is enough for any of those bulbs. The supply voltage could be slightly higher, but we don't want to exceed 50V in any case due to the safety requirements. We don't want folks to have to wear voltage-rated gloves to work on their flashlights or charge their battery packs! (NFPA 70E).

-- Alan


----------



## JimmyM (Aug 20, 2008)

Alan B said:


> OK, I went back to Plan "A", a P channel FET high-side switch. This method is direct drive and does not have the capacitive coupling limitation and so can run at any duty cycle.
> 
> http://akbeng.com/flash/hwreg/20080821 test board.bmp
> 
> -- Alan


A few items. All constructive. Again, not trying to nit-pick.
1) Because of the sharply varying voltage of the pack during ON/OFF cycles, I'd suggest using a 33-100 Ohm resistor between Vbat+ and the input of the LM2936. It will increase the effectiveness of C1 as isolation.
2) P-Channel FETs need to be provided larger current spikes for gate turn on and turn off than N channels. I was using a 500 ohm pullup resistor when experimenting with a P-channel RMS regulator that used an open collector to drive the gate. I found much better results using a TI TPS2829 FET driver. Of course this was 40kHz, so <300 Hz, may not be an issue. But, of course, you have to be mindful of exposing the gate to voltages below -18V under Vbat+ (or whatever you Vg-s max is). Maybe employing a 12V zener across Vbat+ to the Gnd of the TPS2829 could fix that. The AVR would drive the input of the TPS2829. Just thinking out loud here. A fast transition from ON-OFF-ON is the key to reducing heat.

I'm just thinking about reducing linear range switching losses.
Thoughts?


----------



## JimmyM (Aug 20, 2008)

Alan B said:


> (NFPA 70E).
> -- Alan


Now you're just showing off, quoting the NEC! :nana:


----------



## LuxLuthor (Aug 21, 2008)

Alan B said:


> I just took a quick look through LuxLuthor's bulb testing and it looks to me like 35V at 15A is enough for any of those bulbs. The supply voltage could be slightly higher, but we don't want to exceed 50V in any case due to the safety requirements. We don't want folks to have to wear voltage-rated gloves to work on their flashlights or charge their battery packs! (NFPA 70E).
> 
> -- Alan



Alan, honestly I don't think it is really necessary to contemplate even that high of V-A (35V/15A) tolerance. Trying to get the 250+W bulbs covered might seem wonderful, but from a IR heat output standpoint, it is not very practical to use them.

I believe "the money" would be in covering the 150W & lower bulbs if that matters in your setup/parts. Tons of members use the 50-100W bulbs and have no practical soft starting and regulation available. If you can just as easily include the higher wattage bulbs, then go for it.


----------



## Alan B (Aug 21, 2008)

LuxLuthor said:


> Alan, honestly I don't think it is really necessary to contemplate even that high of V-A (35V/15A) tolerance. Trying to get the 250+W bulbs covered might seem wonderful, but from a IR heat output standpoint, it is not very practical to use them.
> 
> I believe "the money" would be in covering the 150W & lower bulbs if that matters in your setup/parts. Tons of members use the 50-100W bulbs and have no practical soft starting and regulation available. If you can just as easily include the higher wattage bulbs, then go for it.


 
Excellent. 40V parts are not too rare (30V is a lot more common though), but the 15A is pushing the P channel FETs a bit with minimal heatsinking. I found one that has 4 mOhm on resistance, but it is physically large and a bit expensive. However if we can physically fit it perhaps it can be an option for those who need it. The low voltage setups (6V) are still going to push the driver toward high current, even a 60W setup is 10A. A lower cost 20 mOhm fet will dissipate about 2 watts at 10A which is more than I'd like but possible with some heatsinking. Since the dissipation is I squared times R things get easier quickly as the current drops. I found some low impedance surface mount FETs that have power limitations (and tend to be 30V), those are quite attractive due to size, cost and dissipation.

So what is a good compromise for current? 5A? 7A? 10A? I will search the parts further and see if something "jumps out" of the crowd. Perhaps I should optimize for super-low loss. One other tendency I noticed is for these smaller FETS to have a 30V limit, so that might reduce things to a rating of 25V or so. Where is the battery sweet-spot under 30V? Is there an over 30V battery that folks want to use? Hopefully that is not common.

It has been awhile since I looked at the KIU socket. How much volume do we have for this board? Is it just inside the socket, or is there some full-body-diameter space between the socket and the tower?? Should some other physical arrangement be considered??

I'm wondering if the prototype test board could be set up so the core part could be cut off and mounted in a flashlight later on, and the rest of the board used for test circuitry. Then one board would serve two purposes. Use it as a single board test setup, or cut off the internal flashlight subsystem. 

-- Alan


----------



## Alan B (Aug 21, 2008)

JimmyM said:


> A few items. All constructive. Again, not trying to nit-pick.
> 1) Because of the sharply varying voltage of the pack during ON/OFF cycles, I'd suggest using a 33-100 Ohm resistor between Vbat+ and the input of the LM2936. It will increase the effectiveness of C1 as isolation.
> 2) P-Channel FETs need to be provided larger current spikes for gate turn on and turn off than N channels. I was using a 500 ohm pullup resistor when experimenting with a P-channel RMS regulator that used an open collector to drive the gate. I found much better results using a TI TPS2829 FET driver. Of course this was 40kHz, so <300 Hz, may not be an issue. But, of course, you have to be mindful of exposing the gate to voltages below -18V under Vbat+ (or whatever you Vg-s max is). Maybe employing a 12V zener across Vbat+ to the Gnd of the TPS2829 could fix that. The AVR would drive the input of the TPS2829. Just thinking out loud here. A fast transition from ON-OFF-ON is the key to reducing heat.
> 
> ...


 
Thanks for the comments. I will add the decoupling resistor. I looked at the driver, don't think that is necessary due to the low frequencies. I will rebalance the resistors for stiffer drive and do some calcs on the dissipation. How much dissipation do you figure is acceptable in this environment??

I think I will also simplify the design a bit. Reviewing everything again. Need to select a small FET also.

-- Alan


----------



## JimmyM (Aug 21, 2008)

Alan B said:


> Thanks for the comments. I will add the decoupling resistor. I looked at the driver, don't think that is necessary due to the low frequencies. I will rebalance the resistors for stiffer drive and do some calcs on the dissipation. How much dissipation do you figure is acceptable in this environment??
> 
> I think I will also simplify the design a bit. Reviewing everything again. Need to select a small FET also.
> 
> -- Alan


I found a nice DPAK P-FET a while ago with very low on resistance.
Infineon SPD50P03L


----------



## LuxLuthor (Aug 21, 2008)

Alan, I look at it more from the practical battery combinations. For high current you almost need the Emoli/Konion safe *Lithium *Manganese in 18650 size, or some combination of Elite NiMH in AA or 2/3A size.

There are several types and I need to hook them up to my CBA-II battery tester to get a printed profile, but I did a quick eyeball discharge check on a fully charged Sanyo Konion type which is 3.6/3.7V nominal and 4.15+ V charged. These safe chemistry cells only have 1200 to 1500mAh of storage. They drop *under a 5A load* almost immediately to 3.6+V and after the first 100mAh, below 3.6V.

There are only a few flashlight bodies that can hold 4 wide x 18650, notably the Elephant & Elephant-II. With extension tubes, there is the capability of 8s & maybe 12s, or some combination of parallel cell numbers. Once you have a setup with even these high output cells (they can output 15-20 Amps), it again becomes impractical to match them up with a high wattage bulb.

Here's a typical example. The 150W 64633 Osram uses 12Amps at 17V. This would need 5s or 6s cells (a weird configuration--most likely 3 stacks of two) with regulation (18-22V range), and 12 Amps is going to blow through 1200mAh of capacity in 5 minutes.

A superb bulb is the Infrared Reflective Coating "IRC" that dramatically improves its efficiency, such as the IRC-65W here. That only needs 6.2 Amps at 18V. Another practical regulated setup would be the 100W bulbs which puts you in a 12-18V range and 8-10 Amps.

My point in these examples is you have to look at what battery combinations are really available for high current demands & how many will fit in our lights. You can use combinations of the Elite 2/3A & AA NiMH cells for high current output (20-30A) which gives a little more flexibility in higher voltage, but the practical battery supply limits for regulating I would say are < 13 Amps & < 26 Volts.


----------



## Alan B (Aug 21, 2008)

LuxLuthor said:


> Alan, I look at it more from the practical battery combinations. For high current you almost need the Emoli/Konion safe *Lithium *Manganese in 18650 size, or some combination of Elite NiMH in AA or 2/3A size.
> 
> There are several types and I need to hook them up to my CBA-II battery tester to get a printed profile, but I did a quick eyeball discharge check on a fully charged Sanyo Konion type which is 3.6/3.7V nominal and 4.15+ V charged. These safe chemistry cells only have 1200 to 1500mAh of storage. They drop *under a 5A load* almost immediately to 3.6+V and after the first 100mAh, below 3.6V.
> 
> ...


 
Excellent comments on the battery setup. That helps when evaluating FETs and potential specifications. I may have to try that 64447 IRC-65W sometime. After I get a regulator built. Sounds like the right way to build a bulb. Nice 5000 lumens on high, 2000 on low. Wonder how it does on extra-low.. Would need 6s LiFePO4 cells. Maybe a fat 2D type arrangement. Would be a handfull.

With the regulator we may have some interest in how LOW these bulbs will work well. It would be interesting if any of these bulbs would work well at fairly low levels, and have a very wide range of light output.

Jimmy, I added your FET to my list of potentials (30V 50A 12.5mOhm).. I found a 30V 18a 4.5 mOhm SOIC that looks very interesting. At 10A this would only dissipate about 500mW. The 12.5 mOhm part would dissipate about 1.3 watts.

One possibility is to leave room for a second FET to parallel the first. A pair of 4.5 mOhm FETs in parallel would handle the larger loads better, while using one FET would be adequate for most purposes.

-- Alan


----------



## JimmyM (Aug 21, 2008)

Alan B said:


> Jimmy, I added your FET to my list of potentials (30V 50A 12.5mOhm).. I found a 30V 18a 4.5 mOhm SOIC that looks very interesting. At 10A this would only dissipate about 500mW. The 12.5 mOhm part would dissipate about 1.3 watts.
> 
> One possibility is to leave room for a second FET to parallel the first. A pair of 4.5 mOhm FETs in parallel would handle the larger loads better, while using one FET would be adequate for most purposes.
> 
> -- Alan


I forgot that you're using -5V gate drive instead of 10. So yeah, 12.5 mOhm is too much. Piggybacking 2 SOIC-8 packages is a really good idea.
I've put together a rough drawing of a N-channel concept using a high side gate driver and a couple of small LDOs that would allow this to work from 6V and higher. The practical limit would be imposed by the FET. With a very low Rds(on) N channel FET like the IRF2408 or IRLR7843. I could easily put this on a 30mm board.
IRLR7843 = 30V max
IRF2804 = 40V max
IRFS3206 = 60V max
The driver (LTC4440-5) is good all the way up to 60V.


----------



## Alan B (Aug 21, 2008)

JimmyM said:


> I forgot that you're using -5V gate drive instead of 10. So yeah, 12.5 mOhm is too much. Piggybacking 2 SOIC-8 packages is a really good idea.
> I've put together a rough drawing of a N-channel concept using a high side gate driver and a couple of small LDOs that would allow this to work from 6V and higher. The practical limit would be imposed by the FET. With a very low Rds(on) N channel FET like the IRF2408 or IRLR7843. I could easily put this on a 30mm board.
> IRLR7843 = 30V max
> IRF2804 = 40V max
> ...


 
If you don't have a place to host the drawing I can do that for you. The software won't care much about these changes so we can support multiple hardware designs pretty easily.

On another subject, the 30mm board is (I presume) what will fit under the kiu bipin socket?

I was thinking today that perhaps a rectangular PCB could be mounted where the [email protected] switch sets, complete with the pushbutton on board. It could mount to the kiu bipin on one end, and contact the battery stack on the other (and have a plastic disk for support), and completely replace the [email protected] switch. This would give more room, and more potential for heatsinking. It would seem to be a better way to go, and not that hard to do. More room, and could have LEDs, jumpers or even an I/O connector under the rubber cover accessible for field adjustments.

-- Alan


----------



## JimmyM (Aug 21, 2008)

Alan B said:


> If you don't have a place to host the drawing I can do that for you. The software won't care much about these changes so we can support multiple hardware designs pretty easily.


When I clean it up a bit I'll send it to you for hosting with the other design files.
re: hardware output stage. That's kind of what I was thinking. The uC just sends an ON-OFF signal, how it is actually employed can vary dependent on application. 5761 bulb or PAR64 landing light. For smaller installs it could use the direct drive P-channel and low voltage LDO, for higher voltage/power the output stage could be built differently.


Alan B said:


> On another subject, the 30mm board is (I presume) what will fit under the kiu bipin socket?


Yup. That's it. 30mm fits under the D-body KIU base.


Alan B said:


> I was thinking today that perhaps a rectangular PCB could be mounted where the [email protected] switch sets, complete with the pushbutton on board. It could mount to the kiu bipin on one end, and contact the battery stack on the other (and have a plastic disk for support), and completely replace the [email protected] switch. This would give more room, and more potential for heatsinking. It would seem to be a better way to go, and not that hard to do. More room, and could have LEDs, jumpers or even an I/O connector under the rubber cover accessible for field adjustments.
> -- Alan


Using the parts count you have in your schematic, this is a real possibility, but starts to get into the realm of heavy modding. But, of course, the base design is capable of the install you describe as well as the monster 30mm board for things like the 12A 64458s, or non-mag mods that will drive the 1000W lights. I like this. The only variation is the output stage. Be it a 4 Amp installation or 22 Amp install, the same program and "base design" will work for either.
For any interface between battery voltage and the uC, I'd prefer to use a slightly higher impedance resistor divider and a 4.5ish volt zener for protection. You KNOW somone will have the setting wrong mistakenly and hit the uC with 10V or something like that and toast it. The zener will protect the uC from high voltage.
If the FET is driven properly, heatsinking requirements should be minimal.

This is really good. A public design that people can implement themselves if thay want, or purchase a prebuilt module made by someone else based on this design.
Ehhxcellent , Smithers. Ehhhhxcellent.


----------



## Alan B (Aug 22, 2008)

JimmyM said:


> When I clean it up a bit I'll send it to you for hosting with the other design files.
> ...
> For any interface between battery voltage and the uC, I'd prefer to use a slightly higher impedance resistor divider and a 4.5ish volt zener for protection. You KNOW somone will have the setting wrong mistakenly and hit the uC with 10V or something like that and toast it. The zener will protect the uC from high voltage.
> ...
> ...


 
That's the idea.

I will create a directory for your stuff when it comes.

I'm wondering if you mean use a zener instead of the regulator on the schematic? Or are you talking about the ADC input??? This regulator is rated for reverse polarity protection, and draws 15uA standby. The micro can be programmed to shut down and periodically wake up and check the control switch input, so the power used can be really, really low. The resistor/zener would not be as good. On the ADC input, the zener is not a bad idea. Shouldn't be needed but it would make the setup more difficult to damage. I will do that.

I'm sketching some physical layouts. Completely replacing the [email protected] switch hardware might not be too hard. The pc board would have four brass hex standoffs soldered to it. Two to mate with the Kiu socket base. One to take a brass screw for the battery + terminal. That screw would go through a plastic disc and then into the board's hex standoff. The fourth hex standoff would have a screw that would dig into the far side of the body tube just like [email protected] does it, to hold the assembly in. So to mod a light you would take out the [email protected] tower and drop this disk/pcb/Kiu assembly in, and lock it into place. Done. The hardest part is soldering the brass standoffs on straight, and that should not be too hard. Three of them are easy, and a simple jig made of a piece of PVC pipe would make the fourth easy too. (The holes on the Kiu base are too near the edge for the brass standoffs to fit, more work required on this..)

So on one end of the PCB the plastic disk would center it in the body tube, on the other end the Kiu socket base would center it, and the screw would push along the board to the ID of the tube. The control switch would be mounted adjacent to the screw and would also be at the edge of the board, so under the switch hole in the body tube would be the edge of the board and the switch and screw. This puts the force in a good direction for the PCB and won't flex it. There are other ways but this is the easiest.

There might be enough room on this board to take as many as four driver ICs. Have to look at that. Parallel FETs work quite well as long as the gate drive is sufficient. That would bring this down to 1 mOhm and eliminate heat in the driver. Only required for the higher current lamps. Load one FET to start and more if needed. Do the board layout so it could handle either TO200 or the surface mount types... Lots of flexibility there.

One other thought is that this driver might work for the new P7 LEDs. A little impedance is required to limit current, basically any direct drive LED setup can use this driver for lower modes. It will handle even several emitters in parallel easily current wise. Or in series. Unlike most LED drivers it can handle the full P7 current...

I was looking at a USB scope on the net today. Might come in handy for this project:

www.hobbylab.us

I have an old Heathkit scope but not sure it is working, also bulky and not easy to get waveforms into files for the net...

-- Alan


----------



## Alan B (Aug 22, 2008)

I took a more detailed look at this [email protected] switch replacement pc board hotwire controller design last night, and made some physical measurements. The space is not quite as large as I had expected, but it looks feasible. The Kiu base mounting holes are so close to the edge that a standoff probably won't fit. May have to drill new holes, or do something else there to mount the pcb to the base.

I'm not sure I'm happy with standoffs soldered to the pcb with continuous tension on them. Would be nice to do something better. I have an idea there that needs investigating.

I found some tactile switches that mount perpendicular to the pcb. These should work for this pcb design.

I did a rough pcb parts placement and it appears possible to use through-hole parts, standing them up to reduce footprint. I like this for a prototype, and it would also be quite nice for a kit. Anyone want kits?

For the FET, the minimum pc board space usage is to use a TO220 package, and stand it up. 

Having the pcb layout be rectangular is nice and easier to work with. The quick-turn boards I use are large enough to take four or maybe six of these on each one, and since the standard order is 3 boards that would yield a half dozen or more prototype boards.

-- Alan


----------



## JimmyM (Aug 22, 2008)

Alan B said:


> I took a more detailed look at this [email protected] switch replacement pc board hotwire controller design last night, and made some physical measurements. The space is not quite as large as I had expected, but it looks feasible. The Kiu base mounting holes are so close to the edge that a standoff probably won't fit. May have to drill new holes, or do something else there to mount the pcb to the base.
> 
> I'm not sure I'm happy with standoffs soldered to the pcb with continuous tension on them. Would be nice to do something better. I have an idea there that needs investigating.
> 
> ...


If you're going to replace the whole switch, then you have the room to stand up the FET. I can't imagine though, that an SMD board would occupy more overall volume. Ideally, this could be built using a double sided SMD board, and fit it in a C cell body. Drive components on one side and the P-channel SOIC-8 FET(s) on the other.

Regarding the output voltage setting. Are you envisioning the output voltage being set by a pot at the "voltage setting" resistor?
I was doing some calculating and it's completely possible without reprogramming the chip to set a new voltage.
Basically, there are 2 inputs to the calculation. The sample of the Vbat while the FET is ON as provided by the ADC, and an "output factor".
Your calculation would be Duty=("ouput factor" ^2)/Vsample^2

You adjust the voltage sampling divider to your desired RMS output voltage. Then the duty will adjust as the Vsample falls. If you wanted just a single setting, you use 1 as your "ouput factor". But as it works out, the Output Factor is directly linked to the percent output of the maximum. 0.5 = 50%, 0.8=80%, etc.
So you can enable multiple power output settings (80-90-100% of your desired RMS regulated voltage) or what ever you want, and also use the "output factor" to implement the soft start.

Just ramp the value of "Output factor" from 0 to the value used for the level setting. This way, you don't have to "field program" different voltages. If you don't (or can't) reprogram an AVR, no big deal. The same program will work for ANY voltage. So it can be preprogrammed for a softstart to any of 3 preset output factors 80-90-100%. The user just sets a pot on the board for their desired voltage.


----------



## Alan B (Aug 22, 2008)

JimmyM said:


> Regarding the output voltage setting. Are you envisioning the output voltage being set by a pot at the "voltage setting" resistor?
> I was doing some calculating and it's completely possible without reprogramming the chip to set a new voltage.


 
I have thought about that, but it makes it hard to do the low battery protection part of the algorithm. 

At this point I'm planning to use registers in the nonvolatile memory of the micro for the settings. To reprogram just plug in the programmer with a pc and adjust any of the parameters desired. The resistors would be fixed and there would be a "calibration cycle" that would involve putting a fixed voltage and the regulator would adjust to the known cal voltage and set internal calibration factors to compensate for the resistors and the particular ADC in the chip.

Hopefully it will be very easy to get the driver out of the light. If a switch replacement is done it might be just a single screw to loosen the unit and slide it out. 

That said, there is no reason there cannot be more than one version of software for this design. One problem with using the variable resistor technique is that anyone wanting to set a particular voltage value would have to have an RMS voltmeter. With the calibrated approach discussed above, only a dc voltmeter is required to read the voltage of the supply to be used in calibration. This value is put in to the chip and then the calibration cycle is triggered.

The software to do these has not been written yet, so this will likely evolve as we go, and will come out possibly a little different as we find out what is easy and convenient.

Has anyone done a good simple design for a [email protected] switch replacement? It would be interesting to look at other designs.

-- Alan


----------



## Raoul_Duke (Aug 22, 2008)

JimmyM said:


> Ideally, this could be built using a double sided SMD board, and fit it in a C cell body.



 OH oh oh... Me me me....   

I Have been reading this from the start...but unfortunatley its way over my head :thinking:

Still, I'm hoping you guys pull it off.....It sounds sweet, and what we realy need; but the technical detail is too great for me with no real experience in what you are doing.

Still, I will definatley be in for some of these iif they ever become available, and if they fit in C cell lights, I will be in for twice as many.

At last count I had over 20 C, D and elephant sized hosts, so atleast quater to half of those realy require & deserve to be regulated to be complete, and all the other details, such as low volt cut of etc, you discussed are much needed.


----------



## Raoul_Duke (Aug 22, 2008)

Alan B said:


> I have thought about that, but it makes it hard to do the low battery protection part of the algorithm.
> 
> At this point I'm planning to use registers in the nonvolatile memory of the micro for the settings. To reprogram just plug in the programmer with a pc and adjust any of the parameters desired. The resistors would be fixed and there would be a "calibration cycle" that would involve putting a fixed voltage and the regulator would adjust to the known cal voltage and set internal calibration factors to compensate for the resistors and the particular ADC in the chip.
> 
> ...




Well the only pics I can think of were these


https://www.candlepowerforums.com/threads/195194


https://www.candlepowerforums.com/threads/192580

Hope mdocod doesn't mind me linking them.


----------



## Alan B (Aug 23, 2008)

Raoul_Duke said:


> Well the only pics I can think of were these
> 
> https://www.candlepowerforums.com/threads/195194
> 
> https://www.candlepowerforums.com/threads/192580


 
Thanks for the comments, and the links. I have been considering hacking something out of aluminum bar, or plastic. Interesting to see what they did with the Judco switch and Delrin. We have a different problem making room for and mounting a pc board, and a small switch. I should get some Delrin, I have not tried it on my lathe/mill. 

If a slug of aluminum is used, the ground becomes easy to handle, and the Kiu base could possibly be eliminated, and more PCB area would result.

If plastic is used, picking up the ground becomes a chore and the Kiu base would still be required. I have some aluminum. Tempting to try one. Lots of material to remove, however. Would also complicate picking up the battery plus a bit, too. Could use a PC board on the battery side to pick up plus, on the end of the aluminum slug.

Aluminum would also make it heavier and probably more expensive to make. But it would add some nice heft and solid quality to the build.

I'm going to focus on getting this thing to work in the space of a D before worrying about size reduction. There is not much circuitry on this design, so by going to smaller parts it should shrink readily.

-- Alan


----------



## JimmyM (Aug 23, 2008)

Alan B said:


> I have thought about that, but it makes it hard to do the low battery protection part of the algorithm.


Ah, yes. Forgot about that bit.


Alan B said:


> At this point I'm planning to use registers in the nonvolatile memory of the micro for the settings. To reprogram just plug in the programmer with a pc and adjust any of the parameters desired. The resistors would be fixed and there would be a "calibration cycle" that would involve putting a fixed voltage and the regulator would adjust to the known cal voltage and set internal calibration factors to compensate for the resistors and the particular ADC in the chip.


These would have to be calibrated before use (obviously). But I'm willing to bet more people have an RMS DMM than have an AVR programmer. Or can a USB cord be plugged in directly to the Tiny85?


Alan B said:


> That said, there is no reason there cannot be more than one version of software for this design. One problem with using the variable resistor technique is that anyone wanting to set a particular voltage value would have to have an RMS voltmeter. With the calibrated approach discussed above, only a dc voltmeter is required to read the voltage of the supply to be used in calibration. This value is put in to the chip and then the calibration cycle is triggered.


Presuming the user has a programmer. I think an RMS DMM is more readily available than a programmer.
Then again, anyone making these for sale to others could offer preprogramming. But that's one of the problems I see with AWs proposed regulator. It has to be programmed before purchase. After that, the user has no "simple" way of adjusting the voltage if they want to use it in a different light.


Alan B said:


> The software to do these has not been written yet, so this will likely evolve as we go, and will come out possibly a little different as we find out what is easy and convenient.


The multiple software option is probably the single greatest ability of this design.


----------



## Alan B (Aug 23, 2008)

JimmyM said:


> ...
> 
> These would have to be calibrated before use (obviously). But I'm willing to bet more people have an RMS DMM than have an AVR programmer. Or can a USB cord be plugged in directly to the Tiny85?
> ...
> ...


 
Excellent points. If folks can get an inexpensive programmer they can do a lot more than an RMS dmm, though. Upload new software, and get to perhaps a dozen or more useful parameters, as well as calibration factors.

Let's do a quick review of some AVR programmers. 

1. USBTinyISP AVR Kit $22 http://www.adafruit.com/index.php?main_page=product_info&cPath=16&products_id=46

2. Serial Port AVR Programer Kit $7.50 http://www.adafruit.com/index.php?main_page=product_info&cPath=16&products_id=26

3. AVR ISP mkII $34-36 http://www.mouser.com/Search/Refine.aspx?Msid=55650000&Mkw=ATAVRISP2 or http://webapps.nuhorizons.com/NuNext/NUHOnlineOrderingPartSearch?mode=Search or http://www.digikey.com/scripts/us/dksus.dll?Detail?name=ATAVRISP2-ND

Number 1 above looks quite interesting if one is willing to solder a few parts. Has both six and ten pin programming cables.

Number 2 is really low cost but probably requires a real serial port which is becoming quite rare. May not work on a USB to serial adapter. This one comes with a ten pin programming cable which would require an adapter to use with the six pin socket I plan to use.

Number 3 is ATMEL's professional programming dongle. Amazing to get such a high end tool for under $36. Has the six pin programming cable.

There are also parallel port programmers that use a couple of resistors, so are really cheap, but parallel ports are not so common anymore.

There are some other options, but a programmer provides the most flexibility and costs possibly less than the regulator will. Perhaps some folks could offer programming services for those who don't want to mess with that. Perhaps the sellers of the boards could pre-program and calibrate the board for the user who is just starting out. The user can later get his or her own programmer as they get more units.

It is also possible to put jumpers on the programming plug. This could be used to select between several different pre programmed sets of values. So it is possible to make a program that has a number of different bulb programs in it. With a programmer the user could tailor the set of bulbs the board was set for, but in the field they could move a jumper around and select different programs.

It is also possible to communicate with the chip via serial using the programming socket. This would require a special cable and would allow changing parameters. With some software development it could possibly allow software installation as well. This should be left for future development, but might be the best way to go in the longer term.

USB is possible as well. This would require an additional connector since the chip still must be programmed the first time at least. Another item for future development.

-- Alan


----------



## Alan B (Aug 23, 2008)

Note that none of these programming options precludes doing what you suggest - using a pot to change the calibration and set a fixed program into the chip. The adjustment procedure would be something like - remove the bulb and use an RMS DMM to measure the output while adjusting the calibration pot. Reinstall the bulb and do a final readjustment.

The battery protection level would shift along with the adjustment, so it would be okay over a small range but over a larger range the battery protection would become either ineffective or have to be disabled. 

-- Alan


----------



## Alan B (Aug 23, 2008)

The "Regulator Sled":

One design for a [email protected] switch replacement that keeps coming back to me is a "Sled" - a bar of aluminum turned to diameter to fit into the tube that has the central section milled down to a bit beyond the mid height level. Both ends are disks with holes. The PC Board sits on this sled (with appropriate insulators), the battery positive on one end (again with an insulated screw coming through the disc), and a pair of standoffs on the other end to the bulb socket (and hole for the socket wires). A hole near the center of the pc board allows access to the screw that threads through the lower aluminum half-cylinder of the sled against the interior of the [email protected] bore to "lock the assembly in" and pick up ground. The programming connector is right next to the lock-in screw. A second small pc board with a programming socket on one end and a pushbutton switch on the other plugs in through the [email protected] switch hole and into the programming socket and positions the switch just under the rubber boot. The sled provides a good ground connection and a great heatsink for the FET (with proper voltage insulation on the FET)

The hardest part of this is making the aluminum sled. I think I can make one but could not make production quantities. Anyone want to make a few? Suggestions?? Improvements??

-- Alan


----------



## LuxLuthor (Aug 23, 2008)

I have read enough about the programmers to know that I could do that & would definitely like to have that capability....essentially having this be a "*Dial-Your-Driver*" for dirt cheap setup, especially the Atmel (as far as I'm concerned those are all doable). I agree this is the only downside to AW's intended regulated fixed voltage output driver.

I don't see it as that big of a deal using a programming dongle vs. a small Pot that AWR used in his...especially if there is a lot more flexibility in options using the dongle. I always loved that word, "dongle."

The "Reg sled" sounds great, but I'm having a hard time picturing all the aspects of it. I'm sure some of the many "Lathe Jockeys" _(said with affection & jealously)_ in our CPF club could work out the milling.

On a follow up note from earlier voltage ranges, I'm now revisiting the possibility of 2 stacks of 7 (14s) of Elite AA's at 16.8V nominal or 3 stacks (21s) at 25.2V. They are a tighter fit in Elephant-II, but just gives more votlage ranges in this setup.


----------



## Alan B (Aug 23, 2008)

LuxLuthor said:


> ...
> 
> The "Reg sled" sounds great, but I'm having a hard time picturing all the aspects of it. I'm sure some of the many "Lathe Jockeys" _(said with affection & jealously)_ in our CPF club could work out the milling.
> 
> On a follow up note from earlier voltage ranges, I'm now revisiting the possibility of 2 stacks of 7 (14s) of Elite AA's at 16.8V nominal or 3 stacks (21s) at 25.2V. They are a tighter fit in Elephant-II, but just gives more votlage ranges in this setup.


 
Small lathes and mills are not that expensive, I have a combo (http://grizzly.com/products/G0516), but I would not want to make a bunch of sleds. I may have enough patience to make one.  

I'm waiting for a code to unlock a free cad program that looks useful, then perhaps I can make some drawings. Until then, maybe this will help explain what I'm thinking of.

Take a rod of aluminum and turn it to fit inside the [email protected] body tube. Face one end, cut it to length plus a bit and face off the other end. Now you have a nice cylinder of aluminum that fits inside the [email protected] bore. Length to be about the same as the [email protected] switch plus the Kiu base.

Clamp it in a mill vise on the circular ends and mill away, leaving a cradle - leave the disks on the ends, and leave (a bit less than) the lower half of the cylinder. 

Drill and tap one hole down through the center of the lower half cylinder (perpendicular to the axis of the cylinder) to put a socket screw into - this will dig into the [email protected] body and lock the sled in place. It will be right below the [email protected] switch hole.

Bore a centered hole in one end of the sled for the + contact to come through, with clearance for insulation. An insulating disk faces the batteries and holds the contact screw centered.

On the other end of the sled three holes are drilled, one for wires and two for standoffs like the Kiu socket. (Maybe Kiu could make these kits!!)

Now lay the circuit board in the rectangle of the cradle. It will have a hole to clear the lock down screw. Right next to the hole for the lock down screw is the six pin programming plug (on the pcb). A second small circuit board with the switch on one end and a plug on the other plugs into this programming socket. It is made so the switch sits in the center of the [email protected] switch hole when plugged in. It is sized to fit through the [email protected] switch hole.

Note that the TO220 driver FET can lay under the PCB on the sled and be heatsinked to it (with proper insulating washer). In fact this is the way to mount the pcb - a screw through the pcb, a small standoff, and through the TO220 mounting hole. Have to keep it electrically isolated from the grounded sled. One other screw through the pcb into the grounded sled will be required to pick up the ground connection, probably diagonally on the other side of the pcb. Maybe a third screw for stability in a triangle arrangement. 

To install this regulator sled, disassemble the D [email protected] Remove the tailcap, batteries, head, switch cover, switch, and the ring inside the body. Slide the completed sled into place and lock it down with an allen wrench through the body switch hole. Slide the new small switch pcb through the [email protected] switch hole and plug it into the regulator pcb on the sled. It should rest just in the right position for the rubber cover to go over it, and be tall enough to stay centered in the [email protected] body switch hole.

A third pc board would be a programming extender. It would reach through the [email protected] switch hole to the programming socket and provide an extension programming plug outside the [email protected] body so the programming can be done while the sled remains in the [email protected] body. Just remove the rubber cover, pull out the switch pcb, and install the extender pcb. 

Make any sense at all? It seems to me like a nice way to do it, mechanically. Very clean and easy to install. The same sled could be used for some nice LED drivers (with a different PCB), now that we have ever more power hungry LEDs to feed..

-- Alan


----------



## Alan B (Aug 23, 2008)

Rough drawing of regulator sled here:

http://akbeng.com/flash/hwreg/reg sled mech 0a.pdf

-- Alan


----------



## Raoul_Duke (Aug 24, 2008)

Alan B said:


> Rough drawing of regulator sled here:
> 
> http://akbeng.com/flash/hwreg/reg sled.pdf
> 
> -- Alan



Cool.

Would the base of the switch benifit from resting on the top of the "-ve screw"? Ie make the screw longer?

Might make it more stable.

I will buy some of your crazy aluminium canoes !!!


----------



## Alan B (Aug 24, 2008)

Raoul_Duke said:


> Cool.
> 
> Would the base of the switch benifit from resting on the top of the "-ve screw"? Ie make the screw longer?
> 
> ...


 
Arrgh. Just got server too busy and lost my post. I usually "copy" them before submitting to avoid that, this time I didn't.

Supporting the switch is a good idea, but this diagram is not accurate enough to design that. The back of the switch has leads angling down to the pcb and it would be hard to get the length of the screw just right anyhow. I wonder if a brass tube soldered to the pcb that slides over the screw head might be better. Good ideas to consider.

I was calculating component values and the voltage range is causing problems. Resistors set for 6V are overheating at 35V, and I don't really want to go to larger resistors. 

I looked into high side driver chips to see if they solved the problem, but they really don't. They don't cover the range either, at least I didn't find any rated 6-40V, or even 6-30V.

So I think I will reduce the voltage range to 6-25V for now. We can keep the 40V parts and then only a few resistors need to be adjusted for different voltage ranges. I need to see if 6-25 can be handled with one set of resistors. More calculations.

Does 6-25V cover most of the practical applications?

-- Alan


----------



## Alan B (Aug 24, 2008)

The Sled could also be made with a pair of discs and a bar (and no milling required), or even a disk and a Kiu base and a bar. The bar forms the lower part of the sled. It would not be as good a heatsink, but should be adequate for most reasonable power levels. 

-- Alan


----------



## Alan B (Aug 24, 2008)

I uploaded a new schematic to reflect the sled design and some new component values and renamed the drawing slightly to make more sense:

schematic:
http://akbeng.com/flash/hwreg/reg sled sch 1c.bmp

drawing:
http://akbeng.com/flash/hwreg/reg%20sled%20mech%200a.pdf

I also did some dissipation calculations and the pullup resistor on the FET gate is determining the dynamic dissipation. It is a lot worse than the earlier calculations with capacitive coupling. It will not be an issue at normal power levels, but at higher currents and vbat - vbulb differences it will require the PWM frequency to be lowered. I doubt if this is a problem but it will have to be watched. I could add an active driver on that side, but it would take more parts so let's leave that for if it is needed.

This is where it would be very useful to capture voltage and current waveforms and put them into a program or spreadsheet and calculate the real dissipation, point by point. I may need a USB scope before this is over... Anyone have experience with this one? or similar??

Bitscope USB:
http://www.bitscope.net/store/?p=view&i=item+3

-- Alan


----------



## LuxLuthor (Aug 24, 2008)

Alan B said:


> Arrgh. Just got server too busy and lost my post. I usually "copy" them before submitting to avoid that, this time I didn't.
> 
> Supporting the switch is a good idea, but this diagram is not accurate enough to design that. The back of the switch has leads angling down to the pcb and it would be hard to get the length of the screw just right anyhow. I wonder if a brass tube soldered to the pcb that slides over the screw head might be better. Good ideas to consider.
> 
> ...




Double Arrgh...just when you get lured into a false sense of security that CPF is operating normally again....you make a post and see this error screen: 
*OpenX has not been installed yet -- please read the INSTALL.txt file.*​OK, let's see if I remember what I was saying all over again.

I think 6-25V is the practical range that includes all of the WA, Pelican, Philips 5761, & most of the practical Osram bulbs - IRC's, 64625/238-USL, 64623-Torch, 64458, and other 100W or less. It may even cover the 150W 64633. There will be those that want the >150W bulbs, but in reality they are not that practical from a beam characteristic, heat buildup, & run time limitation. Those "Incan-Fanatics" can deal with direct drive "WOW" setups.

Once you have used a regulated incan light, it is very hard to go back to direct drive...so I think there would be an incredible demand for this. Look at how many AW D & C drivers he has sold, and that is only soft-starting & multi-level. It is nice to have a drop in available for many users who are mostly not into much modding. When you start adding some of the other features you mentioned on your first post, basically I could die in "flashlight bliss" if this becomes a practical reality.


----------



## Alan B (Aug 24, 2008)

LuxLuthor said:


> Double Arrgh...just when you get lured into a false sense of security that CPF is operating normally again....you make a post and see this error screen:
> *OpenX has not been installed yet -- please read the INSTALL.txt file.*​OK, let's see if I remember what I was saying all over again.
> 
> I think 6-25V is the practical range that includes all of the WA, Pelican, Philips 5761, & most of the practical Osram bulbs - IRC's, 64625/238-USL, 64623-Torch, 64458, and other 100W or less. It may even cover the 150W 64633. There will be those that want the >150W bulbs, but in reality they are not that practical from a beam characteristic, heat buildup, & run time limitation. Those "Incan-Fanatics" can deal with direct drive "WOW" setups.
> ...


 
LL, Thanks for your comments on the ratings and your willingness to "do it again" when CPF takes a drop. I usually do a "control-A, control-C" to select the text and copy it to the clipboard before submitting, just in case there is a problem. If there is one, just re-reply and paste the text in. These problems are not unique to CPF - it can be the ISP or Windoze or the browser or whatever. 

This project is very do-able. We just need a few folks to put in some effort. I've had a little time lately but that will change with other workloads. Hopefully we can get someone interested in building production hardware and I can focus on the software, which is where the development hours will go.

-- Alan


----------



## Alan B (Aug 24, 2008)

OK, I ordered one of these programmers:

http://www.adafruit.com/index.php?main_page=product_info&cPath=16&products_id=46

I have access to some other programmers, but this one looks like the most convenient for others to use, so it would be good to get some experience with it.

I'm filling in the parts information in the schematic capture file, so it will generate a bill of materials for ordering.

-- Alan


----------



## JimmyM (Aug 24, 2008)

Alan B said:


> This is where it would be very useful to capture voltage and current waveforms and put them into a program or spreadsheet and calculate the real dissipation, point by point. I may need a USB scope before this is over... Anyone have experience with this one? or similar??
> 
> Bitscope USB:
> http://www.bitscope.net/store/?p=view&i=item+3
> ...


I use the Owon PDS5022. Search Ebay for it. I find it quite good for the money.
Inputs are not truly independent though. They share a ground.
I haven't found this to be an issue though.


----------



## LuxLuthor (Aug 24, 2008)

Alan, maybe it would be helpful to specify what you mean in 1st post as next step: 



> We need someone to prototype the proposed hardware. This can be a big ugly breadboard, or a circuit board designed to fit into a flashlight. Either way, one prototype to start with and test the basic circuit. After that we need several prototypes for software developers.



If there is anything I can do, please let me know. I have an idea that you need someone more experienced with electronics & building circuits, but maybe not?


----------



## Alan B (Aug 24, 2008)

LuxLuthor said:


> Alan, maybe it would be helpful to specify what you mean in 1st post as next step...
> 
> If there is anything I can do, please let me know. I have an idea that you need someone more experienced with electronics & building circuits, but maybe not?


 
Thanks for the offer. This probably requires someone who has some circuit experience, and is willing to make the circuit and likely fiddle with the code to get it working.

I updated the first post. It seems I'm building a prototype, unless someone wants to take that over. There is some test code to work on. I defined a few test programs.

-- Alan


----------



## Alan B (Aug 24, 2008)

JimmyM said:


> I use the Owon PDS5022. Search Ebay for it. I find it quite good for the money.
> Inputs are not truly independent though. They share a ground.
> I haven't found this to be an issue though.


 
Thanks for the link. Looks nice, and good price. Have to give this more thought.

-- Alan


----------



## SafetyBob (Aug 25, 2008)

Alan, please take to heart what Lux posted above about the range of lights he feels are most useful to all of us. I think he has hit it right on the head. AW's multilevel switch transformed my opinion and usage of incan lights. Frankly, they are now useful. And a 100 watt light or below would be very, very usable to the average CPF member. 

That said I only have one AW switch that I use in my [email protected], after that one purchase I really sort of lost interest with going more powerful because I thought I had found the perfect little incan light in the world. That was 6 months ago. I still love that light even though the 625 I finished today blows it out of the water. 

Since I am not a EE, I really cannot help much if any on this build and it really bothers me because guys like you and Jimmy are doing alot of work for the benefit of all of us. 

The only help I can offer is preproduction certification as in I will drop it, pound it into a [email protected] and power that baby up with every configuration I can think of. 

Paypal ready when you are!!

Bob E.


----------



## Alan B (Aug 25, 2008)

SafetyBob said:


> Alan, please take to heart what Lux posted above about the range of lights he feels are most useful to all of us. I think he has hit it right on the head. AW's multilevel switch transformed my opinion and usage of incan lights. Frankly, they are now useful. And a 100 watt light or below would be very, very usable to the average CPF member.
> 
> That said I only have one AW switch that I use in my [email protected], after that one purchase I really sort of lost interest with going more powerful because I thought I had found the perfect little incan light in the world. That was 6 months ago. I still love that light even though the 625 I finished today blows it out of the water.
> 
> ...


 
Bob, we really appreciate your encouragement. I just went back through this thread and re-read the old postings (and fixed the links to my reorganized drawings). There has been good support from a number of folks, and most seem to still be around. We have not heard from That_Guy for awhile, but he is busy at school and probably has other things to worry about.

Myself, I have a fulltime job, a part time business, a few hobbies and a family so it is hard to fit it all in. I enjoy my [email protected], but don't use it much and worry about flashing the bulb with freshly charged NiMH cells. I'm looking forward to at least ONE of these regulators.

I was really tempted this weekend to put an aluminum rod into the lathe and machine a "Sled" but I have a backlog of orders (non flashlight related) to make parts for, so I could not do that. During breaks I can read and type, but I have to limit that, too.

I did do some research on USB and low-cost scopes. There is a USB scope on eBay that is interesting - the DSO-2150 for $220 plus shipping, and there are the Owon scopes like JimmyM has, and there are the Bitscopes. For a really cheap and cheerful setup there is hobbylab.com. I have not made any decisions, but I need a scope for another project that I am working on, so I may get to buy something there.

-- Alan


----------



## Raoul_Duke (Aug 25, 2008)

I was reading your posts, and thinking about this response...with the thought in mind that you guys must have little or nothing to do to, with bags of time on your hands but to work all this stuff out. ( Very impressive how you have sustained momentum, and kept at this Idea )

I studies electronics for a few years at college, ( 10 years ago)...but haven't had a real in depth knowlede for some years now.

I'm a lot of things at work, one of the roles is "technical custodian instruments" ( which means I manage the team of instrument technicians...but it realy doesn't go into the detail you guys would think....In fact the technical terms that we use are limmited & probably cant be typed here, but when a card, board or instrument breaks down / fails then it either works or it's """doesn't ""( and then the whole unit gets replaced not individual components)

So while my soldering skills were realy good at college) it would take me alot to get back into..So it would realy be a monkey see, monkey do operation; if I were to help, but I'd be willing...although not alot of time, ) I work two week shifts away from home.)


Glad the 64633 will be included....One of, if not, my favorite(s) I think its the highest temp lamp I like to use.


----------



## Alan B (Aug 25, 2008)

How low a quiescent current do we need? This is the current when the light is "off". This parameter is quite important in making some choices about the design configuration.

How long to drain the batteries when off?

Is six months to dead ok? A year??

How important is this parameter??

Are [email protected] tailcap switches available with really low resistance? 

Folks who want to maximize the standby time may want to add a tailcap switch that breaks the circuit, or remove the battery pack, or drop in an insulating spacer with the battery pack. In some cases, reversing the batteries can disconnect them, if the "+" terminal in the sled is countersunk.

What is a good compromise here??

Thanks for your input,

-- Alan


----------



## LuxLuthor (Aug 25, 2008)

Alan B said:


> How low a quiescent current do we need? This is the current when the light is "off". This parameter is quite important in making some choices about the design configuration.
> 
> How long to drain the batteries when off?
> 
> ...



I'm assuming you are asking this because of a need to have some low level of current drain by components of circuit. Ideally, it would be best to have no current draining when light is off, so depending on how much of a drain you are considering, it could be very important. We don't want to have a regulator that drains and/or kills our cells if left sitting unused for 3-4 months.

I think given the self-discharge nature of high current NiMH cells anyway, and habits it creates, 6-12 months is plenty. I try to keep mine charged every 3 months. Of course Eneloop & Li-Ion don't have this issue. I think the key here is if there is a slow drain, to have it be really minimal, even at the expense of some advanced features.



Alan B said:


> Are [email protected] tailcap switches available with really low resistance?


 
There are tailcap mods where the Judco 10A switch is used. Otherwise, most Mags use the side switch location. Unrelated, just thought I would refresh everyone's memory on the low resistance tailcap spring fix.



Alan B said:


> Folks who want to maximize the standby time may want to add a tailcap switch that breaks the circuit, or remove the battery pack, or drop in an insulating spacer with the battery pack. In some cases, reversing the batteries can disconnect them, if the "+" terminal in the sled is countersunk.
> 
> What is a good compromise here??
> 
> ...



Are you saying a break that is beyond the on/off switch? I'm thinking of AW's multi-level soft starter that connects into his PCB, and didn't think it had any drain going on when off. It does remember your last used level when turned back on, but thought that was a drain-free memory feature. I may be wrong about my understanding.


----------



## JimmyM (Aug 25, 2008)

I think we need to name this project. Since there will undoubedly be several derivative works. I know I'll be building one. But it would be very nice to be able to credit the original project by name.
HRDC - Hotwire Regulator Design Collaboration
AB-CRR - Alan-Bs Community RMS Regulator
I dunno, but a name would be nice.


----------



## Alan B (Aug 25, 2008)

LuxLuthor said:


> I'm assuming you are asking this because of a need to have some low level of current drain by components of circuit. Ideally, it would be best to have no current draining when light is off, so depending on how much of a drain you are considering, it could be very important. We don't want to have a regulator that drains and/or kills our cells if left sitting unused for 3-4 months.
> 
> I think given the self-discharge nature of high current NiMH cells anyway, and habits it creates, 6-12 months is plenty. I try to keep mine charged every 3 months. Of course Eneloop & Li-Ion don't have this issue. I think the key here is if there is a slow drain, to have it be really minimal, even at the expense of some advanced features.
> 
> ...


 
The drain of the electronics is not zero. The regulator, micro and FET leakage currents all add up, plus any other currents. I'm reviewing the low-side regulator design again carefully to see if I can make that work. The benefits are enormous, but the standby drain current must be managed.

Adding a mechanical tail switch fixes the leakage, so this is always an option for those who want zero leakage and maximal readiness. Lowering the leakage by adding parts to the board is also possible, and this first design doesn't necessarily have to be optimal in this department. A small "electronics off" switch is also possible, but it would have to be in the vicinity of the cpu, and how to make this accessible to the user? Perhaps some clever "loosen the head" of the light could turn off the electronics. That would be neat!

Let's talk in terms of battery half-life. That is probably a good way to think of it. If you pick up the light after N months it will have half the battery left due to electronics leakage. This should work well for Lithium Ion and for low self discharge NiMH. (Regular NiMH will be dead on its own in three months, without any help from the regulator). If the battery capacity is 2000 mAH (AA NiMH), this means we have 1000 mAH to drain. If the half-life is six months that means we have 1000 mAH in 4380 hours or 230 uA. I have a low side design that should make this value. This lowers the parts count, fixes the drive problems, and allows the use of some truly AMAZING FETs.

I re-found www.emachineshop.com and made a quick sketch of the sled. It is not complete, but I should be able to get some better drawings and cost estimates on it from their free software, and they can make parts as well. I wonder how many of these would be wanted...

-- Alan


----------



## Alan B (Aug 25, 2008)

JimmyM said:


> I think we need to name this project. Since there will undoubedly be several derivative works. I know I'll be building one. But it would be very nice to be able to credit the original project by name.
> HRDC - Hotwire Regulator Design Collaboration
> AB-CRR - Alan-Bs Community RMS Regulator
> I dunno, but a name would be nice.


 
HRDC sounds pretty good.

-- Alan


----------



## Raoul_Duke (Aug 25, 2008)

Alan B said:


> HRDC sounds pretty good.
> 
> -- Alan



Very Modest :twothumbs

On the subject of the second off switch...dont you guys unscrew the tailcap (all you need is a tiny turn to break contact) when the light is not in use.

I always do, as a matter of course, and tap the switch a few times to check that its not still "live"...But I guess thats because things could go wrong if a 100+W light was just resting ( being held) on a ( potentially melted) Kiu'd mag switch.

I have heard concerns of the switch anodising eventually wearing off...but as long as you test it by hitting the switch a few times after the tailcaps backed off, its all good. Or if you are concerned buy another tailcap. None of mine have failed/ worn yet, just keep 'em lubed.


----------



## Alan B (Aug 25, 2008)

Well, folks, I had a thought on the way home from work today. I have been working on a way to isolate the voltage detection circuit from the battery on the low side N channel driver. This was the problem that made me go away from the otherwise excellent low sided driver waay back in this thread.

Let's recap the advantages of the low side driver (older schematics are on file already in the files area www.akbeng.com/flash/hwreg). The N channel output driver goes between the bulb and ground, switching the return side of the bulb. The high side of the bulb goes to +battery. The drive for the FET comes straight from the micro, so we need a FET that will drive well at 4V, but we have much better drive capability from the micro direct than in the high-side P channel design. The voltage detection circuit goes to the +battery also, so the voltage divider that provides a low voltage sample for the CPU to read is always drawing current. The other standby loads are the regulator and the micro. The parts we have chosen for those two have very low standby currents, in the 15-20uA each neighborhood. There is also the leakage of the output FET switch. It is of a similar order, as I recall, though it depends on the specific device chosen, but quite small. 

Remember for a 6 month half-life we need something like 230 uA. The ADC divider with a 100K/10K divider draws about 230uA (at 25V) so it blows the whole budget. We might be able to go higher on these resistor values, I need to do some dynamic analysis to see about that. But if we need to go lower we are pushing on our half-life.

So we need a low current isolated switch to disconnect the voltage divider. No room for a relay.

How about an opto-isolator? I haven't used one quite this way before. Looks pretty good, two parts required, cheap, small, reliable. 50 nano-amps leakage. 

So that's the design I am working on right now. Sorry about the flip-flop, both of these designs are pretty well fleshed out. It feels like we're getting close.

-- Alan


----------



## Alan B (Aug 25, 2008)

Raoul_Duke said:


> Very Modest :twothumbs
> 
> On the subject of the second off switch...dont you guys unscrew the tailcap (all you need is a tiny turn to break contact) when the light is not in use.
> 
> ...


 
I didn't know this worked well on the [email protected]. Not a bad idea. Have to try that on my 30 year old [email protected].

-- Alan


----------



## Raoul_Duke (Aug 25, 2008)

Alan B said:


> I didn't know this worked well on the [email protected]. Not a bad idea. Have to try that on my 30 year old [email protected].
> 
> -- Alan



Well if we are talking an old mag then you will have to check that the serial no had a D or not infront of the serial no.

IIRC the "D" serial no mags, are a touch wider than the Non D mags ( there are other differences also ( Orings in different places etc.)

so if you make "sledges" on the mag ID you have, they probaly wont fit the new ( more common) ones.

OH...and If it doent work, I have a brand new ( old stock ) tailcap that will fit the older non D mags that you can have if the anodising has worn off :thumbsup:


----------



## Alan B (Aug 25, 2008)

Here is a schematic of the new "low-side N channel FET switch" design with opto isolated disconnect (for low off-current):

http://akbeng.com/flash/hwreg/hrdc1.bmp

-- Alan


----------



## Alan B (Aug 26, 2008)

Raoul_Duke said:


> Well if we are talking an old mag then you will have to check that the serial no had a D or not infront of the serial no.
> 
> IIRC the "D" serial no mags, are a touch wider than the Non D mags ( there are other differences also ( Orings in different places etc.)
> 
> ...


 
I have several new [email protected], so the sled will be made to fit the new ones. I set up the old one for a reference light - it is stock except for a [email protected] brand "star" bulb. When I do flashlight presentations I use that for a comparison reference. I have a Malkoff in 3D, the [email protected], and the standard one, plus I borrow a friend's MTE-3. I have parts for a 6 SSC P4 that I haven't completed yet, and the Mac 1000 Lumen Osram (which is 1.5D or so).

I did a presentation at Quartzfest this year on flashlights. Outdoors after dark. This is a Ham Radio group. Told them about the technology of the new better LEDs and then show them a few lights. My 1000 Lumen Osram Ostar arrived just after that so I didn't have it, but I did borrow a MTE-3 triple LED that was pretty impressive. Folks were really impressed by the Tiablo A9s. One guy wanted to buy one immediately. 

Then I fired up the [email protected]. I was showing the difference between a stock 3D and the 85, and one fellow was sure there was something wrong with my 3D. We used to think those were bright. I showed them that the Fenix L0D basically blows the 3D away. 

The next evening there was a fellow who sells LEDs made a presentation and brought a LUX meter. He had some nice low cost lights, but the Tiablo A9s blew his best away. Kinda fun.

For the sled diameter, I think the Kiu base is just about right. Seems to fit very nicely. Might have to go a tad smaller for production models. I figure the prototype I make on my lathe can be fitted to the particular [email protected] I have, which is only a few months old. Blue for "hot". Maybe if I can find a red one I'll change to that, though the [email protected] is well beyond red in color temperature, maybe the blue is a better fit.... I checked at Fry's, they had lots of black, and a few dark green 3Ds.

I also picked up one of those clamps for the D. I'm going to mod it to fit a camera tripod so I can use any D mag as a work light on a camera tripod.

A few years ago I did a presentation on my Pneumatic Antenna Launchers, and the power was out for awhile. The presentation room I had was inside with no windows, so I told everyone to point their flashlights at me and went ahead. No power point, but I had launchers, so I had hardware to show and talk about, so it went well, It would have been really great to pull out something like the Osram Ostar, put it on a tripod and set it for a mid level for runtime and use it to light the room. A hotwire would be great but need 50 minutes runtime... Maybe a [email protected] with 3D Li-Ions, and a regulator! Could run the level down a bit and make it last longer also... With the right regulator, that is..

I see that the Adafruit folks shipped the AVR Programmer already. See the links a few posts back for details on this $20 programmer.

JimmyM, tell us about your plans here! What do you think of the latest low-side design? I gave it the #1 designation. Seems fitting, we started with low-side and now we're coming full circle, with a twist for the voltage sampling...

-- Alan


----------



## Alan B (Aug 26, 2008)

I just ordered some parts to get started here:

AT Tiny 85 processors,

IRL1404Z 3.1 milliOhm 40V 75A Logic Level Gate FETs, 

Optical Isolators,

Tactile Switches,

and a few misc parts.

-- Alan


----------



## Alan B (Aug 26, 2008)

I was doing a search and came across a discussion of RMS PWM regulators for flashlights in sci.tech-archive.net - Looks familiar.

http://sci.tech-archive.net/Archive/sci.electronics.design/2008-06/msg03993.html

I see Digikey shipped already. Quick.

I need to get a screen capture of the "Sled" from the emachineshop program. It looks more like a cradle that would rock quite nicely, as it has the sides on it. The milling is straight down into the cylinder on its side, without punching through the side. This makes it much stronger against the batteries hammering on the one end disc.

I started to write some pseudo-code, and made a simulator and ran through the PWM values and RMS equivalents. For my [email protected] with 9xAA cells it looks like each PWM step is about 20 millivolts. Not too bad. It looks like all the real-time math can be handled by a 8 by 8 bit multiply with a 16 bit result, but there is more work to do there. Two multiplies and a subtract or compare.

Will need to set an interrupt on the PWM edge, and trigger the ADC during the PWM "on" to get a good "loaded" voltage reading.

-- Alan


----------



## LuxLuthor (Aug 27, 2008)

Alan B said:


> I was doing a search and came across a discussion of RMS PWM regulators for flashlights in sci.tech-archive.net - Looks familiar.
> 
> http://sci.tech-archive.net/Archive/sci.electronics.design/2008-06/msg03993.html
> 
> ...



Yeah, Jimmy gets around. Heh. I even bought this from him, but you can imagine how much I have used it. It's on my list of things to do.


----------



## JimmyM (Aug 27, 2008)

Alan B said:


> I was doing a search and came across a discussion of RMS PWM regulators for flashlights in sci.tech-archive.net - Looks familiar.
> 
> http://sci.tech-archive.net/Archive/sci.electronics.design/2008-06/msg03993.html
> 
> -- Alan


Yup. That was me. I was seeking assistance in building a non-uC based unit.
I like the new schematic. You're right. A non-standard use of the opto-isolator.
I had a thought with regards to the low side drive. The only thing that's stopping us from using the beefier FETs is the low gate drive voltage. How about the MIC5018 Fet driver. It has a built in charge pump to boost gate drive voltage to about 11V with a 5V input. Current requirements are quite modest.
http://www.micrel.com/page.do?page=/product-info/products/mic5018.shtml
It will allow the use of beefier FETs and comes in a tiny SOT-143 package.
Sound reasonable? Or am I adding too much. With the input limit of the LDO you've chosen and an FET like the IRLR7843 (30V) or IRF2804 (40V) the range can be expanded quite nicely.


----------



## Alan B (Aug 27, 2008)

JimmyM said:


> Yup. That was me. I was seeking assistance in building a non-uC based unit.
> I like the new schematic. You're right. A non-standard use of the opto-isolator.
> I had a thought with regards to the low side drive. The only thing that's stopping us from using the beefier FETs is the low gate drive voltage. How about the MIC5018 Fet driver. It has a built in charge pump to boost gate drive voltage to about 11V with a 5V input. Current requirements are quite modest.
> http://www.micrel.com/page.do?page=/product-info/products/mic5018.shtml
> ...


 
Wow. I spec'd a 3 milliOhm 75 Amp 40V FET and we want more? This is one power-hungry crowd :twothumbs

I have not looked at the driver you spec'd yet, but we have to be careful because the idle current is always-on, so if it draws more than a few uA when idle it would be noticed in the total. OK I just looked at it. Really nice! 1uA standby!! That looks like a great driver. I don't think we need it, though. I'm going to keep that datasheet for future possibilities, good suggestion!

It should be easy to add a driver like that, with no effect on software. I would like to see how far the direct drive goes before adding the driver. I think the parts in this design will go 35V 20-30A with a bit of heatsink.

Let's see how this IRL1404Z FET might do. If we have 15 amps, and 4 milliOhms the dissipation would be 0.9 watts. In this design the TO220 package would be heatsinked to the aluminum cradle, so it would not heat up at that power level. The dissipation at 10 amps would be less than half that.

It seems "good enough" to start. Did I miss something?

The dynamic dissipation would be the same as calculated earlier for the capacitive coupling case, far better than the high side driver dynamic dissipation.

How fast should we switch these things? 60 hz? 100 hz? 200hz? 300 hz? 500 hz? We will make that a user settable parameter. What should the default be??

If someone doesn't need the lower standby current consumption the opto can be left out and jumpered over, and the circuit a bit simpler still.

-- Alan


----------



## Alan B (Aug 27, 2008)

LuxLuthor said:


> Yeah, Jimmy gets around. Heh. I even bought this from him, but you can imagine how much I have used it. It's on my list of things to do.


 
The sad thing is, if this effort is successful that reg might take a plunge in market value. It looks like a nice design but the programming through the on/off button is a bit hard to do, and I don't think the code or schematic was ever published so support is difficult. Too bad it doesn't accept morse code input, that'd be easier for me... Should we add a morse code input option to this new one???

-- Alan


----------



## Alan B (Aug 27, 2008)

JimmyM said:


> ...
> I like the new schematic. You're right. A non-standard use of the opto-isolator.
> ...


 
The question is, will it work? Are there any surprises there??

I tried to find a FET output Opto. Couldn't find one at Digikey...

-- Alan


----------



## JimmyM (Aug 27, 2008)

Alan B said:


> Wow. I spec'd a 3 milliOhm 75 Amp 40V FET and we want more? This is one power-hungry crowd :twothumbs
> 
> I have not looked at the driver you spec'd yet, but we have to be careful because the idle current is always-on, so if it draws more than a few uA when idle it would be noticed in the total. OK I just looked at it. Really nice! 1uA standby!! That looks like a great driver. I don't think we need it, though. I'm going to keep that datasheet for future possibilities, good suggestion!
> 
> ...


Agreed, lets see how the simpler approach works first. I'm just picky about gate drive and fast transitions. The MIC5018 on a 5V supply draws 0-1 uA with a logic low at the input. I think that should be low enough. 
I ran the JM-SST at ~175 Hz, lower frequency is better for low heat. But the lower your frequency is will effect how bulbs perform when input voltage is MUCH higher than Vrms out. In the extreme case, imagine running a 5761 on a 40V pack with a 10 Hz frequency. I bet the bulb blows in the first few cycles. The ON time per pulse is longer at low frequency for any given duty cycle. Maybe my example is extreme, but you get the idea. Maybe some testing is required to see how things work with a "reasonable" pack/Vrms differential.


----------



## JimmyM (Aug 27, 2008)

How much current can the Tiny85 sink/source to drive the gate?
That MIC5018 can boost the gate drive voltage but it can only supply 9 uA. It shows that it can take from 0.75-2.1 mS (milli seconds) for the gate drive voltage to rise to 4.5V. Hmmm. More searching to do.


----------



## koala (Aug 27, 2008)

Hello Jimmy,
Best is to keep it under 20mA per I/O pin.


----------



## JimmyM (Aug 27, 2008)

koala said:


> Hello Jimmy,
> Best is to keep it under 20mA per I/O pin.


How would it respond to the current spike at the gate during turn on and turn off? What kind of impedance is there? To keep current under control, you might need a gate drive resistor. 1-2.2 K should do it. But then we're in the territory of possibly endangering the fast transition requirement.
Switching losses can climb pretty quickly with a slowed change of state and 10-15 amps flowing. The FET feels the peak current, not RMS while in operation.
Maybe an FET driver like the TPS2829 (good from 4-14 V. 0.2 uA quiescent current). It can handle ~2 Amp peaks and is an SOT-23 package. Just a thought. I know I'm getting pretty tiring with the FET driver talk, but I'd like to see this thing as efficient as possible and require as little heat sinking as possible.
If the current during switching events (measuable on your O'Scope) looks a little too risky, it's something to consider.


----------



## Alan B (Aug 27, 2008)

Jimmy, take a look at the ATTiny85 documentation and see what you think. The outputs are FETs, one to ground, one to supply. Active drive in both directions. They spec output sink at 10mA at 0.6V so this would be an impedance of 60 ohms on the low side and and source of 4.3V at 10mA which is 70 ohms on the high side (on 5V supply). 

If the FET gate is 5kPF then R*C = 0.35uS. If pwm was running at 100 hz, and absorbing 30*15 watts (beyond worst case?) during the two transitions per cycle this would be 32 milliwatts total dissipation. At 300 hz it would be 100 milliwatts. It would be more of a problem at higher frequency. 

At this point I think that 100 hz will be adequate. Any comments on this?

Did I miss something in this estimate?

-- Alan


----------



## Alan B (Aug 27, 2008)

JimmyM said:


> How would it respond to the current spike at the gate during turn on and turn off? What kind of impedance is there? To keep current under control, you might need a gate drive resistor. 1-2.2 K should do it. But then we're in the territory of possibly endangering the fast transition requirement.
> Switching losses can climb pretty quickly with a slowed change of state and 10-15 amps flowing. The FET feels the peak current, not RMS while in operation.
> Maybe an FET driver like the TPS2829 (good from 4-14 V. 0.2 uA quiescent current). It can handle ~2 Amp peaks and is an SOT-23 package. Just a thought. I know I'm getting pretty tiring with the FET driver talk, but I'd like to see this thing as efficient as possible and require as little heat sinking as possible.
> If the current during switching events (measuable on your O'Scope) looks a little too risky, it's something to consider.


 
The Tiny85 has a max current per pin of 40mA, so we need 125 ohms at 5 volts. If the drive is already 60 ohms then an additional 68 ohms should do it. This just doubles the RC losses above, still small. It does protect the IC from the current pulses due to the gate capacitance, which is a good idea.

-- Alan


----------



## JimmyM (Aug 27, 2008)

Those numbers look a lot better than the 5018 driver for higher frequency. Even at 60 ohms / 70 ohms, it will only hold back current at turn on and turn off, so at steady state, the gate voltage will be just about 5V anyway. Nice.


----------



## JimmyM (Aug 27, 2008)

So, I just scanned through the data sheet. That's a weighty tome. It also reinforced what I already knew. It's all greek to me.
I wish there was an "AVRs for dummies", or better "AVRs for the utterly lost"


----------



## Alan B (Aug 27, 2008)

Now for some numbers from a little simulator I wrote that models the behavior of the control loop of the micro, and calculates some of the interesting information. This run has a small amount of soft start, and has random noise added to the ADC conversions, so you can see it converging and regulating.

This is a simple Python program, so if folks wanted to run it and enter the parameters for their favorite bulb and battery they could run it themselves. It is not pretty, but useful. 

It shows the static and dynamic power of the FET as well.

Hotwire Regulator Simulator 0.2 Alan B 8/2008

10.8 Battery Voltage, V
9.6 Bulb Voltage, RMS V
30.24 Bulb Power, W
3.04761904762 Bulb Resistance, ohms
0.79 nominal Duty Cycle
201 PWM nominal value
100.0 PWM Rate,hz
0.024 PWM Nominal Step Voltage dV
3.15 Bulb Current, RMS A
3.544 Bulb Current, Peak
0.04 Static FET Power, W
0.002 Dynamic FET Power, W
0.042 Total FET Power, W

 N Err ADC PWM Duty Vrms Errct Goal Now Noise
RMS Cycl
0 -0.131 92 197 0.77 9.469 -165 1697933 1667408 0
1 -0.107 93 196 0.77 9.493 65 1697933 1695204 1
2 -0.131 92 197 0.77 9.469 -165 1697933 1667408 0
3 -0.107 93 196 0.77 9.493 65 1697933 1695204 1
4 -0.131 91 197 0.77 9.469 -361 1697933 1631357 -1
5 -0.107 92 198 0.77 9.493 -132 1697933 1675872 0
6 -0.083 91 199 0.78 9.517 -297 1697933 1647919 -1
7 -0.059 92 200 0.78 9.541 -66 1697933 1692800 0
8 -0.035 93 199 0.78 9.565 167 1697933 1721151 1
9 -0.059 92 200 0.78 9.541 -66 1697933 1692800 0
10 -0.035 92 201 0.78 9.565 -33 1697933 1701264 0
11 -0.011 91 202 0.79 9.589 -201 1697933 1672762 -1
12 0.012 93 201 0.79 9.612 235 1697933 1738449 1
13 -0.011 93 200 0.79 9.589 201 1697933 1729800 1
14 -0.035 93 199 0.78 9.565 167 1697933 1721151 1
15 -0.059 92 200 0.78 9.541 -66 1697933 1692800 0
16 -0.035 91 201 0.78 9.565 -233 1697933 1664481 -1
17 -0.011 93 200 0.79 9.589 201 1697933 1729800 1
18 -0.035 91 201 0.78 9.565 -233 1697933 1664481 -1
19 -0.011 93 200 0.79 9.589 201 1697933 1729800 1


----------



## Alan B (Aug 27, 2008)

Here is a longer run with more softstart and battery sag:


Hotwire Regulator Simulator 0.2 Alan B 8/2008

10.8 Battery Voltage, V
9.6 Bulb Voltage, RMS V
30.24 Bulb Power, W
3.04761904762 Bulb Resistance, ohms
0.79 nominal Duty Cycle
201 PWM nominal value
100.0 PWM Rate, hz
20 Soft Start, PWM counts
0.001 Battery Voltage Sag, V/iteration
0.024 PWM Nominal Step Voltage dV
3.15 Bulb Current, RMS A
3.544 Bulb Current, Peak A
0.04 Static FET Power, W
0.002 Dynamic FET Power, W
0.042 Total FET Power, W

N Err ADC PWM Duty Vrms Errct Goal Now Noise
RMS Cycl
0 -0.501 92 182 0.71 9.099 10.800 -660 1697933 1540448 0
1 -0.477 91 183 0.71 9.123 10.799 -809 1697933 1515423 -1
2 -0.453 91 184 0.72 9.147 10.798 -777 1697933 1523704 -1
3 -0.428 91 185 0.72 9.172 10.797 -745 1697933 1531985 -1
4 -0.404 91 186 0.73 9.196 10.796 -713 1697933 1540266 -1
5 -0.380 91 187 0.73 9.220 10.795 -681 1697933 1548547 -1
6 -0.357 93 188 0.73 9.243 10.794 -275 1697933 1626012 1
7 -0.333 91 189 0.74 9.267 10.793 -617 1697933 1565109 -1
8 -0.309 92 190 0.74 9.291 10.792 -396 1697933 1608160 0
9 -0.285 92 191 0.75 9.315 10.791 -363 1697933 1616624 0
10 -0.262 93 192 0.75 9.338 10.790 -139 1697933 1660608 1
11 -0.238 93 193 0.75 9.362 10.789 -105 1697933 1669257 1
12 -0.215 91 194 0.76 9.385 10.788 -457 1697933 1606514 -1
13 -0.191 93 195 0.76 9.409 10.787 -37 1697933 1686555 1
14 -0.168 93 196 0.76 9.432 10.786 -3 1697933 1695204 1
15 -0.145 92 197 0.77 9.455 10.785 -165 1697933 1667408 0
16 -0.121 92 198 0.77 9.479 10.784 -132 1697933 1675872 0
17 -0.098 92 199 0.78 9.502 10.783 -99 1697933 1684336 0
18 -0.075 92 200 0.78 9.525 10.782 -66 1697933 1692800 0
19 -0.052 92 201 0.78 9.548 10.781 -33 1697933 1701264 0
20 -0.029 92 200 0.79 9.571 10.780 0 1697933 1692800 0
21 -0.054 93 199 0.78 9.546 10.779 167 1697933 1721151 1
22 -0.079 91 200 0.78 9.521 10.778 -265 1697933 1656200 -1
23 -0.056 91 201 0.78 9.544 10.777 -233 1697933 1664481 -1
24 -0.033 92 200 0.79 9.567 10.776 0 1697933 1692800 0
25 -0.057 93 199 0.78 9.543 10.775 167 1697933 1721151 1
26 -0.082 91 200 0.78 9.518 10.774 -265 1697933 1656200 -1
27 -0.059 91 201 0.78 9.541 10.773 -233 1697933 1664481 -1
28 -0.036 92 200 0.79 9.564 10.772 0 1697933 1692800 0
29 -0.061 92 201 0.78 9.539 10.771 -33 1697933 1701264 0
30 -0.038 93 200 0.79 9.562 10.770 201 1697933 1729800 1
31 -0.063 91 201 0.78 9.537 10.769 -233 1697933 1664481 -1
32 -0.040 91 202 0.79 9.560 10.768 -201 1697933 1672762 -1
33 -0.017 93 201 0.79 9.583 10.767 235 1697933 1738449 1
34 -0.042 92 200 0.79 9.558 10.766 0 1697933 1692800 0
35 -0.066 93 199 0.78 9.534 10.765 167 1697933 1721151 1
36 -0.091 92 200 0.78 9.509 10.764 -66 1697933 1692800 1
37 -0.068 90 201 0.78 9.532 10.763 -233 1697933 1628100 -1
38 -0.045 92 200 0.79 9.555 10.762 0 1697933 1692800 1
39 -0.070 91 201 0.78 9.530 10.761 -233 1697933 1664481 0
40 -0.047 90 202 0.79 9.553 10.760 -201 1697933 1636200 -1
41 -0.024 92 201 0.79 9.576 10.759 33 1697933 1701264 1
42 -0.049 91 202 0.79 9.551 10.758 -201 1697933 1672762 0
43 -0.026 90 203 0.79 9.574 10.757 -169 1697933 1644300 -1
44 -0.003 90 204 0.80 9.597 10.756 -137 1697933 1652400 -1
45 0.020 91 205 0.80 9.620 10.755 -105 1697933 1697605 0
46 0.042 92 204 0.80 9.642 10.754 132 1697933 1726656 1
47 0.018 90 205 0.80 9.618 10.753 -105 1697933 1660500 -1
48 0.040 92 204 0.80 9.640 10.752 132 1697933 1726656 1
49 0.016 91 205 0.80 9.616 10.751 -105 1697933 1697605 0
>>>


----------



## Alan B (Aug 27, 2008)

JimmyM said:


> How would it respond to the current spike at the gate during turn on and turn off? What kind of impedance is there? To keep current under control, you might need a gate drive resistor. 1-2.2 K should do it. But then we're in the territory of possibly endangering the fast transition requirement.
> Switching losses can climb pretty quickly with a slowed change of state and 10-15 amps flowing. The FET feels the peak current, not RMS while in operation... Just a thought. I know I'm getting pretty tiring with the FET driver talk, but I'd like to see this thing as efficient as possible and require as little heat sinking as possible.


 
It was good you mentioned this, I hadn't considered the overcurrent on the AVR pin due to the capacitive load. I didn't find much published on that, but it is good to do the calculation and add the resistor to limit the current to the spec value for the AVR, and these discussions are helping to look at these details. One more R on the schematic.

-- Alan


----------



## Alan B (Aug 28, 2008)

Was reading about KD Li-Ion D cells not working with the AW PWM controller on a high power bulb. Anyone know what frequency the AW PWM runs at?

I would like to be able to use D Li-Ion cells. I wonder if a special soft start that raises the frequency during starting would get by the protection circuits in the cells? As the bulb warms up the frequency can drop back to normal. We can dissipate some power in the FET for a short time to help out the starting, and raise the frequency above that the protection circuit considers a short??

Any data??

-- Alan


----------



## Alan B (Aug 28, 2008)

Digikey parts came today.

Here is another run of the simulator. I've been tweaking it in spare moments. This example shows a bad case - running a WA1185 from 35V with a duty cycle of about 10%. The first 10 cycles are the soft start ramp, then about 10 cycles of regulation. Regulation is pretty bad, plus or minus about 0.1V. This is due to the large PWM steps. Each PWM step is about 0.226 volts, so it cannot do better than that (unless we do dithering of the PWM values, but I'd rather not go there yet).

To make the PWM smaller we want to use voltages closer to the bulb voltage. Stick to about 75% bulb to battery voltage for best regulation.

I reviewed the dynamic power calculations and adjusted them for more accuracy. The present assumption is that the FET impedance is the same as the filament during one gate/drive RC time constant twice per cycle. I believe that impedance matching produces the highest power dissipation here, but have not spent a lot of time looking at it.

Hotwire Regulator Simulator 0.2 Alan B 8/2008

Type: WA1185 From High Voltage

35.0 Battery Voltage, V
10.8 Bulb Voltage, RMS V
34.02 Bulb Power, W
3.42857142857 Bulb Resistance, ohms
0.1 nominal Duty Cycle
24 PWM nominal value
100.0 PWM Rate, hz
10 Soft Start, PWM counts
36.4285714286 ADC Full Scale Voltage
0.01 Battery Voltage Sag, V/iteration
Warning - PWM Step Voltage HIGH
0.226 PWM Nominal Step Voltage dV
3.15 Bulb Current, RMS A
10.208 Bulb Current, Peak A
0.04 Static FET Power, W
0.011 Dynamic FET Power, W
0.051 Total FET Power, W

N Err ADC PWM Duty Vrms Vpeak Err Noise
 RMS Cycl
0 -2.599 245 15 0.05 8.201 35.000 -2417 0
1 -2.314 244 16 0.06 8.486 34.990 -2213 -1
2 -2.038 244 17 0.06 8.762 34.980 -1981 -1
3 -1.771 245 18 0.07 9.029 34.970 -1715 0
4 -1.512 246 19 0.07 9.288 34.960 -1445 1
5 -1.260 246 20 0.07 9.540 34.950 -1209 1
6 -1.015 245 21 0.08 9.785 34.940 -1013 0
7 -0.776 246 22 0.08 10.024 34.930 -737 1
8 -0.543 243 23 0.09 10.257 34.920 -633 -1
9 -0.316 244 24 0.09 10.484 34.910 -357 0
10 -0.093 245 25 0.09 10.707 34.900 -77 1
11 0.124 245 24 0.10 10.924 34.890 157 1
12 -0.099 243 25 0.09 10.701 34.880 -173 -1
13 0.118 245 24 0.10 10.918 34.870 157 1
14 -0.105 244 25 0.09 10.695 34.860 -125 0
15 0.112 245 24 0.10 10.912 34.850 157 1
16 -0.112 244 25 0.09 10.688 34.840 -125 0
17 0.106 244 24 0.10 10.906 34.830 107 0
18 -0.118 245 25 0.09 10.682 34.820 -77 1
19 0.099 244 24 0.10 10.899 34.810 107 0

-- Alan


----------



## Alan B (Aug 28, 2008)

Here is the same setup, but changing the battery to 3*3.7V. Regulation is much better:

Type: WA1185 From Reasonable Voltage (3 * Li-Ion)

11.1 Battery Voltage, V
10.8 Bulb Voltage, RMS V
34.02 Bulb Power, W
3.42857142857 Bulb Resistance, ohms
0.95 nominal Duty Cycle
241 PWM nominal value
100.0 PWM Rate, hz
10 Soft Start, PWM counts
36.4285714286 ADC Full Scale Voltage
0.01 Battery Voltage Sag, V/iteration
0.022 PWM Nominal Step Voltage dV
3.15 Bulb Current, RMS A
3.238 Bulb Current, Peak A
0.04 Static FET Power, W
0.001 Dynamic FET Power, W
0.041 Total FET Power, W

 N Err ADC PWM Duty Vrms Vpeak Err Noise
RMS Cycl
0 -0.235 78 232 0.91 10.565 11.100 -380 0
1 -0.222 78 233 0.91 10.578 11.090 -357 0
2 -0.209 79 234 0.91 10.591 11.080 -101 1
3 -0.196 77 235 0.92 10.604 11.070 -311 0
4 -0.183 78 236 0.92 10.617 11.060 -288 1
5 -0.170 76 237 0.93 10.630 11.050 -501 -1
6 -0.157 78 238 0.93 10.643 11.040 -242 1
7 -0.144 77 239 0.93 10.656 11.030 -219 0
8 -0.131 78 240 0.94 10.669 11.020 -196 1
9 -0.119 76 241 0.94 10.681 11.010 -413 -1
10 -0.106 77 242 0.95 10.694 11.000 -150 0
11 -0.094 76 243 0.95 10.706 10.990 -369 -1
12 -0.081 76 244 0.95 10.719 10.980 -347 -1
13 -0.069 77 245 0.96 10.731 10.970 -81 0
14 -0.057 78 246 0.96 10.743 10.960 -58 1
15 -0.045 77 247 0.96 10.755 10.950 -35 0
16 -0.033 77 248 0.97 10.767 10.940 -12 0
17 -0.021 76 249 0.97 10.779 10.930 -237 -1
18 -0.009 77 248 0.98 10.791 10.920 34 1
19 -0.041 75 249 0.97 10.759 10.910 -485 -1

-- Alan


----------



## Alan B (Aug 29, 2008)

Awful quiet here.

Progress Report

OK. Downloaded WinAVR and AVR Studio and installed them. Studio comes from Atmel, and WinAVR is an open source project. You can find them both via the AVR Freaks website, which is a great resource for all things AVR.
 
www.*avrfreaks*.net/
 
I connected a USB serial adapter to my laptop and plugged it into the STK500 test board I have. The firmware on the board was updated from Studio. I installed the Tiny85 cpu chip and jumpers for programming it and the programmer recognizes the chip and reads the signature and fuses from it.

I started writing the test code. With this board and a couple of jumpers I can control an LED and read a switch, so it is actually a good start for the software development without building hardware.

At this point I am looking at example code and reviewing how to talk to the chip resources in C. It has been a long time since I have done this, and things have changed a bit. The development environment with Studio is very nice, and the Gcc compiler in WinAVR is extremely integrated into the suite. Much more automated than it used to be.

I am going to be RV camping this weekend, but I am taking the development system and may have some time to make progress on the code. I should have internet access via the campground WiFi.

Jimmy, if you like, why don't you make a pcb layout to fit in the D size Kiu base for the prototype circuit. Add a driver if you like. If it is noninverting it won't affect the software at all, but even if it ends up inverting we can add a compile time switch to the software to handle inverted drive.

Another question - what would be good for test bulbs? Assuming that testing is going to be done from a 12V power supply or battery, I would suggest that a pair of test bulbs be selected. One that is low power, just to give a good visual of proper operation. Another one for power testing, something that would draw 2-5 amps. This one could be lower voltage, 6 to 9 volts perhaps. It would be nice if they were all compatible with the same socket, possibly BiPin. Bulb experts, what do you suggest? I have the Kiu sockets, so a test board with that mounted on it sounds useful.

-- Alan


----------



## LuxLuthor (Aug 29, 2008)

Alan, many are watching...but don't know enough about your code printouts to make an intelligent response.

Now regarding bulbs, I think the WA gives a decent range of affordable bulbs and have similar bipin size. I think many would be using 2, 3, or 4 x Li-Ion voltage ranges for many of their <5.5 Amp choices.



*1111 - 7.5V & 3.8A*


*1160 - 7V & 4.2A*


*5761 - 7.2V & 5.5A (Philips larger pins but fits KIU)*


*3854 (ROP-High) - 7.5V & 4.5A (Pelikan)*


*1331 - 11V & 2.1A*


*1166 - 13V & 2.1A*


*1185 - 11V & 3.4A*


----------



## Alan B (Aug 30, 2008)

Below is the output of a fairly simple python program that I tossed together to simulate the control loop of the microprocessor. This is not the code that will run in the micro, it does do precise floating point calculations and at the same time it does integer calculations as the micro will do and presents the results. I find this kind of analysis very useful in predicting system performance. A "simulator" or "model". It is a lot easier to find out if the system is going to oscillate or not be accurate enough this way than by building circuits and making measurements. It is also a lot easier to make changes and try algorithms. I have already tried a number of things to try to improve the regulation and simplify the code that the micro will have to run.

The formatting on the form has messed up the titles a bit. The columns are:

N - iteration of the algorithm
Err - RMS V bulb Voltage error from nominal desired value
ADC reading, with noise (0..255)
PWM value (0..255)
Duty Cycle 0..1 (how much the FET is on)
Vrms to the bulb (this is what we are regulating)
Vpeak to the bulb or battery voltage
Err calculated by the micro integer algorithm
Noise added by the random number noise generator

If we look at the data below we see that the soft start was set to only 10 counts of PWM low which resulted in 235 millivolts low voltage output. For the first 18 cycles of the simulation the regulation was increasing the PWM, ramping up the voltage output while the battery is sagging in voltage. At about cycle 18 they meet and regulation reaches its normal values of up to 50 millivolts of error or so. I probably should have run this simulation a bit farther but the listings get a bit long for the forum here.

The 10 counts of soft start is not what we will really use, it is just enough to see the algorithm work without making the output too long.

I tried some other algorithms in the simulator, and so far this one is the best simple one. It is pretty simple. To get much better regulation would require more PWM precision. This could be done with more complicated software, or it could be done with a different CPU chip. We never really discussed a regulation requirement - is 50 millivolts sufficient?

If anyone else wants to load up python and run this program let me know. You set up the battery and bulb voltage and so on, and run the program and it produces the report. Python is a free download.

-- Alan



Alan B said:


> Here is the same setup, but changing the battery to 3*3.7V. Regulation is much better:
> 
> Type: WA1185 From Reasonable Voltage (3 * Li-Ion)
> 
> ...


----------



## JimmyM (Aug 30, 2008)

Alan B said:


> I tried some other algorithms in the simulator, and so far this one is the best simple one. It is pretty simple. To get much better regulation would require more PWM precision. This could be done with more complicated software, or it could be done with a different CPU chip. We never really discussed a regulation requirement - is 50 millivolts sufficient?
> 
> -- Alan


I think 50 mV is quite good. 50 sounds large. But 0.05V sounds quite small. A simpler equation sounds good to me.
Is your code on your download site? I'd like to have a look at it.
Any tiny 16 bit AVRs?


----------



## Alan B (Aug 30, 2008)

JimmyM said:


> I think 50 mV is quite good. 50 sounds large. But 0.05V sounds quite small. A simpler equation sounds good to me.
> Is your code on your download site? I'd like to have a look at it.
> Any tiny 16 bit AVRs?


 
We don't need a 16 bit avr, we could use more bits in the PWM. Most AVRs have 10 bit pwm, but (many of) the tiny's have 8 bit pwm. We can make 10 bit PWM by dithering between PWM values on each pulse, which is just software, but probably not worth it at this point.

I don't want to upload the code to the web from this campground due to network security, I will do that after we get back. I can email it if desired. PM your email address to me if you want that.

I did change the schematic per Jimmy's suggestion. I added a calibration pot. This is for fine tuning to a cal value rather than setting the output. Of course by changing the values of the components the range can be adjusted. I will upload the changed schematic next week. The pot will not be necessary, it can be jumpered out for max stability and the program coefficients be adjusted for calibration. It gives the user several options.

My present thinking on calibration is to have three techniques. The first is to calculate the calibration coefficient from resistor values. This should be good enough to get in range of the pot. This technique is probably not good enough by itself, due to the variance in the chip's ADC reference voltage, as well as in the resistors.

The second technique is to use a known DC value. So you measure the DC voltage, put this value into the chip, and then run a "calibrate cycle". The coefficient will be automatically determined. This technique should be adequate by itself, but it can optionally be followed by the RMS metering.

The third technique is to use an RMS meter. Set the desired bulb voltages into the program. Use the minimum and maximum values and adjust the pot while in actual operation. This requires the cal values in the program
to be close, so one of the other two cal techniques will be required first.

I picked up an RMS voltmeter for $49 at Fry's Electronics on the way to this campout. It is made by Extech. I see that Radio Shack sells an Extech with RMS also. If there are other RMS meters that would be good for folks to look at perhaps we should mention them here. I don't think an RMS meter is required, but it is useful. We'll have to see if these low cost meters develop accurate readings on this PWM waveform.

-- Alan


----------



## JimmyM (Aug 30, 2008)

Alan B said:


> We don't need a 16 bit avr, we could use more bits in the PWM. Most AVRs have 10 bit pwm, but (many of) the tiny's have 8 bit pwm. We can make 10 bit PWM by dithering between PWM values on each pulse, which is just software, but probably not worth it at this point.
> 
> I don't want to upload the code to the web from this campground due to network security, I will do that after we get back. I can email it if desired. PM your email address to me if you want that.
> 
> ...


I really was joking about the 16bit AVR, because 50 mV seems so inconsequential.

I wanted to look at your code as a roadmap. I'm going to get a couple of books and do a little fiddling. I love the AVR idea, I'm just lost with regards to it. So I need to get with the "program" (pun intended).

I use a Fluke 189 as my primary DMM. I love it. Paid a ton for it, but the last meter I had was a Micronta (Radio Shack) True RMS meter. It did volts, amps, Ohms, uF, Hz, tested diodes, and transistors. But it was missing a few things I wanted. Duty cycle and recording. It also has better accuracy at low voltages. Now I have a scope as well. Pity I bought the 189 just before they came out with the 287. Hmmmmmmmm. Delicious.

Enjoy your camping trip, I can bother you for it next week.


----------



## Alan B (Aug 30, 2008)

JimmyM said:


> ...
> 
> I wanted to look at your code as a roadmap. I'm going to get a couple of books and do a little fiddling. I love the AVR idea, I'm just lost with regards to it. So I need to get with the "program" (pun intended).


 
I have two programs that I'm working on right now. One is the python based simulator, the other is the c based microprocessor test program suite.

Here's a teaser from the microprocessor code suite. This is the code that will actually run in the micro. It has not been tested yet. This is a complete program that will provide really basic flashlight operation. Really a test program, not intended to be for operating. It turns the FET fully on or off based on the pushbutton. So it is essentially an implementation of the mechanical switch, however, using a 3 milliohm FET (or whatever FET you put on the micro).


```
[FONT=Courier New]// Electronic Pushbutton Toggle Switch (test program)[/FONT]
[FONT=Courier New]// Alan Biocca  8/2008[/FONT]
 
[FONT=Courier New]// This program monitors the pushbutton, turning the FET fully on[/FONT]
[FONT=Courier New]// when the button is pressed, and back off when pressed again.[/FONT]
[FONT=Courier New]// There is switching debounce delays[/FONT]
[FONT=Courier New]/***********************************************************/[/FONT]
[FONT=Courier New]#define F_CPU 8e6  // cpu frequency for delay timing[/FONT]
[FONT=Courier New]#include <avr/io.h>[/FONT]
[FONT=Courier New]#include <util/delay.h>[/FONT]
[FONT=Courier New]/***********************************************************/[/FONT]
 
[FONT=Courier New]void delay()  // delay 50ms, (should conserve power)[/FONT]
[FONT=Courier New]{[/FONT]
[FONT=Courier New]_delay_ms(50.0);[/FONT]
[FONT=Courier New]}[/FONT]
[FONT=Courier New]void waitForButton() // Wait for push on button PB2[/FONT]
[FONT=Courier New]{[/FONT]
[FONT=Courier New]uint8_t i; i = 3;[/FONT]
[FONT=Courier New]for (;;) // wait for pushbutton release[/FONT]
[FONT=Courier New]{[/FONT]
[FONT=Courier New]if (PINB2 == 1) [/FONT]
[FONT=Courier New]{[/FONT]
[FONT=Courier New] if (--i == 0)[/FONT]
[FONT=Courier New]  break;[/FONT]
[FONT=Courier New]}[/FONT]
[FONT=Courier New]else[/FONT]
[FONT=Courier New] i = 3;[/FONT]
[FONT=Courier New]delay();[/FONT]
[FONT=Courier New]}[/FONT]
[FONT=Courier New]for (;;)[/FONT]
[FONT=Courier New]{[/FONT]
[FONT=Courier New]if (PINB2 == 0) return;[/FONT]
[FONT=Courier New]delay();[/FONT]
[FONT=Courier New]}[/FONT]
[FONT=Courier New]}[/FONT]
[FONT=Courier New]int main()[/FONT]
[FONT=Courier New]{[/FONT]
[FONT=Courier New]DDRB = 8; // init PB3 as output for gate[/FONT]
[FONT=Courier New]PINB = 4; // ena pullup to observe pushbutton action[/FONT]
[FONT=Courier New]for (;;)[/FONT]
[FONT=Courier New]{[/FONT]
[FONT=Courier New]PORTB = 0; // set gate output low (light off)[/FONT]
[FONT=Courier New]waitForButton();[/FONT]
[FONT=Courier New]PORTB = 8; // set gate output high (light on)[/FONT]
[FONT=Courier New]waitForButton();[/FONT]
[FONT=Courier New]}[/FONT]
[FONT=Courier New]}[/FONT]
```


----------



## JimmyM (Aug 31, 2008)

Alan B said:


> I have two programs that I'm working on right now. One is the python based simulator, the other is the c based microprocessor test program suite.
> 
> Here's a teaser from the microprocessor code suite. This is the code that will actually run in the micro. It has not been tested yet. This is a complete program that will provide really basic flashlight operation. Really a test program, not intended to be for operating. It turns the FET fully on or off based on the pushbutton. So it is essentially an implementation of the mechanical switch, however, using a 3 milliohm FET (or whatever FET you put on the micro).
> 
> ...


It looks like you're using a 50ms delay to debounce the switch input? Is that correct?
What is the PORTB = 8? 8 is ON? 4 is Pull-up? 0 = Gnd? What is the difference between ON and Pull-up?
Sorry for all the questions before I even get a book, but this stuff is really starting to intrigue me.
I've got the AVR studio software already. I just need to get a programmer. How is the programmer you linked to earlier working for you?


----------



## Alan B (Aug 31, 2008)

JimmyM said:


> It looks like you're using a 50ms delay to debounce the switch input? Is that correct?
> What is the PORTB = 8? 8 is ON? 4 is Pull-up? 0 = Gnd? What is the difference between ON and Pull-up?
> Sorry for all the questions before I even get a book, but this stuff is really starting to intrigue me.
> I've got the AVR studio software already. I just need to get a programmer. How is the programmer you linked to earlier working for you?


 
I ran the code through the simulator and found a couple of problems. It appears to work now on the simulator. Perhaps later today I can run it on the STK500 (real hardware). It has been a few years since I wrote code for the AVRs and I have to relearn some of the details.


```
void delay()  // delay 50ms, (should conserve power)
{
 _delay_ms(50.0);
}
#define BUTTON (PINB & 4)
void waitForButton() // Wait for push on button PB2
{
 uint8_t i; i = 3;
 for (;;) // wait for pushbutton release
 {
  if (BUTTON) 
  {
   if (--i == 0)
    break;
  }
  else
   i = 3;
  delay();
 }
 for (;;)
 {
  if (BUTTON == 0) return;
  delay();
 }
}
int main()
{
 DDRB = 8; // init PB3 as output for gate
 PORTB = 4; // ena pullup to observe pushbutton action
 for (;;)
 {
  PORTB = 0+4; // set gate output low (light off) and maintain pullup
  waitForButton();
  PORTB = 8+4; // set gate output high (light on) and maintain pullup
  waitForButton();
 }
}
```
 
The code indents are a bit messed up on the forum. The logic here is to react right away when the pushbutton is detected (it goes to zero), and to debounce on the release (going to one). The 50 milliseconds is for the debounce, the code requires detecting the button released 3 times before re-arming for the next push of the button.

The first couple of lines of code set the data direction bit so that the PB3 pin is an output, and turn on the pullup resistor on PB2 so the pushbutton can be detected when it pulls the pin to ground.

When doing the output to BP3 we have to keep sending a one to PB2 (a value of binary 4) to keep the pullup on.

With WinAVR and AVR Studio installed you can compile this stuff and simulate it, though it is a bit confusing. Comment out the delay calls, bring up the disassembly view (right click on the C statements), and use F10 to step through the code. You can simulate the pushbutton by clicking on the PINB bit for it. It is a bit confusing till you get the hang of it, but you can see the instructions executing and find a lot of bugs without a chip.

I did receive the programmer mentioned above. I brought it along but have not assembled it. The STK500 has onboard programming so I probably won't use it there. Perhaps I can test it on a problem we have been having at work with a board. It would be useful to try it there.

I am working on the PWM software next. Setting up the PWM registers. Each of these items takes a couple of hours to figure out and get working, typically. My next test program will have PWM output and probably soft start, going from 0 up to a fixed PWM value.

-- Alan


----------



## Alan B (Aug 31, 2008)

JimmyM said:


> ...
> What is the PORTB = 8? 8 is ON? 4 is Pull-up? 0 = Gnd? What is the difference between ON and Pull-up?
> ...


 
PORTB = 8 sets the third bit, it drives PB3 that is connected to the FET gate. That will turn the bit high and the FET on.

The pushbutton is on PB2 which is binary 4. The 4 turns the pullup on which we need to see the pushbutton. The pushbutton drives the input to zero.

This is the earlier code that wasn't quite right. We need to send 0+4 to Port B to turn the FET off but keep the pullup on, and we need to send 8+4 to turn the FET on and keep the pullup on. (Note that later on the PWM output will take care of the gate, so we won't be doing this).

On is the output driver, so 70 ohms to supply/ground. Pullup is an input choice with a pullup resistor switched on to plus. The specs on the pullup resistor are in the doc, several tens of K as I recall. (Yes, 20-50K according to spec sheet).

-- Alan


----------



## Alan B (Aug 31, 2008)

The test program above has been successfully loaded into the STK500 board and tested. By adding a couple of wires to the test board the pushbutton switch on the board turns on/off the LED on the board via the test program. The timing delays are longer than spec so I shortened the delay to 5.0. I'll have to look into the delay calibration later.

-- Alan


----------



## Alan B (Aug 31, 2008)

Hope everyone is having a nice Labor Day holiday. I've been having a good day, trading between napping and coding.

Project Progress Report..

Found the delay calibration problem. There is a fuse for dividing the clock by 8 that was set by default. Now delays appear to be okay (but I have not timed them or measured frequency yet).

Major Success - The PWM software is working! The test program is now doing soft-start PWM control. It should be running about 244 hz, and it ramps from 0 to whatever PWM value is set in the program (255 is full DC on). The rate is a couple of seconds, this can be changed as desired. This is running on the STK500 test board, responding to a pushbutton and ramping the LED. The ramp is backwards due to the polarity of the LED drive, but it is right for driving the FET. We are not presently driving the FET.

The chip is only 3.4% full of code, folks. There is some room for expansion here. And we have not written a single line of assembly code, this is all in C. :twothumbs

PWM frequency wise we have choices of 61, 122, 244, 488 hz. I chose 244 hz for now. This can be readily changed.

-- Alan


----------



## Alan B (Aug 31, 2008)

More Progress to report.

Another PWM control test program. Pushbutton Control Variable level. This one has soft start and pushbutton manual variable PWM control from an initial PWM setting to another PWM limit setting:

Short click to turn on, soft-start ramps to PWM1 value
Hold button to ramp toward PWM2, stopping at any point (above PWM1)
Short-click to turn off

This one uses 2.7% of the chip's flash program space. This program is smaller than the last one.

I have not progressed to regulation yet. There are a number of things to set up to get that working (interrupts and ADC reading), more research to do there. My testbed will have to gain more hardware as well.

Somebody build some hardware and let's put this in a flashlight!

-- Alan


```
// Hotwire Regulator Test Program suite by Alan Biocca 8/2008
#ifdef FP4 // Ramped PWM with Soft Start Test Program
#define PWM1 64  // low setting
#define PWM2 255 // high setting
// This program monitors the pushbutton, ramping the PWM up to PWM1
// when pressed. If pressed briefly it will then go off. If pressed
// and held it will ramp up towards PWM2.
//
// The PWM value is ramped in a linear fashion.
// This program does not have regulation, low 
// battery protection or low power consumption. It is intended 
// as a simple test program rather than an operational flashlight 
// program.
void init()
{
 DDRB = 8; // init PB3 as output for gate
 PORTB = 4; // ena pullup to observe pushbutton action
 TCCR1 = 0b00001000;  // use 8 mhz ck/128 for 244 hz pwm
 GTCCR = 0b01010000;
}
#define BUTTON (PINB & 4) // Pushbutton is on PB2 to ground
int main()
{
 uint16_t pwm;
 uint8_t press;
 pwm = 0;
 press = 0;
 init();
 for (;;)
 {
  // read and debounce the pushbutton
  if (BUTTON)  // button released
  {
   if (press > 0) --press;
   if (press > 3)
   {
    if (press < 50 && pwm >= 50) // short press going off
    {
     pwm = 0;
    }
    press = 3;
   }
  }
  else   // button pressed
  {
   if (press < 255) ++press; // measure press duration
   if (press < 3) press = 3;
   if (pwm == 0) pwm = 1;  // was off, coming on
  }
  if (pwm > 0) // light is on
  {
   if (pwm < PWM1) ++pwm;  // soft starting
   else
   {
    if (pwm < PWM2 && press > 50) ++pwm; // ramping
   }
  }
  //OCR1B = 255 - pwm;  // output pwm to FET gate
  OCR1B = pwm;    // invert output for LED on STK500
  _delay_ms(10.0);
 }
}
#endif // FP4
```


----------



## JimmyM (Sep 1, 2008)

You set duty cycle by assigning a value between 0 and 255 to OCR1B?
I really do have to get a book...
DDRB, PORTA, PORTB, TCCR1, GTCCR. I need to get my "Alphabet soup to English" dictionary out. Or maybe the Tiny85 doc again.
Nice work, though.


----------



## Alan B (Sep 1, 2008)

JimmyM said:


> You set duty cycle by assigning a value between 0 and 255 to OCR1B?
> I really do have to get a book...
> DDRB, PORTA, PORTB, TCCR1, GTCCR. I need to get my "Alphabet soup to English" dictionary out. Or maybe the Tiny85 doc again.
> Nice work, though.


 
Yes, setting OCR1B to a value sets the duty cycle. Since we are using the inverted output 0 is full on and 255 is off for the FET. For the LED on the STK500 board I am testing with, 0 is off and 255 is full on, hence the two output statements.

I don't have a book, I am working from the Tiny85 documentation, the WinAVR documentation and examples. It is a bit tricky to figure out sometimes, but you can always go to the internet for more examples and even ask questions if needed. The AVRfreaks website has a lot of stuff to sift through. The examples I'm constructing should be most useful as well.

Progress Report:

I made a test program that adds regulation and low battery protection to the ramping soft start version. Code size is about double, up to 5.7% with the 16 bit arithmetic. I have no way to test that yet, other than compiler and some basic tests. This is the feedback based design that I was simulating before. To test this I need to set up a real FET to drive and add a variable power supply. Come to think of it I don't actually have a variable power supply at this point. Any suggestions on a nice inexpensive variable supply? 

How do folks feel about this user interface I've got now? Suggestions, comments??

Short click turns on/off
Soft start ramps to Low
Long click ramps toward Hi, stopping on release

Status, or what's missing:

Reasonable Calibration
Low power standby
Synchronized ADC
Temperature detection
Using nonvolatile memory for parameters

-- Alan


----------



## SafetyBob (Sep 1, 2008)

Alan, I will chime in. I think you once again are right on target!!

I think most, no, all of us would like some sort of low voltage warning (blinking) or auto shutoff to protect our batteries from destruction. Since all of us are running high powered incans, all of us have a good chunk of money in Li-ions, A123s, or Emoli batteries. None of these are cheap. 

Your interface of a short click to turn on and it automatically goes to low is perfect.....warms up the bulb, starts draining off the juice off of our fully charged batteries to prevent flash....in a word, perfect. Exactly how one would do it for extending the lifetime of all components involved. 

The long hold down click to ramp the light up sounds good too. I assume after the light is on, a short click would bring it down to medium or low again? I imagine it would be easier to program to low then to program multiple levels and such (less code, did I tell you how much I hate code). 

Anyway, keep up the great work.

Bob E.


----------



## JimmyM (Sep 1, 2008)

Alan B said:


> Yes, setting OCR1B to a value sets the duty cycle. Since we are using the inverted output 0 is full on and 255 is off for the FET. For the LED on the STK500 board I am testing with, 0 is off and 255 is full on, hence the two output statements.
> 
> I don't have a book, I am working from the Tiny85 documentation, the WinAVR documentation and examples. It is a bit tricky to figure out sometimes, but you can always go to the internet for more examples and even ask questions if needed. The AVRfreaks website has a lot of stuff to sift through. The examples I'm constructing should be most useful as well.
> 
> ...


The interface looks good for a non-regulation design. The ramping duty looks nice.
So there are only 256 PWM steps (0-255).
I'm doing a little thinking.
Since duty = Vref^2/Vin^2 and we can electronically set Vref...
Incrementing Vref during start up will provide soft-start. Changing it during operation will switch between voltage settings.
But regulation won't be extremely smooth because of the 8 bit PWM.
So output voltage will fall at any given PWM until the the calculation adjusts the duty up by 1 256th of 100. Right?
So, if Vref is a number around 0.5 and Vsam=the ADC converted Vin sample
Duty = ROUND((Vref^2/Vsam^2)*256,0)


----------



## Alan B (Sep 1, 2008)

SafetyBob said:


> Alan, I will chime in. I think you once again are right on target!!
> 
> I think most, no, all of us would like some sort of low voltage warning (blinking) or auto shutoff to protect our batteries from destruction. Since all of us are running high powered incans, all of us have a good chunk of money in Li-ions, A123s, or Emoli batteries. None of these are cheap.
> 
> ...


 
Thanks Bob for the kind words and reply. A short click when on presently turns off. We could change that to 'step down' to the Vlow setting, and then another short click to off, if that's better. Not hard to make that change. Anyway, this is a start.

This code has two voltage levels. Low and High. One can ramp upwards between them, or go off. When turned on it autoramps upward to Vlow.

The code is pretty simple now. We can get complicated later, and users can customize theirs as well. Oh, you don't like code. Well, I like good tight solid code, but not bloated overcomplicated code.

At the moment the undervoltage code overrides the voltage regulation and reduces the PWM (and keeps doing that until the voltage is not low). This makes the light dim enough to protect the battery, or go out completely, depending on how the battery behaves with reduced load.

As I was driving home I was thinking about calibration. I think I will put in preprocessor code to calculate calibration from the resistor values and Vref of the chip. This will be a good first start, and should be close enough to adjust it with the pot. I'm looking for easy solutions first, so let the compiler's compile-time pre-calculations do the hard work and create the integer coefficients for the micro so there will be no runtime calcs to do. I'll put it in the simulation first and get it calibrated, then into the micro code to match. That is almost the way the sim is working already.

-- Alan


----------



## Alan B (Sep 1, 2008)

JimmyM said:


> The interface looks good for a non-regulation design. The ramping duty looks nice.
> So there are only 256 PWM steps (0-255).
> I'm doing a little thinking.
> Since duty = Vref^2/Vin^2 and we can electronically set Vref...
> ...


 
In the ramping version I'm ramping Vbulb and letting pwm come from the regulation calculation. 

The pwm steps vary a lot in size depending on where in the range they are. This is one reason to use a Vbattery that is only a little higher than Vbulb, it gives more control with smaller PWM voltage steps. On the one I just ran the PWM steps are 22 millivolts each. That is with a 11.1 volt battery and 10.8 volt bulb. 3 cell Li-ion on a WA1185 bulb.

The PWM is incremented when Vbattery * Vbattery * duty cycle is less than Vbulb * Vbulb (if I remember correctly), and decremented otherwise. The noise on the Vbattery reading will cause some jumping back and forth between PWM settings. The drift in Vbattery will cause a drift in the PWM, generally towards higher duty cycle as the battery voltage drops. You can see it in the simulation. It is a feedback regulator, integrating the sign of the error. Very stable but not the highest performance possible. The thing I like about it for this is no tuning to get good stability. 

I tried a direct calculation and it was lumpy. The PWM values that it can calculate are not even, it skips some, and in general the integer arithmetic and low resolution ADC and PWM is not as good for this approach. 

-- Alan


----------



## SafetyBob (Sep 1, 2008)

Alan, not asking you to change one single thing you are doing or working on....just a simple question for clarification. 

I asked the same thing to JimmyM on his project. Here is the setup, and I think a few people would follow me here too. Let's think [email protected]..... normally a nice 3x Li-ion or Emoli setup. Now lets go for extra runtime....how about 4 batteries. If you can use PWM to get the proper voltage or target voltage for the bulb, have we not made an 1185 flashlight that lasts a lot longer than normal (and what a thrill that would be)...low for extremely long runtimes, with the ability to ramp the light up just enough to illuminate the situation or ramp it up all the way for a really, really bright light that would last alot longer than it does now.

Possible? If not, no problem. I had to ask the question. 

And, I want to clarify that your planned design set up with two levels is perfect because with the ability to ramp the brightness up to the upper PWM limit is very, very good and anywhere inbetween is even better!!

I agree with you on the code. I used to write a lot of Windows 3.1 code for my father-in-laws company when I worked there. It just got out of control when Win95 came out. I love solid, to the point code, but it was getting out of control for me towards the end. 

Bob E.


----------



## Alan B (Sep 2, 2008)

SafetyBob said:


> Alan, not asking you to change one single thing you are doing or working on....just a simple question for clarification.
> 
> I asked the same thing to JimmyM on his project. Here is the setup, and I think a few people would follow me here too. Let's think [email protected] normally a nice 3x Li-ion or Emoli setup. Now lets go for extra runtime....how about 4 batteries. If you can use PWM to get the proper voltage or target voltage for the bulb, have we not made an 1185 flashlight that lasts a lot longer than normal (and what a thrill that would be)...low for extremely long runtimes, with the ability to ramp the light up just enough to illuminate the situation or ramp it up all the way for a really, really bright light that would last alot longer than it does now.
> 
> ...


 
Bob:

Glad you asked. Yes. The regulation code reads the battery voltage and adjusts the PWM to get the desired RMS Bulb Voltage. With PWM the energy is not wasted, so extra cells gives extra runtime. With the 8 bit resolution of the PWM in this chip the voltage resolution is about 22 millivolts if the battery voltage is a little higher than the bulb. The resolution gets worse as the battery to bulb voltage ratio is increased. Let's run the sim for 3 and 4 cells at 3.7V per cell and bulb voltage of 10.8. PWM resolution goes from 22 millivolts to 40 millivolts per step. That's 0.04 volts per step. Accuracy will be a bit worse than that, as noise and ADC granularity get involved.

What level of regulation is required? Is 0.1V good enough?? The simulations generally show much less than 0.1V change, and it averages out to much less than that over time. These calculations are pretty fast, so we will probably be doing them every PWM cycle, so if they dance around a bit the averaging will be quick.

I took a look at the code required to do the 'click to minimum, then click again to off' that was mentioned. It takes one line of code to do that. I wrote it, but have not tried it. Easy to try and put in or take out. Folks can comment on what they might prefer for the 'standard' interface.

I had a pretty annoying day today. Problems with the sewer drain hose on the trailer, then I get home and find that a bunch of the code I wrote last night didn't get saved. I know I saved it, but it was not there. So I have recovered from that, and upgraded the Regulated Ramped code to have Calibration. I did it with the C preprocessor, so you input the values of the three resistors and the VREF of the chip and it calculates the calibration and scales all the desired values into ADC units when compiling the code. The micro then works exclusively in ADC units. I found a couple of errors in the old ADC configuration, too (as I remember it), and this one shrank in size even though it has more features, to about 5.1% of codespace. It is NOT tested yet. As mentioned earlier my test board cannot yet test all this new functionality. This new code version needs one thing to make it into what I would consider a real "flashlight alpha release". It needs to have the low power sleep code done. I will probably work on that a bit yet tonite. Perhaps.

To debug the feedback and ADC I may need to hook up the serial output from the chip and view some internal values. There is a fancy uart in the chip for that, and it may be required to understand something. I'll try to avoid that for now to save time. I'm hoping that I can hook up a pot to the ADC and watch the output change as I vary the 'apparent battery' voltage, but if it doesn't work it might take some debugging. The simulator may be used as well, but that can be tricky with analog input.

The ADC is not presently synchronized with the PWM but with this feedback algorithm I think that would work okay unless the batteries were really poor. That's probably the next thing after the low power to get working. With that I would probably consider it "release candidate 1".

The temperature protection is not done either but that is probably not high priority, along with other things on the wish list. The opto-isolator drive is not in there yet either, but that is not required at first either. The battery half-life is still pretty decent without that.

Jimmy, I have not soldered together the programmer yet. It looks like a nice kit. Perhaps a little searching on the internet might turn up a review. I did see that the software to drive it is included in WinAVR, so that is nice. It will probably require running a batch file to do the programming after doing a compile. Not hard to do, once the arguments are worked out for the command line and put into the batch file.

Prototyping Anyone?

I have four chips, so I could possibly part with one. Perhaps I should make one programmed chip available to someone for a hand wired prototype. This would probably be in a week or maybe less, when I have a version that appears to do regulation according to my testing. Alpha-One. Anyone game? Whoever takes it will have to hook it up and test it and report back to the forum in a reasonable time period. It could be a 'semi-kit' since I have some of the other parts, but it would not include a pc board or all the parts. 

-- Alan


----------



## JimmyM (Sep 2, 2008)

Alan B said:


> Jimmy, I have not soldered together the programmer yet. It looks like a nice kit. Perhaps a little searching on the internet might turn up a review. I did see that the software to drive it is included in WinAVR, so that is nice. It will probably require running a batch file to do the programming after doing a compile. Not hard to do, once the arguments are worked out for the command line and put into the batch file.
> 
> Prototyping Anyone?
> 
> ...


I could probably prototype an etched / assembled board for you, I can't really commit to do testing though. I barely have time to scratch my a** lately.


----------



## Alan B (Sep 3, 2008)

Status Report:

The new RMS Voltage Regulated Software version "appears" to be working, as does "low power mode". This means it "runs" on the test board driving an LED instead of the FET gate. The ADC is not actually doing anything, I'm overriding the value since I have no voltage hooked up to read yet. The 'sleep' mode on the chip is working insofar as the interrupt is waking the chip back up. I have not measured the current draw, but if the chip is in the proper mode it should be very low. The hardest part is getting it to recover, which it does.

I'm trying a 30mm pcb layout to fit under the Kiu base. This is pretty tight. I'll have to use some surface mount parts. I will skip the opto isolator and pot for this version, as they are not required and space is tight. The off state drain will still be under 300 uA which is not bad.

-- Alan


----------



## Alan B (Sep 3, 2008)

JimmyM said:


> I could probably prototype an etched / assembled board for you, I can't really commit to do testing though. I barely have time to scratch my a** lately.


 
Thanks for the offer, JimmyM. How long would it take you to make a 30mm board? Maybe I should stop doing my layout??

-- Alan


----------



## JimmyM (Sep 3, 2008)

Alan B said:


> Thanks for the offer, JimmyM. How long would it take you to make a 30mm board? Maybe I should stop doing my layout??
> 
> -- Alan



It shouldn't take all that long. Using surface mount parts, you can fit a LOT on a 30mm board.
I'd suggest a simple square/rectangular board for proof of concept. A DIP-8 socket for the AVR. Through-hole components allow easier modification.
Once the schematic/design is locked, then we can transfer to a 30mm round board using SMD components and a small pin-header for programming.
For the JM-SSC, I'm fitting 1 DPAK, 1 SOIC-8, 3 SC-70, 2 SOT-23, 2 2mm POTs, and a few resistors/capacitors/diodes. All on a 30mm board with room for 2 KIU mounting screws.
It's a matter of finding the time.


----------



## JimmyM (Sep 3, 2008)

Alan B said:


> Thanks for the offer, JimmyM. How long would it take you to make a 30mm board? Maybe I should stop doing my layout??
> 
> -- Alan



What software do you use for schematic/pcb design?


----------



## Alan B (Sep 3, 2008)

JimmyM said:


> What software do you use for schematic/pcb design?


 
The ExpressPCB package.

-- Alan


----------



## JimmyM (Sep 3, 2008)

I use PCB Artist from Advanced Circuits. CRAP! It couldn't have been nice and easy could it? Oh well. It would take a couple of hours to convert your schematic in ExpressPCB to PCB Artist and then build the PCB design.

Your headers in the schematic are 2.54mm OC pin headers?
I suppose the high current path should be something more robust.


----------



## Alan B (Sep 3, 2008)

JimmyM said:


> I use PCB Artist from Advanced Circuits. CRAP! It couldn't have been nice and easy could it? Oh well. It would take a couple of hours to convert your schematic in ExpressPCB to PCB Artist and then build the PCB design.
> 
> Your headers in the schematic are 2.54mm OC pin headers?
> I suppose the high current path should be something more robust.


 
How does PCB Artist compare to ExpressPCB? I have not really tried others, have been using this one a long time but very intermittently used.

The input and output power should be larger pads. I was planning to use Anderson Powerpoles on those.

The programming plug is 0.1" 2x3 grid. Have to get the numbering right. There are AVR docs on this.

-- Alan


----------



## JimmyM (Sep 3, 2008)

Alan B said:


> How does PCB Artist compare to ExpressPCB? I have not really tried others, have been using this one a long time but very intermittently used.
> 
> The input and output power should be larger pads. I was planning to use Anderson Powerpoles on those.
> 
> ...


It was free and pretty good. I got used to it. The auto routing is a bit rubbish. But, I like it thus far.

How are the libraries in ExpressPCB?


----------



## JimmyM (Sep 3, 2008)

Honestly, I'm all giddy about this project. It'll probably get me into AVRs big time. But I've got the JM-SSC to complete, or $100+ in experimental parts goes down the tubes and God knows how many hours of my time. That's gotta go out before I can afford to do any more development. Things are lean these days. Know what I mean?


----------



## Alan B (Sep 3, 2008)

JimmyM said:


> It was free and pretty good. I got used to it. The auto routing is a bit rubbish. But, I like it thus far.
> 
> How are the libraries in ExpressPCB?


 
Libraries? Seem pretty weak to me. No autoroute, does show you the net. Very simple. 

Progress Report:

Just played around with the temperature detection. It works! I set it for 20C and it turns off in a couple seconds (it only checks the temperature every 256 loops). Set it to 30C and it stays on. So I set it to 60C for now. 

I also added a high voltage shutoff, so if the supply is over the voltage range of the ADC it won't put power to the bulb. 

Well, I have a rough layout for a 30mm board. Just major parts placement. Not sure I have time to finish that now. Would really like to have something to stuff in my [email protected] soon.

I did find the code that I lost on the weekend. I already recreated it, so it is not useful, but at least it didn't really get lost. Just a might bit misplaced. Now I know what the editor was doing.

I also have a simplified schematic. Left off the pot, opto, and the vref capacitor. 

Any tips on laying out for the Kiu base? 30mm diameter, connections near the center, holes for the mounting screws. Anything else??

-- Alan


----------



## JimmyM (Sep 3, 2008)

Alan B said:


> Any tips on laying out for the Kiu base? 30mm diameter, connections near the center, holes for the mounting screws. Anything else??
> 
> -- Alan


Bat negative should be near the edge for easy connection to the mag switch bat neg connection. One switch connection should be near the edge for routing to the bottom of the mag switch. The other should be near the center for easy connection to the top of the mag switch.

When I assembled the PIR I popped the cup out of the bottom of the switch and inserted a plastic disk to isolate the bottom of the switch from the battery positive connection. Then I routed a wire from the board on top, down the side and into the switch cavity at the bottom. This way you can use the Mag switch so that it's isolated from the battery voltage.

The high current connections should be near the edge for connection to the battery, and near the center for connection to the bulb. A Mag85 isn't really a high current bulb so you should be able to get away with fairly wide traces (2mm) on a 2oz board for 5 Amps. Or narrow traces with solid 18-20ga wire soldered on top of them.

For the Mag switches I've sold for the Larry14K and other 600-1000W class lights, I use flattened 10 ga solid copper.


----------



## Alan B (Sep 3, 2008)

JimmyM said:


> Bat negative should be near the edge for easy connection to the mag switch bat neg connection. One switch connection should be near the edge for routing to the bottom of the mag switch. The other should be near the center for easy connection to the top of the mag switch.
> 
> When I assembled the PIR I popped the cup out of the bottom of the switch and inserted a plastic disk to isolate the bottom of the switch from the battery positive connection. Then I routed a wire from the board on top, down the side and into the switch cavity at the bottom. This way you can use the Mag switch so that it's isolated from the battery voltage.
> 
> ...


 
Great tips. 

The PC Artist package looks possibly better than ExpressPCB. I may try it. At some point. Need more time. Need to work on other stuff, too.

-- Alan


----------



## SafetyBob (Sep 3, 2008)

Jimmy......don't worry about selling the JM-SSCs, we will cover your time and investment. I think you will have more people wanting them than you will have completed boards. 

Jimmy and Alan, let me kinda speak for the group....we all are looking forward to this project. It continues to sound like a marvelous board which should add even more WOW to our already cool lights. All of us are completely in your guys debt. 

I looked at the AVR stuff a couple of years ago when I was attempting to really go digital in my home automation project. It just got way to complicated and over my head since I really am not a EE candidate, OK, let's just call me advanced hobbiest/home repairman. It looked really cool then, I am glad you guys have the expertise to make this happen. 

Thinking about it......this is really, really going to add alot of fun AND cool factor to our lights.......where is that paypal button again.......:twothumbs

Bob E.


----------



## Alan B (Sep 3, 2008)

SafetyBob said:


> ...
> 
> Jimmy and Alan, let me kinda speak for the group....we all are looking forward to this project. It continues to sound like a marvelous board which should add even more WOW to our already cool lights. All of us are completely in your guys debt.
> 
> ...


 
Bob, thanks for the kind words. I'm sitting here playing with the SDK500 test board, with an LED and pushbutton wired up to the little micro running the software. It clicks to low, then to off with short clicks. Either a click or click-hold to on, the click-hold ramping it up to and beyond VLO toward VHI. Another short click takes it back down to VLO (Your idea). From there either a short click to off or a click-hold ramps it back up again. Seems like a good interface for a hotwire. If you like I could add SOS :devil:.

This has been fun, but I'm getting anxious to get it in a flashlight! :candle:

Software wise there are two things I'm thinking about next. One is to synchronize the ADC with the PWM so it always reads the battery under load. The other is a software calibration adjustment, so we won't really need the external pot. It can still be used, but this adjustment will allow the same thing to be done in software. Install a jumper on the programming plug to let the micro know it is in 'cal' mode, and then use the button to adjust the calibration up and down. The calibration factor will be stored in the chip's nonvolatile memory. Remove the jumper and away you go.

There are a number of other parameters that will not be changeable this way, at least for now. This only does the calibration, which needs to be done to compensate for component values.

The other parameters are:


```
// Ramped Regulated Calibrated with Soft Start Test Program
#define VLO 2.0  // bulb low setting, in rms volts
#define VHI 10.8 // bulb high setting, in rms volts
#define VBATLO 9.5 // battery low, in volts, comment out to skip test
#define TEMPLIM 60 // deg C shutoff, comment out to skip test
#define LOPWR  // enable low power sleep mode
// calibration factors
#define R1 47e3  // resistor, +battery to pot, ohms
#define R2 0  // adjustable cal pot, adc on wiper (0 if none)
#define R3 10e3  // resistor, pot to ground, 10K recommended
#define VREF 2.56 // chip ADC reference, in volts, 2.56 typical
#define VCAL 1.0 // additional calibration factor for tuning
// timing controls
#define SHORT 50 // duration of short vs long click (main loop cycles)
#define LOOPD 4.0 // main loop delay (floating point milliseconds)
```
 
So the above values are set, the code compiled, the chip programmed. At this moment the ways to calibrate are to use the pot, or to use the VCAL feature above. To use VCAL you measure the RMS and put the ratio between what you measured and what you wanted (say for VLO) into VCAL instead of 1.0. Recompile and reload the chip. Should be right on then. This has not been completely tested yet.

-- Alan


----------



## JimmyM (Sep 3, 2008)

SafetyBob said:


> Jimmy......don't worry about selling the JM-SSCs, we will cover your time and investment. I think you will have more people wanting them than you will have completed boards.
> 
> Jimmy and Alan, let me kinda speak for the group....we all are looking forward to this project. It continues to sound like a marvelous board which should add even more WOW to our already cool lights. All of us are completely in your guys debt.
> 
> Bob E.


Echo Alan's "thanks". But he's doing most of the "heavy lifting" here.

It looks like I have this weekend free. I should be able to get some more work on the JM-SSC done, as well as a prototype board etched. I have "permission" from the wife to burn up Saturday doing "my stuff".
I might be able to get Alan's, schematic converted to PCB Artist.
I've really got to get myself a proper PCB etching rig.


----------



## SafetyBob (Sep 3, 2008)

Alan, that does sound like a wonderful interface. Again, thanks for putting so much of your time into this. 

My only clarification was you said a single quick click initially and it goes to low.....then another (quick?) click and it goes off or would that be at least two quick clicks and off? 

I get the long click or click and hold to ramp it up to high. Thank you for putting the "then click and it goes back down to VLO" in the program, I think once everyone gets to using the light they will appreciate the fact they can show off the "huge" light sabre they have built, put it on low and walk back inside the house. 

My only comment about using a jumper to adjust VCAL vs a pot.....as long as you guys are adjusting it for us, it doesn't matter. Highly recommend that at least initially, you offer switch for sale as......one switch for [email protected] using 3x Emoli batteries or one switch for [email protected] using 9xAA Eneloops. Does that make sense? That way, we can tell you what battery setup we are using and you can program it in for us so we can't screw it up!!! 

What I really mean is how many people have meters that read "true RMS", I think you will need to set that up for us. I think during prototyping the VLO for the few standard bulbs here will become obvious and you can just use those numbers vs. something we try to adjust (I can see that being a nightmere despite me have a couple of meters that read true RMS around here). 

And if I get this right, with the ADC reading the battery under load you would be able to flash the light or simple turn the light off when we reach say 9 volts with the Emoli's or 8.1VDC with the eneloop or NiMH solution. With the nice thing about a simple shut the light off deal (especially on high) is that when one would go, hum wonder what happened, you would hit the switch it would go to low and you could find your way back in the house....at least that's what I would do.....and get my 623 or 625...POB? You get what I mean. 

Sorry for the rambling, just helping you with the final fine tuning and QA that I am noted for at work and around the house (don't ask the wife please). 

Bob E.


----------



## Alan B (Sep 3, 2008)

This STK500 board makes a pretty weak flashlight. The yellow LED is not very bright. It is tethered to the wall wart, and the pushbutton is small. But it proves that most of the software is working.

Okay, I just uploaded the simplified schematic with the resistors numbered to match the calibration software.

http://akbeng.com/flash/hwreg/hrdc1c.bmp

I'm torn between trying to make a prototype that fits on a 30mm board and making a cradle/rectangular board to replace the [email protected] switch entirely. We should probably do both, eventually.

Back to other projects...

-- Alan


----------



## Alan B (Sep 3, 2008)

SafetyBob said:


> Alan, that does sound like a wonderful interface. Again, thanks for putting so much of your time into this.
> 
> My only clarification was you said a single quick click initially and it goes to low.....then another (quick?) click and it goes off or would that be at least two quick clicks and off?
> 
> ...


 
Bob,

I have a cal technique that doesn't require an RMS meter also. We can do that as well. RMS meters are pretty low in cost, but whoever builds and programs the chip will probably calibrate it. With the programming software free, and the programming hardware about $20 I would hope that a few folks would equip themselves so they could play with the software, customize the interface and parameters.

This is all subject to change, but at the moment the low battery just regulates to protect the battery (simple), so the light goes into moon mode and then off. 

The interface is simple but hard to explain without confusion. Let's see if I can make a simpler precise explanation with a set of rules:

if off, short click turns on and ramps to VLO.

if at VLO, short click goes off.

if above VLO, short click ramps to VLO.

if off, long click turns on and ramps to VLO, and then keeps ramping until button released or VHI reached.

if on, long click ramps toward VHI and stops when button released or VHI reached.

regulation is accomplished by PWM, so battery voltage must exceed bulb voltage RMS regulation value to be able to regulate. If the bulb request voltage exceeds the battery voltage the FET will switch solid on and be direct drive, falling out of regulation (until battery voltage falls below set low value).

if battery voltage is below set low value voltage is ramped down until either battery voltage is no longer low, or the light goes off, overriding regulation. 

the light will not come on if battery voltage is low. it will try, and turn off so quickly that it will probably not be noticeable.

if overtemperature is reached, light goes off, overriding regulation. this test is done every couple of seconds, so turning it back on will work for a moment.

if overvoltage is noted (ADC overrange), light will not come on.

-- Alan


----------



## JimmyM (Sep 3, 2008)

Alan,
You could easily fit that on a 30mm board. You could fit that with a DPAK FET. Noooooo Problem.
Edit: You could fit that with a PAIR of DPAKs.


----------



## Alan B (Sep 4, 2008)

JimmyM said:


> Alan,
> You could easily fit that on a 30mm board. You could fit that with a DPAK FET. Noooooo Problem.
> Edit: You could fit that with a PAIR of DPAKs.


 
Unfortunately I have a tube of 10 TO220's 40V 75A 3.1mOhms 5V gate, and Digikey doesn't have the DPaks of this FET except by special order or reels or whatever.

What size resistors do you generally use? I have no surface mount parts in stock here. Other than some ham radio kits I bought and have not assembled yet. Need to do the qrp dummy load with 44 resistors to get some SMT practice. We do surface mount prototyping at work, but I don't work with the parts.

It looks like a TO220 FET and a surface mount CPU will work with surface mount resistors. The TO92 regulator is smaller than the surface mount part.

If I make the square board for the switch replacement cradle things will fit easier. The TO220 can go under the board on the aluminum or perhaps stand up above the board, and the square board will have a little more space in the corners. I don't know if the switch I got will feel very good on a big light. It is small. Any good pushbutton recommendations??

-- Alan


----------



## Raoul_Duke (Sep 4, 2008)

Alan B said:


> Bob,
> 
> I have a cal technique that doesn't require an RMS meter also. We can do that as well. RMS meters are pretty low in cost, but whoever builds and programs the chip will probably calibrate it. With the programming software free, and the programming hardware about $20 I would hope that a few folks would equip themselves so they could play with the software, customize the interface and parameters.
> 
> ...




That is so cool


----------



## Alan B (Sep 4, 2008)

Two files posted to the website:

The first file is a Python program that calculates the regulator behavior for selected values of battery and bulb voltage. It runs on your PC and requires Python to be installed. Python is free from www.Python.org.

Simulator for Hotwire Regulator:

http://akbeng.com/flash/hwreg/pwm_sim.py


The second file is a version of the test program for the microprocessor. It is written in C and requires the avr-gcc compiler and libraries. I use WinAVR and AVR Studio to compile and load this software into the ATTiny85 chip. This version of the file contains a number of test programs. It does not contain the latest version of the software which is still undergoing a lot of changes. It does include the ramped PWM control program with soft start.

Test Code for Hotwire Regulator:

http://akbeng.com/flash/hwreg/HotwireRegulatorTests.c

-- Alan


----------



## mudman cj (Sep 4, 2008)

What about adding a click sequence to ramp straight to VHI from off? I would like to suggest two rapid clicks separated by less than x seconds, where x is 0.5-1.0 seconds. This would be beneficial for things that go bump in the night.

I too would like to thank you gentlemen on behalf of CPF members everywhere for your selfless contributions to the community. :thumbsup:


----------



## Alan B (Sep 4, 2008)

mudman cj said:


> What about adding a click sequence to ramp straight to VHI from off? I would like to suggest two rapid clicks separated by less than x seconds, where x is 0.5-1.0 seconds. This would be beneficial for things that go bump in the night.
> 
> I too would like to thank you gentlemen on behalf of CPF members everywhere for your selfless contributions to the community. :thumbsup:


 
Thanks for the kind words.

With this interface you can go straight to VHI by click-hold. It will ramp straight to VHI. Two quick clicks from HI to off. The speed of the ramp can be controlled.

Other interfaces can be developed as well. We can have several. Perhaps the inverse of the one we are starting with would be popular for some users and applications. Short click to HI, ramp to LO.

Another thought that would be compatible with the present design. A Long click from off could go straight to HI. It pretty much does that already though by ramping to HI. The ramp is pretty quick, depending on the main loop rate settings. Right now they are 4ms per loop, and it takes about 512 loops to ramp all the way to full PWM on, or about 2 seconds. If the voltage to the bulb is lower than the battery voltage it will reach the PWM value sooner. In practice probably about 1.5 seconds. So a long click from off could go a bit faster. How fast do we want to go and still consider it soft-start?

The parameters are very configurable, and the code fairly easy to fiddle with, so lots of ideas can be tried on for size.

We just need to get some hardware built to run this software on.

At this point I see three builds:

1) test board, too large for flashlight

2a) 30mm breadboard to fit in Kiu base

2b) 30mm pc board for Kiu base mount in D [email protected]

3) [email protected] switch replacement subsystem - aluminum cradle and pcb, slides into D [email protected] and replaces switch.

I am leaning toward working on #3 myself, and JimmyM has tenatively indicated he may work on #1. Does someone want to try building #2a? A breadboard sized to fit in a light?? Be the first on the block to have this system in a light?? I will make one 8-dip pre-programmed CPU available to the person willing to commit to making #2a within a fairly short time schedule, say a few days to a week or so, and report back to the group and post photos. I will also supply a TO220 FET and the TO92 regulator. Builder to supply other parts. No programmer needed. Anyone ready to breadboard??

-- Alan


----------



## SafetyBob (Sep 4, 2008)

Sounds great Alan!! 

Bob E.


----------



## JimmyM (Sep 4, 2008)

Getting started. Aside from the AVR Studio and WinAVR software... What do I need? I see that there is the STK500, But I remember the PIRs programmer, that was a little black box with a USB plug. Inside there wasn't much more. It was a USB female(B) receptacle on a board with one chip.
Basically this? In system programmer:
ATAVRISP2-ND
From there it went to the ribbon cable that would plug into the PIR. So how much is really needed to program the chip?
Would the STK500 be used for development, then, later could a simpler programmer be used? Like the one used with the PIR?


----------



## Alan B (Sep 4, 2008)

JimmyM said:


> Getting started. Aside from the AVR Studio and WinAVR software... What do I need? I see that there is the STK500, But I remember the PIRs programmer, that was a little black box with a USB plug. Inside there wasn't much more. It was a USB female(B) receptacle on a board with one chip.
> Basically this? In system programmer:
> ATAVRISP2-ND
> From there it went to the ribbon cable that would plug into the PIR. So how much is really needed to program the chip?
> Would the STK500 be used for development, then, later could a simpler programmer be used? Like the one used with the PIR?


 
The STK500 is for testing software without hardware. You can plug just about any AVR into that board and both program it, as well as run it. There are some LEDs and pushbuttons for simple interfacing. You can adjust the power supply voltage and clock rates. It is quite nice. In my case for the hotwire driver software here I have the Tiny85 chip installed, plus two jumper wires to connect the on-board programmer to the chip, and one wire for the pushbutton and one more for the switch. The wires/plugs are the ones with square pin 0.025 sockets on each end. The programming plug wires came with the STK500 (it comes with a bunch of cables), and I bought a few more single wires with those sockets from Fry's electronics.

The STK500 has both the 6 pin and the 10 pin SPI programming sockets, and cables on it. So you can use it to program other systems that have the programming connectors. It requires a wall wart, about 12V, and a serial connection to the host computer (or usb to serial adapter).

But you don't need the STK500 board.

All you need is a programmer. I think the one you linked above is fine (AVRISP II), or the 

http://www.ladyada.net/make/usbtinyisp/

or there are many others. I have one of the usbtinyisp's above, which cost $22 in kit form, and it looks good. I have not built it yet. 

I found a couple of reviews on the usbtinyisp. Here is one:

http://www.evilmadscientist.com/article.php/usbtinyisp

Another blog mentioned some mis-labeled parts on the pcb, but the issue seemed quite minor. The above review liked this programmer better than the Atmel product. It has several features over the Atmel.

Things to AVOID in a SPI programmer:

10 pin only programming socket. You want a 6 pin socket, or both.

Parallel port programers - they do pin timing and require a real parallel port.

Serial port programmers that do timing on the handshake pins - they require a real serial port and even then are possibly problematic.

Programmers that don't have tristate buffers to automatically disconnect from the target chip when not programming - when doing testing you want to compile / program / test quickly, without unplugging. The tristate allows that. Some programmers have switches to disconnect. Very tiring.

----

If you have a target board that has a six pin SPI programming plug on it all you need is the free software and the $22 programming dongle.

-- Alan


----------



## Alan B (Sep 4, 2008)

Progress Report:

ADC reading code synchronized with PWM pulses. This means that loaded battery Voltage is always sampled after the start of the 'on' cycle instead of being randomly sampled asynchronously to the PWM. This has been partially tested. If it didn't work the code would hang, and it is running, so presumably it is working.

Breadboard Parts Offer :candle:

I edited the post a few back and added the parts for breadboard offer, perhaps there is no interest..

On a related topic, Are the Kaidomain 32600 Li-Ion cells the only game in town for Li-Ion D cells? Since this board does low voltage protection we probably don't need protected cells. Perhaps a fuse would be a good idea, but that can be added in the switch area?? 3 Li-Ion D cells sounds like a good match for this regulator and a WA1185 bulb... Or 2 cells and a good 6V bulb??? I see I'm going to need more than one of these regulators. :devil:

-- Alan


----------



## JimmyM (Sep 4, 2008)

Alan B said:


> The STK500 is for testing software without hardware. You can plug just about any AVR into that board and both program it, as well as run it. There are some LEDs and pushbuttons for simple interfacing. You can adjust the power supply voltage and clock rates. It is quite nice. In my case for the hotwire driver software here I have the Tiny85 chip installed, plus two jumper wires to connect the on-board programmer to the chip, and one wire for the pushbutton and one more for the switch. The wires/plugs are the ones with square pin 0.025 sockets on each end. The programming plug wires came with the STK500 (it comes with a bunch of cables), and I bought a few more single wires with those sockets from Fry's electronics.
> 
> The STK500 has both the 6 pin and the 10 pin SPI programming sockets, and cables on it. So you can use it to program other systems that have the programming connectors. It requires a wall wart, about 12V, and a serial connection to the host computer (or usb to serial adapter).
> 
> ...



Cool. Thanks. I really can't wait to get started. It's gonna take a bit of learning, but once I've got some skills under my belt, I think things are gonna get really interesting.


----------



## Alan B (Sep 5, 2008)

I forgot to mention, we are up to using 7.2% of the chip. 

-- Alan



Alan B said:


> Progress Report:
> 
> ADC reading code synchronized with PWM pulses. This means that loaded battery Voltage is always sampled after the start of the 'on' cycle instead of being randomly sampled asynchronously to the PWM. This has been partially tested. If it didn't work the code would hang, and it is running, so presumably it is working.
> 
> ...


----------



## Alan B (Sep 5, 2008)

New Calibration Idea

We still have two programming pins that can be used for I/O. These could be used for calibration. Make a plug for the programming socket with two pushbuttons, one for cal up, and one for cal down. Plug this into the programming jack during calibration. A long click on either of these would slowly ramp the calibration when the light was set to VLO or VHI. 

A Non RMS meter can be used for calibration if you have a variable power supply. Use an AC meter to measure the output of the regulator and power the regulator from the variable power supply. You can tell if PWM is on or off by reading the AC meter. When the PWM goes to dc the AC value will drop from some value to zero. If you adjust the variable power supply you will see the regulator transition from PWM to DC when the power supply comes down through the RMS voltage setting (and the regulator drops out of regulation). Above that the PWM will come back on. Find this point and then measure the DC power supply level, and that is the RMS setting of the regulator. Use the calibration adjustment to make this correct, and the system is calibrated.

If we combine the above two techniques, you set the DC power supply for the desired RMS output (which is programmed into the chip already), and adjust the CAL UP and CAL DOWN buttons until the PWM just transitions to DC on.

I have not written the code to do this, but we have the technology. :devil:

-- Alan


----------



## Alan B (Sep 5, 2008)

mudman cj said:


> What about adding a click sequence to ramp straight to VHI from off? I would like to suggest two rapid clicks separated by less than x seconds, where x is 0.5-1.0 seconds. This would be beneficial for things that go bump in the night.
> 
> I too would like to thank you gentlemen on behalf of CPF members everywhere for your selfless contributions to the community. :thumbsup:


 
New Feature for Mudman

#define BLAST // causes long click at turn-on to go straight to VHI

This is still soft-start ramped and regulated, but is at least twice as fast as the click-hold ramp, and it does not stop if the button is released. It does not affect other controls, only the click hold at turn on.

This feature can be enabled or disabled at program build time.

The code is written but not tested..

-- Alan


----------



## JimmyM (Sep 5, 2008)

Alan B said:


> Or 2 cells and a good 6V bulb??? I see I'm going to need more than one of these regulators. :devil:
> -- Alan


Or 3 A123 cells and the 5761 running at 7.2V Niiiiice and white.
Or 4 A123s and a 64625 @ 12.8V He he he he.
I'm going to be doing a lot of work on electronics this Saturday. I've got some PCB etching equipment to put together. Once that is put to bed, I'll get started on the PCB design for the HRDC.


----------



## Alan B (Sep 5, 2008)

JimmyM said:


> Or 3 A123 cells and the 5761 running at 7.2V Niiiiice and white.
> Or 4 A123s and a 64625 @ 12.8V He he he he.
> I'm going to be doing a lot of work on electronics this Saturday. I've got some PCB etching equipment to put together. Once that is put to bed, I'll get started on the PCB design for the HRDC.


 
I have all that PCB etching equipment packed away. Takes too much time. Now I send them out.

I have a 3D [email protected], looking for something interesting in a 2D to go with this regulator. I like A123 cells but we need one in D size. 

Good luck with your projects on Sat. I hope to find time to cut some metal for the regulator cradle this weekend.

Thinking about "stealth" mode for the regulator software. This will restrict the light to LOW until the secret handshake is given. Then the full interface is enabled.

The question is - what should the secret handshake be? I'm tempted to use a morse code like sequence - selectable by the user of course - Perhaps tapping ". . . _ _ _ . . ." would unlock the daemon. Or whatever sequence is chosen. Each element would be either short or long, no space recognition. That's pretty easy to do.

-- Alan


----------



## Alan B (Sep 6, 2008)

Alan B said:


> I have all that PCB etching equipment packed away. Takes too much time. Now I send them out.
> 
> ...


 
Are you going to try the laserprinter to PCB transfer method? I never tried that, it might make it a lot more practical. I was doing the UV sensitizing system, even cleaning, spraying, drying in oven sensitizing business. Quite a process.

Back on topic, I've got a pretty good looking parts layout for the switch replacement board. Need to cut aluminum and make the part to finalize the dimensions.

Did a small test code that reads/writes the eeprom nonvolatile memory.

-- Alan


----------



## Alan B (Sep 6, 2008)

Alan B said:


> ...
> Back on topic, I've got a pretty good looking parts layout for the switch replacement board. Need to cut aluminum and make the part to finalize the dimensions.
> 
> ....


 
Just laid the traces on this switch replacement board layout. Need to finalize the mechanical dimensions (waiting on the aluminum parts) and layout the paddle boards for programming, etc

-- Alan


----------



## JimmyM (Sep 7, 2008)

Alan B said:


> Are you going to try the laserprinter to PCB transfer method? I never tried that, it might make it a lot more practical. I was doing the UV sensitizing system, even cleaning, spraying, drying in oven sensitizing business. Quite a process.
> 
> Back on topic, I've got a pretty good looking parts layout for the switch replacement board. Need to cut aluminum and make the part to finalize the dimensions.
> 
> ...


I used the toner transfer method for the JM-SSTs. I'm going to use that method just for proving the board deign. Then I'll send it out for fab.

I converted your design over to PCB artist. I still need to tweak it for component packages, but everything is through-hole right now. I have to choose better pin-headers and mess with the PCB layout to optimize the high current path, but it all pits on a 2" x 2" board even with the very large programming header.


----------



## Alan B (Sep 7, 2008)

JimmyM said:


> ...
> I'm going to be doing a lot of work on electronics this Saturday. I've got some PCB etching equipment to put together. Once that is put to bed, I'll get started on the PCB design for the HRDC.


 
How did it go?

I've got some time today, but lots of other things I need to do. Perhaps I'll find time to put together the USBtinyISP kit.

-- Alan


----------



## JimmyM (Sep 7, 2008)

Alan B said:


> How did it go?
> 
> I've got some time today, but lots of other things I need to do. Perhaps I'll find time to put together the USBtinyISP kit.
> 
> -- Alan


It went well. I had to define a couple of new components, but overall, it went well. I'll send a picture of it to you. PM me your email.


----------



## Alan B (Sep 7, 2008)

JimmyM said:


> I used the toner transfer method for the JM-SSTs. I'm going to use that method just for proving the board deign. Then I'll send it out for fab.
> 
> I converted your design over to PCB artist. I still need to tweak it for component packages, but everything is through-hole right now. I have to choose better pin-headers and mess with the PCB layout to optimize the high current path, but it all fits on a 2" x 2" board even with the very large programming header.


 
We were simul-posting, and your answer beat by query but within the same minute. 

Great progress on your test board. My 1.1 by 1.3" pcb layout for the D switch replacement is pretty cramped, and the TO220 is standing which saves a lot of space. One thing I'm having some trouble finding is a right angle pcb female connector to mate with the programming pin header on the main pcb.

We could choose a smaller programming connector, but it would be nonstandard and require an adapter for everyone who does programming. That might be ok, though I am hoping that a lot of folks will want/need to be able to program the chips, even if they don't write code, and so the standard connector would have benefits. 

Another direction we could take is to put a bootloader into the chip and load programs over a simpler serial connection. The bootloader progamming would still require the programming interface (6 pins), but after that initial load the other programming (or parameter changes) would only require the serial interface, which could be a 3 circuit 2.5mm headset type connector. It might still require an adapter to convert the 5V serial, but perhaps a direct to USB adapter would be convenient, or perhaps some of the standard USB to serial adapters will work ok with the 5V serial already.

At any rate, keeping the standard 6 pin connector is useful if we can do it. 

Someday I'll have to give the direct toner method a try. Or it would be fun to build a computer controlled router pcb cutter. Those are pretty slick..

I wrote some of the code for 'dyamic calibration'. This is the software replaces potentiometer approach. During calibration two additional pushbutton switches are connected to the programming header. One pushes the calibration up, the other down. The cal gets stored in the EEPROM and stays between runs. A limit is placed on the range of adjustments, so if the EEPROM is not programmed, or is way off, it will be ignored. The cal buttons will only work when the light is at min or max, where you know what the RMS should be.

The setup sequence would be:

Put the board into a light or test circuit, with no bulb. Connect an RMS DVM to the bulb output. Load the batteries.

Set the parameters - lo and hi bulb, battery minimum voltage, etc. into the program. Compile and load into the chip.

ADC Calibration:

Connect the up/down buttons to the programming plug. Click the light on, it goes to VLO. Adjust the RMS output with the up/down buttons. Hold the button down, it will slowly change the calibration coefficient. Then do the long-click and ramp to VHI. Check the RMS and re-tweak if required. Click the light off. Wait one minute before removing batteries (the EEPROM write occurs after about 1 second after the light is turned off and allowed to sit without pushbutton input.

Optionally repeat the adjustment process with the bulb installed and the DVM reading the RMS voltage across the bulb.

Disconnect the ADC calibration adjustment buttons.

-- Alan


----------



## JimmyM (Sep 7, 2008)

Digikey's got a TON of pin-header connectors. Lots of 1mm, 1.27mm, and 2mm pitch as well as the standard 2.54mm (0.1") connectors.
search Digikey for this part# WM27006-ND. Dial-row, 90 deg, 6 pin, Gold plate. $0.79 ea. Molex makes similar headers as well as AMP.
1.5mm pitch connectors. Single row, shrouded header. See Digikey P/N 455-1673-ND. It's only 10.5mm wide x 2.7mm high. The 2.54mm pitch 2x3 connector would need to accommodate a plug that's 7.6mm wide x 5.1mm high.
JST has a 1mm pitch connector: P/N 455-1806-1
Header is shrouded and is 8mm wide by 2.9mm high. The plug (P/N 455-2187-ND) would fit inside that.

Nice and small. I like the idea of a bootloader, but then we'd have to have 2 headers on board. Unless the chip is a DIP-8 , then it could be programmed initially OUTSIDE the regulator then plugged in.
Regarding the SMD version... I'd like to have the option of a purely SMD device. I think it could fit in a C cell body. There'd be no room for 2 headers. There may only be room for a board edge type conection.


----------



## JimmyM (Sep 7, 2008)

Alan B said:


> Put the board into a light or test circuit, with no bulb. Connect an RMS DVM to the bulb output. Load the batteries.
> -- Alan


Since the voltage divider is in the B+ wire you won't need a dummy load on the FET. If, for any reason, we decide to implement high-side switching with the divider between the FET and the bulb, the calibration will have to be done with a dummy load because of the capacitance of the FET.

Maybe small tactile feedback switches could be designed on board for calibration. You know, like the recessed buttons in things where you "push to reset". They can't be that big.


----------



## Alan B (Sep 7, 2008)

Since the DMM is downstream of the FET switch, and reading the output, a small load might be required for it to read accurate PWM. We'll see when we test it.

OK, I assembled the USBtinyISP, plugged it in, loaded the driver and used the avrdude that was installed by WinAVR. It worked to program the chip on the STK500 board. 

Here's the command I used to program the chip:

avrdude -c usbtiny -p t85 -U flash:w:HotwireRegulator.elf

The elf file is the binary file from the compiler. I put this in a batch file, so programming is easier. 

So this $20 programmer works! :thumbsup:

-- Alan


----------



## Alan B (Sep 7, 2008)

JimmyM said:


> Digikey's got a TON of pin-header connectors. Lots of 1mm, 1.27mm, and 2mm pitch as well as the standard 2.54mm (0.1") connectors.
> search Digikey for this part# WM27006-ND. Dial-row, 90 deg, 6 pin, Gold plate. $0.79 ea. Molex makes similar headers as well as AMP.
> 1.5mm pitch connectors. Single row, shrouded header. See Digikey P/N 455-1673-ND. It's only 10.5mm wide x 2.7mm high. The 2.54mm pitch 2x3 connector would need to accommodate a plug that's 7.6mm wide x 5.1mm high.
> JST has a 1mm pitch connector: P/N 455-1806-1
> ...


 
OK. Thanks. Found a dual-row female 6pin 0.1" through hole mount that I needed for the [email protected] switch replacement and extender. Sometimes the parts selector just doesn't get there, have to page through the virtual catalog.

We don't need the connector shrouds, but do need to leave space on the PCB for the cable connector around the pins on the board. The male connector goes on the target system, the female on the cable to the programmer.

Probably should use a smaller pitch connector for the C [email protected]. Make a little PCB adapter and use a standard cable between the adapter and the project. The nice thing about the six pin SPI is that it does everything, no need to do a bootloader, etc. One connector, done. Let's leave that decision for later.

So, the good news for today is that the low cost USBtinyISP programmer works. Takes less than an hour to build. Has more parts than this regulator, but is not hard. I made one goof - soldered the LEDs to the board before noticing they were supposed to be above it. Not important, but makes them harder to see. One is for USB connectivity, the other is for programming in progress. Neither of which is required - the program shows when it is programming, verifying, etc anyway. They can be seen through the holes but would be more visible if closer to the holes.

The USBtinyISP vendor also has very short USB cables. Nice to have a short 3 footer for this. Here is their web page:

http://www.adafruit.com/index.php?main_page=index&cPath=16

-- Alan


----------



## SafetyBob (Sep 7, 2008)

Great job guys!! Sounds like we are getting really, really close. 

We can get into it later, but Alan, you are making it sound like with even say above average computer knowledge (like, you have built your own computer....a couple of times) that programing this thing by us rank amatuers would be feasible. If so, we will have to put reasonable instructions to paper so that stupid doesn't take over and foul everything up. Do some of that writing instruction crap and boy can it get complicated to idiot proof something. 

If you could post or PM a picture/diagram of what switch housing you are thinking about for this, please do. If I have time this week I would love to just go play on the metal lathe and see what comes out.....at least let's see how easy it is to make a replacement switch housing or just how we want to proceed with this. Since most of us have a metal lathe or know someone who does, it would be nice to see what we need to do or have done....

Bob E.


----------



## Alan B (Sep 8, 2008)

SafetyBob said:


> Great job guys!! Sounds like we are getting really, really close.
> 
> We can get into it later, but Alan, you are making it sound like with even say above average computer knowledge (like, you have built your own computer....a couple of times) that programing this thing by us rank amatuers would be feasible. If so, we will have to put reasonable instructions to paper so that stupid doesn't take over and foul everything up. Do some of that writing instruction crap and boy can it get complicated to idiot proof something.
> 
> ...


 
Developing software:

If you put in a bulb that can take full battery voltage, there is not much risk at all. You can look at the sample programs I uploaded earlier, or on the website, they are pretty simple. Starting with one of those and making changes to it should not be hard at all. My test program with lots of features is getting a bit complicated, but that is not necessary.

On the Mechanical part

I have no reasonable drawing at this point, but have a good idea of what I want to do. Start with a stock D [email protected] Remove tailcap, batteries and head. Remove the rubber switch cover. Remove the switch tower. All that is left is the body tube with ring clip inside.

Now I'm thinking that I want to leave the ring in to provide good support for the switch unit when the batteries hammer it in a drop (or when you are driving nails with the lite). If we cut off the stock switch tower and attach a Kiu base, that is the volume I'm thinking we should work in. So I'm thinking of turning an aluminum rod to body ID less a few thou, and turning the forward part enough more so that it will pass through the ring, leaving a shoulder that will rest on the ring. Now we have a dual-diameter cylinder that will slide in and occupy the volume of the old switch plus the Kiu base. Actually make it a little shorter for a full diameter insulator on the battery side, or at least a large diameter insulator (in this case face in a ring to take the insulator). Face off both ends and center bore in a quarter inch or so on both ends, one for the wires to the socket, and the other for the + screw (use a brass screw?) plus insulators. The milling will reach these holes.

Now clamp this in a mill vise and mill a space for the circuit board. Make as much room as practical. Go just over half way down so the pc board can sit a bit below mid-plane. I'm hoping that the brass screw from the plus can screw into a small metal block that is sitting on top of the pc board, and screwed to the PCB. This would bring the + to the PCB and support the PCB on one end. 

That's the general idea. Some details will be adjusted or refined when metal cutting is going on. The goal is to get a reasonable space for the PCB. The estimate I have is 1.3 by 1.1 inches, with two of the corners cut to clear to the ring reduction in diameter. So the PCB outline is two rectangles joined. I have a preliminary PCB layout that is this size, so I hope to get about that much space for it in the aluminum.

So is this completely crazy? Any suggestions??

Thanks for reading,

-- Alan


----------



## Alan B (Sep 8, 2008)

Alan B said:


> ...
> 
> On the Mechanical part
> 
> ...


 
So here is a photo of my idea for this PCB mounting system to replace the switch in a D [email protected]:

http://akbeng.com/flash/hwreg/Mag D PCB Sled.JPG

The batteries sit against the left end, and the right end, smaller in diameter, slides through the stop ring inside the body tube. The standoffs and hotwire socket would sit toward the upper right, and the circuit board would sit down into the Sled. There is one tapped hole in the bottom of the sled, there will be a hole in the circuit board so an Allen wrench can reach through and tighten against the inner tube to pick up ground and lock this 'drop-in' into place...

-- Alan


----------



## SafetyBob (Sep 8, 2008)

Well, I would say that is close to what I thought you were talking about. I will draw mine up too. Did quick draft earlier but have lost time trying to get my FET switch going with comparator and it isn't going well. 

Will get my version, which isn't much different than yours, up tomorrow. I will try to draw it up good and let the comments begin.....

Bob E.


----------



## Alan B (Sep 9, 2008)

One question on the Kiu base setup. Can my switch replacement switch tower be any more forward toward the bulb, or is the height of the Kiu base about the limit, or is there a better height. I need room for the circuit board so hopefully it does not need to be any shorter.

-- Alan


----------



## Alan B (Sep 9, 2008)

I was looking into fuses. How about a 15 amp picofuse? Might save some embarassment if there is a short when using D Li-ions...

Or a short on some A123 cells, in which case the poof is not the batteries, but something else in the current path. :devil:

-- Alan


----------



## JimmyM (Sep 9, 2008)

Alan B said:


> I was looking into fuses. How about a 15 amp picofuse? Might save some embarassment if there is a short when using D Li-ions...
> 
> Or a short on some A123 cells, in which case the poof is not the batteries, but something else in the current path. :devil:
> 
> -- Alan


How about using an ADC input for some sort of current sense? Bwahhh haa haa. You've got me thinking "AVR". But I suppose a fise in the tail would be more of a simple, "catch all" approach.
You want a fuse to be replacable anyway.


----------



## wquiles (Sep 9, 2008)

First, my hat is off for you guys for this awesome project. Ever since I worked with the Willie Hunt LVR regulators I always dreamed about doing on for myself as a cool project, so I am glad to see what you guys are working on it already!

Although I have not contributed from the start, I would love to offer my free help during the testing/debugging areas. 

Here is some possibly pertinent bench work I have done here in the forums:

1) Quite a bit of testing with the Willie Hunt Designs:

https://www.candlepowerforums.com/threads/124058

https://www.candlepowerforums.com/threads/126127

https://www.candlepowerforums.com/threads/125451


2) Here are some tests I did on TaskLED's excellent D2DIM:
https://www.candlepowerforums.com/threads/118448


3) Bench Testing of Incandescent Soft Start Circuit:
https://www.candlepowerforums.com/threads/101677


Please do let me know if I can be of help 

Will


----------



## Alan B (Sep 9, 2008)

wquiles said:


> First, my hat is off for you guys for this awesome project. Ever since I worked with the Willie Hunt LVR regulators I always dreamed about doing on for myself as a cool project, so I am glad to see what you guys are working on it already!
> 
> Although I have not contributed from the start, I would love to offer my free help during the testing/debugging areas.
> 
> ...


 
Looks like some good work, Will. Thanks for the comments.

Well, what do you want to do? At this point JimmyM has a test pcb layout pretty far along, and I have a D [email protected] replacement switch circuit board partially laid out. I need to make the metal next so I can finish the details on the dimensions of the board. Jimmy has a little touchup to do on the test board, and then I think he is going to cut a board using a laserprinter toner process. I'm not sure if Jimmy has time to work with the board or perhaps someone else could do that.

I have some parts, and I did make an offer if someone wants to breadboard the regulator and report back here I will supply a pre-programmed micro and the FET and regulator IC. The rest would have to be provided by the builder.

I ordered a few more parts today, and an AVR Dragon board. That board will allow me to do In Circuit Emulation for debugging, which could be very useful, but is not required.

What would you like to do?

-- Alan


----------



## Alan B (Sep 10, 2008)

*Low Voltage Bulb Performance Data*

Perhaps one of the Bulb Experts can comment on good LOW level voltages for some of the bulbs. With the LOW-HI ramping interface it is nice to have a useful low level voltage to program. We have some excellent High end bulb voltage data, but do we have data on the low end?

*Calibration Thoughts*

I was rereading some of the old threads that wquiles referenced and some that were referenced in post #1 of this thread. I had forgotten that even some of the supposedly RMS reading meters didn't always work correctly on this PWM. So one thing we need to do is test that and see what works. From the PIR1 manual (linked in article #1 also) we have:

*Calibration notes from the PIR1 manual:*

Using a standard common averaging DC meter:

1) Vrms = sqrt (Vbat * average(Vbulb))

Using a scope or meter that reads duty cycle:

2) Vrms = Vbat * sqrt(duty cycle)

*Calibration Solution for Everyone*

I just went through the math to verify equations #1 and #2 above.

Equation #1 is perhaps the most useful when wanting to determine the RMS of a PWM signal. With a DC meter measure the battery voltage and the average bulb voltage. Then the RMS can be computed. Of course, we probably want to do the opposite during calibration. We measure the battery voltage, and we have decided on an RMS bulb voltage and programmed it into the chip. So we need to know what average voltage that will be. Turning the equation around:

3) Average(Vbulb) = Vrms * Vrms / Vbat

So we measure battery voltage and compute from the RMS we are seeking the average that will be. Then we can adjust the calibration of the board to achieve this average value. No PWM measurement of duty cycle needed. This is probably the way to go for most folks. Use a light load on the regulator, such as a bulb that can take full battery voltage or a resistor, and it also won't load the batteries too much and change their value during the on cycle of the PWM. These equations assume the battery voltage is constant during the PWM cycle, and that is the voltage in the equation known as Vbat. If the load is heavy, or the battery is not holding voltage, the results will not be accurate. But very little is required in the way of load, and a light load will not pull the battery down.

Incidentally, equation #1 is essentially what this micro voltage regulator uses to close the feedback loop with and control the regulation with. We've been through this math before. The micro does it with squares rather than bothering taking the square root, so it is a bit easier and faster to do for the chip.

-- Alan


----------



## Alan B (Sep 10, 2008)

JimmyM said:


> How about using an ADC input for some sort of current sense? Bwahhh haa haa. You've got me thinking "AVR". But I suppose a fise in the tail would be more of a simple, "catch all" approach.
> You want a fuse to be replacable anyway.


 
You are beginning the journey to the dark side. :naughty:

I have thought about watching for a precipitous voltage drop on the battery to trigger a fuse-type response, but have not done so yet. At the moment the code will regulate the PWM back sharply if the battery drops below battery minimum values, but this would not be as fast as one would like. I will put it in, though.

Of course the fuse is really for those extreme circumstances. A 15A fuse will require something like 30A to pop quickly, so it will take a short. One thing I worry about is the bulb resistance during bulb failure. Sometimes I think the bulb develops a really low resistance short during its failure process, and this could lead to current spikes. Also there is the slip with a probe, or mounting the board with an accidental short. That's what this is for. Of course, a piece of solid wire can be substituted if the fuse is not desired. And we can do both a real fuse and an electronic fuse in software.. A single ADC reading of less than 5 volts or so could trigger an immediate OFF command. That only requires one line of code...

-- Alan


----------



## wquiles (Sep 10, 2008)

Alan,

Thank you for allowing me to help you guys. Yes, I would love to breadboard the regulator board and report how it works. Although my digital storage scope does not read RMS directly, I have a Fluke 189 that can read RMS Volts directly. That and the captured scope traces should help to give you guys with feedback as to how things are working.

If you have a parts list I can start ordering parts this Thu/Fri, and start building it fairly quickly. We can work with PM's but for attachments email is easier: (edited to counter SPAM)

Will


----------



## Alan B (Sep 10, 2008)

Alan B said:


> You are beginning the journey to the dark side. :naughty:
> 
> I have thought about watching for a precipitous voltage drop on the battery to trigger a fuse-type response, (but have not done so yet:thinking. At the moment the code will regulate the PWM back sharply if the battery drops below battery minimum values, but this would not be as fast as one would like. I will put it in, though.
> ...
> -- Alan


 
Well, I just went to add in the fuse code, and I effectively already have it in there. If the voltage drops below 5.9 volts, it shuts off, bang This is part of the voltage range checking. So a short or unusually heavy load should trip this in most cases, though with really stiff batteries like A123 Lithium Iron NanoPhosphate, it might not drop as much, especially for a high voltage pack. We might add a settable level that could be closer to battery nominal, I suppose.

-- Alan


----------



## Alan B (Sep 10, 2008)

wquiles said:


> Alan,
> 
> Thank you for allowing me to help you guys. Yes, I would love to breadboard the regulator board and report how it works. Although my digital storage scope does not read RMS directly, I have a Fluke 189 that can read RMS Volts directly. That and the captured scope traces should help to give you guys with feedback as to how things are working.
> 
> ...


 
Thanks for helping out. Email has been dispatched.

-- Alan


----------



## Alan B (Sep 10, 2008)

*In System Calibration*

This morning I wrote (but did not test) code for the EEMEM based calibration. This allows a pair of pushbuttons to be added that adjust calibration up and down over a limited range and store the calibration coefficient in EEMEM parameter memory of the AVR cpu chip. This memory is preserved without power (nonvolatile), so once set this cal parameter will stay. The purpose of this calibration is to calibrate the adc over a limited range. The nominal resistor values should already be in the compile time program configuration, so only a 30 percent range of adjustment is allowed in this calibration. This range is also a compile time parameter. This calibration is to compensate for the variations in resistor values and the chip's reference voltage.

In my [email protected] switch replacement design there are two small boards that can fit through the pushbutton hole in the body and plug into the regulator board inside the body. One is the regular on/off control. This board is small and the switch comes flush with the flashlight body, so it can be covered by the usual rubber cover and is used in normal operations. The other board is longer and sticks out of the body of the light about 4cm. It has 3 buttons - on/off, cal up and cal down. Additionally it has a 6 pin jack for programming the CPU chip. So the program can be changed without significantly disassembling the flashlight.

Also, through the hole it will be possible to probe and measure battery voltage when the plug in board is removed. This is useful when using an averaging meter to do the calibration, as the battery voltage measurement is required to calculate the RMS voltage.

-- Alan


----------



## SafetyBob (Sep 10, 2008)

Just a couple of questions to visualize the small pushbutton switch.....

Does it have legs (best language I can describe it) or will it have a thin flat wire(s) going to a plug to the board? What I am getting at is that the distance from the switch location to the middle of the flashlight where I assume the mainboard will reside will be around a half an inch? 

Tomorrow I will play at work and see if our two visions are the same. 

Bob E.


----------



## Alan B (Sep 10, 2008)

SafetyBob said:


> Just a couple of questions to visualize the small pushbutton switch.....
> 
> Does it have legs (best language I can describe it) or will it have a thin flat wire(s) going to a plug to the board? What I am getting at is that the distance from the switch location to the middle of the flashlight where I assume the mainboard will reside will be around a half an inch?
> 
> ...


 
My current thinking is to use a switch with perpendicular legs, and a right angle plug on the switch board, so the switch pcb sits perpendicular to the regulator board inside the light, and the switch cantilevers off the switch board, about a half inch above the regulator board which is about on centerline of the flashlight as you indicated.

-- Alan


----------



## SafetyBob (Sep 11, 2008)

Perfect Alan, I will show you what I think would be good for the positive end of things too once I get the pencil out and the scanner warmed up tommorrow. 

Close your eyes here it is. For the positive end of the switch next to the batteries, think of a round head screw with it's threaded end turned down to it can go into a socket on the board (which it doesn't need to) so instead (and I just this second thought of it)....Brass round head screw, goes through reasonable thickness of plastic......on the part inside of switch, simply use couple of ring (eye) connectors screwed down in place with nut. One ring goes to Kiu socket, the other (small wire) goes to power up board. 

Going back to the original idea, we could have some sort of socket on the board to pick up a reduced diameter shaft which would automatically give power to board, then just have simple screw down attachment of B+ to kiu socket positive wire to bulb.........I will show you will illustration, but I think you can visualize that pretty close to what I/you am thinking.....larger version of that right angle plug for switch pad. 

Bob E.


----------



## Alan B (Sep 11, 2008)

SafetyBob said:


> Perfect Alan, I will show you what I think would be good for the positive end of things too once I get the pencil out and the scanner warmed up tommorrow.
> 
> Close your eyes here it is. For the positive end of the switch next to the batteries, think of a round head screw with it's threaded end turned down to it can go into a socket on the board (which it doesn't need to) so instead (and I just this second thought of it)....Brass round head screw, goes through reasonable thickness of plastic......on the part inside of switch, simply use couple of ring (eye) connectors screwed down in place with nut. One ring goes to Kiu socket, the other (small wire) goes to power up board.
> 
> ...


 
We are thinking along the same lines. I have an area on the PCB right in the center of the edge toward the battery plus reserved to take a small block of metal that has two threaded holes - one the brass screw from battery + threads into (making the pc board slightly below centerline), and the other, offset and perpendicular, takes a screw from the bottom of the pc board, and this conducts plus to the pc board. The area I have on the board is about 0.2 by 0.4 inches, but it can be adjusted some if there is space. There is a fuse on the pc board, and a pad right next to it with heavy traces on both sides to carry current, and the bipin socket wire can land there. For higher current setups, as you suggest, the bipin wire may need to bypass the PCB and go straight to the brass + screw.

-- Alan


----------



## JimmyM (Sep 11, 2008)

I made a couple of small changes to the board. I increased the drill hole diameter on the connectors to 1.7mm to fit 14 gauge wire. I also, changed one of the high current tracks and redid some of the copper pours. I'll email the new pcb file.


----------



## Alan B (Sep 11, 2008)

*CPU Chip Choices*

I was looking at a smaller memory version of this same processor (there are three flavors available - ATTiny25/45/85), so just for fun I changed the compiler settings and recompiled my most complicated version for the smallest, the ATTiny25. It took only 46 percent of the program space. These chips are even lower in cost, and may be completely adequate for production. I'll get a couple for testing in my next order.

I built a solar controller based on the Tiny15 many years ago, I think I will change it to the Tiny25 so I won't have to write assembler for it, and I can upgrade it significantly...

-- Alan


----------



## JimmyM (Sep 11, 2008)

The Tiny85 is about ~$2.75 each and the Tiny25 is about $1.70 each. If you can get all that programming into a Tiny25 with 54% left over, I say go for it.


----------



## wquiles (Sep 11, 2008)

JimmyM said:


> The Tiny85 is about ~$2.75 each and the Tiny25 is about $1.70 each. If you can get all that programming into a Tiny25 with 54% left over, I say go for it.



+1

Not a huge difference, but saving a dollar here and there makes the resulting boards more affordable - always a good thing :twothumbs

The only thing I will note, after 20 years of running engineering projects - the firmware "will" grow to fill the available memory. It is not a mater of "if", but "when". Given this, it would be wise to plan (or allow) moving back to the Tiny85 if/when needed 

Will


----------



## wquiles (Sep 11, 2008)

Alan B said:


> Thanks for helping out. Email has been dispatched.
> 
> -- Alan



Got the email and will be ordering the AVR stuff and the parts I don't have from Digikey tonight.

I have a HP regulated 60V - 10Amp Power Supply and a huge 100-watt variable power resistor (0-100 ohms), so I should be able to simulate many battery and bulb combos, before we move to the "real" bulbs 

I will update the thread once parts arrive, and of course, like I like to do here in the forums, I will be posting TONS of pictures 

Will


----------



## Alan B (Sep 11, 2008)

wquiles said:


> Got the email and will be ordering the AVR stuff and the parts I don't have from Digikey tonight.
> 
> I have a HP regulated 60V - 10Amp Power Supply and a huge 100-watt variable power resistor (0-100 ohms), so I should be able to simulate many battery and bulb combos, before we move to the "real" bulbs
> 
> ...


 
Sounds like a plan, Will. That is one heck of a power supply. The variable supply I built years ago got cannibalized for some project a long time ago, so I don't presently have one. That is about the only thing I probably need to get pretty soon for this work. I don't think I'll get a DC RMS meter at the present time, but that would be handy with this project. 

My good news for today is that there were two packages for me when I came home. One from Digikey that included the Dragon AVR development board, and one from Hobbylab.us with the USB Scope adapter. I have not tried them out yet, but hope to get to that in a bit.

On the Dragon board - This is NOT required for this project, but is a way to develop and debug programs for the AVR CPUs. It has various programming capabilities and also has DebugWire, a way to do ICE (In Circuit Emulation) on the equipped AVR processors. This way you can single step, set breakpoints, etc. Really useful if you need to work on software that just isn't doing what you expect. I have not had this capability for years (it used to cost $15,000), but now this can all be done for $49

The Digikey box also had the right angle programming connectors that I need to make the [email protected] switch replacment work. It is going to be tight, but there is hope for this...

On the size of the program - There is a LOT of growth space in the 8K Tiny85, my small programs are only about 5% and my largest one is about 12%. The Tiny25 is 2K and the Tiny45 is 4K. They all have the same pinout and the same capabilities, it is very easy to move between them. Whatever it takes, they are all under three bucks in small quantities. The price difference is small until you need to buy 100 of them, then it is important. I plan to test at least with the 25 and 85 so we can be sure that we have the flexibility to change easily.

-- Alan


----------



## LuxLuthor (Sep 12, 2008)

Holy Cannoli ! This is moving along wonderfully. So EXCITING!!!

Alan, could you say a bit more on low end bulb voltages....in terms of how low from optimal overdriving voltage, and watt size of bulbs? Probably good to just pick a couple common bulbs to start with, like 1164, 1185, Philips 5761? Not sure if you are also wanting to jump into 12V Osram 90-100W category.


----------



## Alan B (Sep 12, 2008)

LuxLuthor said:


> Holy Cannoli ! This is moving along wonderfully. So EXCITING!!!
> 
> Alan, could you say a bit more on low end bulb voltages....in terms of how low from optimal overdriving voltage, and watt size of bulbs? Probably good to just pick a couple common bulbs to start with, like 1164, 1185, Philips 5761? Not sure if you are also wanting to jump into 12V Osram 90-100W category.


 
*Selecting VLO (the low voltage setting)*

Well, the only bulbs I have are WA 1185's. Some thoughts that come to mind on the low voltage end are:

What is the minimum voltage to see the filament glowing. This is a good place to start VLO when initially testing, perhaps.

What voltage would put out similar lumens to a standard 3D [email protected]. It might be reasonable to set VLO there, so the light behaves kind of like a standard [email protected] when first turned on. It would also be useful for demonstrations, "this is the output from a standard [email protected]... and now for the upgraded version"...

Another possible VLO is the minimum voltage at which the Halogen process works and redeposits tungsten onto the filament, below which bulb life is poor.

Are there other thoughts about selecting some suggested values for VLO??

== Alan


----------



## Alan B (Sep 12, 2008)

Alan B said:


> ...
> 
> My good news for today is that there were two packages for me when I came home. One from Digikey that included the Dragon AVR development board, and one from Hobbylab.us with the USB Scope adapter. I have not tried them out yet, but hope to get to that in a bit.
> 
> ...


 
I had to reboot to get the Hobblylab drivers to install, but it works now. I didn't hook up probes and the test board yet, but it seems to be working as expected. This inexpensive USB scope has digital inputs, analog inputs and digital outputs. It also has decoding for various serial protocols which are common on these micros. It is not high bandwidth, but is plenty for these projects, and is small and inexpensive. 

-- Alan


----------



## Alan B (Sep 12, 2008)

I connected the Hobbylab and Dragon to the STK500 and the whole thing plays. The timing is just over 4ms, right where expected. 

The Dragon programs the STK500 mounted Tiny85 chip fine, and there are no ground loops.

One of the probes that came with the Hobbylab has an open ground. The probes are pretty low budget, not surprising since a pair of high quality probes can cost as much as the whole kit.

-- Alan


----------



## LuxLuthor (Sep 12, 2008)

Alan B said:


> *Selecting VLO (the low voltage setting)*
> 
> Well, the only bulbs I have are WA 1185's. Some thoughts that come to mind on the low voltage end are:
> 
> ...



Alan, the problem (& my confusion) is mostly related to the variability from bulb to bulb. When I did my destructive testing, they would all begin glowing at very low voltages relative to their nominal spec. I think to avoid a sickly orange it would be better to have VLO set at say *10% below their nominal rating*....or what the user wants to choose for a given bulb. For example, the 1185 30W bulb has a nominal spec of 9.6V @ 3.15A, so it would look "decent" at 8.5 Volts. Some bulbs would look respectable at 20-30% below their nominal values.

I don't think it is plausible to equate these high performance bulbs on VLO to a standard Mag 3D in terms of lumens. I don't know how you would figure the threshold voltage at which there is reasonable halogen supported tungsten redeposition. I think it is going to be more of a VLO "eyeball" voltage setting of what looks 'half-way decent,' which is easy to recognize with the kind of ramping up testing I did.


----------



## Alan B (Sep 12, 2008)

*Dragon Chases Bugs*

I got the AVR Dragon board debugger working. I had to remove a reset jumper on the STK500 that was loading the reset line down. The DebugWire communications takes place using OneWire protocol over the Reset line. There is a fuse in the CPU that has to be set for DebugWire to work, and this fuse prevents ISP (programming) from working. So you set the fuse using ISP, and then clear it with a DebugWire command. If the wires are right, there needs to be no wire changes between modes, so it is not a problem once it is understood.

I single stepped through some of the code, very nice to be able to do that. You can do that in the simulator without the Dragon, but that is only useful for the non I/O parts of the code, at some point you need real hardware. Then the ICE (In Circuit Emulation) of the Dragon shows its value. The Dragon is NOT needed for simple programming changes, I have done without one for many years, but it is helpful when a sticky problem comes along.

*More Power*

I stopped at Fry's on the way home and purchased a small variable power supply. Just a little guy at 18V 3A but enough to be useful. I see what LexLuthor is talking about - these bulbs do light at very low voltages. I would think with a light meter we could do a [email protected] equivalent voltage for them, perhaps it will vary a bit between bulbs but with soft start the bulb life will be so long we can redo it for the rare bulb changes.

*More Parts*

I found a number of interesting parts on www.Sparkfun.com. They have 25mm round prototyping boards, micro programmers, and lots of interesting parts. They have a USB programmer that is STK500 compatible, so it can be used from AVR Studio with a couple of mouse clicks. This is a little more convenient than the USBtinyISP which requires either a command line batch file to run it, or some other software to interface it to Studio. The Sparkfun unit does cost a bit more, though, about double what the $22 USBtinyISP costs.

-- Alan


----------



## Alan B (Sep 13, 2008)

*More USBtinyISP*

This evening I did some work with the USBtinyISP. I have to say the more I use this the more I like it. This evening I connected it to a solar regulator board I made a few years ago, and installed a Tiny85 CPU. I set the jumper on the USBtinyISP to supply power to the board. So my entire development/test system consists of (the laptop,) a 3 foot USB cable (from the same company that sells the USBtinyISP), and my little solar board. The test board is powered from the USB, so no wall wart etc required. I loaded the flashlight test program in the board and cycled an LED on the board to be certain I was loading the board properly. It takes the following command to load the file into the CPU:

avrdude -c usbtiny -p t85 -U flash:w:HotwireRegulator.hex

I have placed that in a batch file and keep a small command window open. To reload the chip takes two keystrokes. F3 <return>. Plus maybe a mouse click to bring the window up. This is not much harder than doing it from the STK500 GUI. It is not as pretty, but just as effective. Not bad for $22.

-- Alan


----------



## wquiles (Sep 13, 2008)

Glad to hear your PC/USB scope is working well 

For my part, DigiKey says my order shipped yesterday!!!

Now the waiting begins ... :mecry:


----------



## Alan B (Sep 13, 2008)

wquiles said:


> Glad to hear your PC/USB scope is working well
> 
> For my part, DigiKey says my order shipped yesterday!!!
> 
> Now the waiting begins ... :mecry:


 
*Digikey wait loop*

They are sure quick. And you're about half as far from them as I am, so you'll have yours on what, monday??

*USB Scope screendump*

I took a screendump from the scope yesterday and here it is. This is a large file, over a megabyte. (the smaller version is below). I'll have to compress it later but it does look nice. This is the output of the microprocessor generating PWM.

http://akbeng.com/flash/hwreg/scope/080912 stk500 output.bmp

-- Alan


----------



## wquiles (Sep 13, 2008)

That looks freaking AWESOME!!! :twothumbs :twothumbs :twothumbs

As to reducing the image to the 800x600 which is the max that this forum allows, I have yet to find an easier and simpler (and totally free!) utility as Irfanview:
http://www.irfanview.com/

One of the best features is their batch mode conversion - you can take many pictures without worrying about the size, and then select the batch mode, and convert all of them at once, not only size wise, but also with fewer colors (which helps folks without broadband connections!).

Will


----------



## Alan B (Sep 13, 2008)

wquiles said:


> That looks freaking AWESOME!!! :twothumbs :twothumbs :twothumbs
> 
> As to reducing the image to the 800x600 which is the max that this forum allows, I have yet to find an easier and simpler (and totally free!) utility as Irfanview:
> http://www.irfanview.com/
> ...


 
Looks like a nice program. Good ratings, etc. Have to give it a try... Used it for this, nice. 

*Scope Image Resized*







This is the output from the Tiny85 driving PWM. It is driving a transistor/LED on the STK500 board.

When the control button is pushed you can see the LED change intensity and the PWM smoothly shift from one value to another. No problems at this power level. I'll have to investigate the "signal parameters" part of the USB Scope - it appears to be doing some AC/DC measurements. Wonder if it is doing DC RMS properly.. The Frequency looks to be inconsistent with the waveform since it says 268 hz but the waveform is longer than 4ms, so it should be slightly below 250 hz. The programmed value should be 244 hz but the Tiny85 internal RC oscillator is uncalibrated. It can be calibrated but there is no requirement for that in this project.

At this point I'm pretty impressed with this little USB scope. It is not a replacement for a high bandwidth scope, but for microprocessor and audio work it is adequate, small, inexpensive and makes nice screen captures. It also has digital input and output logic analysis, spectrum analysis and other features as well that I have not tried yet. It comes from www.hobbylab.us and costs well under $200.

-- Alan


----------



## Alan B (Sep 14, 2008)

Yesterday I took a little diversion. I put one of the Tiny85 CPUs into a board I made a few years ago, a Microprocessor controlled Solar Controller. I whipped up a C program for it and got it working in a couple of hours. The older chip I had used was only programmable in assembler and that was a pain.

Then I was looking at the extra bare board I have, and I realized with a little hacking it could be a prototype for the Hotwire Regulator here. I made some plans but it was too late, and I have too many things to do today to spend any time on it. It is probably not worth hacking up that PCB because Jimmy and Will are about to have prototypes going soon anyway (and it can be used to make a perfectly nice micro controlled FET switch for Solar or other uses). 

It is starting to look like we might have a full fledged prototype about next weekend or so, with a little luck.

I have been refining the design of the [email protected] sled a bit. The switches I bought seem too small and hard to operate, so I found a much better looking switch in Digikey's catalog. I need to make another order soon. This is worse than buying flashlights on the pocketbook. 

-- Alan


----------



## LuxLuthor (Sep 14, 2008)

I just want you guys to know that I have wet myself at least 3 times reading this thread.


----------



## Alan B (Sep 14, 2008)

LuxLuthor said:


> I just want you guys to know that I have wet myself at least 3 times reading this thread.


 
Hmmm. Should I send you a programmed CPU chip?

-- Alan


----------



## Alan B (Sep 15, 2008)

I wonder how folks are doing. Hopefully wquiles was not affected by the storms in Texas. Wonder if JimmyM had any progress this weekend... His prototype test PCB layout looks very nice  The PCB Artist program he uses has a lot of features and produces nice looking boards. The ExpressPCB software I have been using is probably easier to get started with, but the boards don't have quite the refinement. They remind me more of the older tape style of PCB design in the way they look. Each of these programs is tied to a single manufacturer of boards. I looked again at Eagle layout, which is not coupled to a manufacturer. It costs $, though you can use a restricted free version if you are not selling your product, but for a reasonable version it is $750, or more.

I got impatient and sent my [email protected] board in for prototype manufacturing this morning. ExpressPCB has a deal for three boards that is pretty low in cost and 1 day turn, plus shipping. I was waiting to make some metal, but I realized that this board is about as small as I can make it, and I can probably fit the metal to it. If I can't fit the metal to it, significant changes will be required like surface mount parts. Even without the metal it will be good to test the circuit and board. I should have them late this week. (Faster than buying stuff from DX) 

Any progress or plans?? 

I need to get the in-light calibration software working.

-- Alan


----------



## wquiles (Sep 15, 2008)

Alan,

I am in Texas, but in the Dallas area, so we only had rain and mild winds - pretty normal stuff our way. Of course, it was a different story altogether for folks near the Galveston coast and Houston ... my best wishes for a speedy recovery 

Regarding the fitting of parts, I also have a bench lathe and mini-mill, so I have also worked on "getting parts to fit" for other projects as well - this might come handy later on :twothumbs

The stuff I ordered from Digikey "should" arrive this week, so if I am lucky by this upcoming weekend I will be playing with the firmware stuff and getting hands-on experience with the development/debugging tools 

Will


----------



## Alan B (Sep 15, 2008)

wquiles said:


> Alan,
> 
> I am in Texas, but in the Dallas area, so we only had rain and mild winds - pretty normal stuff our way. Of course, it was a different story altogether for folks near the Galveston coast and Houston ... my best wishes for a speedy recovery
> 
> ...


 
Glad to hear all is well there. 

Those lathe and mill tools are quite useful. I've only had them for a few years, I don't know how I got along without them before.

Email from ExpressPCB says I should have the [email protected] PC Boards Thursday.

-- Alan


----------



## Alan B (Sep 16, 2008)

*Calibrating the ADC Readings*

Tonite I spent a few minutes playing with a new ADC calibration routine. Seems to work, the last one had some problem that I didn't debug. Applying the calibration correction in 16 bit integer math requires a little care. I tested this routine in the Micro Solar Charge Controller, but I will probably adapt it for the Hotwire Regulator as well. 

*Auto Calibrate*

In the Solar Controller a "CAL" jumper is placed on the board before power is applied, and the voltage level set to 12.0 volts, the CAL value. This is applied to the board. The software recognizes the jumper and goes into calibration mode. It adjusts its own cal factors on both ADCs until they are right on, then it changes the LED outputs to let you know it is done. If it goes out of cal range it blinks one of the LEDs.

We could do the same thing on the Hotwire Regulator, but it would require the user to have a DC supply at the cal voltage. In this case we don't really need the auto-cal routine since setting the variable supply near the bulb RMS voltage will cause PWM to stop below the bulb RMS value (goes into direct drive) and restart again above bulb RMS. So it will be easy to see where the calibration is by where it changes to full ON versus PWM.

-- Alan


----------



## Alan B (Sep 16, 2008)

Naming

Just occurred to me we could call this the "Programmable Hotwire Driver".

"PHD". Maybe "PHDD" for the D size.

Probably too confusing, though.

-- Alan


----------



## wquiles (Sep 16, 2008)

Alan B said:


> In the Solar Controller a "CAL" jumper is placed on the board before power is applied, and the voltage level set to 12.0 volts, the CAL value. This is applied to the board. The software recognizes the jumper and goes into calibration mode. It adjusts its own cal factors on both ADCs until they are right on, then it changes the LED outputs to let you know it is done. If it goes out of cal range it blinks one of the LEDs.


What causes the ADC's to go out of calibration? What is the internal reference that would "loose" precision?

Will


----------



## Alan B (Sep 16, 2008)

wquiles said:


> What causes the ADC's to go out of calibration? What is the internal reference that would "loose" precision?
> 
> Will


 
The calibration needs to be done once after assembly. Three things affect it - the two resistors in the voltage divider, and the CPU's internal voltage reference. The largest variation is the CPU's reference, so even buying precision resistors does not solve the large part of the problem.

After the initial calibration it should not require adjustment unless the chip is changed.

We could use the 5V power as the voltage reference, but this would probably also require calibration, and it would be subject to noise and loading. 

There is another 1.1V reference in the CPU that could be used. I'll have to check on that one, it might be more accurate, but I felt the higher voltage was a bit easier to deal with.

In the unit I tested last weekend the calibration was about 3% off. When I input 13.8 volts it read 14.2 volts.

-- Alan


----------



## mudman cj (Sep 16, 2008)

PhD - That's a great name, Alan. This device is just what the doctor ordered. 
By extension they could also be referred to as 'Dr. D' and 'Dr. C' for the Mag D and C sizes respectively.


----------



## Alan B (Sep 17, 2008)

Alan B said:


> ...
> 
> I got impatient and sent my [email protected] board in for prototype manufacturing this morning. ExpressPCB has a deal for three boards that is pretty low in cost and 1 day turn, plus shipping. I was waiting to make some metal, but I realized that this board is about as small as I can make it, and I can probably fit the metal to it. If I can't fit the metal to it, significant changes will be required like surface mount parts. Even without the metal it will be good to test the circuit and board. I should have them late this week. ...
> -- Alan


 
Email from ExpressPCB indicates the [email protected] PC Board Prototypes have shipped.

I made another order from Digikey today and it already shipped as well. Pretty impressive performance.

I soldered my AVR Butterfly and Carrier board this evening, and it works. Yet another low cost AVR Development board. My plans for that board are to make a highly programmable Thermostat controller for the house, but it would make an interesting flashlight regulator development board, with the built in display that could be used for debugging info. 

Jim's HRDC1 test PC board layout is really looking good also. Progress!

-- Alan


----------



## wquiles (Sep 17, 2008)

mudman cj said:


> PhD - That's a great name, Alan. This device is just what the doctor ordered.
> By extension they could also be referred to as 'Dr. D' and 'Dr. C' for the Mag D and C sizes respectively.



I really like those names, but I don't want to restrict it to just the D/C Maglights.

I personally would still like to find a way to create a variation of this board/solution that would work to create the next M6R (maybe the M6-PhD would be a good starting name for this subproject) - there are lots of folks (myself included) that were let down by Andrew and his regulated solution, and it would be great if we can find a solution to all of those folks here in the forums who want to have a regulated, softstart incandescent solution for the mighty M6 

Given the confines/size restriction for the M6, this solution will likely need its own PWB. So if you guys don't mind, I would like to spear-head the M6-PhD solution 

I will wait a little bit longer until the basic MagLight version is debugged and working as expected before formally starting the M6-PhD project, and I will then start a separate thread just to focus on the collaboration project for the M6-PhD since more than likely it will be a regulator/battery pack combo to replace the MB-20 factory pack - more on this later.

Will


----------



## wquiles (Sep 17, 2008)

Alan B said:


> The calibration needs to be done once after assembly. Three things affect it - the two resistors in the voltage divider, and the CPU's internal voltage reference. The largest variation is the CPU's reference, so even buying precision resistors does not solve the large part of the problem.
> 
> After the initial calibration it should not require adjustment unless the chip is changed.
> 
> ...



Thanks Alan - makes sense


----------



## Alan B (Sep 17, 2008)

wquiles said:


> I really like those names, but I don't want to restrict it to just the D/C Maglights.
> 
> I personally would still like to find a way to create a variation of this board/solution that would work to create the next M6R (maybe the M6-PhD would be a good starting name for this subproject) - there are lots of folks (myself included) that were let down by Andrew and his regulated solution, and it would be great if we can find a solution to all of those folks here in the forums who want to have a regulated, softstart incandescent solution for the mighty M6
> 
> ...


 
I'm not familiar with the space available in the M6, so you have the lead there. Sounds like a tight packaging project. Sounds like a good sub-project! I like the idea of a battery/regulator combo, though would you use the stock switch? That would somewhat limit the user interface options, but there are still some possibilities there.

Tail wags the Dog

How about a regulator in a tailcap? Quick exchange, easy to get out to program, could have some user interface mounted there. Level knob, pushbutton, toggle switch, etc. Interesting ideas. The front switch would still work. Only problem is getting that + battery wire back to the tailcap. :mecry:Could be part of the battery pack, though. So a tailcap/battery combo might be good.

Level Memory

I played around with some "Level Memory" code this morning. Doesn't look too hard to fit into my existing code as a compile time option. Did not test it, though. Code is easier when you don't test it. Reality creates certain problems during that pesky test phase...

-- Alan


----------



## wquiles (Sep 17, 2008)

Alan B said:


> I'm not familiar with the space available in the M6, so you have the lead there. Sounds like a tight packaging project. Sounds like a good sub-project! I like the idea of a battery/regulator combo, though would you use the stock switch? That would somewhat limit the user interface options, but there are still some possibilities there.
> 
> Tail wags the Dog
> 
> ...



Alan,

Excellent questions/suggestions - these exact questions/issues/options are why I want to keep the M6-PhD in a separate thread - far too complicated/distracting since the M6 (like you said) brings a different paradigm into the equation (for ex., there is no front switch in the M6, the M6 is designed to work with both the high current MN21 and the lower-current MN20 - each one requiring a different RMS voltage, etc.). 

Forum member *js* already figured this out once using the Willie Hunt LVR, so "it is" possible, and "I know" there is a way to make the PhD work in this scenario, although it might need (besides packaging issues), slightly different firmware configuration, options, etc.. It will be for sure a great collaborative project once we get the Mag's version running smoothly 

My apologies if the M6-PhD seems to confuse/distract from the main PhD project that you started :sigh:

Will


----------



## Alan B (Sep 17, 2008)

wquiles said:


> Alan,
> 
> Excellent questions/suggestions - these exact questions/issues/options are why I want to keep the M6-PhD in a separate thread - far too complicated/distracting since the M6 (like you said) brings a different paradigm into the equation (for ex., there is no front switch in the M6, the M6 is designed to work with both the high current MN21 and the lower-current MN20 - each one requiring a different RMS voltage, etc.).
> 
> ...


 
A separate thread is fine, I don't think it distracts from this one either. It is all part of the same larger problem. 

This thread will hopefully get very busy with testing here in a few days. Your parts are due in, and my boards and an order of parts. I have had much quicker service from Digikey since I started using Priority Mail. Much faster than UPS Ground and much cheaper than Second Day UPS.

We can detect jumpers on the programming socket. I forget how many combinations there are, but it is several (see below), and this could be used to differentiate bulb params. We are already using two of the positions for the calibration pushbuttons, but there are others available. 

*Jumper Combinations Available*

Looks like there are seven jumper combinations possible. One of PB0 to VCC or PB1 to VCC and One of PB2 to PB0 or PB1. That's 4 possibilities of a single jumper, plus one of no jumper. Then there are the two jumper setups. Two more of those. So 7 altogether. This is just working with the standard ISP programming plug on the board and standard shorting jumpers (as used on disk drives, etc). So it would be pretty easy to have a few sets of parameters to pick from via jumpers.

-- Alan


----------



## wquiles (Sep 18, 2008)

Thanks Alan - I will definitely need your guidance/help/expertize to get the M6-PhD project going 

Back on the PhD project ... Good news, I got the Atmel "kit" tonight. I have not touch it yet - I had to first get a laptop ready for this (had Ubuntu on that laptop, but I am re-formatting for Win XP since the tools are Windows-based), so hopefully this weekend I will get the development system running for the first time 

Will


----------



## Alan B (Sep 18, 2008)

wquiles said:


> Thanks Alan - I will definitely need your guidance/help/expertize to get the M6-PhD project going
> 
> Back on the PhD project ... Good news, I got the Atmel "kit" tonight. I have not touch it yet - I had to first get a laptop ready for this (had Ubuntu on that laptop, but I am re-formatting for Win XP since the tools are Windows-based), so hopefully this weekend I will get the development system running for the first time
> 
> Will


 
OK, great. If you want to fire up the STK500 with a Tiny85 CPU (which did you get?), I can write up some instructions. It takes about three jumpers on the board plus the ISP cable. Then you can program the chip and test it against an LED. That's how I did the development.

If you don't have some of those one wire .025 post fitting female socket jumper wires they have them at www.Sparkfun.com for a much better deal than the ones I bought at Fry's. The two wire units that came with the STK500 can be used to start with.

-- Alan


----------



## wquiles (Sep 18, 2008)

Alan B said:


> OK, great. If you want to fire up the STK500 with a Tiny85 CPU (which did you get?), I can write up some instructions. It takes about three jumpers on the board plus the ISP cable. Then you can program the chip and test it against an LED. That's how I did the development.
> 
> If you don't have some of those one wire .025 post fitting female socket jumper wires they have them at www.Sparkfun.com for a much better deal than the ones I bought at Fry's. The two wire units that came with the STK500 can be used to start with.
> 
> -- Alan



My WinXP laptop is almost ready - yes, I would love for you to give me some detail instructions :twothumbs Lets start by using the two wire units that came with the STK500 

I ordered the ATTINY85-20PU-ND (8-pin DIP), but I placed a second order a couple of days ago for the "V" or low voltage version to test low voltage operation later.

Will


----------



## Alan B (Sep 18, 2008)

wquiles said:


> My WinXP laptop is almost ready - yes, I would love for you to give me some detail instructions :twothumbs Lets start by using the two wire units that came with the STK500
> 
> I ordered the ATTINY85-20PU-ND (8-pin DIP)...
> 
> Will


 
OK. Lets do this in a couple of installments.

*Testing HotWire Software on the STK500 AVR Development Board*

*Part I*

Download and install WinAVR and AVR Studio.

A 9 pin serial port is required to talk to the STK500. If one is not available a USB to Serial adapter works. This may require a driver. Install this if needed.

A 12V wall wart power supply is required for the STK500. Check the manual for specs. There is a diode bridge on the board so the polarity of the coaxial plug does not matter. 

With the laptop, serial cable, STK500 board and power supply connected run AVR Studio. Create a New GCC Project, give it a name and select a location. Under Project/Configuration Options you can set the CPU type to Tiny85.

Bring up the Tools/Program AVR/Connect to connect to the STK500. Select the STk500 and either Auto or the COM port the serial connected STK500 is using. Once connection is established a programming window will come up with several tabs. You can explore those and set the voltage on the STK500 board to 5.0V for the target. Some things won't work yet since the target chip is not installed.

Shut down the programming window, power off the STK500 board and install the Tiny85. Be sure to remove any other CPU from the target sockets on the STK500 - only one target CPU allowed at a time. You can refer to the STK500 documentation to see how this is done. Install the Tiny85 in the blue 8 pin target socket SCKT3400D1, and the 6 pin ISP cable is installed between the Blue ISP pins SPROG1 and the ISP6PIN pins. Watch the pin 1 stripe on the cable is on the 1/2 side of the pins on both plugs. A jumper is required between PORTB PB5 and PORTE RST. This should be enough to communicate to the Tiny85.

Two more jumpers are required for the flashlight software testing. Switches/SW0 to PORTB PB2, and LEDS/LED0 to PORTB/PB3. You can use the two wire jumpers and hang the second socket into space, just using one of the pins. Watch the wire color and use the same wire/socket at each end for the connected pin, of course.

It should be possible now to reestablish communications with the STK500 board after powering it up, and read the chip signature from the Tiny85.

More later...

-- Alan


----------



## wquiles (Sep 18, 2008)

Alan,

A couple of quick updates:
1) Finished the laptop with XP Pro (Pentium 4 1.4Ghz, 2Gig RAM, and has built-in serial and 2 USB ports - perfect for this project!)
2) Installed the AVR Studio 4 as it came with the DVD in the package/kit
3) Updated AVR Studio 4 to the latest on the Atmel Web (4.14 build 589)
4) Got the 12V PS wired up and got the default/"demo" button/LEDs to work as expected.

I will start this weekend on the steps you outlined above, but before I do, do I need to remove the uC that came in the kit, right? That is just for demo/getting started, right?

Will


----------



## Alan B (Sep 18, 2008)

wquiles said:


> Alan,
> 
> A couple of quick updates:
> 1) Finished the laptop with XP Pro (Pentium 4 1.4Ghz, 2Gig RAM, and has built-in serial and 2 USB ports - perfect for this project!)
> ...


 
Sounds like good progress. I should put out the next installment of instructions for the HotWired STK500.

The STK500 board should only have one target CPU plugged in at a time. The sockets are wired in parallel, so more than one CPU would cause I/O pin conflicts. I forgot to mention that earlier.

-- Alan


----------



## Alan B (Sep 19, 2008)

*Testing HotWire Software on the STK500 AVR Development Board

Part II*

In Part I the STK500 board was configured and communications with the development system were established. Next is to prepare software and download into the target CPU chip.

Open AVR Studio and select the test project you made earlier. It should have created an empty ".c" file, and this window should be open near the center of the Studio window. 

Open the Hotwire Regulator Test Software page:

http://akbeng.com/flash/hwreg/HotwireRegulatorTests.c

Copy/paste the contents of this page into your test ".c" file. It doesn't matter what this is named in your project, let's call it "test.c".

Compile the program by pushing Build/Rebuild All. (or F7)

Connect the STK500 serial port to the computer and power up the STK500 board.

In AVR Studio select Tools/Program AVR/Auto Connect. (or the AVR chip on the tool bar)

In the STK500 ISP window that comes up, select the Program Tab.

In the bottom window for the ELF file select the ELF file being produced by the compiler - the file to load. This is in a subdirectory of the directory the test.c file is in, this subdirectory is called 'default'. It will remember this selection in the future so it will be easy to reprogram the chip.

Click on the 'Program' button in the ELF box to load the program. It should program and verify the chip.

The test program is now running. 

What happens next depends on which program was selected in the file. There are several different programs there with various parameters that control how they behave.

The file that is on the web right now will start with the fixed PWM program that goes on click from off to low, and click-hold ramps toward high, and a short click goes back to low. Another short click at low goes off. The SW0 pushbutton on the STK500 board is the button to click, and the LED adjacent to it will operate as the flashlight lamp. 

Note that the LED lights on LOW and the FET goes on with a high signal, so the two are opposite. The program has two output statements, so the incorrect one needs to be commented out or the opposite result will occur.

This seems complicated to explain, but that is due to the graphical nature of it. It is a few clicks, and once set up many of them are remembered so it goes very quick. 

We will be able to simplify it for folks who just want to load new software into their flashlight, in most cases. Later 

-- Alan


----------



## Alan B (Sep 19, 2008)

AVR Dragon Board

Incidentally, the Dragon debug board is sensitive to being touched while powered up, and it can blow the power inverter on the board. It would be good to make an enclosure to protect it. Debugging with the Dragon board can be quite useful, but it takes some time to set it up and learn how to use it. Proceed with caution, and remove the 'reset' jumper on the STK500 when talking to the Dragon. There are a few other tricks, look for them on the net. If you 'lose' the chip when trying it, it is probably in DebugWire mode, waiting for the Dragon to contact it in that mode. After connecting with it in DebugWire mode it can be set back to ISP mode for reloading firmware.

-- Alan


----------



## Alan B (Sep 19, 2008)

For the folks who are getting bored with all this software stuff:

[email protected] prototype PC Boards did arrive today. They look nice, but no time for building today. :mecry:

Also, a DigiKey order with a tube of Tiny25 CPUs arrived. Hope I find a good use for these chips :naughty:.

:shrug:

-- Alan


----------



## wquiles (Sep 20, 2008)

Alan B said:


> OK. Lets do this in a couple of installments.
> 
> *Testing HotWire Software on the STK500 AVR Development Board*
> 
> ...



Alan,

Making good progress tonight (although starting late since I was taking a side-detour as I was adding a tachometer to my lathe/Shumatech!).

I got everything here running as you indicated - read the chip signature properly 

I started doing the second step, but the AVR Studio complained about needing the "WinAVR" before doing the compilation. Was this something you had to do as well?

EDIT: I found it, installed it, and got everything working. I now have the test program working on the STK500 

I will continue playing with it and learning more about the code tomorrow Sat 

Will
(typing this from my Project Laptop!)


----------



## Alan B (Sep 20, 2008)

Will, Excellent Progress :thumbsup:

I have some progress of my own to report.

*[email protected]** Prototype PCB Testing Status*

 or no , that's the question 

Tonite I milled out a set of pc boards from the larger board that arrived yesterday. I installed the components, did some voltage tests, and installed the micro. Connected the programmer and programmed the chip.

The bulb flickered a bit until I changed the clock/8 fuse to off. The PWM was 244/8 = 30 hz so a bit too slow. This fuse can be set by the programmer, or it can be over-ridden by the software. Perhaps I should put this in the software, since the chips are sent with the fuse 'on'. This fuse makes the CPU run 8 times slower, and saves power. We save power by sleeping with clocks off and don't want to run that slow when regulating.

After a few different tests, results indicate the board seems to be working at this power level. I have a WA1185 connected to the regulator (driven by the FET), and the PWM is working. The ADC does not seem to be working, it was not tested completely before since there was no voltage on it. The voltage on the ADC pin is reasonable, but I don't seem to get useful numbers, or at least the program doesn't work when I use the data from the ADC. It works when the data is forced to a value which is what I was doing earlier. So there are a few minor things to work on.

But, overall, it is working at this power level. I'm running about 6.5 volts from the supply at the moment so the bulb doesn't get too bright and hot for software test purposes. It runs up to 2 Amps with the WA1185.

I have used both the USBtinyISP and the STK500 to program the board.

I will inspect the ADC code to see if there is something obvious, if not I will have to set up a way to see what the ADC is reading, maybe even the debugger:candle:. (It seems kind of like reading the instructions, or even asking for directions to use the debugger...)

-- Alan 

*More Progress*

Well, I found one problem last night. The low voltage battery protection feature was set higher than the test voltage I'm using, so it was shutting things down. It is coming on dimly now, there's still something wrong with the ADC readings.

-- Alan


----------



## Alan B (Sep 20, 2008)

*But does it Regulate?*

This morning I did a "light level regulation" test. With the regulator on at VLO, I varied the power supply voltage (simulating battery). I adjusted over the range from 6 to 17 volts. The good news is that the bulb doesn't blow up. It is partially regulating. Not quite perfectly, as it brightens up a bit at low and high voltage, so there is a point about 7 or 8 volts where it is a bit dimmer than 6 or 17 volts. So there is room for improvement in the regulation algorithm. :sigh:

-- Alan


----------



## wquiles (Sep 20, 2008)

Alan B said:


> *But does it Regulate?*
> 
> This morning I did a "light level regulation" test. With the regulator on at VLO, I varied the power supply voltage (simulating battery). I adjusted over the range from 6 to 17 volts. The good news is that the bulb doesn't blow up. It is partially regulating. Not quite perfectly, as it brightens up a bit at low and high voltage, so there is a point about 7 or 8 volts where it is a bit dimmer than 6 or 17 volts. So there is room for improvement in the regulation algorithm. :sigh:
> 
> -- Alan



This is still good process - nice going Alan :twothumbs

Do you have the high level flowchart of the project? Some high level view of what each part of the code is trying to accomplish?

Tonight I should have some time to "play" with the code/tools to get more familiar with them. Thanks again for your help to get me started - I hope to move from "slowing you down" to "contributing" shortly :thumbsup:

Will


----------



## Alan B (Sep 20, 2008)

wquiles said:


> This is still good process - nice going Alan :twothumbs
> 
> Do you have the high level flowchart of the project? Some high level view of what each part of the code is trying to accomplish?
> 
> ...


 
Hi, Will. No flowchart at this time. Lots of comments. 

I wonder if my power supply is causing some of the problem. This PWM load is probably pretty hard on the regulation, and so the waveform may be poor. I have not tried hooking up the scope, but I suspect that is part of the problem. I'm seeing the low voltage test code cut in, so the ADC is reading some low values. This could happen with a 'soft' real battery as well, so the code should deal with it. Hopefully without a lot of 'tuning'. 

I tried an AGM battery, and things seem to work fine, but that is a fixed voltage so I can't really see how well the regulation is working at all. Your high current supply may be a better testbed. I might try a large capacitor across my supply to stiffen it up. I have a couple of 1F 16V caps around here somewhere.

By the way, the voltage range I'm testing over is a bit unrealistic, so this is working better than it sounds. I'm putting 3V to the bulb and running from 6V to 17V. It is rather a severe case. At this level the bulb is pretty sensitive to voltage changes and not too bright so it is easy to work with.

-- Alan


----------



## JimmyM (Sep 20, 2008)

Alan B said:


> Hi, Will. No flowchart at this time. Lots of comments.
> 
> I wonder if my power supply is causing some of the problem. This PWM load is probably pretty hard on the regulation, and so the waveform may be poor. I have not tried hooking up the scope, but I suspect that is part of the problem. I'm seeing the low voltage test code cut in, so the ADC is reading some low values. This could happen with a 'soft' real battery as well, so the code should deal with it. Hopefully without a lot of 'tuning'.
> 
> ...


The caps will definitely help. I have a SMPS 50V/20A that doesn't like getting hit with a 10A load at 175 Hz. I use a 80V/75,000uF Cap. It helps a LOT.
Excellent progress guys. Sorry I haven't been much help lately. I might have time to print a couple of boards tomorrow though.


----------



## LuxLuthor (Sep 20, 2008)

Really great progress. I read this thread at least daily! Again, many thanks and waves of support. :twothumbs


----------



## Alan B (Sep 20, 2008)

JimmyM said:


> The caps will definitely help. I have a SMPS 50V/20A that doesn't like getting hit with a 10A load at 175 Hz. I use a 80V/75,000uF Cap. It helps a LOT.
> Excellent progress guys. Sorry I haven't been much help lately. I might have time to print a couple of boards tomorrow though.


 
That would be great, Jim.

It is probably a bit of overkill, but I hooked up a 1F capacitor across my power supply. After sitting for months it still had almost 9V on it. I last used it in June...

It helps. However the brightening trend at high voltage seems to still be there. The low end improved. I wonder what is causing it, but it may be a non issue anyway as it is pretty far away from the normal ratio. It might be the zener starting to conduct a little and making the ADC read low (not likely)... I may have to set up a test program that reads the ADC out to a serial stream so we can really see what it reads.

-- Alan


----------



## Alan B (Sep 20, 2008)

LuxLuthor said:


> Really great progress. I read this thread at least daily! Again, many thanks and waves of support. :twothumbs


 
Thanks for the drive-by encouragement!

Actually, I'm pretty happy thus far:

1) The three PC boards I designed seem to have no electrical errors. ([email protected] Regulator PCB, Control Switch PCB, and Programming/Calibration PCB. Mechanically they also look reasonable, but the real details there will not be verified until the metal support parts are fabricated.

2) The software is working, aside from the less than perfect regulation, and parts that are unfinished...

3) The FET is not heating up (at WA1185 power levels).

4) The new mechanical switch I chose has potential. More testing is required, and making some real metal parts.

-- Alan


----------



## wquiles (Sep 20, 2008)

JimmyM said:


> I have a SMPS 50V/20A that doesn't like getting hit with a 10A load at 175 Hz.



Real batteries have the same problem. I experienced this when testing with the MN20 and MN21 for the SureFire M6. Although the "resting" voltage of the OEM battery pack is 9 volts (3 cells, and two of these in parallel for extra current), when the MN21 bulb is connected, the actual voltage is like 6.7-6.8Volts - talk about voltage sag. With the MN20, the loaded voltage was in the 7.5-7.6Volts or so


----------



## Alan B (Sep 20, 2008)

wquiles said:


> Real batteries have the same problem. I experienced this when testing with the MN20 and MN21 for the SureFire M6. Although the "resting" voltage of the OEM battery pack is 9 volts (3 cells, and two of these in parallel for extra current), when the MN21 bulb is connected, the actual voltage is like 6.7-6.8Volts - talk about voltage sag. With the MN20, the loaded voltage was in the 7.6-7.6Volts or so


 
I'm sure the batteries sag under heavy load. They might not do quite what power supplies do, however, as the supply feedback loop will respond and increase output during the pulse. I am working on code that will compensate for the voltage waveform :devil:.

The super capacitors available today could be added to a flashlight to help this voltage sag out. It would make the PWM work better and help the batteries efficiency. These high current pulses are not good for the batteries, and drive up losses as well as trip protection circuits. It is possible to get a Farad or so in a fairly small space these days .

-- Alan


----------



## Alan B (Sep 21, 2008)

*New Calibration Method Implemented*

I put in a bit of code with conditional compilation that turns the bulb on when the supply voltage exceeds a settable fixed value (for example 8.0V). With this test code loaded, run the voltage up until the bulb just comes on. Record this DC value. Enter this DC value into the calibration formula in the program and recompile. Reload and retest, the bulb should come on right at 8.0V supply voltage now. Comment out the definition and recompile/reload, the test code is gone but the board is still calibrated. No RMS meter required. Just a DMM and a variable supply. Note that the voltage the bulb comes on with is not the same as the supply voltage, but VLO, which should be a safe value.

There will be other ways of calibrating the ADC, this is just a very simple and straightforward one to use now.

-- Alan


----------



## wquiles (Sep 21, 2008)

Alan B said:


> I connected the Hobbylab and Dragon to the STK500 and the whole thing plays. The timing is just over 4ms, right where expected.
> 
> The Dragon programs the STK500 mounted Tiny85 chip fine, and there are no ground loops.
> 
> ...



I also got my Dragon board - how do I connect it to the STK500/Tyny85 chip?

Will


----------



## wquiles (Sep 21, 2008)

Alan B said:


> The calibration needs to be done once after assembly. Three things affect it - the two resistors in the voltage divider, and the CPU's internal voltage reference. The largest variation is the CPU's reference, so even buying precision resistors does not solve the large part of the problem.
> 
> After the initial calibration it should not require adjustment unless the chip is changed.
> 
> ...



I am reading more and more, to get more familiarized with the Tiny85, and there seems to indeed be an internal 1.1V/2.56V reference voltage. If the ratio of the external resistors could be set to bring the RMS voltage under load to withing the 2.56V voltage, would there be any reason to need the external calibration stuff? 

Last night, while looking at the Willie Hunt Regulator LVR schematic, and based on my email exchange to him about changing operating voltage points, it "seems" to me that he might be either using the PIC's internal reference, or the precision 5V regulated output as the reference - it would be great if we can do something similar with the Tiny85 :naughty:


----------



## Alan B (Sep 21, 2008)

wquiles said:


> I also got my Dragon board - how do I connect it to the STK500/Tyny85 chip?
> 
> Will


 
To use the Dragon board, make sure that it is not touched while in operation. It is both static sensitive and capacitive/resistive sensitive while operating.

The six pin ISP cable on the STK500 can be used to connect the Dragon to the STK. Move the end near the STK500 board edge to the Dragon's ISP connector. 

-- Alan


----------



## Alan B (Sep 21, 2008)

*CPU Voltage Reference*

The ADC requires a voltage reference to make measurements. There are several possible with the Tiny85 et al. including the internal 1.1V, 2.56V, Vsupply or External Reference Input.

I use the internal 1.1V reference for the temperature measurement, and the internal 2.56 volt reference for Vbatt measurement. The external resistor divider brings the peak DC battery voltage to less than 2.56V.

They use the term precision referring to the stability of the reference, not the calibration accuracy.

The problem is - the reference is not initially accurate. Calibration is establishing the actual value of the reference and divider resistors.

For example, on my test board the cal factor is 8.0/7.42 which means that if I put in 7.42 volts it calculated 8.0 volts, so this factor is applied to coefficients to correct things. So mine was 8% off without calibration. That is according to my DVM which has its own accuracy rating, probably a few percent.

The spec sheet shows about 10% accuracy on the precision reference, and the resistors I used are 5%, so the total range is somewhat less than plus or minus 20%.

-- Alan


----------



## JimmyM (Sep 21, 2008)

wquiles said:


> Real batteries have the same problem. I experienced this when testing with the MN20 and MN21 for the SureFire M6. Although the "resting" voltage of the OEM battery pack is 9 volts (3 cells, and two of these in parallel for extra current), when the MN21 bulb is connected, the actual voltage is like 6.7-6.8Volts - talk about voltage sag. With the MN20, the loaded voltage was in the 7.5-7.6Volts or so


The issue was actually quite bad. Its transient response was quite bad. It was a hard switch to 10A then it would turn off. On the scope it looked like saw teeth spread way out.
With the cap, it just looked like a tiny dip in voltage under load, then back to normal. I use 12Ga superflex wires about 3 feet long. So the drop in voltage was probably just the drop in the wires. I don't have a kelvin sense lead.


----------



## Alan B (Sep 21, 2008)

JimmyM said:


> The issue was actually quite bad. Its transient response was quite bad. It was a hard switch to 10A then it would turn off. On the scope it looked like saw teeth spread way out.
> With the cap, it just looked like a tiny dip in voltage under load, then back to normal. I use 12Ga superflex wires about 3 feet long. So the drop in voltage was probably just the drop in the wires. I don't have a kelvin sense lead.


 
I can see that. My testing is very affected by the variations. A result won't make sense at all until factoring that in. Putting the capacitor in makes a complete change in some test results.

This must be accounted for in operating software as well. I have an idea how to do that, but the code doesn't seem to be solving the problem yet. I wonder how much inductance these filaments have. Would not expect that to be significant.

-- Alan


----------



## wquiles (Sep 21, 2008)

Alan,

I have been playing/studying the conditional control programs to get familiar with the instruction set and also the ideas being implemented. I am confused as to how the PWM duty cycle is being adjusted in relation to the battery voltage as it drains. In the original Hillie Hunt documentation, he states that if you read the output voltage at the bulb with a "normal" DMM (lets call this Vout) and then read the input voltage at the battery while the FET is ON (lets call this Vin), then:

Vrms (true voltage seen by the bulb) = sqrt (Vin * Vout)

However, in order to do this accurately, you need to measure two different voltages, one of them having to be measured only during the ON cycle of the FET. 

The other formula that Willie shared was based on the % duty cycle and the Vin:

PERC = percent of time the PWM is ON, as a fraction (1=ON all of the time)

Vrms (true voltage seen by the bulb) = sqrt (PERC * Vin^2)

Here in this formula "you" know what the PERC is, but again need to know the loaded Voltage at the battery during the FET=ON time.

When are you reading the voltage at the battery and exactly when are you measuring it? How are you testing/reading this value and what math are you following to verify (and use this as feeback into your logic) that the PWM/duty cycle has achieved the desired RMS voltage? 

My goal is to try to get us to what Willie implemented. Here you can see the actual soft start in operation, and then steady state PWM. In other experiments I did, as I lowered the battery voltage (power supply), you can see how the duty cycle is increased until it was at 100%:






Will


----------



## Alan B (Sep 21, 2008)

wquiles said:


> ...
> 
> The other formula that Willie shared was based on the % duty cycle and the Vin:
> 
> ...


 
Sounds like a good start, Will.

One thing to keep in mind is that there are a few different versions of the code that do different things in slightly different ways. I have one 'development' version that has a lot of extra stuff in it for testing, remnants of things and ideas for other things. Then I have the cleaned up published versions that are a lot easier to read and work with.

The regulation in the version of the code on the website, which is the basis for the versions I have played with thus far, uses:

Vbulb_desired = sqrt( Vbatt*Vbatt * duty_cycle )

Which is the same as the equation you mentioned and quoted above. Now we can make this easier by squaring both sides of the equation:

Vbulb_desired*Vbulb_desired = Vbatt*Vbatt * duty_cycle

The feedback in the regulation code merely balances this equation in real time:


```
if (Vbatt*Vbatt * duty_cycle < Vbulb_desired*Vbulb_desired)
    then increase duty_cycle
    else decrease duty_cycle
```
 
The timing of the ADC read in the code is one thing I have been playing with. The version I put on the web is not synchronized, so it should produce an "average" supply voltage. If the supply is stiff, this should work fine (large capacitor). If the supply is varying the RMSactual will be somewhat lower than desired.

One fly in the ointment is the above equations assume Vbatt is constant. If it changes during the pulse the result will not be RMS.

What was the actual performance of the earlier Hunt unit? Would it maintain constant RMS over a large range such as 6 to 17V? I'm not sure how much variation I'm getting since I have not measured it. I can see it in the bulb, but at these low voltages the bulb is quite sensitive to change and may be magnifying the result.

Are you just working with the STK500 board, or did you build a prototype with FET, ADC, etc?

At this point I have very nice ramping intensity control, and some degree of regulation. My goal at this point is to understand the regulation, or lack of it. 

I just set up the simple regulation code with 4.0V output and tested it visually. It seems to stay constant to somewhere about 11V. Then it brightens up. This is with a 1Farad capacitor, the supply is very stiff.

I hooked up the scope. Waveforms look excellent, with the 1F cap. No sign of any problems there.

-- Alan


----------



## Mr Happy (Sep 21, 2008)

Alan B said:


> The timing of the ADC read in the code is one thing I have been playing with. The version I put on the web is not synchronized, so it should produce an "average" supply voltage. If the supply is stiff, this should work fine (large capacitor). If the supply is varying the RMSactual will be somewhat lower than desired.
> 
> One fly in the ointment is the above equations assume Vbatt is constant. If it changes during the pulse the result will not be RMS.
> 
> What was the actual performance of the earlier Hunt unit? Would it maintain constant RMS over a large range such as 6 to 17V? I'm not sure how much variation I'm getting since I have not measured it. I can see it in the bulb, but at these low voltages the bulb is quite sensitive to change and may be magnifying the result.


I think the supply voltage will vary due to internal resistance of the cells and other in-circuit resistance. So when the FET is off, you will see the open circuit voltage of the supply, and when the FET is on you will see the lower, loaded voltage. However, batteries appear to have a significant time lag in their voltage response so when you turn the FET off it will take some time for the voltage to recover to the resting open circuit voltage (probably several PWM cycles, depending on the frequency).

In my estimation the best algorithm would be wait until the FET is turned on, then wait a certain time for the voltage to stabilize, and then sample that voltage. That would be a good estimate of the voltage that would appear at the bulb terminals if the FET was on permanently. This voltage then is the voltage that could be fed into the formula for the PWM duty cycle. Even better might be to filter that voltage a bit to smooth out any residual variations.


----------



## wquiles (Sep 21, 2008)

Alan B said:


> Sounds like a good start, Will.
> 
> One thing to keep in mind is that there are a few different versions of the code that do different things in slightly different ways. I have one 'development' version that has a lot of extra stuff in it for testing, remnants of things and ideas for other things. Then I have the cleaned up published versions that are a lot easier to read and work with.
> 
> ...



Alan,

Maybe I am looking at older code - I have not seen that math before. Is that on the ifdef FP5 that was incomplete?. I have been looking in here, and it only had a code piece from Sept 4th:
http://akbeng.com/flash/hwreg/

Is there a newer version of the code that has the regulation/math/etc.?




Alan B said:


> The timing of the ADC read in the code is one thing I have been playing with. The version I put on the web is not synchronized, so it should produce an "average" supply voltage. If the supply is stiff, this should work fine (large capacitor). If the supply is varying the RMSactual will be somewhat lower than desired.


When I tested the LVR from Willie Hunt with real battery packs, which of course had voltage sag during the ON cycles, the Vrms stayed constant, so I can only conclude empirically that Willie was reading the Vbat only during the ON cycles. We should try to do the same if we can - unless there was something in the PIC processor he used that is not available to us with the Tiny85?





Alan B said:


> One fly in the ointment is the above equations assume Vbatt is constant. If it changes during the pulse the result will not be RMS.


Well, once the battery "settles" from the current drain, during the rest of the ON pulse, the battery voltage is rather constant - at least enough for the ADC to take an accurate measurement. Basically, allow a little time for the supply to settle from the high current draw, and take the ADC measurement.





Alan B said:


> What was the actual performance of the earlier Hunt unit? Would it maintain constant RMS over a large range such as 6 to 17V? I'm not sure how much variation I'm getting since I have not measured it. I can see it in the bulb, but at these low voltages the bulb is quite sensitive to change and may be magnifying the result.


The performance of the LVR was freaking awesome - much better than I anticipated when I first got it. I varied the Vbat quite a bit, and the LVR maintained a constant RMS over a large range - you could not see "any" change in the output of the bulb during all of these variations. Back then I still did not have the Fluke 189, so to measure Vrms I used the storage scope (to measure the loaded battery voltage during the ON cycle), and then taking the average DC with a standard Voltmeter.





Alan B said:


> Are you just working with the STK500 board, or did you build a prototype with FET, ADC, etc?


I have all of the parts to build a running prototype outside the STK500, but I don't want to until I understand what is it that I am trying to verify/debug/test - this is also why I asked earlier about the flowchart. Without a flowchart I have been trying to look and learn from what is in the code. 

At this point I am using just the STK500 board, along with the Tek3034 Storage Scope to capture/analyze the output waveforms (seeing your varying duty cycle in my storage scope is awesome!). 





Alan B said:


> At this point I have very nice ramping intensity control, and some degree of regulation. My goal at this point is to understand the regulation, or lack of it.
> 
> I just set up the simple regulation code with 4.0V output and tested it visually. It seems to stay constant to somewhere about 11V. Then it brightens up. This is with a 1Farad capacitor, the supply is very stiff.
> 
> I hooked up the scope. Waveforms look excellent, with the 1F cap. No sign of any problems there.


At the higher voltage range the duty cycle has to become lower, so maybe here the average battery ADC voltage vs. the actual loaded battery ADC voltage measurement has a larger error? 

Once you feel comfortable, to verify that regulation is working as you expect, you could use a real battery pack and take measurements every 10-15 minutes to let the battery drain. Record the Vbat_under_load (using your USB scope), and the average V at the bulb with your voltmeter - as the battery drains, and until the duty cycle becomes 100%, the Vrms should change "very" little or hardly at all.


I have two other questions to help me understand how this is working: What is the base frequency of the PWM cycle, about 250Hz or so? How are you controlling this frequency, based on a timer, interrup, or something else?

Will


----------



## Alan B (Sep 21, 2008)

wquiles said:


> Alan,
> 
> Maybe I am looking at older code - I have not seen that math before. Is that on the ifdef FP5 that was incomplete?. I have been looking in here, and it only had a code piece from Sept 4th:
> http://akbeng.com/flash/hwreg/
> ...


 
OK. I see that the version of the code on the web doesn't have the regulated version, so I will have to update that. Probably not tonite, though.

I'm beginning to wonder if I have a math problem - things work very smoothly until a point, after that the PWM pretty much stops reducing in pulsewidth. So it is either the calculations, the ADC or the PWM not doing what was expected. It goes down to about 400 uS or so and then stops reducing. 

The PWM rate is determined by hardware, it is hardware generated by a PWM register in the CPU. The rates are selected when setting up the clock dividers. It is 244 hz as I recall. Note that if the divide by 8 clock fuse is left at factory default this drops to 30 hz and that did flicker noticeably. However the newer code has the default overridden, so the fuse doesn't matter. It sets to 8 mhz clock with divisor of 1 during initialization now.

On the regulation, I think we're already there for real systems. We would not recommend this wide a range of battery to target bulb voltage anyway. I would still like to fix it to have a really regulated low.

I have tried code that takes measurements at various places during the "on" cycle. It doesn't seem to matter a great deal, the only thing I noticed is that taking the reading randomly on my power supply with no capacitor produced a little flicker. Looking at the power supply waveform with the scope, I see why. It looks worse than a battery without the cap. So some voltage readings are weird and cause a minor pulsing in the output as the main loop delay works across the PWM waveform and slides the sampling along.

With the capacitor it should not matter when the voltage is sampled. There is no significant drop when the FET turns on, at least with this bulb. 1.0 Farad can run the lamp for a long time without the power supply, actually. It makes it strange to turn the voltage down since it doesn't go down until the lamp draws it down. The supply knob works well up, but not so well in the down direction. I should probably use a smaller cap.

In terms of what can be done, if I remember correctly, this CPU can execute 80 instructions during one 'bit' of the PWM. Each PWM cycle is 256 of those 'bits'. So we can reliably detect even the narrowest PWM with a software loop, and of course we have interrupts on pin changes as well. 

In terms of the flowchart, there isn't much to chart. There is the initialization, then the loop that never exits. The first part of the loop deals with user input - the one button. The rest of the loop deals with reading the ADC and computing the PWM and outputting it. 

-- Alan


----------



## wquiles (Sep 22, 2008)

Thanks Alan - things are starting to make more sense to me now. Let me know as soon as you can upload (or email me) the latest code so that I can also look at it and try help out from my side.

I will try tonight to start building the external circuit - once I get your code and I can program it on my Tyni85, we can start debugging with the real circuit and real batteries. I really want to see how it behaves with real battery sag and how well it regulates. 

I just check and I do have two 1185 bulbs, so we could test the same code you have been testing since I would be using the same bulb you are using. Question - what value resistors are you using or the 1185 bulb?

Will


----------



## Alan B (Sep 22, 2008)

*Problem Solved*

I don't know how many times I thought about doing this, but I didn't want to clip wires until I was sure. But I just did a test and now I am certain. With the fix installed, from 6V to 14V I could not see a change in the bulb intensity.

I had a couple of good clues what the problem was, but until I came up with and did a test this evening I was not sure. I hooked up the scope and set up a special version of the code that merely output the ADC reading as the PWM setting. Then I measured the voltage input versus on-time of the PWM and plotted it. At about 9 volts it starts to diverge from a straight line, falling gradually below the line's trajectory. YES. We know what could do that. 

So I cut one lead and remeasured. Nice straight line. Then I reloaded the regulation program. Works fine from 6V to 14V. At 14V it turns off because the ADC is running out of range (with my resistor setup, 47K/10K). 

So what was it? The zener (D2), of course. These devices leak considerably before they conduct. This divider is too high an impedance for this leakage to be ignored. 

:twothumbs

Now back to your regularly scheduled program...

-- Alan


----------



## Alan B (Sep 22, 2008)

wquiles said:


> Thanks Alan - things are starting to make more sense to me now. Let me know as soon as you can upload (or email me) the latest code so that I can also look at it and try help out from my side.
> 
> I will try tonight to start building the external circuit - once I get your code and I can program it on my Tyni85, we can start debugging with the real circuit and real batteries. I really want to see how it behaves with real battery sag and how well it regulates.
> 
> ...


 
Great! Code is on the website. 

*Software Update*

http://akbeng.com/flash/hwreg/software/HotwireRegulator.c

-- Alan

I'm using the WA1185 bulb only. To protect it, I just stay below 9.6V until I have some confidence that the software is working. Then I venture higher. No blown bulbs so far.

If you want a greater input voltage range use a higher value for R1. I used 47K, you can use up to 100K. R2 is 10K and I left the pot out. 47K is right for 3x4.2V Li-ions, or 9x1.2V NiMH which is what I have, but you can go higher if you like.

-- Alan


----------



## wquiles (Sep 22, 2008)

A couple of photos of my setup.

My multiple-projects-at-the-same-time electronics bench (Storage Scope not shown):






Bottom one is the big and heavy 60V-10Amp power supply:






Here is the smaller power supply:






Here is an old, and "very" nice bench meter, with both 2-wire and 40wire resistance measurement capability:






Here is the Fluke 189 that can measure Vrms directly:






Here is the 100 watt, 0-100 Ohm power resistor, next to a 5W 0.1 Ohm resistor, next to a standard 1/4 watt resistor:











Here is my Dell Laptop (running AVR studio), and my STK500 running your older program:











Here is tonight, building the circuit using your older schematic as a reference with the parts from Digikey and my own "stash":






First tested the regulator section. Set PS for 8.00V:











Then assembling the actual circuit:











and the final circuit (the two wires sticking out go to the actual bulb):






As soon as I get the final changes from you I will try it out. I am going to bed now 

Will


----------



## Alan B (Sep 23, 2008)

Will:

Great Progress, and a very nice test bench. :twothumbs

*Changes (1 only):*

1) Omit D2 (the zener diode across the ADC input of the CPU), or use a signal diode such as 1N4148. This is not needed for normal operation, and the zener used caused problems. It was intended for overvoltage and reverse polarity protection for the ADC. Using the signal diode will provide reverse polarity protection. Overvoltage protection is only required above input voltages of double the normal range, so it is not too critical.

*Not a Change, but a Choice:*

2) If you want higher voltage input range use R1 = 100K for 25V max, else use R1 = 47K for about 14V max or something in between if you like. This determines the range of voltages the ADC can measure. Making it larger gives larger range, but lowers the precision of the measurement. Put the values you use into the program configuration and it will adjust for your values, providing coarse calibration.

-- Alan


----------



## Alan B (Sep 23, 2008)

Alan B said:


> *Problem Solved*
> 
> I don't know how many times I thought about doing this, but I didn't want to clip wires until I was sure. But I just did a test and now I am certain. With the fix installed, from 6V to 14V I could not see a change in the bulb intensity.
> 
> ...


 
OK, here's the data:






This is Voltage input versus PWM uSeconds ON. The total PWM period is a bit over 4000 uS. The ADC value is being loaded directly to the PWM. 255 corresponds to DC, 254 corresponds to 254/255 of the total period. The gap is due to the endpoint of one series not having a data value for the other series. During these measurements the bulb was removed and the only load on the FET was a 10K resistor. 

-- Alan


----------



## wquiles (Sep 23, 2008)

Alan,

When I posted my long post with photos and went to sleep I did not realized you posted right before with your update and fixes - congratulations !!! 

I just took a look at the new code. I will try tomorrow (have already plans for tonight!) to run it on my STK500, to program the Tiny85, and then just move the Tiny85 to the breadboard for testing (I will eventually add the header so that I can re-program in place, but I do want to get started!).

Question: To program in place on the breadboard, using the header: Do I just run the 6-pin header on the STK500 (ISP10PIN) to the breadboards" 6-pin header? What do I have to change (if any) on the AVR studio? 

I will remove D2 and change the resistor before I start, but I have a question. Question: Do I have to do "anything" to the code in the web for it to run "as is" on the actual breadboard?

Will


----------



## Alan B (Sep 23, 2008)

wquiles said:


> A couple of photos of my setup.
> 
> ...
> 
> ...


 
Will, I may be confused but the FET doesn't look right to me. Drain and Source appear to be swapped, unless your FET is not GDS. Also the white wire from the drain appears to be going to the wrong end of D2. The ISP is not hooked up, so you probably have not double checked the wiring yet, and you were working late. It is early here now as I type on the laptop in bed.. :twothumbs

-- Alan


----------



## Alan B (Sep 23, 2008)

wquiles said:


> Alan,
> 
> When I posted my long post with photos and went to sleep I did not realized you posted right before with your update and fixes - congratulations !!!
> 
> ...


 
Our posts are overlapping this morning, also.

To program on your breadboard you move the target end of the cable from the STK500 to the breadboard. The cable socket near the edge of the board is the programmer output, the one nearer the center is the target end.

One thing to watch out for is Vcc. The ISP cable can supply it or use it. The Vcc jumper on the STK500 should be removed if the target has Vcc, or installed if the STK is supplying Vcc to the target. No changes to AVR Studio.

I used the code as uploaded on my test board. If you use 47K it should work straight off. If you use 100K the voltage cal will be low but it should still work.

My schedule is getting busy as I have a trip thursday-sunday. I will be away from email during this trip. On wednesday I will be loading the RV and getting ready for early thursday departure. So I may not be as responsive.

-- Alan


----------



## wquiles (Sep 23, 2008)

Alan B said:


> Will, I may be confused but the FET doesn't look right to me. Drain and Source appear to be swapped, unless your FET is not GDS. Also the white wire from the drain appears to be going to the wrong end of D2. The ISP is not hooked up, so you probably have not double checked the wiring yet, and you were working late. It is early here now as I type on the laptop in bed.. :twothumbs
> 
> -- Alan



Alan,

Thanks - I definitely have pins 2/3 (Drain/Source) backwards, and the white wire should to to ground (to connect the Source to GND as in the schematic) - I am glad I opted to go to sleep instead of "trying it out" last night !!!

I am happy at least one of us is awake  

Will


----------



## wquiles (Sep 23, 2008)

Alan B said:


> Our posts are overlapping this morning, also.
> 
> To program on your breadboard you move the target end of the cable from the STK500 to the breadboard. The cable socket near the edge of the board is the programmer output, the one nearer the center is the target end.
> 
> ...



Gotcha - thanks much. I am now ready to get everything running :twothumbs

I will keep you posted 

Will


----------



## Alan B (Sep 23, 2008)

wquiles said:


> Alan,
> 
> Thanks - I definitely have pins 2/3 (Drain/Source) backwards, and the white wire should to to ground (to connect the Source to GND as in the schematic) - I am glad I opted to go to sleep instead of "trying it out" last night !!!
> 
> ...


 
I think the middle pin is Drain, the Source is on the left in the photo.

Check everything three times. It is extremely difficult to put the smoke back in those parts.

Good luck!

Today I tried floating point in the Tiny25 for the control loop. It did fit. I'm not sure how slow it is, my plan is to use it for some tests only, not for final builds. It is pretty amazing to take floating point square roots in an 8 pin chip 

-- Alan


----------



## wquiles (Sep 23, 2008)

Alan,

You have to show me/teach me the floating point code - that sounds cool!. When I did floating point, it was like 15 years ago, in a fixed point, 16-bit DSP, and it was only done in assembly - no C code, but since the DSP is purposed built for math, it was fast, fast, fast!!!

OK, a little more progress tonight. I fixed the two bugs that you pointed earlier, and I "created" a 6-pin header for my breadboard (I am going to use the VCC of the STK500):











With any luck (after I double check things again), I should be able to power a real bulb in the next day or so at the latest 


Will


----------



## Alan B (Sep 24, 2008)

wquiles said:


> Alan,
> 
> You have to show me/teach me the floating point code - that sounds cool!. When I did floating point, it was like 15 years ago, in a fixed point, 16-bit DSP, and it was only done in assembly - no C code, but since the DSP is purposed built for math, it was fast, fast, fast!!!
> 
> ...


 
Looking good, Will. I'm not checking all the wiring, but those photos are good enough to do that. What do you take them with?

The floating point on GCC-AVR is easy compared to what you had to do on the DSP. You add the AVR math library to your link list, declare some floating variables and write the equations.

I go back and forth on which end supplies VCC, sometimes using the programmer and sometimes using the target VCC. Just try to not do both at the same time. I have done so, and no smoke escaped, but if the voltages were different it would probably be bad.

I wrote a little piece of code in Python to read the scope capture text file and compute RMS. I don't have time to do much with it yet, and I did notice that the calibration is a bit different on each of my measurement devices, so that will have to be accounted for, but I can get a true RMS value from the scope capture this way that should be pretty accurate. So I can put some numbers on regulation accuracy. You may be able to do that a lot easier with your high quality meters. It will be interesting to see how it comes out.

I had a bit of a scare today when I went to demo my test board with a 10 C NiMH pack I have, and it did not work. I wondered if I had popped something. Upon digging a bit deeper I found that the fully charged voltage was high enough that the ADC was close to or just over full counts. I have some protection code in my test program that shuts the PWM off if the ADC gets near full scale, since the actual voltage is unknown. So I changed the philosophy slightly - if the ADC is over-ranged just don't go to full output. Unless the voltage is really high, the low setting is quite safe for the filament. In this case putting the load of the low filament brings the Vbatt down into the ADC range and things work great - it doesn't limit to the low filament value that I could tell. It turns on at low, then clicking to high works since the loaded Vbatt is in range.

Using a 47K/10K divider is okay for 9 NiMH cells, or 3 Li-Ion cells, but for any more the 47K should be larger. I'm going to leave it for now in my board since it is targeted for 9xNiMH, and the algorithm now handles even 10 just fine. Lots of little details to learn and account for in the code.

Good luck on your progress. I will check the board a few times tomorrow, but thursday-sunday will be out of net range. By the way, you might want to pluck that zener out of your test board (unless you changed it to a signal diode already). Leaving it in will not prevent it from working, but the regulation will suffer a bit.

-- Alan


----------



## wquiles (Sep 24, 2008)

Alan B said:


> Looking good, Will. I'm not checking all the wiring, but those photos are good enough to do that. What do you take them with?


Older photos in the older links, with a Canon Rebel XT and "L 24-105mm F/4 lens. All of the new photos in this thread are with my replacement camera (sold the Canon), a Fuji FinePix S100fs:
http://www.dpreview.com/reviews/specs/Fujifilm/fujifilm_S100FS.asp






Alan B said:


> The floating point on GCC-AVR is easy compared to what you had to do on the DSP. You add the AVR math library to your link list, declare some floating variables and write the equations.


I would be very grateful if you can send me the "lines" of code - I would love to try it out as well. Lots for me to learn ...





Alan B said:


> I go back and forth on which end supplies VCC, sometimes using the programmer and sometimes using the target VCC. Just try to not do both at the same time. I have done so, and no smoke escaped, but if the voltages were different it would probably be bad.


Here both are 5V, but point taken. Better be extra careful 
Edit: I also removed the diode this morning.




Alan B said:


> I wrote a little piece of code in Python to read the scope capture text file and compute RMS. I don't have time to do much with it yet, and I did notice that the calibration is a bit different on each of my measurement devices, so that will have to be accounted for, but I can get a true RMS value from the scope capture this way that should be pretty accurate. So I can put some numbers on regulation accuracy. You may be able to do that a lot easier with your high quality meters. It will be interesting to see how it comes out.
> 
> I had a bit of a scare today when I went to demo my test board with a 10 C NiMH pack I have, and it did not work. I wondered if I had popped something. Upon digging a bit deeper I found that the fully charged voltage was high enough that the ADC was close to or just over full counts. I have some protection code in my test program that shuts the PWM off if the ADC gets near full scale, since the actual voltage is unknown. So I changed the philosophy slightly - if the ADC is over-ranged just don't go to full output. Unless the voltage is really high, the low setting is quite safe for the filament. In this case putting the load of the low filament brings the Vbatt down into the ADC range and things work great - it doesn't limit to the low filament value that I could tell. It turns on at low, then clicking to high works since the loaded Vbatt is in range.
> 
> Using a 47K/10K divider is okay for 9 NiMH cells, or 3 Li-Ion cells, but for any more the 47K should be larger. I'm going to leave it for now in my board since it is targeted for 9xNiMH, and the algorithm now handles even 10 just fine. Lots of little details to learn and account for in the code.


Alan,

After reading the whole complete thread, I have a much better appreciation of this multi-month, multi-person effort, but I am still troubled by what we are expecting the recipients of this work to do, in order to get this to run, as it seems that we are trying to design ONE PhD regulator that will have to be modded/adjusted by the end user in order to work in multiple applications - I personally feel this is not a good path to follow.

You, Jimmy, "many" here in forums, and myself are engineers. For this project, you, Jimmy, and I have lots of expensive equipment to design, analize, tweak, etc. these circuits. I am sure that there are many other members that also have this capability and knowledge, and yet many that would put all to shame, but I also have to believe that we need to carter to the majority of the forum - the many, many folks who like to tinker, and have basic soldering equipment and a simple DMM (the typical 80% / 20% rule). That majority of the forum should be the real target of this effort as they are the life and blood of this great forum. If we make this PhD a solution that requires too much from the end user, we are not going to have as many folks take advantage of the great work being done here in this PhD project - many will "fear" it, many will shy from it, many will say "this is just to complicated to use ..."

Most here in the forums are used to very "simple" interfaces and very simple configuration/settings. The best regulators and the most common interface for regulators sold for flashlights here in the forums (true, only for LED drivers, but that it is still what folks are used to) have a simple ONE button interface. I honestly feel, that once we get the PhD working, we should concentrate in creating a really simple configuration interface.

I am not trying to start a diversion/division, and my opinion in no way will affect this collaboration, but I don't personally feel is is reasonable for any end user/modder to have to buy or use an USB programmer, nor have to do anything to calibrate the PhD regulator. Our goal, besides developing this kick-*** PhD project, should also be to try to minimize user intervention/calibration/pots/modding/adjustments/etc..

The interface should be simple - very simple. Even if this means that there will be products based on the PhD work that will be sold in several versions in order to "attack" the various applications (for example, a regulator that would handle voltage range A and a second regulator that would handle voltage range B, etc., maybe with their corresponding max current/ampere, etc - again, these are just examples). 

I just wanted to share my opinion. I honestly feel this PhD project will be awesome, and I just want more and more folks to be able to leverage this great effort/collaboration. I am hopeful this is not making anyone angry as that was not my intention.

OK - I am now taking my philosophy hat off, and putting my engineer hat on again 

Will


----------



## Alan B (Sep 24, 2008)

wquiles said:


> ...
> 
> I would be very grateful if you can send me the "lines" of code - I would love to try it out as well. Lots for me to learn ...
> 
> ...


 
I will include the floating point example in a future release after I have done more testing with it. I threw it together yesterday and it didn't seem to work quite right. The code jumped to 1440 bytes, so I'm sure it was in there, and it sort of worked, but the lamp intensity was off.

Thanks for sharing your thoughts on this, Will.

This project thread has lots of words in it, and it makes things look more complicated than they really are. 

I would like to see this available in several forms, from kit to drop-in, but that will depend on the folks who choose to build and sell hardware. It was not my intent to do so, though I might do something I don't plan or expect to be the only one.

In terms of interfaces, I have a high end one button interface in a top of the line custom flashlight. In my opinion the one button interface is too complicated for this use, especially in a hotwire that can blow bulbs and possibly FETs. There are many parameters and modes and the chance of successfully setting everything is low, and the time consumed to do so is high, and it is difficult to know when it is right.

This project does not preclude a one button complicated interface at all.

If I look at the parameters that need setting - bulb voltages, Li-Ion or NiMH battery protection voltage - plus options like 'double click to high blast', 'single level vs varilevel', etc., these are more easily manipulated with a better user interface and loaded into the chip, and not accidentally changeable in the field by a few random button pushes.  

I envision builders - would pre-program and pre-calibrate a module so the end user would not have to, but those end users that want to have the option of buying a $20 interface and getting access to all the parameters would have it. Not all users would do so, of course. 

Another option, if the chips are socketed, is to sell pre-programmed chips. The user would specify the values they want, and someone would send them a chip for a few $. Only fine calibration would have to be done by the end user and that can be done with a regular DMM.

There are a number of possible jumpers on the programming plug, so several sets of parameters can be preloaded and selected by jumpering. So a few battery/bulb combinations could be preprogrammed and the user select between them.

There are two types of calibration here - coarse and fine. The coarse calibration is the voltage divider network, and that is selected and compiled into the software. It doesn't need to be fiddled much, though it may make sense to have a 'low' range and a 'high' range. If you always use the high range most flashlights will never use the top half of the ADC and they will lose one bit of precision in their Vbatt measurement. Since the internal calculations are scaled to the ADC value, the whole calculation is less precise. It probably doesn't matter very much, but this is up to the board builder.

Fine Calibration can be handled a couple of different ways. Jim likes the pot approach, and this has been included in the baseline design. I prefer something in software and have designed a pushbutton interface with an up and a down button that adjusts the calibration. There is also a tuning coefficient in the software now, but this is more of an interim solution until the other solutions are implemented.

If someone wants to develop a one-button interface software for the standard hardware platform, they are welcome to do so! I myself would prefer to put all the parameters into the chip ahead of time and just select between them with a jumper, but there can be many different software packages that run on this platform. Different implementors can make their own "value added" to the basic package.

-- Alan


----------



## wquiles (Sep 24, 2008)

Alan B said:


> I will include the floating point example in a future release after I have done more testing with it. I threw it together yesterday and it didn't seem to work quite right. The code jumped to 1440 bytes, so I'm sure it was in there, and it sort of worked, but the lamp intensity was off.
> 
> Thanks for sharing your thoughts on this, Will.
> 
> ...



Alan,

Cool - looks like we are very aligned on the overall goals. We can keep working on getting the fundamentals nailed down - the actual "productization" of the PhD project will impart its own requirements based on complexity, price, time, flexiblity, etc. => maybe I am just worrying too much about it 

I bought some 12.8V/250mA and 13.8V/1.04A cheap incandescent bulbs ($0.53/ea) today at lunch so that I can "play" tonight/tomorrow. I will start with the 100watt high power resistor first (set it up for like a 1 or 2 Amp draw to start with), and I will use another 13.8V/10A regulated PS that I have - I will let you know how things go. If things work as I expect, then I will move to the "cheap" bulbs, and then I will work with the actual 1185 bulbs (I only have two of them!).

Will


----------



## LuxLuthor (Sep 24, 2008)

Alan/Will, your foresight on practical user interface is noted and appreciated. On the other hand, so this doesn't become an obstacle, I think there would be enough willing to do the USB programming for others, assuming there can be a straightforward template of steps to follow. 

Having used a number of AWR's Hotdriver with POT adjustment for Vbulb while measuring with DMM, it is great to have that flexibility. The only other alternative proposed almost a year ago by AW was for customer to tell him in advance what Vbulb they wanted, and it would be locked into that one choice.

Bottom line: having some user options under any kind of control makes this a truly great project. Most of the lines in your last link make sense to me, with only a noob level of experience with compiler coding, but likely people would only be needing to change a few items, compile and upload to chip.

I have a bit of a concern with people fiddling with a pushbutton interface, and inadvertently screwing up a setting, so the dipstick option is probably going to work out better for the "make it real simple" users.


----------



## wquiles (Sep 24, 2008)

LuxLuthor said:


> Alan/Will, your foresight on practical user interface is noted and appreciated. On the other hand, so this doesn't become an obstacle, I think there would be enough willing to do the USB programming for others, assuming there can be a straightforward template of steps to follow.
> 
> Having used a number of AWR's Hotdriver with POT adjustment for Vbulb while measuring with DMM, it is great to have that flexibility. The only other alternative proposed almost a year ago by AW was for customer to tell him in advance what Vbulb they wanted, and it would be locked into that one choice.
> 
> Bottom line: having some user options under any kind of control makes this a truly great project. Most of the lines in your last link make sense to me, with only a noob level of experience with compiler coding, but likely people would only be needing to change a few items, compile and upload to chip.


Absolutely. Well said. There is no doubt in my mind that several folks will go ahead and get the tools/software/programmer and do their own tweaks, changes/etc., but I still expect this to be a minority here in the forums. I just want to make it easier for the more "typical" CPF'er to use the PhD in his/her own projects 





LuxLuthor said:


> I have a bit of a concern with people fiddling with a pushbutton interface, and inadvertently screwing up a setting, so the dipstick option is probably going to work out better for the "make it real simple" users.



"The" benchmark or watermark for an outstanding, used-by-hundreds-here-in-the-forum, simple to use, but yet fully configurable interface, is the ONE button interface from TaskLed on his LED drivers.

His interface is tried and true, and with no chance to inadvertently change settings - just a simple, beautiful, ONE button interface. This TaskLed interface allows for multiple levels, low bat warnings, multiple tables, different warning lights/signals, etc.. When I wrote my note 2 posts ago, it was this exact interface what I had in mind.

My proposal would be to develop an interface that would do something similar, but specifically for the PhD driver: in other words, to deal just with the settings/values needed for an incandescent/hotwire project. I have used the TasLED drivers a "lot" and have sold many custom lights with several versions, so I will go ahead and "lead" the development for the ONE button interface for the PhD project - after all I am the one "convinced" that this is worthwhile doing. I guess it is my own fault - I am the one fixated on this, right? 

Some folks will use this one button interface, some will not. I am sure some will "productize" the PhD in various ways - that is the beauty of this open source project - you can use whatever you want.

Although I will develop this code for the one button interface, I want to put that aside in the short term as it is more of a "nice to have" - right now I need to help Alan and keep working/testing the PhD before we have to worry about the UI 

Will


----------



## Alan B (Sep 24, 2008)

wquiles said:


> Alan,
> 
> Cool - looks like we are very aligned on the overall goals. We can keep working on getting the fundamentals nailed down - the actual "productization" of the PhD project will impart its own requirements based on complexity, price, time, flexiblity, etc. => maybe I am just worrying too much about it
> 
> ...


 
Sounds like a plan. If you keep the power supply below 9.6V or 3A you cannot hurt the 1185's either, so it is safe. Since this program uses the PWM register it cannot leave the switch 'stuck on'. However it can program the PWM for a value that is too high (including full on at 255/255). 

The other day when I didn't have a variable supply available I put a statement right before the PWM output:

if (pwm > 128) pwm = 128;

That absolutely limits the output to 128/255 duty cycle so the 12V battery can't hurt the 9.6V 1185 bulb. I calculated that the PWM could go to 180/255 and not hurt the bulb. It gets awfully bright though and hot so I don't generally operate much up there for testing. Just brief demos for non flashaholics.

-- Alan


----------



## Alan B (Sep 24, 2008)

LuxLuthor said:


> Alan/Will, your foresight on practical user interface is noted and appreciated. On the other hand, so this doesn't become an obstacle, I think there would be enough willing to do the USB programming for others, assuming there can be a straightforward template of steps to follow.
> 
> Having used a number of AWR's Hotdriver with POT adjustment for Vbulb while measuring with DMM, it is great to have that flexibility. The only other alternative proposed almost a year ago by AW was for customer to tell him in advance what Vbulb they wanted, and it would be locked into that one choice.
> 
> ...


 
I keep resisting the urge to put Bluetooth into the flashlight. Resist. 

My next goal is to get some numbers on the regulation and check the calibration so the RMS value agrees with theory. It is regulating at least adequately well now. 

My other next goal is to get my prototype mounted in my [email protected]. Then I will have something mechanically complete and nice to show off.

I picked up a 2D [email protected] today for my second prototype. Need to order a pair of D Li-Ions. The question is, what bulb? 

I have 9 of my [email protected] prototype circuit boards. These are small - sized for the sled to fit in a "D" [email protected]. Anybody else wanna play with one of these? Maybe Bob who was interested in cutting metal? 

One note to Jim - on the prototype test PCB - it might be good to put some hole pairs to put wire loops or .025" pins on for meter/scope test points. It is a pain to get probes hooked up to my small board and I'm always worried that a short from a probe moving will let some smoke out. Two holes 0.1" apart for a small wire loop would really be handy in a few select places. Ground, Vbattery, the bulb/FET junction, and the ADC input pin, and perhaps the 5V bus. Jim's test board will really be better for software development/testing than the small [email protected] board I have now.

Is anyone else interested in protoyping this setup, or setting up to develop software? How many of Jim's boards do we want?? I want one. Maybe someone with a good collection of bulbs should have one to test the power handing capability of the design, and the PWM effects on different filaments? Perhaps a half dozen of these test boards would be useful??

-- Alan


----------



## LuxLuthor (Sep 24, 2008)

Will, thanks for adding that specific TaskLed example, of which I was unaware. Certainly, we should be open to something that you know works. Your description does sound impressive.

Alan, I have a pretty diverse collections of bulbs/batteries, and a decent understanding of bulb performance & battery resources, so if I can bring a more average CPF member's perspective to testing, that would be great. I'm not going to volunteer for writing software, but could likely learn what variables to change, run a compiler, upload, and test various setups. No problem getting the components you recommend. I use a Fluke 179 DMM, but currently have no scope.


----------



## Alan B (Sep 24, 2008)

LuxLuthor said:


> Will, thanks for adding that specific TaskLed example, of which I was unaware. Certainly, we should be open to something that you know works. Your description does sound impressive.
> 
> Alan, I have a pretty diverse collections of bulbs/batteries, and a decent understanding of bulb performance & battery resources, so if I can bring a more average CPF member's perspective to testing, that would be great. I'm not going to volunteer for writing software, but could likely learn what variables to change, run a compiler, upload, and test various setups. No problem getting the components you recommend. I use a Fluke 179 DMM, but currently have no scope.


 
I would think that your testing would be quite useful. I have noted during my testing that changing the algorithm affects whether it will start the bulb or not, and clearly testing this with only one bulb type will not be adequate. I would prefer to have an algorithm that worked for lots of bulb types without a lot of adjustment. 

For example, the starting a cold bulb with low supply voltage puts a very low impedance across an already low voltage battery. If the battery voltage sags very much, which it is likely to do during starting, this causes the safety code to think the battery is being overdischarged, and shuts things down. So you have to ignore a short-term battery voltage that dips below the normal low value. On the other hand, we don't want to allow the system voltage to drop below some value that affects the way the controller works, or the FET may overheat due to underdrive, or the ADC get bad readings, etc. 

Getting all these characteristics right in the code may take some experimenting with real bulbs and real batteries. What are the best ramp rates? What are good low voltage values for different bulbs? What difference does the battery impedance make to the starting or regulating process? Does the PWM ramping have to be adjusted to work properly with some protected cells? When do protected cells trip with PWM? 

I think the best use of this regulator will be with unprotected cells. Put the protection into the software. It can monitor voltages but not current. The fuse can protect against really high current faults, but telling the difference between starting a high power bulb and a partial short may be difficult or even not possible. Using protected cells may provide some current protection, but this same feature prevents starting some bulbs.

Hopefully the regulator will just work with everything, but I suspect there will be some learning. Quite a few times I have been surprised by a new improvement's side effects, like it won't start the bulb at low supply voltage, or it shuts down under some not unusual circumstance due to an unforseen situation.

Incidentally, for a proven one button interface, how about Morse Code? That one I know already. We could send, in morse code on the button, the parameters with checksums so they could not be confused.

-- Alan


----------



## wquiles (Sep 25, 2008)

Alan,

Good news, I got the PhD working on my computer bench 

I started with R1 set to 47K as you suggested, but because of the 13.6V PS and the "cheap" 13.5V/0.59A bulb, I had to play with R1, since the circuit would either not regulate at all (send the full voltage to the bulb), or would not start at all - the bulb was completely off. Once I replace R1 back to 100K, then things started working 

I also had to fiddle with the software values/defaults, specifically with VBULB (defaults to 4.0). I tried also VBULB=8.0 and VBULB=6.0, but none match the measured RMS values as I expected - aren't these suposed to be the RMS value in volts? 

I also was able to verify the soft-start operation at different duty cycles - works great (kudos!), but much, much slower than the Willie Hunt LVR solution. From my days working on the LVR, and CPF member *js* a target of 50mS for the soft-switch was all that was needed, maybe no more than 100mS, even with high power/high current bulbs, so perhaps this is something we can lower for production (although it makes a hell of a nice demo as is since it happens slow enough to point out to others!!!). How can this soft-start time be changed in the code?

This experiment proved something else I expected - sending somebody a pre-programmed chip for debugging/testing purposes at this point in the development cycle is a no-no. At this stage on the development, you really need to have the capability to change code, build, connect to the target, program the device, disconnect, run target - then repeat as necessary (trying out different values) as I did tonight. If I had just a pre-programmed chip, I would have been SOL. Kudos to you Alan for helping me get setup with the complete software development system (although I have yet to try the Dragon!).

I will post some pics tomorrow - I am tired and going to bed now ...

Will


----------



## wquiles (Sep 25, 2008)

Alan B said:


> Incidentally, for a proven one button interface, how about Morse Code? That one I know already. We could send, in morse code on the button, the parameters with checksums so they could not be confused.



No arguing the Morse Code - talk about something that is "truly" proven!. However, I would get lost quickly. When I was a HAM 15 years ago, I got the TECH no code license - my brain seem to have a problem doing "code" 

Will


----------



## Alan B (Sep 25, 2008)

wquiles said:


> Alan,
> 
> Good news, I got the PhD working on my computer bench
> 
> ...


 
Will:

Congrats on getting things going.

The 13.6 volt supply is too high for a 47K/10K divider. Just like my fully charged 10 cell NiMH. It is right near the top of the ADC range and depending which code you run, may have high voltage protection that shuts it off. Going to the 100K gives more range, but completely changes the calibration of course. There is a define for the R1 value in the code, so you change that to match whatever resistor you used, and it will roughly calibrate everything. If you used the 47K value it will read the Vbatt quite low and probably turn up the PWM too much.

If you had stuck to the stock program, and lowered the voltage to the range it can handle it would have worked ok, most likely. 

I don't understand the part about going fully on. I have never seen it do that. Wonder what that was. If you use 13V and a 100K/10K divider it will think it is 6V and turn the PWM on very high. That could be what you saw.

The Vbulb values should be in RMS volts, but there may be some errors yet in scaling and calibration. Part of the work ahead is to resolve those issues. Integer math introduces some change and it may not be quite correct yet.

The soft-start is slow. I had no requirement to follow so at this point it adjusts the PWM by 1 count every loop, at most. So to go from PWM = 1 to PWM = 255 would take about 1sec. The system has very low gain, and is extremely stable and simple. No changes required for different bulbs, currents, voltages, etc. 

Changing this rate is not trivial the way the code is now. I have played with making this adjustable, but it was not pretty and simple the way it is now. We can look at the magnitude of the error (instead of just the sign), and make larger steps when the error is large. Or a different approach can be taken. There are so many ways to do this type of control. We can predict the PWM required, but this takes a square root, and the Vbatt is not going to be right for the changed load, probably, so it won't be correct anyway.

So what is our requirement for soft-start? How much faster do we want to go?? Is it necessary to get there in 50 mS? That is only 12 PWM pulses! What is the longest we want to take??

As you point out, the present ramp-up is kind of fun to watch and demo.

We probably want to get the RMS calibration worked out first.

-- Alan


----------



## wquiles (Sep 25, 2008)

Alan B said:


> Will:
> 
> Congrats on getting things going.


I couldn't have without your help/assistance - thanks again 





Alan B said:


> Will:
> The 13.6 volt supply is too high for a 47K/10K divider. Just like my fully charged 10 cell NiMH. It is right near the top of the ADC range and depending which code you run, may have high voltage protection that shuts it off. Going to the 100K gives more range, but completely changes the calibration of course. There is a define for the R1 value in the code, so you change that to match whatever resistor you used, and it will roughly calibrate everything. If you used the 47K value it will read the Vbatt quite low and probably turn up the PWM too much.
> 
> 
> If you had stuck to the stock program, and lowered the voltage to the range it can handle it would have worked ok, most likely.


Yep, makes sense. I remembered you talked about it in a recent post, and that is why I decided to change the resistor back to 100K. I forgot, however, to change the DEFINE statement - I should be able to fix this and re-run it tonight 






Alan B said:


> I don't understand the part about going fully on. I have never seen it do that. Wonder what that was. If you use 13V and a 100K/10K divider it will think it is 6V and turn the PWM on very high. That could be what you saw.


When I say fully ON, I mean that the Vbulb was exactly the Vbatt. In other words, PWM was on at 100%. It only did it once - maybe something I did/touch in the circuit perhaps? Lets not worry about it again, until it happens again.





Alan B said:


> The Vbulb values should be in RMS volts, but there may be some errors yet in scaling and calibration. Part of the work ahead is to resolve those issues. Integer math introduces some change and it may not be quite correct yet.


The difference between the value in that DEFINE and the real/actual Vrms was bigger than I expected (in one case the Define says 6.0 -> real is about 10 volts, but it could have been since the RESISTOR define was set to 47K instead of the 100K I was using). I will do more measurements and tests tonight. How exactly are you measuring the RMS voltage in your setup to verify that it matches the value in the DEFINE statement?





Alan B said:


> The soft-start is slow. I had no requirement to follow so at this point it adjusts the PWM by 1 count every loop, at most. So to go from PWM = 1 to PWM = 255 would take about 1sec. The system has very low gain, and is extremely stable and simple. No changes required for different bulbs, currents, voltages, etc.
> 
> Changing this rate is not trivial the way the code is now. I have played with making this adjustable, but it was not pretty and simple the way it is now. We can look at the magnitude of the error (instead of just the sign), and make larger steps when the error is large. Or a different approach can be taken. There are so many ways to do this type of control. We can predict the PWM required, but this takes a square root, and the Vbatt is not going to be right for the changed load, probably, so it won't be correct anyway.


Maybe hard to do now, but I am confident we will figure it out. I like your idea of looking at the size of the initial error instead of doing single increments from zero - there are probably several ways to skin this cat 





Alan B said:


> So what is our requirement for soft-start? How much faster do we want to go?? Is it necessary to get there in 50 mS? That is only 12 PWM pulses! What is the longest we want to take??


Yes, that is exactly how Willie Hunt's LVR work and if you look at my original posts on my evaluation of the LVR, you will see that the soft start indeed takes only a few PWM pulses, in some cases just 5-6 pulses. That is also how it works in the regulated Surefire A2 (which Willie also designed). The goal is for the startup to be fast enough that folks will not even "see" it - the light apears to behave "normal", but in fact the bulb is benefiting from the soft start every time  . So yes, I feel our goal should also be in the 50-75-100mS range, but not more. 



OK, here are some photos from last night:










The two cheap volts I am currently using:















Here is part of the current long soft start in action - is long, but it works - good job Alan!:





On this one, you can see on the very beguining of the ON pulse how the PS voltage sags a little and how the PS' feedback loop restores the voltage back to "full" for the duration of the ON pulse - neat, isn't? 





Dimmed bulb (I selected these "cheap" bulbs for their operating range - even if the PWM is not working, they will not blow!):






Will


----------



## wquiles (Sep 25, 2008)

Alan,

Here in the code I adjusted R1 to be 100K and set VBULB to 6.0 volts:







I made mode measurements tonight, and I still show an actual Vrms of 5.27V vs. the VBULB=6 in the code. Maybe this is due to my particular Tiny85 not being calibrated properly perhaps? How do I go about calibrating my own Tiny85?

Here is the second, more accurate reading of the Vrms using the Vbatt under load and the duty cycle. Of course this actually depends on reading from the screen, which is not inherently an accurate operation. Still, with the upgraded software on my Storage Scope, you can see that it actually calculated the actual Vrms spot on within one decimal point:






My hand calculations of the Vrms based on the scope capture above was about 5.38Volts - not bad for reading cursors in the screen, but look at my first pass (with less screen resolution at 5.60Volts):







Here is my True-RMS Fluke 189 setup in the mode in which it reads Vrms directly (called AC+DC mode) = 5.27V, which is pretty much identical to the scope's built-in RMS measurement 






And look at how much error there is, on the same True-RMS "premium" DMM, but this time in the standard DC mode = 2.23V => not even close!. To try a non-Fluke DMM, I tried with an "old" CIRCUITMATE DM26L DMM, and it read 2.18V. 






Hopefully once I can figure out the calibration on the Tiny85, we will get closer Vrms value measurements. For now, the difference between 6.0 (target) and 5.2 (actual) is too large (13%) 

Still, we are making progress 

Will


----------



## JimmyM (Sep 26, 2008)

One note to Jim - on the prototype test PCB - it might be good to put some hole pairs to put wire loops or .025" pins on for meter/scope test points. It is a pain to get probes hooked up to my small board and I'm always worried that a short from a probe moving will let some smoke out. Two holes 0.1" apart for a small wire loop would really be handy in a few select places. Ground, Vbattery, the bulb/FET junction, and the ADC input pin, and perhaps the 5V bus. Jim's test board will really be better for software development/testing than the small [email protected] board I have now.
[/quote]
I JUST printed out the PCB for toner transfer. I'll see if I can put a few test points on the board where you suggest.


----------



## JimmyM (Sep 26, 2008)

OK. Test points:
TP1 - B-
TP2 - B+
TP3 - ADC input voltage
TP4 - 5V buss Voltage
TP5 - Bulb to FET
TP6 -FET gate

$208 for 25 of them with a 2 week turnaround from Advanced Circuits.


----------



## JimmyM (Sep 26, 2008)

I forget if I asked this earlier or not...
Would it be possible to have an additional pin be availble to output a logic high or low to enable/disable an external component? Current requirements would be very low... < 0.1mA


----------



## wquiles (Sep 26, 2008)

JimmyM said:


> I forget if I asked this earlier or not...
> Would it be possible to have an additional pin be availble to output a logic high or low to enable/disable an external component? Current requirements would be very low... < 0.1mA



Alan will give us the final number (he might have something reserved), but from the schematic and the datasheet, we should have 2 pins available or I/O 

The I/O pins have internal pull up or pull down resistors - what do you have in mind?

Will


----------



## JimmyM (Sep 26, 2008)

wquiles said:


> Alan will give us the final number (he might have something reserved), but from the schematic and the datasheet, we should have 2 pins available or I/O
> 
> The I/O pins have internal pull up or pull down resistors - what do you have in mind?
> 
> Will


That's a secret. BWaaa haaa haaa.
Oh, hell.
An FET driver with a built in charge pump. I've found a couple, but they have an operating current from 10-900 uA depending on FET condition.
Most have an enable/shutdown pin to reduce power to something like 0.1-1.0 uA. 5V gate drive is fine for most applications, but to drive a big FET, or several, you need a gate drive of 10+ volts. The existing design is fine for now. But for the 500+ watt crowd, I'd like to have options open.
A pin goes high or low to enable the driver/chargepump when the light is switched on. When it's turned off, the driver/pump goes to sleep, conserving power.
I need to get some programming stuff first though. Just thinking about future applications.


----------



## wquiles (Sep 26, 2008)

Jim,

That is in fact a very cool application - good idea!. Like I was telling Alan, there will be a "need" for various versions of this PhD "platform" :naughty:

I am also thinking about using one the I/O pins and set it up as an output for use as a debugging LED - something that could indicate that things are OK, or not, or that the code is stuck in some weird mode, or that it got into an error routine, or perhaps when things are in regulation vs. not, or to indicate that the battery is depleted enough that the duty cycle is now at 100%, etc. - many posibilities once you have a microprocessor available 

Again, darn glad to have you on this project :twothumbs

Will


----------



## JimmyM (Sep 27, 2008)

Alan, Will,
In respect to your measurements versus predictions.
I 've been doing some work lately with the now shelved JM-SSC to reduce component count. In doing so I was messing around with Zeners. Zeners do have reverse bias leakage. Since the sampling divider for the ADC carries very little current, that leakage may be depressing the voltage at the sampling point. Since the leakage would vary a little with applied voltage, perhaps that is causing some error that the internal calibration can't adjust for. I only suggested using the zener as protection when the use of a pot was a idea. It would have protected the uP if the user cranked it too far with a high voltage pack.
Try removing the zener and running your tests again. Also, you might want a capacitor in place of the zener. It would suppress noise induced by the sharp switch transients. Noise plays hell with ADCs. Try 0.1 uF.


----------



## wquiles (Sep 27, 2008)

Jim,

Excellent observation, and in fact, we already removed the Zener, since as you point out it was not working as Alan expected. All measurements done in the posts above are without the zener in place. I still "suspect" that my particular Tiny85 needs calibration - I am sure Alan will steer me as to how to do it once he is back 

Will


----------



## JimmyM (Sep 27, 2008)

Will,
What model Tektronix do you have?
I love my Fluke 189 and was thinking about getting the 287. Then I could run 2 measurements simultaneously. But Whooooo are they EXPENSIVE!


----------



## wquiles (Sep 27, 2008)

JimmyM said:


> Will,
> What model Tektronix do you have?
> I love my Fluke 189 and was thinking about getting the 287. Then I could run 2 measurements simultaneously. But Whooooo are they EXPENSIVE!



My Tek is the TDS3034 (300Mhz), with the 3FFT and 3TRG options. Quite versatile and powerful - I am still learning how to use it properly as it has so many functions/features.

You are right about the high-end Fluke: that 287 sure looks like a great tool, but yes, at $350-375, a little bit pricey at the moment 

Will


----------



## wquiles (Sep 27, 2008)

Man, I need to learn to read better/slower/etc.. As I spend more time with the code today, I re-read Alan's comments regarding the equations/math. I found the VCAL value, which is set to 1.0 by default, but that is "adjusted" to calibrate the ADC readings. Once I set my VCAL=1.15 (based on the error measured), my Vrms (for VBULB=6.0) was 6.02Volts 

Now I can play with other VBULB values and see how the circuit tracks these changes.

Will


----------



## wquiles (Sep 28, 2008)

OK, additional data from tonight, using VCAL=1.15, still using the fixed voltage 13.6Volts regulated PS, and using the low power bulb (13.5V @ 0.59A):

(and by the way, it is extremely cool on the storage scope to see Alan's PWM code get closer to 100% as the set voltage is increased!)
VBULB = 6.0 => Vrms = 6.02Volts => Error (%) = 0.3
VBULB = 7.0 => Vrms = 7.09Volts => Error (%) = 1.3
VBULB = 8.0 => Vrms = 8.13Volts => Error (%) = 1.6
VBULB = 9.0 => Vrms = 9.15Volts => Error (%) = 1.7
VBULB =10.0 => Vrms =10.2Volts => Error (%) = 2.0
VBULB =11.0 => Vrms =11.3Volts => Error (%) = 2.7
VBULB =12.0 => Vrms =12.3Volts => Error (%) = 2.5

So we still have some error, even after calibration. So here is a question to all: what is an acceptable "error" or deviation from the set voltage? On a high power application set 12Volts and 5-8Amps: would 12.3Volts be disastrous (meaning too much voltage)?

Will


----------



## JimmyM (Sep 28, 2008)

wquiles said:


> OK, additional data from tonight, using VCAL=1.15, still using the fixed voltage 13.6Volts regulated PS, and using the low power bulb (13.5V @ 0.59A):
> 
> (and by the way, it is extremely cool on the storage scope to see Alan's PWM code get closer to 100% as the set voltage is increased!)
> VBULB = 6.0 => Vrms = 6.02Volts => Error (%) = 0.3
> ...


Hmmm. I would expect that the error would be higher at lower voltages due to the duty cycle to Vavg/Vrms relationship.
0.3V at 12V target is too much. the 64625 is very sensitive at those voltages.
Try calibrating it at a target of 12V and see what happens. See if the error is different when you calibrate it at a higher voltage then go to lower voltage.


----------



## petrev (Sep 28, 2008)

JimmyM said:


> . . .
> I 've been doing some work lately with the now shelved JM-SSC to reduce component count.
> 
> . . .


 
Hi 

Sorry to hear JM-SSC shelved ! ! !

Lurking here and watching all the great work going on by all of you . . . very interesting from a not very technical viewpoint . . .

Great to watch your progress

Keep up the good work
Pete


----------



## wquiles (Sep 28, 2008)

JimmyM said:


> Hmmm. I would expect that the error would be higher at lower voltages due to the duty cycle to Vavg/Vrms relationship.
> 0.3V at 12V target is too much. the 64625 is very sensitive at those voltages.
> Try calibrating it at a target of 12V and see what happens. See if the error is different when you calibrate it at a higher voltage then go to lower voltage.



OK, additional data, but this time I am using a VCAL=1.115 which gives me 12.0Volts (instead of 12.3Volts). Still using the fixed voltage 13.6Volts regulated PS, and using the low power bulb (13.5V @ 0.59A):

As expected, with VCAL moving "the other way", the actual voltages will be lower:
VBULB = 6.0 => Vrms = 5.9Volts => Error (%) = -1.66

VBULB = 8.0 => Vrms = 7.8Volts => Error (%) = -2.50

VBULB =10.0 => Vrms = 9.8Volts => Error (%) = -2.00

VBULB =12.0 => Vrms =12.0Volts => Error (%) = 0

So, this is still very early, and done with a PS, not the "real" batteries, but I think that you are right: I rather calibrate for the high voltage and incur in a "small" penalty just below the set point than risking a bulb explode :shakehead

Will


----------



## Alan B (Sep 28, 2008)

Good work, folks. Catching up on the mail. Hot, tired and sweaty from unloading the rig. Had a nice trip to the desert, lots of dirty toys to clean up and put away. 

The calibration should work better than it seems to, we're going to have to work on that a bit. Perhaps I'll sync the ADC to the PWM start plus a delay instead of the present FP7 code which is averaging the supply without regard for the PWM.

Jim, if you look back to where I discovered what the zener was doing, it is not a good idea even for a pot adjusted setup as it makes things quite nonlinear. It would be OK for a single voltage setup, but for anything variable it is going to make a mess of all setpoints except the one calibrated.

Yes, we have at least two pins available for things. I have been planning to use them for the electronic calibration pot up and down adjust buttons, but there are many ways to do this that don't use both pins. I was also planning to share one for controlling the opto to disconnect the ADC divider, but I don't think this is going to be required.

In many cases the pin usage can be shared between a couple of functions with some thought. 

One reason I have not tried to calibrate the RMS is that I don't have a meter that reads it. I wrote some software that takes a scope capture and computes RMS so that will probably be my best measure, but I didn't have a chance to try it for more than one sample case yet.

Later,

-- Alan


----------



## wquiles (Sep 29, 2008)

Welcome back Alan - I hope you had a good time 

Yes, measuring the Vbatt during the ON times will likely be a good improvement, specially since once we go to batteries, there will be no 1F capacitor and the batteries will sag a lot, making the difference between ON/OFF cycles much larger (like from 9 to 6.7 for the MN21 at 5Amps). 

I have been thinking about going to a global 1mS timer/interrupt and a state-based system, since we will need to measure time for the GUI options, so maybe this would be a good time to transition to this scheme as it would give us a precise time-base for the alignment of the actual ADC calculation during the ON time.

The only thing I am not sure is how can we tie the ON pulses with the ADC measurement since it we are using the hardware-based PWM. I need to read more into the PWM module to see what/how can be tied to the ADC.

Will


----------



## Alan B (Sep 29, 2008)

Well, CPF did it to me again. IT lost my last post. I had copied it, but used the copy function on something else before I noticed that CPF was again down. I've never seen another forum that was down so much. 

Too late now, time to go to work. Suffice to say that one bit time of PWM is 125 instruction times, so it is easy to sync to the PWM, even with software, and interrupts are also available (though problematic).

-- Alan


----------



## Alan B (Sep 29, 2008)

wquiles said:


> Welcome back Alan - I hope you had a good time
> 
> Yes, measuring the Vbatt during the ON times will likely be a good improvement, specially since once we go to batteries, there will be no 1F capacitor and the batteries will sag a lot, making the difference between ON/OFF cycles much larger (like from 9 to 6.7 for the MN21 at 5Amps).
> 
> ...


 
If we can use the PWM period as the system timing things will be simpler. It is about 4ms which should be suitable for UI timing.

The single bit time (1/255th) of the PWM is about 125 instruction cycles, so software can easily monitor the pin state. I have the code working. A delay after the PWM cycle starts can be used to time the ADC. The question becomes how much delay?

The PWM edge goes away at pwm = 0 and pwm = 255, so these cases need to be handled. Using pin change interrupts is possible but probably not worth the trouble. This would give an interrupt on both edges, and would give no interrupts on pwm = 0,255. Since we have exactly two things to do - monitor UI and compute pwm, doing this in lock step with the pwm (or a timer of the same period in the absence of pwm) is the way I've structured things so far. It can be changed, but people will have more success with the simplicity if they need to make changes.

*Low Power Sleep Interrupts*

I have used the interrupts for power down sleep to reduce power consumption. I'm not currently using that code in order to keep things simple, but it can easily be added back later. In the case that the light is off, and the UI is inactive, the chip is reconfigured for low power sleep and the interrupt for the pushbutton configured. All clocks are stopped in this sleep, it is looking for a low level on the pushbutton input to wake it up. I have tested the code but did not measure the power consumption yet. It should be about 15uA.

I will publish an updated code soon with ADC sync and a few other improvements. I need to clean it up and test it a bit more. My next goal is to get the calibration accuracy working properly. I have a lot of other stuff that I've played with, but until the calibration is accurate I want to keep things simple. That's what I'm going to focus on. 

*Jim's Test Board*

We also need to figure out what to do about the test board. Jim, what are your thoughts? Do you want to make them and sell them? I'm not sure we have a need for 25. Probably more like 5 right now. I could use one, and I might guess that about a half dozen would be useful. Who else wants one? 

-- Alan


----------



## wquiles (Sep 29, 2008)

Alan B said:


> If we can use the PWM period as the system timing things will be simpler. It is about 4ms which should be suitable for UI timing.


I really like that idea. A global timing of 4ms is perfect!. Will this also allow us to get the soft start to happen in 50mS to no more than 100mS? 

Maybe we can pick 64mS, as this would be a nice multiple of 4mS - which means that we can do the soft start in 16 PWM cycles. We can calculate the initial error between actual battery and desired Vrms, and use this error to calculate the "step" necessary to finish by 16 PWM cycles. What do you think? 

We might still have the problem about the very "first" PWM cycle. Do we simply start with a value of 1, and then see the error? Would this value of 1 be long enough to really get a good indication of the error? Would the battery sag enough with a value of 1 to be worth-while, or do we want to start with a larger value than 1? Looks like there are many ways of doing this ...






Alan B said:


> The single bit time (1/255th) of the PWM is about 125 instruction cycles, so software can easily monitor the pin state. I have the code working. A delay after the PWM cycle starts can be used to time the ADC. The question becomes how much delay?


The biggest "hit" on the battery as you can see on the screen shots happens at the beginning of the ON pulse, but by the time the ON pulse is about to end, the battery is stable, so ideally, I would measure towards the end of the pulse for best stability. Since we know the exact width of each ON pulse, and we know how long it takes for the ADC to make the measurement, we "should" be able to start the ADC measurement within the ON time and end before the pulse goes away. So I would suggest: Assuming the ADC conversion time is ADCtime, we start the ADC measurement 2*ADCtime before the end of the positive pulse, that is, assuming that this "scheme" work when the PWM value is one (narrowest).






Alan B said:


> *Low Power Sleep Interrupts*
> 
> I have used the interrupts for power down sleep to reduce power consumption. I'm not currently using that code in order to keep things simple, but it can easily be added back later. In the case that the light is off, and the UI is inactive, the chip is reconfigured for low power sleep and the interrupt for the pushbutton configured. All clocks are stopped in this sleep, it is looking for a low level on the pushbutton input to wake it up. I have tested the code but did not measure the power consumption yet. It should be about 15uA.


That is perfect - good work Alan.






Alan B said:


> I will publish an updated code soon with ADC sync and a few other improvements. I need to clean it up and test it a bit more. My next goal is to get the calibration accuracy working properly. I have a lot of other stuff that I've played with, but until the calibration is accurate I want to keep things simple. That's what I'm going to focus on.


That would be great. I have been learning quite a bit from your original code - thanks much for taking the time for the in-line comments - very helpful!





Alan B said:


> *Jim's Test Board*
> 
> We also need to figure out what to do about the test board. Jim, what are your thoughts? Do you want to make them and sell them? I'm not sure we have a need for 25. Probably more like 5 right now. I could use one, and I might guess that about a half dozen would be useful. Who else wants one?
> 
> -- Alan


I don't need any at this point - I can always do a perforated board if I need something more "solid" than my proto-board for further development/test.

Will


----------



## Alan B (Sep 29, 2008)

wquiles said:


> I really like that idea. A global timing of 4ms is perfect!. Will this also allow us to get the soft start to happen in 50mS to no more than 100mS?
> 
> Maybe we can pick 64mS, as this would be a nice multiple of 4mS - which means that we can do the soft start in 16 PWM cycles. We can calculate the initial error between actual battery and desired Vrms, and use this error to calculate the "step" necessary to finish by 16 PWM cycles. What do you think?
> 
> ...


 
*ADC Synchronizing*

It is possible to sync with the end of the PWM pulse but I have not done it. It is probably not useful in the long run as there are better solutions. Just to start with I will include optional code for a fixed delay into the PWM pulse so we can synchronize and still avoid the leading edge. Later after calibration is worked out we can do something better. I already have this code, it will be in the next release. What would be a good default value for this fixed delay?

*Fast Soft Starting*

I took a look at fast soft-start and have come up with something that will probably meet the new requirements. It is causing some problems elsewhere in the user interface code since the state of Vbulb was being used by the UI, but that should probably be separated anyway. This will delay the release of the next code revision a bit. 

Basically this fast-soft-start looks at the error magnitude and adds extra kick to the pwm when a threshold is exceeded. So it amounts to a one line change in the operating code. There are a few lines of compiler computations, and the addition of two definitions - one for the number of main loop cycles to use for fast-soft-start, and the other for the nominal battery voltage used to calculate nominal pwm values, etc. I'm planning to make the nominal value of the fast-soft-start to be 25 cycles which is about 100 milliseconds.

*The Road Ahead*

The main issue at the moment is the calibration. Measurements of test systems are pretty good but deviate more from predictions than I like. I want to understand that. I have also added the ADC to PWM test code to the next version. This allows the developer to know the actual ADC values by measuring the PWM output of the regulator. It is dangerous to bulbs, so must be used with care. Whatever the ADC reads gets put out as the PWM value. So with a variable power supply and a scope the ADC can be precisely tested. If you want to try this, it is one line of code. Just before the PWM is output add the statement:


```
pwm = adc;  // ADC to PWM for testing - WARNING - DANGEROUS TO BULBS
```
 
-- Alan


----------



## Alan B (Sep 29, 2008)

JimmyM said:


> OK. Test points:
> TP1 - B-
> TP2 - B+
> TP3 - ADC input voltage
> ...


 
OK, so Will is not interested, I could use one, others??

-- Alan


----------



## wquiles (Sep 29, 2008)

Alan B said:


> *ADC Synchronizing*
> 
> It is possible to sync with the end of the PWM pulse but I have not done it. It is probably not useful in the long run as there are better solutions. Just to start with I will include optional code for a fixed delay into the PWM pulse so we can synchronize and still avoid the leading edge. Later after calibration is worked out we can do something better. I already have this code, it will be in the next release. What would be a good default value for this fixed delay?


As to what delay would be acceptable, that also depends on the value of pwm, specially when it is set to 1. Here is what I mean. On a scale of 100uS/div, here is what the ON pulse, on steady state (duty cycle of approx 55% - I guess that would be pwm of about 140, right?







and here, on the same scale, is the very first pulse (pwm=1):






If I take these again at 40uS/div, here is the steady state ON pulse:






and here on the same 40uS/div is the very first pulse (pwm=1). In here, it seems that if you could measure the ADV voltage right in the middle, about 20uS after the beguining of the pulse, you would get a reasonable voltage level. Note that this is so fast/narrow and short a pulse (this being the beguining of the soft start), that the bulb is not quite reacting fast enough and that the voltage at the battery will be lower than during steady state:





Does this help estimate a good delay?





Alan B said:


> *Fast Soft Starting*
> 
> I took a look at fast soft-start and have come up with something that will probably meet the new requirements. It is causing some problems elsewhere in the user interface code since the state of Vbulb was being used by the UI, but that should probably be separated anyway. This will delay the release of the next code revision a bit.
> 
> Basically this fast-soft-start looks at the error magnitude and adds extra kick to the pwm when a threshold is exceeded. So it amounts to a one line change in the operating code. There are a few lines of compiler computations, and the addition of two definitions - one for the number of main loop cycles to use for fast-soft-start, and the other for the nominal battery voltage used to calculate nominal pwm values, etc. I'm planning to make the nominal value of the fast-soft-start to be 25 cycles which is about 100 milliseconds.


That sounds cool. Let me know when you have code I can test on my setup.





Alan B said:


> *The Road Ahead*
> 
> The main issue at the moment is the calibration. Measurements of test systems are pretty good but deviate more from predictions than I like. I want to understand that. I have also added the ADC to PWM test code to the next version. This allows the developer to know the actual ADC values by measuring the PWM output of the regulator. It is dangerous to bulbs, so must be used with care. Whatever the ADC reads gets put out as the PWM value. So with a variable power supply and a scope the ADC can be precisely tested. If you want to try this, it is one line of code. Just before the PWM is output add the statement:
> 
> ...


I think I know what you are doing, but I need to understand where you are putting the decimal point/how you convert from one to the other. What I mean is that the pwm value goes from 0 to 255 and that controls the duty cycle from 0 to 100%, right? Then, the ADC value is 0-2.56v, but which bits are you using? When you set pwm = adc, that is the translation of what I can see on the scope (duty cycle) and the analog adc value?


Will


----------



## Alan B (Sep 30, 2008)

wquiles said:


> As to what delay would be acceptable, that also depends on the value of pwm, specially when it is set to 1. Here is what I mean. On a scale of 100uS/div, here is what the ON pulse, on steady state (duty cycle of approx 55% - I guess that would be pwm of about 140, right?
> ...
> and here, on the same scale, is the very first pulse (pwm=1):
> ...
> ...


 
Nice traces. Looks like the supply is pretty slow to compensate the last bit. 

It probably does not matter if the ADC is accurate at PWM=1. For purposes of getting the calibration accurate it might be best to use a capacitor so it does not matter where the ADC reads. Compensating for the waveform is a separate optimization after calibration, in my thinking.

The ADC runs from 0 to 255 and so does the PWM. 0 corresponds to zero volts, and PWM output always low. 255 corresponds to 2.56 volts at the ADC input pin and DC high on the PWM. 127 is the midpoint and corresponds to half the voltage and 50% duty cycle.

As far as the ADC test goes, perhaps plotting voltage input vs on-period uS in a spreadsheet would be a good way to look at the data. That would show the linearity clearly. A calculation at each point could show volts per microsecond, and this should be a constant, so it can be analyzed for error. This will right away show us if the ADC is the source of the error. This is how I found the zener problem. Your meters have more resolution than mine and are likely more accurate, so you will get more accurate data than I did. I think it will show the ADC is quite good, but I wonder if there is enough offset to be concerned about. At the moment I assume no offset and a single calibration point. If we have offset we may need two calibration points (low and high) which would not be too hard to do, but adds extra effort and code so I want to avoid it unless required.

For the ADC test I remove the bulb and use a 10K resistor for the load. Thus there is no load on the supply and the voltage stays very constant.

Then perhaps a PWM test of some sort should be designed. Generate the PWM for a series of known voltages from a known power supply and see how they all measure. For example make the control switch set the output to 3.0, 4.0, etc volts from a fixed 15.0 volt supply. Each tap of the control pushbutton cycles to the next position. Use a light load resistor to avoid distortion (and a capacitor across the supply would not hurt either). This would test the PWM output. All that is left is the math in the middle. So we can basically break the problem down into these 3 pieces.

I was working on a floating / integer version of the code that computes the PWM each time rather than using a feedback loop. I should finish this version also as it uses a different set of math to do the computations. It was not working quite right as I recall when I last left it.

-- Alan


----------



## Alan B (Sep 30, 2008)

*Software Update*

New Version of the software has been uploaded. The new FP8 program is a test suite with many tests and several regulation control algorithms in it.

http://akbeng.com/flash/hwreg/software/HotwireRegulator.c

-- Alan


----------



## wquiles (Sep 30, 2008)

Alan B said:


> *Software Update*
> 
> New Version of the software has been uploaded. The new FP8 program is a test suite with many tests and several regulation control algorithms in it.
> 
> ...



Alan,

In the new code we no longer have VBULB - how do I set a different Vrms target now? Looks like we have a variable value vbulb now, but I can't set it to any given Vrms target - it seems calculated during the button press/debounce routine.

After adjusting for my resistor values, the RMS is set to an actual 5.8Vrms. I tried short and long button presses, but I can't see to be able to change the actual target voltage 

Will


----------



## Alan B (Sep 30, 2008)

wquiles said:


> Alan,
> 
> In the new code we no longer have VBULB - how do I set a different Vrms target now? Looks like we have a variable value vbulb now, but I can't set it to any given Vrms target - it seems calculated during the button press/debounce routine.
> 
> ...


 
This test code generates a sequence of voltages. It starts at 0.0, then 1.0, then 2.0, then 3.0, then 4.0, up to 12.0. Each buttonpress goes to the next voltage, then after 12.0 the next one goes to 0.0 again.

Make sure you have some kind of load on the output if you remove the bulb. I use a 10K resistor. Probably a slightly lower value would be better as the 10K leaves a bit of tail on the waveforms which will affect RMS measurements, unless you measure with a scope and ignore the tails.

-- Alan


----------



## wquiles (Oct 1, 2008)

Alan B said:


> This test code generates a sequence of voltages. It starts at 0.0, then 1.0, then 2.0, then 3.0, then 4.0, up to 12.0. Each buttonpress goes to the next voltage, then after 12.0 the next one goes to 0.0 again.
> 
> Make sure you have some kind of load on the output if you remove the bulb. I use a 10K resistor. Probably a slightly lower value would be better as the 10K leaves a bit of tail on the waveforms which will affect RMS measurements, unless you measure with a scope and ignore the tails.
> 
> -- Alan



I though something like that was going on by looking at the code, but it does not work. No mater what I do, no mater how I do the button press, it just works ON or OFF, with the ON always being at the same level. I think it might still be using the old code - probably a problem on my side. Let me check again today 

By the way, I am still using the low voltage/current bulb as the output.

Will


----------



## wquiles (Oct 1, 2008)

Alan,

Yup, that was it. I had a problem with the file name used in the new version. Although it was compiling/building the new one, I was still using the old ELF file. Like I guessed, something wrong on my side :shakehead

I need to go to work now, but I will play with it some more tonight 

Will


----------



## Alan B (Oct 1, 2008)

wquiles said:


> Alan,
> 
> Yup, that was it. I had a problem with the file name used in the new version. Although it was compiling/building the new one, I was still using the old ELF file. Like I guessed, something wrong on my side :shakehead
> 
> ...


 
The program loader has its own memory of filename, so even while compiling the new program it will load the old binary into the chip. I'm trying to standardize on one fixed filename to reduce this problem in the future.

-- Alan


----------



## wquiles (Oct 1, 2008)

Like I warned when I started in this project .... I take a lot of pictures ..... I hope that folks reading this post have broadband ....



Alan,

Here is the latest program in operation. I am using VCAL = 1.115, R1 = 99.9K, R2=0, R1=9.98K (those are the actual measurement for the resistors I am using). Note that the Storage Scope is not changed from photo to photo - you can see how as the target Vrms increases, so does the pulse width. Voltage in Vrms (actual) can be read on the Fluke 189. Photo taken with Fuji S100fs in manual mode (lens on full angle) with the same exposure for all shots (F2.8 @ 1/10). Note that since calibrated my Tiny85 for 12volts, I am almost spot on for the higher voltages.


Output when it starts up:
VbattDC = 13.1V (manually from Scope)
VbulbRMS = 1.53V (Fluke) / 1.58V (Scope)
Total Period of PWM (hopefully constant) = fairly constant at 3.94mS (manually from Scope)
On Period of PWM for each setting = hard to measure by hand, but scope says duty cycle is 1.6%






after one button press:
VbattDC = 13.2V (manually from Scope)
VbulbRMS = 1.66V (Fluke) / 1.60 to 1.80V (Scope)
Total Period of PWM (hopefully constant) = fairly constant at 3.94mS (manually from Scope)
On Period of PWM for each setting = hard to measure by hand, but scope says duty cycle is 1.74% to 2.13%






after two button presses:
VbattDC = 13.4V (manually from Scope)
VbulbRMS = 2.37V (Fluke) / 3.33 to 3.48V (Scope)
Total Period of PWM (hopefully constant) = fairly constant at 3.94mS (manually from Scope)
On Period of PWM for each setting = hard to measure by hand, but scope says duty cycle is 3.3% to 3.7%






after three button presses:
VbattDC = 13.5V (manually from Scope)
VbulbRMS = 3.28V (Fluke) / 3.25 to 3.35V (Scope)
Total Period of PWM (hopefully constant) = fairly constant at 3.94mS (manually from Scope)
On Period of PWM for each setting = hard to measure by hand, but scope says duty cycle is 6.18% to 6.57%






after four button presses:
VbattDC = 13.6V (manually from Scope)
VbulbRMS = 4.16V (Fluke) / 4.13 to 4.21V (Scope)
Total Period of PWM (hopefully constant) = fairly constant at 3.94mS (manually from Scope)
On Period of PWM for each setting = hard to measure by hand, but scope says duty cycle is 9.78% to 10.15%






after five button presses:
VbattDC = 13.6V (manually from Scope)
VbulbRMS = 5.17V (Fluke) / 5.15 to 5.21V (Scope)
Total Period of PWM (hopefully constant) = fairly constant at 3.94mS (manually from Scope)
On Period of PWM for each setting = hard to measure by hand, but scope says duty cycle is 14.88% to 15.28%






after six button presses:
VbattDC = 13.6V (manually from Scope)
VbulbRMS = 6.13V (Fluke) / 6.12 to 6.17V (Scope)
Total Period of PWM (hopefully constant) = fairly constant at 3.94mS (manually from Scope)
On Period of PWM for each setting = hard to measure by hand, but scope says duty cycle is 20.8% to 21.1%






after seven button presses:
VbattDC = 13.6V (manually from Scope)
VbulbRMS = 7.12V (Fluke) / 7.09 to 7.15V (Scope)
Total Period of PWM (hopefully constant) = fairly constant at 3.94mS (manually from Scope)
On Period of PWM for each setting = hard to measure by hand, but scope says duty cycle is 27.7% to 28.2%






after eight button presses:
VbattDC = 13.6V (manually from Scope)
VbulbRMS = 8.07V (Fluke) / 8.06 to 8.12V (Scope)
Total Period of PWM (hopefully constant) = fairly constant at 3.94mS (manually from Scope)
On Period of PWM for each setting = hard to measure by hand, but scope says duty cycle is 35.8% to 36.0%






after nine button presses:
VbattDC = 13.6V (manually from Scope)
VbulbRMS = 9.03V (Fluke) / 9.04 to 9.09V (Scope)
Total Period of PWM (hopefully constant) = fairly constant at 3.94mS (manually from Scope)
On Period of PWM for each setting = hard to measure by hand, but scope says duty cycle is 44.6% to 45.0%






after ten button presses:
VbattDC = 13.6V (manually from Scope)
VbulbRMS = 10.01V (Fluke) / 10.0 to 10.1V (Scope)
Total Period of PWM (hopefully constant) = fairly constant at 3.94mS (manually from Scope)
On Period of PWM for each setting = hard to measure by hand, but scope says duty cycle is 54.8% to 55.2%






after eleven button presses:
VbattDC = 13.6V (manually from Scope)
VbulbRMS = 10.9-11.0V (Fluke) / 11.0 to 11.1V (Scope)
Total Period of PWM (hopefully constant) = fairly constant at 3.94mS (manually from Scope)
On Period of PWM for each setting = hard to measure by hand, but scope says duty cycle is 65.3% to 66.3%






after twelve button presses:
VbattDC = 13.6V (manually from Scope)
VbulbRMS = 12.09V (Fluke) / 12.1 to 12.2V (Scope)
Total Period of PWM (hopefully constant) = fairly constant at 3.94mS (manually from Scope)
On Period of PWM for each setting = hard to measure by hand, but scope says duty cycle is 79.8% to 80.2%






Will

EDITED with new data on 10/02/08 - 11:19PM
EDITED with correct %duty cycle for 7th button press on 10/03/08 - 7:55AM


----------



## Alan B (Oct 1, 2008)

Will:

Interesting. Nice photos. Hope folks have broadband.

A data set from this measurement is:

VbattDC (hopefully constant)
VbulbRMS for each setting
Total Period of PWM (hopefully constant)
On Period of PWM for each setting

This is probably visible in your photos, though you can see it better at full res. We could pop the data into a Google Spreadsheet and share it, that might be an interesting way to work on the data.

I will have to research the PWM very carefully and see if there is something about it that is different from what I was expecting. There is also an asymmetrical on/off characteristic of the FET that might have some effect, though I think this error is too large for that.

Another test that would be interesting is to override the ADC, putting in the correct value for your supply voltage as a fixed value, and rerun the test. That is one way to get the ADC itself out of the equation.

Another test would be to change to the floating point control algorithm and see if that does any better.

Plotting the data from this run would also be interesting, to see if it has any telltale form.

Excellent Update to the data, Will! :thumbsup:

-- Alan


----------



## Alan B (Oct 1, 2008)

A quick plot of the data shows a pretty straight line except for the first point. 

The first point is probably the code for triggering the scope that I had in there, it uses a PWM of 1 instead of 0 so the scope will not stop triggering. So we can ignore that point.

-- Alan


----------



## Alan B (Oct 1, 2008)

Here is a spreadsheet computing the PWM and rounding it up, then adding 0.5, then computing the RMS voltage. It is rather interesting how far off the zero value is. That is 1/255 period.

The spreadsheet should be here but won't display worth a darn..

So here it is on Google Spreadsheets:

http://spreadsheets.google.com/pub?key=pJxYQtNDGEkRr3fAf2VSZQQ

-- Alan


----------



## JimmyM (Oct 2, 2008)

Alan, Will,
Sorry I've been absent. Been working my a** off lately. I have a little catching up to do. Looks like a lot of good reading.
If we have 10 made, the total is ~$181. I can't pop for the whole $181 for these. With the demise of the JM-SSC, I'm out a couple/few, unrecoverable, hundred bucks, but I'd be willing to go three ways with you guys ($60 a piece) I'll keep 2 boards, and you guys can split the other 8.
It's a 2 week turn-around.


----------



## Alan B (Oct 2, 2008)

JimmyM said:


> Alan, Will,
> Sorry I've been absent. Been working my a** off lately. I have a little catching up to do. Looks like a lot of good reading.
> If we have 10 made, the total is ~$181. I can't pop for the whole $181 for these. With the demise of the JM-SSC, I'm out a couple/few, unrecoverable, hundred bucks, but I'd be willing to go three ways with you guys ($60 a piece) I'll keep 2 boards, and you guys can split the other 8.
> It's a 2 week turn-around.


 
So, folks, who wants one of these test boards?

-- Alan


----------



## wquiles (Oct 2, 2008)

Alan B said:


> Will:
> 
> Interesting. Nice photos. Hope folks have broadband.
> 
> ...


I will try to run it again tonight and collect better information than what is available in the pictures.




Alan B said:


> A quick plot of the data shows a pretty straight line except for the first point.
> 
> The first point is probably the code for triggering the scope that I had in there, it uses a PWM of 1 instead of 0 so the scope will not stop triggering. So we can ignore that point.
> 
> -- Alan


Yes, the first set of values looks "off".





Alan B said:


> Here is a spreadsheet computing the PWM and rounding it up, then adding 0.5, then computing the RMS voltage. It is rather interesting how far off the zero value is. That is 1/255 period.
> 
> The spreadsheet should be here but won't display worth a darn..
> 
> ...



I think that "calc pwm" means calculated PWM value, but what is the "prev V" column?

Will


----------



## wquiles (Oct 2, 2008)

JimmyM said:


> Alan, Will,
> Sorry I've been absent. Been working my a** off lately. I have a little catching up to do. Looks like a lot of good reading.
> If we have 10 made, the total is ~$181. I can't pop for the whole $181 for these. With the demise of the JM-SSC, I'm out a couple/few, unrecoverable, hundred bucks, but I'd be willing to go three ways with you guys ($60 a piece) I'll keep 2 boards, and you guys can split the other 8.
> It's a 2 week turn-around.



Jim,

Although I am committed to help with the project, my target platform is not the Mag (at least not initially), but the SureFire M6, which will require a completely different board and changes to the firmware (the M6 has no switch for starters!), but I would expect that since many are following this thread, that others would be interested in some of these test boards.

Will


----------



## Alan B (Oct 2, 2008)

*Source of the RMS Error, Perhaps*

I modified FP8 and made PWM vs pulsewidth ontime measurements on my board and added a new page to the spreadsheet (select the second page):

http://spreadsheets.google.com/pub?key=pJxYQtNDGEkRr3fAf2VSZQQ

It shows that the ontimes are longer than the PWM request for short pulses. At longer pulselength they appear to shorten up slightly, but it may be that they are all long by the same amount, and that the resolution of measurement on the longer pulses is such that I can't see the additional time. Perhaps Will's system with higher bandwidth will make a more accurate measurement of PWM vs Pulse Length. I will post the new FP8 code that has the PWM output option tonite. This new option puts out 1,2,4,8,16,32,64,128,254 pulse length pwm, selected by the pushbutton as before. No ADC etc is involved, just put a constant value to the PWM and let it run.

I didn't do a calculation but this does appear to be part of the source of the RMS error. The FET is on slightly longer than the PWM setting would indicate. It may be due to the FET gate drive asymmetry. We may be able to compensate for it by adding a small constant into the control equation. We could also use a gate driver as Jim has suggested, but that would add hardware, volume, cost and power consumption. If we can solve it in software it keeps the parts count down and lowers cost. Of course we can provide for doing it either way.

There is also the thought that if calibrated at the higher or highest output value the error at lower values is unimportant. It will have a small effect on regulation over a large voltage input change, but with batteries the actual range of input voltage change is not that great.

What do folks think? What precision of voltage regulation are we requiring??

-- Alan


----------



## Alan B (Oct 2, 2008)

wquiles said:


> I will try to run it again tonight and collect better information than what is available in the pictures.
> 
> Yes, the first set of values looks "off".
> 
> ...


 
That is the predicted voltage (Pred V) based on the PWM setting computed. That is what it would be if the PWM did what the code requested. I take the PWM calculated, round it down, and then add 0.5 since the PWM code jumps back and forth between the PWM values on either side of the correct value.

It would probably be of more value to do the fixed PWM vs Measured RMS feature of the new FP8 code.

Another source of error we need to watch out for is the 'crest factor'. Some of these short pulses may be bad for the RMS meter. We should check them with a scope and calculations to verify.

I just did a quick calc on the quantity of the error, and it may be a couple of counts in PWM. This should be easy to compensate for, but it is way too much to be the FET driver. Perhaps the way the PWM hardware works is different from what was expected. Have to research that a bit. In any case, subtracting 2 from the PWM may do the job...

-- Alan


----------



## Alan B (Oct 2, 2008)

The more I think about this, the more I think there are several sources of error. The PWM/FET error is far less than one count, so it is not enough to do much. The other error appears to be about 2 counts, which is the major part of the problem. That I don't know the cause of yet.

That 2 count error may not be the right amount, though, because that is based on Will's measurements and my assumptions about those measurements. What was the supply voltage? I assumed 13.5 from the fuzzy value on the scope screen, but that is not perhaps the right value.

I added a page showing the ADC to PWM measurement that I made earlier when troubleshooting the zener diode problem.

-- Alan


----------



## JimmyM (Oct 2, 2008)

Alan B said:


> Source of the RMS Error, Perhaps
> We could also use a gate driver as Jim has suggested, but that would add hardware, volume, cost and power consumption. If we can solve it in software it keeps the parts count down and lowers cost. Of course we can provide for doing it either way.
> -- Alan


The TI TPS2829 uses 0.1uA while in the OFF state. It's an SOT-23-5 package so it's quite small. If a software solution fails, then this may be an option.
They're $1.43 each for 1, $1.14 each for 25. Not all that expensive really
The Micrel MIC4416 uses 50uA while in the OFF state, but it's even smaller (SOT-143). They're $1.29 each for 1, and $1.07 each for 25. Not much cheaper or smaller, but it uses 500x the power when off.

See what you can do in software, but also consider that different FETs will have different rise/fall times so they will have to be compensated for differently in software. I'd like to have a hardware configuration that performs consistently enough not to need another calibration setting.


----------



## wquiles (Oct 2, 2008)

Alan B said:


> The more I think about this, the more I think there are several sources of error. The PWM error is far less than one count, so it is not enough to do much. The other error appears to be about 2 counts, which is the major part of the problem. That I don't know the cause of yet.
> 
> That 2 count error may not be the right amount, though, because that is based on Will's measurements and my assumptions about those measurements. What was the supply voltage? I assumed 13.5 from the fuzzy value on the scope screen, but that is not perhaps the right value.
> 
> ...



Alan,

Please realize that of all of the numbers measured, the Vrms on the Fluke 189 is by far the most accurate (there is no human interaction/approximation - the Fluke reads the value directly, to several digits, and it is not jumping around much at all - it is a fairly stable measurement with little jitter). 

The pulse width and % duty cycle are achieved by moving vertical cursors in the scope display, and try to line them up manually as best as possible with the rise/fall edges, so there the inherent accuracy is lower, and it also depends on the actual horizontal scale used (basically a 2x multiplier every time you change the scale). 

Lets wait until tonight - I will record the values you stated above (to be best of my ability), and then you will have better/more accurate data 

Will


----------



## JimmyM (Oct 2, 2008)

What is the smallest time increment that the Tiny25/45/85 can manage?
Maybe you've already thought of this and discarded it, but...
What about having it turn the output on every 0.005 seconds (200Hz) then turn it off "x" amount of time later. Can the uP manage "x" in small enough values to end up with a higher resolution PWM?
8 bit = 256 PWM levels.
But, if it can manage microseconds. then 0.005 seconds / 0.000001 seconds = 5000 levels. Maybe have it use its internal CPU clock, and count clock cycles before turning off the output. That's 8MHz right?
Just spitballing here. Call me crazy


----------



## JimmyM (Oct 2, 2008)

Alan B said:


> The more I think about this, the more I think there are several sources of error. The PWM/FET error is far less than one count, so it is not enough to do much. The other error appears to be about 2 counts, which is the major part of the problem. That I don't know the cause of yet.
> 
> That 2 count error may not be the right amount, though, because that is based on Will's measurements and my assumptions about those measurements. What was the supply voltage? I assumed 13.5 from the fuzzy value on the scope screen, but that is not perhaps the right value.
> 
> ...


I'm inclined to agree. The measurement of the signal may be the culprit more than the creation of the signal.
Of course I'm still in the "FET driver" camp. "Vive la FET driver!"


----------



## Alan B (Oct 2, 2008)

We need a bit more data, but at this time the FET driver cannot account for more than a small fraction of a bit-time on the PWM. My recent measurement shows 0.12 bit times. The error in Will's measurements vs expected are about 2 bit times, or 20x larger. Hopefully we can nail the 2 bit time error, and the 0.12 bit time error won't matter - it is in the noise.

The Fluke is a wonderful meter, but it has limitations on measurements and measurement accuracy. Narrow pulses may cause considerable errors. I don't know if this is happening, but we need to be sure.

-- Alan


----------



## Mr Happy (Oct 2, 2008)

Alan B said:


> The Fluke is a wonderful meter, but it has limitations on measurements and measurement accuracy. Narrow pulses may cause considerable errors. I don't know if this is happening, but we need to be sure.


I understand the Fluke 189 has a crest factor limit in the range of 3 to 6. When measuring PWM pulses with a very low duty cycle (short pulses with large gaps), I think the crest factor could easily be much higher than 6.


----------



## Alan B (Oct 2, 2008)

*New Software Release*

The new test software has been uploaded to the website. FP8 now has some new options including generating specific PWM pulsewidths. Each press of the button advances through the set 1,2,4,8,16,32,64,128,254 and back to 1. This is the pulsewidth integer loaded into the PWM generator in the chip. 0 is off, 255 is on, 1..254 is PWM.

http://akbeng.com/flash/hwreg/software/HotwireRegulator.c

It would be quite interesting to measure and tabulate (perhaps on Google Spreadsheet):

*Constants over the Test:*
PWM Total Period,
DC Supply Voltage (should be very stiff, use capacitor if possible)

*for each PWM value 1,2,4,..,128,254:*
PWM integer, (assume from sequence)
VbulbRMS, (measured with RMS meter)
VbulbMEAN (measured with averaging meter)
PulseWidth ON Period (measured with scope)

Preferrably all voltage measurements would be with the same meter.

Thanks in advance,

-- Alan


----------



## wquiles (Oct 2, 2008)

Mr Happy said:


> I understand the Fluke 189 has a crest factor limit in the range of 3 to 6. When measuring PWM pulses with a very low duty cycle (short pulses with large gaps), I think the crest factor could easily be much higher than 6.



Thanks much - good information to know. The crest factor is in fact approx. 9 in our case for the first PWM pulse, but 6 and under for the rest, so in theory we should be OK except for the very first one. The problem is that the pulses are not exactly square (since we are dealing with a real bulb and its inductance), so that makes things more "interesting". We can always use our math from numerical analysis and calculate the area under the curve for each 20uS block and at it all up - our college teachers would be proud of us even remembering this 

Here is again the very first pulse on the latest program (v0.93) showing the non-square shape. If you look at my very next post, you will see that it gets even more interesting as the pulses are not steady, but alternating between two values:






Will


----------



## wquiles (Oct 2, 2008)

Alan B said:


> *New Software Release*
> 
> The new test software has been uploaded to the website. FP8 now has some new options including generating specific PWM pulsewidths. Each press of the button advances through the set 1,2,4,8,16,32,64,128,254 and back to 1. This is the pulsewidth integer loaded into the PWM generator in the chip. 0 is off, 255 is on, 1..254 is PWM.
> 
> ...



Alan,

I only have a little bit of bench time every right, so I am going to collect some data points, but not 254*4 data points 

As a consolation, I updated the data in post #432, still using the older program (V0.93):
https://www.candlepowerforums.com/posts/2646129&postcount=432

For now, here is some interesting detail data using the last program (V0.93) from yesterday.

Again, after the first press, first the individual pulse, then 3 of them:











but the real reason for this post tonight, is about what is happening after the second button press: we have two alternating values for this PWM output, note that one of those pulses is the "old" or prior single button pulse, plus a newer and wider pulse:





Here is 3 of them, and if you note, the Scope's built-in duty cycle measurement is alternating between 1.73% and 2.11%











Is this due to what you mentioned earlier about the PWM flipping between two values with +/- 0.5?

And by the way, this happens on all other button states - there is always this dual/alternating output in all, except the very first one. In fact, the data on post #432 that I updated, showed this variation in the voltage/duty cycle measurements in the scope.

Will


----------



## Alan B (Oct 3, 2008)

wquiles said:


> Alan,
> 
> I only have a little bit of bench time every right, so I am going to collect some data points, but not 254*4 data points
> 
> ...


 
Will,

I understand the time limitation. I'm trying to get things out so they can be worked on if time is available, but it will happen as time is available.

254*4 points? :sick2: I would not do that to you! There are only 1,2,4,8,16,32,64,128,254 values or 9 points with three measurements at each point.

Interesting data on the crest factor, that's what I like to hear - Data so we can put some trust where it belongs, and uncertainty where it is due.

The dual/alternating output is present in the integrating feedback loop, my standard control algorithm. It evaluates for error at each iteration and should alternate between "too high" and "too low" since the pwm is never quite right, and will bounce between those two values. Noise will cause occasional changes beyond that, most likely. If we want more precision we can arrange the bouncing to have a particular frequency distribution to make the RMS come out right, but that is not worthwhile at this stage. Our errors are larger than that.

The first position is probably the scope trigger option coming on at otherwise zero PWM, and it sets the PWM to one and leaves it there (to trigger my scope). ((One thing they missed on my USB scope is auto-trigger. It is either free running or triggered, so I sometimes force the PWM to have an edge all the time with the scope option in the code for testing.))

The new PWM test code does not bounce between values. It just puts a PWM value into the hardware when the button is pushed, then no changes after that till the button is touched again. So it should NOT bounce around.

Another interesting test is to try the floating point version and see how it compares. It should not bounce much, as it computes PWM from voltage and sends it out, though noise on the ADC may cause some bounce.

I'm puzzled by the waveform. Mine looks better here, but there are a few differences. I alternate between running from a C NiMH battery and a power supply with 1F capacitor. Thinking about inductance in the bulb, that would affect current, not voltage. The FET is 3 milliohms in series with bulb RL. So the entire supply should appear across the bulb as soon as the FET comes on. I'm guessing that this is the supply reacting to the load change, and the capacitor should fix that. Batteries will behave better than a supply, for the most part. We probably don't want to measure the supply response as that will distort our RMS findings. We can work on compensating for funny waveforms later, now I want to get the RMS values right on with good clean power.

Thanks for your effort,

-- Alan


----------



## Alan B (Oct 3, 2008)

Will,

I went back and reviewed your updated post. Great work! There appears to be a duplicate/wrong data on button press #7.

I'll try to add that to the spreadsheet and see what it reveals.

-- Alan


----------



## JimmyM (Oct 3, 2008)

Will,
Does the voltage always tail off like that, even on higher duty cycle measurements? Just looking at the wave form, it looks like the FET isn't turning off fast enough. Is the inductance of the bulb that significant?
Also, a PWM value of 1 is awefully low. In use, the duty cycle will never be that low except during soft-start. I would sacrifice PWM=1 stability/accuracy for accuracy higher up in the range.


----------



## Alan B (Oct 3, 2008)

*New Data Looks Good*

I collected some new data sets and did some analysis. The data is in the spreadsheet on the 081003 page (page 4).

http://spreadsheets.google.com/pub?key=pJxYQtNDGEkRr3fAf2VSZQQ

Test Conditions and Equipment:

Sled PCB, Tiny25 CPU, NiMH C Battery 10 cell, rested
10K load resistor, DiSco USB scope, FP8 0.94 software

Collected data files for Feedback mode, Floating point mode,
and PWM test mode.

Analyzed the data files with a Python program that computes Vrms and duty cycle from the samples.

Neglected to turn on the B channel of the scope so used 12.0 volts for supply. This value can be verified in the data for the A channel when the output is high, and is valid since the load here is light and we are not testing for distorted waveforms in these tests. With this light load the voltage does not sag.

The ADC was uncalibrated and default values were used for resistors. This resulted in the regulated output values being low. Added a column with scaled results based on the 12.0 volt output setting. This scaled column shows good voltage accuracy for both the feedback and the floating point algorithm for all voltage settings.

We need to understand what is happening with Will's tests vs these tests. Part of it may be waveform distortion from the power supply. But there appears to be more than that.

-- Alan


----------



## JimmyM (Oct 3, 2008)

Those results actually look pretty good!
This shouldn't be used for less than 25% duty cycle anyway. That's the equivalent of running a 10V bulb on 20V. It's just outside the realm of reasonable use. Error above 25% duty is 0.61% or lower.
That's pretty darn good.


----------



## wquiles (Oct 3, 2008)

Alan B said:


> Will,
> 
> I went back and reviewed your updated post. Great work! There appears to be a duplicate/wrong data on button press #7.
> 
> ...



Opps - sorry :mecry:

I updated press#7 numbers 

Will


----------



## wquiles (Oct 3, 2008)

JimmyM said:


> Will,
> Does the voltage always tail off like that, even on higher duty cycle measurements? Just looking at the wave form, it looks like the FET isn't turning off fast enough. Is the inductance of the bulb that significant?
> Also, a PWM value of 1 is awefully low. In use, the duty cycle will never be that low except during soft-start. I would sacrifice PWM=1 stability/accuracy for accuracy higher up in the range.



Jim,

You know, thanks for pointing that out. This "bothered" me, but I was not thinking about it much as to "why". Looking at the schematic it looks like for a discharge path, that the 100K would be too big, so the gate must be trying to discharge via the Tiny85 instead. So I decided to try a couple of values, 10K and 1K specifically. But to do that, I started looking at a second trace - the Vgate to test if in fact there is a noticeable delay - guess what? Just like you though, there is a significant delay for the OFF!

Here is the same old program (v.93) but with the second trace. Yellow trace is still the voltage across the bulb as always, and the blue trace is the Vgate (never mind the actual amplitude as I can't ground that probe or I would short the bulb!).

Here is the circuit as before, with R6=100K as always:






and the same circuit after the first button press:






In both above you can see that once the voltage to the gate is turned off, it takes quite a while for this voltage to discharge and for the FET to turn off. Worst of all, the longer the FET is "semi-ON", the longer the FET is acting in linear mode and therefore heating up - not a problem now with this very low power bulb, but "significantly" a larger problem with the high power bulbs.


So then I tried using 10K instead of 100K. A "little" bit better, but still not "fast" enough in my book:






But look at things now with a value of 1K, much nicer, isn't? :devil: :






Here it is again (still with 1K), but at 10uS/div instead of 20uS/div:
First start:






After first button press:







So I decided to keep the 1K, and use real batteries for a change, to see what could change. I am using 3x 18650 LiIon cells (resting voltage of 11.8V) for this tests, but still using the low power bulb (since the bulb is a 13.5V bulb, I can't hurt it even if something goes wrong):






Here is how things look like (note the background getting brighter as the bulb gets a higher Vrms voltage). This is still using the older firmware (v.093) with the same resistor divider values and still using the same Vcal factor that I used earlier).

Starting up:
Vrms at the bulb (Fluke): 0.279V (we now know that due to crest factor this is not an accurate measurement)
Vbat (from scope during the ON pulse)= 10.4V






After the first press:
Vrms at the bulb (Fluke): 1.11V 
Vbat (from scope during the ON pulse)= 10.8V






After the second press:
Vrms at the bulb (Fluke): 2.04V 
Vbat (from scope during the ON pulse)= 11.2V






After the third press:
Vrms at the bulb (Fluke): 2.96V 
Vbat (from scope during the ON pulse)= 11.4V






After the fourth press:
Vrms at the bulb (Fluke): 3.99V 
Vbat (from scope during the ON pulse)= 11.4V






After the first press:
Vrms at the bulb (Fluke): 5.02V 
Vbat (from scope during the ON pulse)= 11.5V






After the sixth press:
Vrms at the bulb (Fluke): 6.00V 
Vbat (from scope during the ON pulse)= 11.6V






After the seventh press:
Vrms at the bulb (Fluke): 7.03V 
Vbat (from scope during the ON pulse)= 11.6V






After the eight press:
Vrms at the bulb (Fluke): 8.01V 
Vbat (from scope during the ON pulse)= 11.6V






After the ninth press:
Vrms at the bulb (Fluke): 8.98V 
Vbat (from scope during the ON pulse)= 11.6V






After the tenth press:
Vrms at the bulb (Fluke): 9.99V 
Vbat (from scope during the ON pulse)= 11.6V






After the eleventh press:
Vrms at the bulb (Fluke): 10.97V 
Vbat (from scope during the ON pulse)= 11.6V






After the twelfths press:
Vrms at the bulb (Fluke): 11.29V 
Vbat (from scope during the ON pulse)= 11.6V






After you press again, it goes back to the original value.


Will


----------



## Alan B (Oct 3, 2008)

Good catch, Jim.

Good work, Will.

There is something else wrong here. 

The Tiny85 has an impedance of about 70 ohms either high or low to the supply rail/ground. I wonder if the low side FET driver in this particular Tiny85 is blown.

The 100K should make NO difference. It is there for one purpose - to keep the FET off when the CPU is asleep/booting up/etc.

-- Alan


----------



## wquiles (Oct 3, 2008)

Alan B said:


> Good catch, Jim.
> 
> Good work, Will.
> 
> ...



How does your signal look like during the short time FET is turning OFF?

Can you post a picure or screen shot of this same measurement in your system with the USB scope? 

I will try another Tiny85 (I think I bought 3 of them), to see if it looks any different.

Will


----------



## Alan B (Oct 3, 2008)

wquiles said:


> How does your signal look like during the short time FET is turning OFF?
> 
> Can you post a picure or screen shot of this same measurement in your system with the USB scope?
> 
> ...


 
I will try and collect that waveform.

I wonder if the floating grounding is part of the problem. It might work better to use both traces and do A-B to get the bulb V, and keep the common ground in the usual place.

-- Alan


----------



## wquiles (Oct 3, 2008)

Alan B said:


> I will try and collect that waveform.
> 
> I wonder if the floating grounding is part of the problem. It might work better to use both traces and do A-B to get the bulb V, and keep the common ground in the usual place.
> 
> -- Alan



I am still using the old (V0.93), so I am still using the old #define INTEGRAL code

The floating ground for Vgate gives a false reference for the blue trace (so the amplitude is wrong, but the shape is still spot-on). But since the yellow trace is measuring right across the bulb, I can't use a common ground to measure the Vgate - I tried it and it shorts the bulb to ON full time (like I would expect since it effectively by-passes the FET).

Still, all measurements above were done without the second scope probe - just the one across the bulb, so there is no floating ground for the data collected after each button press.

Will


----------



## Alan B (Oct 4, 2008)

wquiles said:


> I am still using the old (V0.93), so I am still using the old #define INTEGRAL code
> 
> The floating ground for Vgate gives a false reference for the blue trace (so the amplitude is wrong, but the shape is still spot-on). But since the yellow trace is measuring right across the bulb, I can't use a common ground to measure the Vgate - I tried it and it shorts the bulb to ON full time (like I would expect since it effectively by-passes the FET).
> 
> ...


 
Rather than connect Scope Gnd to Bulb-, one could connect scope ground to board ground (Batt-), and connect probe A to Bulb+ and probe B to Bulb-; Then display A - B. This keeps all the grounds in the usual and expected places.

-- Alan


----------



## wquiles (Oct 4, 2008)

Alan B said:


> Rather than connect Scope Gnd to Bulb-, one could connect scope ground to board ground (Batt-), and connect probe A to Bulb+ and probe B to Bulb-; Then display A - B. This keeps all the grounds in the usual and expected places.



Alan,

Good point about letting the scope's built-in math work for us. I actually went a little bit further to try to understand a little bit better what is going on, specially with the change in R6 from 100K to 1K. For these tests, I am using a 6.5Ohm 100watt resistor - roughly 2 amps from the 13.5V supply that I am using. It gets toasty when the duty cycle is about 100%!!! :naughty:

Here is a new scope shot and Fluke measurement, of your latest firmware (V0.94), right after startup. This is using R6=100K. Note the Vrms on the Fluke (although not accurate as an absolute value due to crest factor, we can still use this measurement for A vs. B comparisons):






Here is a close-up of the scope:
Ch1 - Yellow trace: Vbat + (which is also Vbulb+)
Ch2 - Blue trace: Vgate +
Ch3 - Pink trace: Vbulb -
Math - Red trace: Ch1 - Ch3, or Vbulb+ - Vbulb- => voltage across the bulb's pins
I am triggering on Ch2, which is the Vgate+.






A couple of things to note:
- Note the Vgate going high, which causes a dip on the Vbat+ (remember we just switched a 6 Ohm resistor across the PS)
- Note when the Vgate is switched off (blue trace) that it is a very slow process to switch off the bulb
- The FET is in linear mode for a relatively long time - not a good thing!
- Note also that as Vgate is "dying off", it has a couple of steps, not just one.
- Note the Vbulb on the Fluke as being 1.48Volts


OK, lets do the same thing, but this time using R6=1K. This is also recorded right after starting up like above - just the resistor change.






and the close-up of the scope:






A couple of things to note:
- The "dip" on the battery is about the same, but now we have what looks to be like an inductive kick-back on Vbatt when the FET finally turns off.
- Note when the Vgate is switched off (blue trace) that it is much quicker now, but still not as fast as when going ON.
- The FET is in linear mode for a relatively shorter time - a good thing!
- Note also that as Vgate is "dying off", it "still" has a couple of steps, not just one.
- Note the Vbulb on the Fluke as being 0.36Volts - since the "area under the curve" is now smaller, the Fluke correctly calculates a smaller Vrms value.



Here are a few more shots, but this time pressing the button.
After pressing once:






After pressing twice:






After pressing three times:






So we "still" have what looks like an RC time constant affecting the FET turning off. Things are much improved with R6=1K, but I don't think we know everything that is going on yet.

Have you been able to capture these traces in your setup? I am curious to see if it is something just in my setup :mecry:

Have you tried different values for R5 - any particular reason you went with 68 Ohms?

Will


----------



## wquiles (Oct 4, 2008)

(duplicate post - ADMINs, please delete)


----------



## JimmyM (Oct 4, 2008)

Alan may be right, it looks like the Tiny85 pull-down FET is shot ot out of spec. The 100K is not meant for gate pull down. It's just a safety-off. With the 1K in its place, it's now acting as a pull-down. Like the uP is only performing active pull-up. Using a passive pull-down resistor now actively loads the uP output whenever it's on. It will lower the voltage at the gate by acting as the lower half of a voltage divider. The upper half is the resistance of the Tiny85s pull-up FET.
Just for sh*ts and giggles. Swap out the Tiny85 and see if the condition is the same. I don't like the look of that Vgate. If it were just one steep RC discharge curve, that would be fine. In reality, all gate voltage curves will be an RC charge or discharge curve. The gate has capacitance, and it is charged or discharged through a non-zero resistance of some kind.
But the double RC curve with that plateau in between will spell doom for the FET under high load conditions. An FET driver does all the heavy lifting with respect to the gate. It has tenths of ohms of resistance, and can pass several amps of current to drive the gate hard. The driver input has nF-pF of capacitance and can be passively pulled up or down by a 10K resistor quite easily.
For experimental purposes, the Micrel MIC4422 (Digikey P/N 576-1195-ND) would be an interesting experiment.


----------



## Alan B (Oct 4, 2008)

Will,

Nice scope work. 

My setup is taken apart right now, was doing some cleanup on the bench. Will try to get some data this weekend. However I can see from the data I already have that my FET is turning off much faster. The sampling rate on this inexpensive USB scope is 5uS. The one trace I have with the WA1185 bulb shows less than 5uS turn-off, and no 'tail'. On that trace there are two off transitions, one has a single in-between value, the other has no in-between values:

70 -0.0273620218022786
75 -0.0707670763079939
80 3.66206761118352
85 13.645230147498
90 13.5584200384866
95 13.5150149839809

4060 -0.157577185319424
4065 -0.244387294330855
4070 -0.244387294330855
4075 15.0341918916809
4080 13.4716099294752
4085 13.3847998204637


The series gate resistor is chosen to keep the max pin current within the chip's ratings while charging the FET gate capacitance.. The limit is 40mA per pin, and the internal chip impedance is 65-70 ohms. Note that connecting a high capacitance probe or meter across that pin might exceed the 40mA.

How warm is your FET getting? This is pretty slow turn-off, much worse than it was calculated to be.

If the micro's FET is 70 ohms to ground during turn-off the 1K would not make much difference, hence the low side FET must be non functional. Or there is a diode in series there that we don't want.

-- Alan


----------



## JimmyM (Oct 4, 2008)

Alan B said:


> The one trace I have with the WA1185 bulb shows less than 5uS turn-off, and no 'tail'.
> -- Alan


A larger load will affect the gate characteristics. Since the gate acts like it has a capcitors from itself to both the source and drain. Resistance between the drain and ground (via the bulb) will alter the gate charge-discharge. A low impedance charge/discharge path can largely mitigate that. If the Tiny85's pulldown FET is bad, then that would definitley be one cause. But why did the FET go bad? Too much load from a large gate capacitance? Nevertheless, are we worrying about a condition that will most likely never occur? <1% duty? We're all theorizing about what might happen at high load. Why not just connect a big bulb (64623) and see what happens. The FET would be the only victim.
I think I have a TPS2829 on a SurfBoard in my shop.
Would it help if I could round up a couple and send them to you guys?


----------



## wquiles (Oct 4, 2008)

Alan B said:


> You might want to trim down the duplicate post.


Opps - don't know hot it happened 




Alan B said:


> My setup is taken apart right now, was doing some cleanup on the bench. Will try to get some data this weekend. However I can see from the data I already have that my FET is turning off much faster. The sampling rate on this inexpensive USB scope is 5uS. The one trace I have with the WA1185 bulb shows less than 5uS turn-off, and no 'tail'. On that trace there are two off transitions, one has a single in-between value, the other has no in-between values:
> 
> 70 -0.0273620218022786
> 75 -0.0707670763079939
> ...



The FET has never been warn - this is still too low power for the FET.

But clearly, you were right about the low side FET not being functional. I changed to a new Tiny85 and after programming it, things are behaving more like we expected - so yes, it appears that the output pin on my initial Tiny85 was somehow damaged during testing 

At any rate, the new Tiny85 is doing good, so I put back the 100K for R6, and still using a power resistor for output.

Initial is initial output (V0.94 firmware). Note that the ON and OFF times are much quicker now, as we expected!. 






After first press:






After second press:






After third press:






So we are back to making progress again. I will try later today using a real bulb to see if those battery spikes during ON and OFF are real or not 

Also, I will need to collect some new data as the actual Vrms should be a small amount smaller, since the pulse width is slightly narrower now :mecry:

Will


----------



## Alan B (Oct 4, 2008)

Here are my Drain and Gate signals, hot off the USB scope:






-- Alan


----------



## Alan B (Oct 4, 2008)

Will, glad that turned out to be a tiny problem (sorry). As to how the CPU driver became damaged, we might speculate, but with a prototyping board it is pretty easy to have a momentary problem. With the series resistance limiting the current to within chip specs it should not be a problem.

The gate and drain waveforms look pretty reasonable in both Will's new setup and mine. Someone will have to set up a more robust test for larger current bulbs, the prototyping setup won't handle the current properly.

The calibration appears to be 'adequate' at this point, so perhaps we can move on to other things.

Jim, you might consider putting space on the test board for the driver, and a jumper to select between direct/buffered drive. Then it would be easy to try that.

It is interesting even with the very long off-time the FET didn't get warm.

At this point it seems as though only one or two test boards are needed, so perhaps just making them with the laserprinter is the way to go. I don't have to have one, so maybe LuxLuthor and Jim are it for the moment? Did I miss any??

-- Alan


----------



## Mr Happy (Oct 4, 2008)

Alan B said:


> Will, glad that turned out to be a tiny problem (sorry). As to how the CPU driver became damaged, we might speculate, but with a prototyping board it is pretty easy to have a momentary problem. With the series resistance limiting the current to within chip specs it should not be a problem.


Could the "OFF spike" perhaps have enough energy to damage the Tiny85 output circuit? In other cases, inductive spikes can be very dangerous to electronics. I wonder whether it might be appropriate to place a diode somewhere to ground any back EMF and prevent it feeding back into the Tiny85? (If indeed there is a location a diode could be placed without affecting the normal operation of the circuit.)


----------



## Alan B (Oct 4, 2008)

Mr Happy said:


> Could the "OFF spike" perhaps have enough energy to damage the Tiny85 output circuit? In other cases, inductive spikes can be very dangerous to electronics. I wonder whether it might be appropriate to place a diode somewhere to ground any back EMF and prevent it feeding back into the Tiny85? (If indeed there is a location a diode could be placed without affecting the normal operation of the circuit.)


 
The pin damaged on the Tiny only connects to two things - a resistor to ground, and a resistor to the gate of the FET.

Would this be bulb inductance? Coupled through the capacitance of the FET to the CPU pin? We could model that if we knew the inductance. I think the rest of the values are known.

I've been subjecting my test board to a lot of abuse. Showing it to people, handling it, carrying it to work, using different power sources, hooking up various probes, bending the parts, taking the bulb in and out, trying new software, etc. So far no failures.

Our statistics are pretty small. Hard to draw any conclusions from that.

-- Alan


----------



## wquiles (Oct 4, 2008)

I like Mr. Happy's idea for a protection diode, but I honestly think it is more likely that I had a brief short in mine while moving probes, etc... Having "tall" components like I have in my breadboard makes it very easy to do that 

Will


----------



## Unforgiven (Oct 4, 2008)

Continued


----------

