Adventures in TinyAVR 1-Series

276 posts / 0 new
Last post
Fescron
Offline
Last seen: 15 hours 49 min ago
Joined: 10/17/2020 - 10:16
Posts: 204
Location: Belgium

C5 will indeed be a decoupling capacitor, it’s a typical value for one of those. I’m pretty sure C4 in the feedback-loop makes this an op-amp integrator circuit. R6, R7 and R8 might be there to facilitate “DC-gain control”. But I can be wrong about it, haven’t looked at it too closely. Maybe you can find more info in https://www.electronics-tutorials.ws/opamp/opamp_6.html

EDIT: On second thought, V+ is not connected to GND so it is definitely not a “regular” integrator circuit.

EDIT2: It’s also possible that PWM only works on lower frequencies due to gate-capacitance-related factors. Maybe the MCU pin can’t supply/discharge enough current to charge/discharge the gate-capacitor fast enough.

gchart
gchart's picture
Offline
Last seen: 9 hours 55 min ago
Joined: 03/19/2016 - 11:57
Posts: 3158
Location: Central IL
thefreeman wrote:
One question that have is about Timer/Counter D, when it says that there is one, does it means that only one of the 2 pins which can use it at a time, or is that not what it means at all ?

First off, thanks for the great diagram and explanation!

Nope, the one “timer” is one instance of a timer configuration. The different timers can be set up for different clock sources, dividers, etc for different frequency and resolution. Once you set that timer up, any of the waveform-output pins can be set up to have a PWM signal generated on them. Without looking at a datasheet, I think Timer D has 4 outputs? Note that the Timer D setup is a bit different. In that a couple of the outputs can be set to follow each other and such.

thefreeman
thefreeman's picture
Online
Last seen: 5 min 58 sec ago
Joined: 01/06/2020 - 09:56
Posts: 873
Location: France

You’re welcome and thanks for the answer. So I’ll wire my 2 channels to those TCD pins

gchart
gchart's picture
Offline
Last seen: 9 hours 55 min ago
Joined: 03/19/2016 - 11:57
Posts: 3158
Location: Central IL

Btw, I’ve got some Timer D sample code here:

http://www.ghart.com/blf/firmware/Tests/pwm_tcd_led.c

thefreeman
thefreeman's picture
Online
Last seen: 5 min 58 sec ago
Joined: 01/06/2020 - 09:56
Posts: 873
Location: France

Fescron wrote:
C5 will indeed be a decoupling capacitor, it’s a typical value for one of those. I’m pretty sure C4 in the feedback-loop makes this an op-amp integrator circuit. R6, R7 and R8 might be there to facilitate “DC-gain control”. But I can be wrong about it, haven’t looked at it too closely. Maybe you can find more info in https://www.electronics-tutorials.ws/opamp/opamp_6.html

EDIT: On second thought, V+ is not connected to GND so it is definitely not a “regular” integrator circuit.

EDIT2: It’s also possible that PWM only works on lower frequencies due to gate-capacitance-related factors. Maybe the MCU pin can’t supply/discharge enough current to charge/discharge the gate-capacitor fast enough.

I’ve seen it described simply as voltage follower, for example here.

Fescron
Offline
Last seen: 15 hours 49 min ago
Joined: 10/17/2020 - 10:16
Posts: 204
Location: Belgium
thefreeman wrote:
I’ve seen it described simply as voltage follower, for example here.

Yeah you’re probably right, I’m overthinking this Facepalm . I just saw a capacitor in the feedback-loop and thought hmm, I’ve seen that before in opamp-configurations, but I did not think about the other things on the input/output…


Perhaps it’s possible C4 is there to not “overload” the opamp-output if the gate (capacitance) of the mosfet gets charged? Although R6 already limits this current charging/discharging current.

R7’s function (because of the rather high and pretty common value) might be to make sure the gate get’s pulled low if the OPAMP is disabled (high-impedance output instead of a low/high?), and so to make sure the mosfet is open.

R8 (because of its common value) might be there to limit the current flowing in -V (which is very low but not totally non-existend) and so not mess with the voltage over Rsense (~high-impedance voltage measurement, a multimeter for example has an impedance in the MegaOhm-range).

icpart
Offline
Last seen: 13 hours 27 min ago
Joined: 04/15/2019 - 01:13
Posts: 332
Location: Bulgaria

Capacitor C4 is needed for AC frequency compensation of circuit because we don’t have any negative feedback and we will have open loop amplifier circuit which will oscillate very easy.
https://circuitdigest.com/tutorial/frequency-compensation-of-op-amp

thefreeman
thefreeman's picture
Online
Last seen: 5 min 58 sec ago
Joined: 01/06/2020 - 09:56
Posts: 873
Location: France
icpart wrote:
Capacitor C4 is needed for AC frequency compensation of circuit because we don’t have any negative feedback and we will have open loop amplifier circuit which will oscillate very easy. https://circuitdigest.com/tutorial/frequency-compensation-of-op-amp

Yeah that’s what I roughly got after a bit of reading, and unsurprisingly it is also necessary when using the same current control loop with a switching converter.

edit : thanks for the link.

icpart
Offline
Last seen: 13 hours 27 min ago
Joined: 04/15/2019 - 01:13
Posts: 332
Location: Bulgaria

Quote:
To explain a bit, the signal from the MCU (attiny1634) is divided down to Rsense level (50mV for a 10mΩ Rsense and 5A) by R3-R4, and is filtered by R4-C3 and fed to the non inverting input of the Op Amp, output to the gate of the mosfet, and Vsense to the inverting input, creating a feedback loop which makes the op amp adjust Vgs of the mosfet to maintain both its input at the same voltage. Reducing the duty cycle on PB3 lowers the voltage at the op-amp’s Vin+, for example at 10% we get 5mV, thus the gate voltage is lowered to get Vsense at 5mV, so 0.5A.

Some corrections: RC filter of that PWM DAC is R3C3 not R4-C3. I don’t like that one stage filtering. It is very slow and noisy in most of time. Also that slow down reaction of CC driver of input signals especcially in strobes. Better choice is to be used at least dual stage RC filter. Also another problem is heat from mosfet. Most of time at high currents and low Vf LED its need to dissipate a lot of wasted power and it is possible to overheat. That is major drawback for linear driver.
thefreeman
thefreeman's picture
Online
Last seen: 5 min 58 sec ago
Joined: 01/06/2020 - 09:56
Posts: 873
Location: France
icpart wrote:
Some corrections: RC filter of that PWM DAC is R3C3 not R4-C3. I don’t like that one stage filtering. It is very slow and noisy in most of time. Also that slow down reaction of CC driver of input signals especcially in strobes. Better choice is to be used at least dual stage RC filter. Also another problem is heat from mosfet. Most of time at high currents and low Vf LED its need to dissipate a lot of wasted power and it is possible to overheat. That is major drawback for linear driver.

Ah yes you’re right for the RC filter.
About it being slow, I’m not sure this is really an issue with 2pKhz PWM that we can do on the TCD counter at 10bit on those 1 series. Personally I don’t care about strobe in the slightest, but I guess some people do.

The advantage about linear drivers is that they’re quite simpler than switching topology, low BOM and board space, and if the feedback loop is done by the MCU instead of the OpAmp by reading the sense voltage by the ADC, like on the Unicorn 1.0, then the part count is ridiculously low. On this driver it consists of the RC filter, the sense resistor and the mosfet. 4 parts + the MCU ! It is then trivial to add another 4 low power/small parts for a lower current channel to achieve very low current.
Having this implemented in FSM/anduril would be great, but I know nothing about this, I don’t know if this is complex or not.

On the same light there is thermal compound between the mosfet and body to help thermal transfert, adding thermal pads might be a good idea, doesn’t help the efficiency though.

thefreeman
thefreeman's picture
Online
Last seen: 5 min 58 sec ago
Joined: 01/06/2020 - 09:56
Posts: 873
Location: France

Alright, here’s my first driver, actually first PCB I’ve ever designed. I started with a simpler linear driver to familiarise myself with Kicad :

Not tested

Features :

- 22-20mm, 18mm GND ring inner diameter.
- Constant current Linear 5A, can probably do more with better dissipation, can be configured for less of course.
- One sided, all 0603 passives (except one 0805 sense resistor) for ease of fabrication.
- Very low moonlight.
- Attiny1616 VQFN-20 or others compatible, 3 wires flashing.
- RGB AUX LEDs

Here is the schematics :

I explained the solution I came up with for moonlight on the Lume X1 thread

Basically with a 10mΩ sense resistor for example, the sense voltage becomes too low as we decrease Vref to reduce the LED current, with 10bit it goes down to 49μV (50mV/1023) on the lowest level, at this point even with a very precise OpAmp there is (probably) noise which makes the output flicker. We don’t want to use a bigger sense resistance as it would reduce efficiency and need a high power resistor.

The idea is to switch to a higher sense resistance for low currents, we can dim with 1:250 or 1:500 ratio that doen’t produce flicker, for example from 5A (50mV) to 10mA (100μV) with the high current range (10mΩ sense resistor), and then from 10mA to 20μA with the 5Ω sense resistor. We switch between the two sense resistors with a very low RdsON NMOS (Q2).

Simulation example :

Red is current and green is Vsense.

At first Q2 is ON so we’re in the high current range, then we dim to 10mA At 9ms Q2 is turned OFF to switch to the low current range, the reference need to be put back to 50mV, we also get 10mA Then we can dim to 20μA. Q2 RdsON needs to be very low as to not influence the sense resistance too much (Q2 is part of it). The mosfet chosen has a RdsON arround 2.2mΩ at 2.8V (Logic voltage). Due to RdsON variation (parts, temperature), the current won’t be as precise as it would normally be, but should still be OK for our application. We could use a gate driver with charge pump to drive the mosfet with a high Vgs and reduce its resistance but it increases BOM and board space.

Before I publish it on Oshpark I’d like people check that I wired the MCU properly, I wired the current control (PWM_CC) to a TCD pin since it can do higher frequency at lower power consumption. Also if anybody see any mistakes, or has comments for improvements.

Regarding Oshpark fabrication limitation, it seems like the copper can’t be closer than 0.4mm to the edge, so I added that much to be filed down, kind of annoying though.

The code will need some adaptation to switch between the two ranges, I imagine it’s not very complicated but I’m kind of dreading that part as I’m quite bad with this Tired I hope that Gchart or somebody else can help with this.

Parts : 

- LDO : 2.8V, this one only have reverse batt protection but not reverse current protection thus it doesn’t protect the MCU from reverse voltage, I haven’t found a 2.8V with both, MIC5225 has both but only 2.7V, will increase Q2 RdsON a bit. I don’t really want to use a diode due to the voltage drop.
- Q1 : needs a lot of margin for the safe operating area so it doesn’t blow (mosfets don’t like being in the linear region), this one is a bit expensive though, can use a PSMN2R4-30MLD instead, it seems like a popular reference.
- Q2 : lowest RdsON I could find at Vgs=2.8V in a 3.3×3.3 package, not exactly cheap.

I was also working on a boost driver based on the TPS61288, with the same multi sense resistor topology for very low moonlight, but Loneoceans showed his driver first, in his thread he said that he is using the same solution, so the good thing is that it confirmed for me that this is a viable solution. In his driver I am pretty sure he is using 3 sense resistors and 2 mosfet to achieve an even higher dynamic range!

gchart
gchart's picture
Offline
Last seen: 9 hours 55 min ago
Joined: 03/19/2016 - 11:57
Posts: 3158
Location: Central IL

Looks very nice! Here’s my thoughts after looking at it for about 1 minute:

  • With Oshpark, I run my copper to the edges without any problem. I wouldn’t worry about leaving a margin and then filing it down.
  • It seems like 0805 is kinda small for the main sense resistor? It seems like we usually have 1206 sense resistors due to the amount of current flowing through them.
  • A few months back I switched the order of the flashing pads, putting Gnd (V-) in the middle. It makes some layouts easier, plus if you reverse the programming key on accident, I feel like you’re less likely to fry your MCU from reverse voltage. Here’s a link to the updated programming key. And a pic of a recent driver using that layout:

thefreeman
thefreeman's picture
Online
Last seen: 5 min 58 sec ago
Joined: 01/06/2020 - 09:56
Posts: 873
Location: France

Thanks.

  • So I can put the edgecut directly at the final diameter ?
  • I think I saw some drivers with similar current with 0805 sense resistors, it would need to dissipate 200mW in the current configuration, I saw power rating of 500mW and even 1W for 0805. We can also reduce the resistance  a bit because now we have so much dynamic range and we can just use 1:250 dimming, not too much though because then the mosfet’s RdsON would influence the sense resistor too much, though some actual testing would be needed here.
  • I will change that, pitch is 0.127 1.27 mm (1/20inch) ?
gchart
gchart's picture
Offline
Last seen: 9 hours 55 min ago
Joined: 03/19/2016 - 11:57
Posts: 3158
Location: Central IL
  • Yup. That’s how I always do it at Oshpark and they come out just fine.
  • That’s fine then, no problems.
  • Sound good. And yeah, 1.27mm spacing (center-to-center). I use via’s (0.4mm drill with 0.75mm outer diameter), but it’s not necessary. They just help keep the pins in place while you’re flashing.
Quadrupel
Quadrupel's picture
Offline
Last seen: 1 hour 39 min ago
Joined: 12/03/2017 - 10:40
Posts: 730
Location: Lithuania

So many components … Smile , here how looks linear Infireon driver from Geko headlamp
Here Avsel linear

thefreeman
thefreeman's picture
Online
Last seen: 5 min 58 sec ago
Joined: 01/06/2020 - 09:56
Posts: 873
Location: France
Quadrupel wrote:
So many components … Smile , here how looks linear Infireon driver from Geko headlamp

I talked about it 5 posts above, the control loop is done by the MCU so no need for an OpAmp and all its passives, but this is entierly software and I don’t have the skills necessary, nor do I really want to learn them, and as far as I know Inferion code isn’t open source, if it was it would certainly be easier for people here to implement it in anduril.

Aside from that it can’t do low moonlight, they could add 4 small components costing a few cents for a second channel but they don’t I don’t know why. By the way this new headlamp looks really bad, maybe they are just really cheap.

Anyway I mostly made this linear driver as an exercise and also to propose something not too hard to build, moonlight capable, and a step up from 7135s. Next I will do boost and buck drivers because I like efficiency.

Edit : Avsel one is similar to any linear driver with OpAmp, except it doesn’t have a LDO, I don’t know why, can the MCU output a fixed voltage PWM no matter the Voltage on the VCC in ?
It doesn’t have moonlight levels.

loneoceans
loneoceans's picture
Offline
Last seen: 6 months 1 week ago
Joined: 01/08/2017 - 00:18
Posts: 283

There are MCUs on the market with integrated op amps, logic blocks, and some other peripherals. For example, some of the very low cost 8 bit PICs have op amps, likewise the powerful PSOCs and MSP430s etc (some with similar or lower price points than the AVR 8-bit MCUs). As far as I am aware though, there are no Attinys with integrated op amps though the 1616 does have some analog comparators and a small amount of programmable logic. That said, thefreeman's design probably offers some additional benefits such as Anduril and better control of the analog loop with component choice and feedback optimization. Even if constrained (at least for now) to the Attiny series, Anduril itself is worth the extra cost. thefreeman, nice job, always great to see more options with new designs cool. As a side note... the pandemic is really affecting supply chains around the world. Many of the QFN AVR1-series MCUs are sold out or very short in supply at the moment, with a lead time of almost 3/4 a year..

www.loneoceans.com/labs/

- Next-gen Switching Drivers: Lume X1 and Lume1
- High Power Boost Drivers: GXB100 GAN 100W, GXB172 17mm 50W
- Older: GXF22, GFS16, GXB17 & GXB20

gchart
gchart's picture
Offline
Last seen: 9 hours 55 min ago
Joined: 03/19/2016 - 11:57
Posts: 3158
Location: Central IL

Holy crap, I new the microcontroller market was getting rocked but I didn’t know it was this bad. I just check attiny1616 stock at the usual places and they’re ALL GONE. Scouring Octopart now… Sad

Edit… well, I think I’ve got 10 on hand which will last me a little while. I just went ahead and ordered 25 at Mouser, they’re expecting more sometime in July. If I can’t get them now, I might as well at least be in line for some.

thefreeman
thefreeman's picture
Online
Last seen: 5 min 58 sec ago
Joined: 01/06/2020 - 09:56
Posts: 873
Location: France

I planned to order at Farnell but that’s in UK, do they ship to US at reasonable cost ? Indeed stock has disappeared at Mouser, last time I looked there was stock Shocked , I should hurry to make my order.

I added the suggestion from Gchart :

- only one via for the flashing pads because I couldn’t fit more without moving a lot of things
- gnd in the middle of the pads
- edgecut at 22mm

loneoceans wrote:

There are MCUs on the market with integrated op amps, logic blocks, and some other peripherals. For example, some of the very low cost 8 bit PICs have op amps, likewise the powerful PSOCs and MSP430s etc (some with similar or lower price points than the AVR 8-bit MCUs). As far as I am aware though, there are no Attinys with integrated op amps though the 1616 does have some analog comparators and a small amount of programmable logic. That said, thefreeman’s design probably offers some additional benefits such as Anduril and better control of the analog loop with component choice and feedback optimization. Even if constrained (at least for now) to the Attiny series, Anduril itself is worth the extra cost. thefreeman, nice job, always great to see more options with new designs cool. As a side note… the pandemic is really affecting supply chains around the world. Many of the QFN AVR1-series MCUs are sold out or very short in supply at the moment, with a lead time of almost 3/4 a year..

Thanks Big Smile

Yeah I don’t exactly know how it is done in the Unicorn 1.0/Geko, I thought I read that Vsense is read by the ADC, with some wizardry to increase resolution, then a PID loop to control the current, not sure though, maybe it’s something else.

gchart
gchart's picture
Offline
Last seen: 9 hours 55 min ago
Joined: 03/19/2016 - 11:57
Posts: 3158
Location: Central IL

I saw those at Farnell and some over in Asia. Every place wanted like $40+ in shipping fees to get them here – no thanks! Well, I guess Farnell “only” wanted £25 in shipping. I guess I’ll wait for my Mouser order this summer. I’ll try to make my 10 on hand stretch out until then.

Scallywag
Scallywag's picture
Offline
Last seen: 13 hours 48 min ago
Joined: 01/11/2018 - 22:23
Posts: 2062
Location: Ohio, United States

Quadrupel wrote:
So many components … Smile , here how looks linear Infireon driver from Geko headlamp
Here Avsel linear

That Geko looks like a decent ZL clone – except if there’s no moonlight there’s no point cloning ZL (to me anyway)
Mike C
Mike C's picture
Offline
Last seen: 1 day 5 min ago
Joined: 01/22/2014 - 08:03
Posts: 2584
Location: Sweden

I’ve been away for a while… nice to see that your work with 1-series is catching on.

gchart wrote:
A few months back I switched the order of the flashing pads, putting Gnd (V-) in the middle. It makes some layouts easier, plus if you reverse the programming key on accident, I feel like you’re less likely to fry your MCU from reverse voltage.

Maybe I’m being a stickler, but the 1 series doesn’t need three flashing pads. It’s needs GND and UDPI, and the MCU needs to be powered. If I don’t have the driver powered already I just connect V+ from the Xplained Nano to the battery spring with a crocodile clip.

Another thing… you mentioned shortage of 1616s and you see them on Farnell UK. The US branch newark.com has them in stock (selling fast though), do you still have to pay that much postage if you order through Newark? They do refer to UK stock but you might be able to get around the shipping? I can’t order from Farnell UK directly myself, but in Sweden we have a components shop that allows anyone to order from Farnell UK and only pay local Swedish postage from the Swedish shop. I just got a bunch of 1616s delivered. Perhaps there is a similar service in the US for Newark if you can’t order from them directly?

gchart
gchart's picture
Offline
Last seen: 9 hours 55 min ago
Joined: 03/19/2016 - 11:57
Posts: 3158
Location: Central IL

I think when I tried Newark, it was quoting me outrageous international shipment fees since the stock was going to come from UK.

I agree, you don’t need VCC if the MCU is powered, but what if you want to flash a driver that isn’t installed in a flashlight? Or it’s not able to be powered when you have access to the flashing pads (most flashlights)? In my mind, it’s no more difficult to include all 3 pads and it gives you more flexibility. Just my 2 cents.

thefreeman
thefreeman's picture
Online
Last seen: 5 min 58 sec ago
Joined: 01/06/2020 - 09:56
Posts: 873
Location: France

Hmm, and here I was wondering if it mattered if the V+ for flashing was connected before or after the LDO, if like, the MCU was powered from a lower voltage (ldo voltage) than the UDPI signal it would cause issues (maybe a stupid question…).

gchart
gchart's picture
Offline
Last seen: 9 hours 55 min ago
Joined: 03/19/2016 - 11:57
Posts: 3158
Location: Central IL

FWIW, when making one of my programming keys, I accidentally put the resistor inline with the VCC line instead of the UPDI line. If I remember right, the computer didn’t even recognize that the MCU was connected. So I just connect the pins directly at the MCU, without anything like LDOs or diodes in the path.

Mike C
Mike C's picture
Offline
Last seen: 1 day 5 min ago
Joined: 01/22/2014 - 08:03
Posts: 2584
Location: Sweden

gchart wrote:
What if you want to flash a driver that isn’t installed in a flashlight? Or it’s not able to be powered when you have access to the flashing pads (most flashlights)?

Just as I wrote, I have V+ from the Xplained Nano connected to the battery spring by a crocodile clip. The Xplained Nano powers the MCU. You did write you made the change to make layout easier, I just added this because layout is even easier with two pads instead of three, it works fine for me.
gchart
gchart's picture
Offline
Last seen: 9 hours 55 min ago
Joined: 03/19/2016 - 11:57
Posts: 3158
Location: Central IL
Thumbs Up sorry, I was skimming as I’m working at the moment. I should know better than to try multi-tasking…
JaredM
JaredM's picture
Offline
Last seen: 8 hours 59 min ago
Joined: 10/31/2011 - 13:33
Posts: 2236
Location: Pittsburgh, Pennsylvania

Digikey

Is this the right component?

gchart
gchart's picture
Offline
Last seen: 9 hours 55 min ago
Joined: 03/19/2016 - 11:57
Posts: 3158
Location: Central IL

Well I’ll be! They got a batch in earlier than expected. I’m halfway tempted to try and cancel my Mouser order and place one at Digikey.

JaredM
JaredM's picture
Offline
Last seen: 8 hours 59 min ago
Joined: 10/31/2011 - 13:33
Posts: 2236
Location: Pittsburgh, Pennsylvania
gchart wrote:
Well I’ll be! They got a batch in earlier than expected. I’m halfway tempted to try and cancel my Mouser order and place one at Digikey.

Aaaaannndd they’re gone

Pages