64 posts / 0 new

## Pages

Author
Message

Hi All,

I have not done any circuit design in 40 years, and that was freshman circuits (from Smith) and a senior MCU project (w/ 6800), but I have done a lot of embedded s/w study and development.  I got into AVR MCUs about 9 months ago, and looking for smal projects to get my hands dirty.

Just for fun I wanted to see if I could design and prototype a 12v pulse for potential use in UPDI protocol.  The objective is learning correct electrical and software design.  Optimal end-cost of the implementation is not my objective, but comments appreciated on that in any case.

The components are AVR 5v MCU (e.g., mega328 or mega32U4), and the usual capacitors, resistors, etc.   My approach is to use a charge pump.  In three cycles I intend the following:

1) charge C1 from MCU

2) charge C2 from MCU

3) charge C3 from C1, C2 and MCU +5v in series

constraints:

1) The output should provide 11v-12v for a period of 100 ms.

2) There is no limit on time to charge C3, before 12v source becomes available.

3) The max output current draw is guessed to be 2 mA.  T

4) Since the MCU can provide ~ 40 mA to the pin I use 1 k resisters to limit  current to 5 mA.

5) With 0.1 uF caps, the time constant is (1000 ohm)*(0.1e-6 F) = 0.1 msec, clock at 8-ish kHz

In the table, +5v means pin is output-high, gnd means pin is output-low, inp means input-low.

Note: On at least the mega328 the transition from output-high to input-low requires two separate instructions.

Is this sufficiently safe to hook up and go for a run to measure the output voltage?

In the diagram C1 is the lower 0.1 uF cap, C2 is the upper 0.1 uF cap and C3 is the right hand side cap.

## Attachment(s):

This topic has a solution.
Last Edited: Mon. Oct 14, 2019 - 12:53 PM

If you do that what voltages will be at B2 and B3 during 3rd time period?  What are max ratings for the ports?  Do you think they are compatible?

David

edit - typo

Last Edited: Sat. Sep 28, 2019 - 03:45 PM

In the third period ports B2 and B3 are input so essentially open, right?  The voltage will be above 5 v, but does that matter?

Yes, it matters.

For example, every AVR port pin has a pair of protection diodes. One  diode is from the port pin to ground and the other is from the port pin to Vcc. They are arranged so that the  diodes are reverse biased when the port pin is between Vcc and Ground. They are there to protect against static discharge. So, when you set those pins to be inputs, they are open circuit, sort of - until the pin voltage goes above Vcc or below ground by a few tenths of a volt.

Not sure if it is enough, but a simple charge pump will generate approximately 2xVcc. In a pinch, you can use a MAX232 and not bother with the RS232 interface circuitry. If course, this will side-step the goal of designing a circuit!

Jim

Until Black Lives Matter, we do not have "All Lives Matter"!

Last Edited: Sat. Sep 28, 2019 - 04:22 PM

fyi, there's a shunt regulated 12.7V boost converter in STK500.

Schematic and layout | STK500 (sheet 6, lower right)

"Dare to be naïve." - Buckminster Fuller

Thanks all.   At least I didn't smoke a chip.   Maybe I get a chance another time.

Edit: And 328 data sheet says max input rating is Vcc+0.5v.  Lesson learned.

Last Edited: Sat. Sep 28, 2019 - 04:42 PM

And someone else had suggested ST662:

You could use PWM & make a little boost converter  5V to  12V...just need coil, diode, transistor & a few caps

You can even generate very high voltages, enough to treat your friends.

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Thanks.  That might be fun.  I will look into it.  I've gone back to my intro textbook and re-reading the semiconductor chapters.

When I was an undergrad many of my friends were EEs; they seemed to love the power converter class the best.  (Middlebrook and Cuk were the instructors!)

That really needs some feedback. You also need to choose a value for L1 that is appropriate for the "square wave" that drives the switch. If it does not have feedback, then you need to be careful of both the voltage rating of C1 and the reverse breakdown of D1. Without feedback, the output voltage is quite unpredictable and can be relatively high. If C1 is high enough in value without feedback, it can actually be more than a bit hazardous (short duration high current at high voltage).

Jim

Until Black Lives Matter, we do not have "All Lives Matter"!

That really needs some feedback

Oh absolutely!! I'm assuming the ADC is used for measuring so the pwm will maintain the proper setting.  At low freq (say 75KHz) (and not super efficient), no gate driver is needed (just 50 ohms to an AVR pin).

You can get 78KHz from a 20MHz AVr & 256  res PWM.

Note the standard simple boost cannot be 100% shut off (fwd diode), but an output transistor can switch the loading as desired

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Thanks.  Will submit for review before power-on!   (I have PhD in ECE/control just to indicate I know enough to be dangerous!)

I've just finished fixing a few problems with someone else's design on a  product that does just this. It controls a bock converter using PWM.  Interestingly the previous engineer used only the Integral term in PID control to control the PWM and it took absolutely ages to start up (About 2 seconds). I added some Proportional signal which made an order of magnitude difference but 'I couldm't control the overshoot.

I shall watch this thread with interest in your progress.

<edit>Silly typo: Changed "could control" to "couldn't control". Meaning I could not eliminate it completely.</edit>

Last Edited: Sun. Sep 29, 2019 - 08:20 AM

I added some Proportional signal which made an order of magnitude difference but 'I could control the overshoot.

Interesting, in that I do neither (though I am well versed in both). I make PWM adjustments simply step up or down as needed, maybe 100 adjustments a second, sometimes with a count or two of hysteresis to prevent chatter.  If the error to desired target level is large & above some threshold I take bigger steps (say 8x) & halve them at each iteration (4 2 1 ), until back to single stepping, now close around the target.  Sometimes I'll make the the PWM turn-down rate 2x faster than the turn-up rate, which reduces ping-ponging. With software you can do these fancier things that are very tough with opamp circuitry.  Of course, each has its merits.

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Last Edited: Sat. Sep 28, 2019 - 07:58 PM

Back 20 years ago I made 12V just for fun with a 8515 with a ferrit bead as a transformer, and I was surprised that I actually could make 12V 5ma with just 2 5V port pins.

Was that really a ferrite bead which is quite lossy? Most ferrite beads of that era were around 0.7cm OD, maybe 0.5cm long and had a hole of a few mm in diameter. And they only allowed one wire through the hole because the hole is  small.

I can believe using small ferrite core that might be 1-2cm OD, or larger.

Jim

Until Black Lives Matter, we do not have "All Lives Matter"!

Last Edited: Sat. Sep 28, 2019 - 08:58 PM

But nowadays you can just be lazy and pick a cheap boost controler like the sx1308.

Basically like the circuit in post #8 but instead of a MOSFET, you get MOSFET + control logic in a single package. I've tested this chip with crap components from Aliexpress and it works fine for 150mA or so (5V -> 12V), more than that and the poor quality inductor I'm using saturates and starts to heat up. For UPDI it should be more than enough.

Last Edited: Sat. Sep 28, 2019 - 10:45 PM

Perhaps they have an other name, it was a bead about 7 mm i diameter (I lived in US at that time so 1/4 inch I guess)made out of ferrite. It had a hole about 3mm, and then about 2 mm high.

There was plenty of space to make a transformer with a total of 20 turns with wire you can solder. (not sure for correct name)

ka7ehk wrote:
Was that really a ferrite bead which is quite lossy?
reduced loss :

Wirewound Ferrite Beads | Coilcraft (3.43mm max height, approx 2 ohms min for 310mA max)

"Dare to be naïve." - Buckminster Fuller

So just taking my time to look at this, but wanting to post to keep the thread alive.   Right now looking very electronics-ish but the AVR coding will come along later.

Here is initial diagram.  I may modify a bit on the way.  I wonder if we can keep the inductor size small by adding a resistor in the closed path with the FET.

Below B0 is the AVR output for switching and A0 is the AVR analog input for measuring output voltage, scaled to be in the range 0-5v.

EDIT: I believe there is a sign error in the first equation: Ldi/dt = - (Vo - Vi)

Last Edited: Sun. Sep 29, 2019 - 05:44 PM

I wonder if we can keep the inductor size small by adding a resistor in the closed path with the FET.

No, resistance increase losses

You calculate ckt by saying avg inductor voltage must be zero.  For %v in & 12V out , this gives a duty cycle of 58.3% (neglecting losses & drops)

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Let me pretend I still know this stuff (closed case):

V and L are constant in this case (assuming the MOSFET is a perfect switch) so they can be outside the integral:

Initial time is zero, so the equation for the closed case is

The other, lol, won't even try*.

* well, maybe later.

edit: This is a schematic of the idealized circuit:

Last Edited: Sun. Sep 29, 2019 - 07:24 PM

No integral or integration is needed, thus avoiding sudden sleepiness syndrome.  Just assume the AVG inductor voltage must be zero (equal & opposite areas).

The Volt-seconds areas during the on-time: Vin(DT) must match with the off-time: (Vout-Vin)(1-D)T   ...

or  simply Duty=(Vout-Vin)/Vout

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Are you sure? I don't believe the duty cycle will be independent from load.

edit: Anyway, your idea reminded me that indeed, some kind of conservation of energy approach will probably simplify the problem.

That is, in the steady state, the energy stored in the inductor will equate the energy loss in the load.

Last Edited: Sun. Sep 29, 2019 - 07:41 PM

Ok, here we go

Energy stored in an inductor:

So substituting the equation

assuming I0 is zero, that is, the inductor gets fully discharged at each cycle, the energy stored in our inductor is

where tHIGH is the time the MOSFET is on (HIGH part of PWM wave)

During the discharge part, this energy is consumed by the load. The energy dissipated in our resistive load is:

where tLOW is the time the MOSFET is closed (LOW part of PWM wave)

Now, considering the duty cycle formula is:

and the frequency of the PWM wave is

If I didn't mess up somewhere, the duty cycle is given by the formula

where

Let me exemplify with f=1MHz, L=1uH, R=1 kohm, VIN=5V and VOUT=12V:

k=173.6 gives d aprox. 10%

With a heavier load of 50 ohm, we get k=8.7 so d is aprox. 38%

I have not designed these beasts before, but doing some sanity checks on sizing.  For example, for a 1 uH inductor, and constant 5 v supply, the current grows like 5 A / us when the FET is closed, right?  That's why I ask about putting a resistor in there to limit the current and be able to use small inductor.

Last Edited: Sun. Sep 29, 2019 - 10:30 PM

right

jim

Until Black Lives Matter, we do not have "All Lives Matter"!

MattRW wrote:

I have not designed these beasts before, but doing some sanity checks on sizing.  For example, for a 1 uH inductor, and constant 5 v supply, the current grows like 5 A / us when the FET is closed, right?  That's why I ask about putting a resistor in there to limit the current and be able to use small inductor.

In small aux supplies like this, a resistor can be a good idea.

Yes, it increases losses, but in such a circuit you are chasing simplicity, more than top end efficiency.

I would suggest adding a Zener clamp to the final Vo, which ensures the ringing voltage can never get out of hand, no matter what loads change.

For many applications, no analog voltage feedback could be needed, the Zener does the regulation.

I've seen some designs feed the Zener to a transistor base, so the collector goes low as a 'voltage reached' digital flag, but if you know the L,C,R & loads, and PWM, you now how long it takes to reach clamp voltage.

Checking Digikey, it seems 1uH thru 33uH are all much the same price, & in 0805, so you can select inductor to suit operation.

sparrow2 wrote:

Perhaps they have an other name, it was a bead about 7 mm i diameter (I lived in US at that time so 1/4 inch I guess)made out of ferrite. It had a hole about 3mm, and then about 2 mm high.

There was plenty of space to make a transformer with a total of 20 turns with wire you can solder. (not sure for correct name)

Most would call that a small ferrite toroid.

assuming I0 [iniital current] is zero, that is, the inductor gets fully discharged at each cycle

Well that might be nice, but it's not true for most real loading...the inductor is being charged ,or just supporting the loading (a triangle shape above zero, at an avg of the avg output current).

The current triangle looks more & more like an RC if its time constant is too fast.

During the "D" on time, the inductor has a voltage of Vin (neglecting losses, such as fet drop & inductor IR loss)  so the area is Vin*DT

During the opposite (off) time the inductor has a voltage of Vin-Vout (neglecting the diode drop)  ...Vout>=Vin, so the area (positive quan) is (Vout-Vin)*(1-D)T

Regardless of shape, the avg voltage must ALWAYS be zero

These for an avg of zero, these areas must be equal & opposite.   ...note that just like the Buck,  both L & T (period,freq) drop out.

Rearranging gives: Vout/Vin= 1/(1-D).

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Interesting, to me the idea of using an MCU to run a converter has merits.

Good to see people still investigate circuit operation by experimenting; I call it "Live" SPICE.

Find that it works best as it takes all possible practical parameters into account and due to its ad hoc/experimental nature gives one a much better chance to discover better solutions in terms of design and price.

Recently ran a few experiments with higher current (amps) boost, buck and buck/boost converters using the CTC on the 328 and found the mentioned resistor can be helpful.

The CTC of course can run things without processor support and checking it every few seconds or so is all that is needed for battery charging from a solar source.

I used an efficient inductor and used a 1.5" yellow/white core from a SMPS with 25 turns of 1mm enamelled copper wire, some 50uH.

(Great to be able to use that inches again, its illegal here)

Was able to get some decent currents and efficiency of over 80% with out to much effort.

So think a decent inductor, if you have space, is better than trying to scrimp on it.

Last Edited: Mon. Sep 30, 2019 - 12:38 AM

I wonder if we can keep the inductor size small by adding a resistor in the closed path with the FET.

To be clear, no, a certain output rating will require a certain size inductor.  Adding a resistor will not reduce the size of the required inductance, but will increase the losses, and require something  to work harder to make up for it.

Adding a resistor might help avoid saturating the inductor, but hopefully you aren't doing that in the first place.   A current mode controller chip, will limit the current (indirectly including the inductor), anyhow.

A series resistor speeds up the L/R time constant, but lowers the final target (Ifinal) to V/R.

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Wikipedia's page on switch-mode converters says that as long as the converter operates in "continuous" mode, the output voltage is determined by the input voltage and the duty cycle.

I interpret "continuous mode" means that the current is always being limited by the inductance - no zero-current initial state, no steady state at the end, no saturation effects, no imperfect components.

Getting that to work in practice means picking appropriate inductances, frequencies, paying attention to the output current, and so on...

Now, the needs of UPDI are a bit "interesting" WRT this problem.  Efficiency is unimportant, and the load current is going to be very low.  Also, you need to switch the signal between the 12V value, and a regular 5V (or lower) logic signal level.  Preferably without frying the pin that the logic signal is coming from.

westfw wrote:

Wikipedia's page on switch-mode converters says that as long as the converter operates in "continuous" mode, the output voltage is determined by the input voltage and the duty cycle.

I interpret "continuous mode" means that the current is always being limited by the inductance - no zero-current initial state, no steady state at the end, no saturation effects, no imperfect components.

Getting that to work in practice means picking appropriate inductances, frequencies, paying attention to the output current, and so on...

Now, the needs of UPDI are a bit "interesting" WRT this problem.  Efficiency is unimportant, and the load current is going to be very low.  Also, you need to switch the signal between the 12V value, and a regular 5V (or lower) logic signal level.  Preferably without frying the pin that the logic signal is coming from.

Yes, another thread mentioned 2x VCC for threshold, and it will be quite low currents.

At low tens-of-uA levels, the flyback converter will mostly be in ringing mode, a long way from continuous conduction.

You may find even the smallest PWM setting, generates enough ringing energy to pulse above 12V, hence the suggestion for a simple clamp zener, as you do want to avoid frying the device you are trying to program !

At low tens-of-uA levels, the flyback converter will mostly be in ringing mode, a long way from continuous conduction.

Nobody mentioned flyback, we are talking about a boost converter! Did you see a transformer fly by?

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

avrcandies wrote:

At low tens-of-uA levels, the flyback converter will mostly be in ringing mode, a long way from continuous conduction.

Nobody mentioned flyback, we are talking about a boost converter! Did you see a transformer fly by?

Hmm.....  a transformer is not a required part of flyback :)

The important detail of a flyback converter, is that the output diode conducts as the inductor flys back, so the diode is ON when the switch is OFF.

In the other type, a forward converter, load transfer is also when the switch is on, and likewise that may be transformer, or simply series inductor based. (called buck in the USA )

Hmm.....  a transformer is not a required part of flyback :)

I'll mostly disagree, since that is not the definition of a flyback converter, as far as I've heard.   It is derived from a boost or perhaps buck-boost type, but that does not mean it is a boost.

I think another hearty bowl of solder soup will settle the matter for all.

The flyback converter is an isolated power converter. The two prevailing control schemes are voltage mode control and current mode control (in the majority of cases current mode control needs to be dominant for stability during operation)

Flyback converters are one of the simplest DC-DC converter topologies to include electrical isolation. Although generally only viable for lower range power supplies (up to 100W), they do have a number of advantages. Other than the converter’s inherent simplicity, perhaps the greatest of these is that the design does not require an additional inductor. The transformer provides isolation, and yet also functions as a pair of coupled inductors

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Boost/flyback the design procedure is much the same. Whilst if someone said ‘flyback’ converter, i’d expect to see the transformer. Where it gets fuzzy is where you have a tapped inductor or ‘autotransformer’ for a greater boost voltage. Is that a ‘boost’ or ‘flyback’ converter?

Yep, that seems to be at least the standard "naming convention"

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Candyman, you are correct, but so is Who-me. Blue Steel, LaTigre or Magnum?

I have some simulations in Octave going.   Here is the set of equations:

I'm simulating, in Octave, from initial condition with capacitor discharged.  I wanted to see the start-up operation.   For sample period of 10 us I had to push the inductance up to 300 uH before I was able to achieve steady state.  I want to dig into that.   The following is with L 300 uH, C 10 uF, R 12 kohm and d 7/12.  In the following iL is in amps and Vo is in volts.

Should some evil, barefooted brat point out Roman Black's work?  http://romanblack.com/smps/conv.htm

I built one of his buck regulators to see if I could, grabbing junk box parts with values in the ballpark of his. Would you believe the stupid thing not only worked, but had nice characteristics.

If you don't know my whole story, keep your mouth shut.

If you know my whole story, you're an accomplice. Keep your mouth shut.

Yeah, if the frequency is just 100kHz, you will need a sizeable inductor. Normally if you want to use small inductors, F should be a lot higher, like 1MHz or so.

why would you use Octave?

Get a copy of LTspice...you will have a much better simulation (example inductor series resistance), transistor response, etc

https://www.analog.com/en/design-center/design-tools-and-calculators/ltspice-simulator.html

Try some of the many included circuits they include ...amplifiers, transistors, power circuits, timers, etc...you can see how they run...FREE

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Last Edited: Thu. Oct 3, 2019 - 04:32 PM

avrcandies wrote:

why would you use Octave?

Get a copy of LTspice...you will have a much better simulation (example inductor series resistance), transistor response, etc

https://www.analog.com/en/design-center/design-tools-and-calculators/ltspice-simulator.html

Try some of the many included circuits they include ...amplifiers, transistors, power circuits, timers, etc...you can see how they run...FREE

There are Mac and Windows downloads but no Linux.  Luckily, my there is NGspice for Linux, 600+ page manual, tutorials.  And it's integrated with KiCad.  And comes with shared library that I can link into my AVR chip simulator.

MattRW wrote:
There are Mac and Windows downloads but no Linux.
Way back, LTspice IV ran well on Wine 1.

LTspice XVII apparently runs well on Wine 4 though does have some defects, with workarounds, on CrossOver 18.1 on Chrome OS.

https://www.analog.com/media/en/simulation-models/spice-models/LTspice_ShortcutFlyer.pdf?modelType=spice-models

[page 2]

-wine Force use of WINE(Linux) workarounds

WineHQ - LTspice/Switcher CAD

LTSpice XVII | What Runs | CodeWeavers (CrossOver)

LTspice | Design Center | Analog Devices

edit :

Running Under Linux - LTwiki-Wiki for LTspice

"Dare to be naïve." - Buckminster Fuller

Last Edited: Sun. Oct 6, 2019 - 02:35 PM

In this note there is a formula relating switching frequency and inductor size for continuous operation: min L > (Vo * period)/(16 * load current).

I have a simulation going in ngspice: it takes much longer than my octave sim, so thinking that is good to verify, and not sure it can be hooked up to a AVR chip sim.

I'm not sure operating in continuous mode with switching frequencies generated by AVR chip will be practical.

fyi, one tinyAVR with a boost converter :

ATtiny43U - 8-bit AVR Microcontrollers

"Dare to be naïve." - Buckminster Fuller

I'm not sure operating in continuous mode with switching frequencies generated by AVR chip will be practical.

Be sure to use an AVR that has the high speed PWM mode, such as the tiny85.  You can easily generate 75 or 100 KHz for your booster & it will work great.  Grab a fet, diode & inductor & build one up!
In a hour you will have your voltage!

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

gchapman wrote:

fyi, one tinyAVR with a boost converter :

ATtiny43U - 8-bit AVR Microcontrollers

Interesting, but note it is not a 12V capable boost design...

" Boost Converter: Built-in boost voltage converter providing 3V to the processor while only requiring between 0.7-1.8 volts from its external power supply (1.8-5.5 volts when the voltage converter is bypassed). "

Last Edited: Sun. Oct 13, 2019 - 12:21 AM
This reply has been marked as the solution.

The original cap booster idea was dismissed because of the internal pin clamping diodes, but seems to be easy to overcome in various ways (diodes).

Some advantages are it uses common parts and its quite hard to get into trouble. Diode selection can be used to tweak max voltage, cap values can be tweaked as needed also. The output can be clamped, but with component value selection one could probably eliminate the need (or maybe use a resistor to create a minimum output load). Not much thinking required on the software side, either.

This version uses a complementary output pwm (or similar), but adding another diode and cap would then need only a single pwm output. I'm sure there are a thousand and one variations.

I used a max232 type chip for 12v when I made my avr 'Fuse Buster'-

http://www.mtcnet.net/~henryvm/4AvrFuseBuster/4avrfusebuster.JPG

but I also had an old style r232 port so had that available anyway.

edit-

also added an npn version, and changed the diodes to bat41 type to make up for the losses.