Adventures in TinyAVR 1-Series

121 posts / 0 new
Last post

Pages

gchart
gchart's picture
Offline
Last seen: 8 hours 45 min ago
Joined: 03/19/2016 - 11:57
Posts: 2888
Location: Central IL
Adventures in TinyAVR 1-Series

Microchip (Atmel) has been releasing some interesting new MCU’s over the past couple of years, their new 0-Series and 1-Series ATtiny’s (eg, the 412, 416, 817, 3217). The 0-Series and 1-Series are nearly identical, but the 1-Series has a few more peripheral options. I feel like they include some new features that, while not vital to our uses, have some benefits. And any guesses on how old our tried & true ATtiny85 is? 14 years, as of the time of this writing (it was launched early 2005). While microcontrollers may not be developing at breakneck speeds, a lot can change in 14 years.

Benefits

  • Easier wiring for flashing. These guys use the UPDI interface which is only 3 wires: VCC, GND, and UPDI. Compared to our traditional 6-pin wiring, this makes programming clips easier to wire up and makes programming pads & keys appreciably smaller.
  • Internal 32.768KHz ultra-low power oscillator: useful for time keeping (though not as accurate as an external crystal) and can also be used as the main clock source for very low power active states (think ~10uA while active vs the main clock set to 5MHz consuming ~1.6mA )
  • New peripherals: RTC interrupts (replacement for what we use WDT for), true TWI/I2C support, multiple 16-bit timer/counters, QTouch touch controller (capacitive touch sensing), an event system that can run while sleeping and perform simple tasks without waking the main processor… etc
  • For space-constrained applications, available in QFN (4×4mm) and VQFN (3×3mm) packages
  • Internal voltage and temperature sensing (though the ’85 does have this)
  • Need a lot of program space? You can have 32KB with the ATtiny3217

Potential downsides

  • If you want to stay away from QFN (quad flat no lead) chips and stick with our 8-pin SOIC footprint, the biggest chip so far is the ATtiny412 with 4KB. The ’85, albeit with a larger footprint than SOIC-8, has 8KB.
  • There’s not as much information available yet on the 1-Series versus the ’85 which has been used and abused for 14 years
  • Coding for the 1-Series is a bit different than the older ATtiny’s – the registers are named and structured differently. So existing firmwares would need to be ported (but not terribly difficult – I’ve ported RampingIOS)

Development Tools

  • ATtiny416 Xplained Nano (info) (buy): nice, tiny dev board for testing out code and great for programming off-board chips
  • ATtiny817 Xplained Mini (info) (buy): bigger dev board with more options, good for testing out code, and can be used for programming off-board chips (though it’s a bit large if this is all you plan on doing with it)
  • To use one of the Xplained dev boards to program an external chip, you simply need to remove 4× 0 Ohm resistors/jumpers to disconnect the onboard chip. Then you can run VCC (from the VREG pin), GND, and UPDI leads to your chip/board. I soldered on header pins so that I could easily swap back and forth between on-board and off-board.
  • AVR JTAG ICE (info) (buy): without going the “official” route with the Xplained boards, El Tangas has devised a way to use this as a flashing device (think AVRISP replacement)… though it’s a bit hack-y. I have this in my possession, but haven’t tried it yet. In order to use it, you need to modify the AVRDUDE config files.

Windows: Development
Atmel Studio 7 makes dev’ing for this chips easy. Everything is built-in. Just choose the right MCU and go!

Windows: Flashing
Once again, flashing from Windows can easily be done using Atmel Studio. Note that if you’re going to flash a different chip than what your Xplained board came with (saying using an 416-XNano to flash an ATtiny412) you need to enable the mEDBG (“mini embedded debugger”?) to be used with other target. AS7: Tools (Main Menu) -> Options … -> Tools -> Hide Unsupported Device -> False

Linux: Development
This is definitely possible. I’ve built hex files in Linux using AVR GCC. The trick to this is downloading and extracting the Atmel ATtiny Device Family Pack and including those files when you compile your code. See my build script here (it’s an offshoot of TK’s build scripts). Note that you’ll need to update the DFP variable with the directory of your unzipped Device Pack

Linux: Flashing
I think we have two options: (1) follow the El Tangas instructions linked in the AVR JTAG ICE dev tool mentioned above, or (2) use AVRDUDE. The problem is that as of the time this writing, you’ll need to compile AVRDUDE from source in order to get mEDBG + UPDI support. I haven’t tried the second one. But I’ve used the AVR JTAG ICE and it works great.

Code Samples

Chip Information and other Resources

Random Thoughts

  • The 412 has a similar footprint to some PIC chips, it makes replacing those easy. I used it as a straight replacement in my D25 headlamp without any funky wiring or trace cutting
  • The default clock on these guys is usually 3.33MHz (20MHz / 6). Changing it is easy, but remember to respect the CCP (configuration change protection).

Oshpark Boards

  • UPDI Programming Key – can be used with the AVR JTAG ICE (with a 4K7 resistor), or just put a jumper across the resistor pads for use with the Xplained boards… very tiny
  • Smart Tailcap – tested, working well; uses the 416
  • 3A Single Sided Driver – uses a 416 or 816 and 3x CN5710’s (received, not fully tested!)
  • 5A Emisar D1S Driver – uses a 412 and 5x CN5710’s (received, not fully tested!)

Edited by: gchart on 11/25/2020 - 14:05
gchart
gchart's picture
Offline
Last seen: 8 hours 45 min ago
Joined: 03/19/2016 - 11:57
Posts: 2888
Location: Central IL

reserved… Justin Case

MRsDNF
MRsDNF's picture
Offline
Last seen: 2 months 1 week ago
Joined: 12/22/2011 - 21:18
Posts: 13473
Location: A light beam away from the missus in the land of Aus.
Thumbs Up

 

djozz quotes, "it came with chinese lettering that is chinese to me".

                      "My man mousehole needs one too"

old4570 said "I'm not an expert , so don't suffer from any such technical restrictions".

Old-Lumens. Highly admired and cherished member of Budget Light Forum. 11.5.2011 - 20.12.16. RIP.

 

chadvone
chadvone's picture
Offline
Last seen: 7 hours 5 min ago
Joined: 08/28/2015 - 23:48
Posts: 1876
Location: Iowa

Great. What does all this mean?

FmC
FmC's picture
Offline
Last seen: 1 week 1 day ago
Joined: 03/31/2013 - 05:23
Posts: 2197
Location: Brisbane, AU
chadvone wrote:
Great. What does all this mean?

It means that us folks that like to build & flash drivers will be buying a bunch of new components soon…. Big Smile

Keep up the good work Thumbs Up

DavidEF
DavidEF's picture
Offline
Last seen: 4 days 8 hours ago
Joined: 06/05/2014 - 06:00
Posts: 7699
Location: Salisbury, North Carolina, USA

gchart wrote:
reserved… Justin Case

Well I’m subbed… Justin Case! LOL

The Cycle of Goodness: “No one prospers without rendering benefit to others”
- The YKK Philosophy

WTF
Offline
Last seen: 1 month 2 weeks ago
Joined: 03/05/2017 - 20:13
Posts: 318

Once upon a time Wight made one of these adapters to replace a pic with an attiny. https://oshpark.com/shared_projects/iN0zkxJn

Could a similar adapter board be made to convert the 25, 45, and 85 SOIC footprint to a 20 pin QFN footprint of a 1616?

Consider the size of the SOIC package with space for the programming clip. Take that footprint and cram the QFN package to one corner and in the opposite corner make a three pin L shaped programming port. The programming key would have two pins on one side of a printed circuit board and one on the other. If there is space left over and the trace routing isn’t horrible a few I/O pads could be made. Probably not enough space for a crystal but an accurate clock would be nice.

Newer drivers could have the programming ports on the spring side. The L shaped layout would make it impossible to put the key on the wrong way.

I know it won’t be as easy as it sounds, but it would be nice if it could happen.

clientequator
clientequator's picture
Offline
Last seen: 8 hours 44 min ago
Joined: 12/05/2018 - 15:42
Posts: 250

I think I recall mr Mike C is using the Attiny1617 for his flashlight driver projects also! I think this is related to new AVR1 series because it also has updi?

gchart
gchart's picture
Offline
Last seen: 8 hours 45 min ago
Joined: 03/19/2016 - 11:57
Posts: 2888
Location: Central IL

Is he? Last I checked in with him I think he was using the 1634, which is the older style, but is a QFN footprint.

WTF
Offline
Last seen: 1 month 2 weeks ago
Joined: 03/05/2017 - 20:13
Posts: 318

Pretty sure Mike is using the 1634, before that he was using the 841. As far as I know gchart is the first one here to use anything with updi.

I’m surprised this isn’t getting more attention. People around here seem to have wanted more pins and memory for a long time but it’s always been the chicken and egg story. Why build a driver using an mcu no one has written firmware for and how do you develop firmware without any hardware to test with?

Without having to use Atmel ice, programming these new drivers is surprisingly cheap. It’ll be even cheaper if usbasp can support updi, and from what gchart is saying that is not too far away. If an adapter board can be made any driver can be converted for cheap. I believe the 1616 is cheaper than an 85 and a tiny driver adapter board at Oshpark should only be a couple bucks for three. The explained board and the total cost of three programming keys wouldn’t be much more than a Ponoma clip. I know how easy it is to wear out a Ponoma clip but I can’t imagine wearing out a programming key.

More I/O pins and up to four times as much memory, the new one series looks good.
gchart
gchart's picture
Offline
Last seen: 8 hours 45 min ago
Joined: 03/19/2016 - 11:57
Posts: 2888
Location: Central IL

I will say, I don’t have any fancy tools (no hot air station or reflow oven) and no stencils yet, so these VQFN have been a pain to solder. I imagine they’ll get easier as I get more experience. The 412 has been easy-peasy of course.

Speaking of programming keys…

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

WTF wrote:
Pretty sure Mike is using the 1634, before that he was using the 841.

That’s correct. Besides more memory I found that the 1634 was far better suited for OTSM than the 841, low power operations are much better.

WTF wrote:
I’m surprised this isn’t getting more attention.

Not me, not any more. I thought that more would be interested in moving over to 16kb MCUs because I was reading about interest in the 1616 and 1617 about the time I started using the 1634. That was quite some time ago, but to my knowledge nothing happened.

I’m quite happy with the 1634. Believe or not I’ve actually made a driver that uses every single IO on it, but what has my interest is the three pin UDPI programming. That might very well get me on to the 1616 or 3217. I’m some what reserved though, the reason why I went with the 1634 is because it’s 4×4mm with 20 pins. The pin density is high enough, I’ve had some issues with amount of solder paste on them but I seem to have got it dialed now. The 1616 has 20 pins crammed in on 3×3mm, and the 1617/3217 have 24 pins crammed in on 4×4mm. I can’t say I’m looking forward to building drivers with them… I’ve looked for 4×4mm QFN 20 pin options with at least 16kb and UDPI but didn’t find anything. I won’t move over to anything less than 16kb regardless of other benefits so my own options are limited, but gchart’s work with UDPI is something I’m following with great interest.

Microa
Offline
Last seen: 7 hours 42 min ago
Joined: 06/29/2011 - 21:20
Posts: 241

Hi gchart,
How to wire the 412 for your RampingIOS ?
PIN 1 VCC
PIN 2 SW
PIN 3 —-
PIN 4 PWM
PIN 5 ATL
PIN 6 UPDI
PIN 7 —-
PIN 8 GND

WTF
Offline
Last seen: 1 month 2 weeks ago
Joined: 03/05/2017 - 20:13
Posts: 318

Mike C wrote:
That’s correct. Besides more memory I found that the 1634 was far better suited for OTSM than the 841, low power operations are much better.

Not me, not any more. I thought that more would be interested in moving over to 16kb MCUs because I was reading about interest in the 1616 and 1617 about the time I started using the 1634. That was quite some time ago, but to my knowledge nothing happened.

I’m quite happy with the 1634. Believe or not I’ve actually made a driver that uses every single IO on it, but what has my interest is the three pin UDPI programming. That might very well get me on to the 1616 or 3217. I’m some what reserved though, the reason why I went with the 1634 is because it’s 4×4mm with 20 pins. The pin density is high enough, I’ve had some issues with amount of solder paste on them but I seem to have got it dialed now. The 1616 has 20 pins crammed in on 3×3mm, and the 1617/3217 have 24 pins crammed in on 4×4mm. I can’t say I’m looking forward to building drivers with them… I’ve looked for 4×4mm QFN 20 pin options with at least 16kb and UDPI but didn’t find anything. I won’t move over to anything less than 16kb regardless of other benefits so my own options are limited, but gchart’s work with UDPI is something I’m following with great interest.

I always thought it was the cost of programming equipment and that held back use of the updi mcu’s, its not the first time I’ve been wrong.

I just soldered the pogo pins on a six pin Harley Quinn programming key. Even with the vias to locate the pins I need a little magnification to line things up. It’s 100 times nicer than using a Ponoma clip. Gchart’s little three pin key would be even better. Would love to figure out a way to attach one to a dial indicator stand.

I’m not sure how gchart is soldering his mcu’s without a hot plate or hot air station, that can’t be easy. I have most of the parts for a GXB172 driver so I’ll be finding out how hard soldering qfn packages is pretty soon. It looks like trying to toothpick the solder in place will be a disaster. I’m hoping thinning down some solder paste with some liquid flux and smearing it around will work OK. Bought a couple spare MCU’s to practice with, trashing boost converters will get expensive.

Do you think putting some vias near the center of the chip to give excess solder a place to go would help?

gchart
gchart's picture
Offline
Last seen: 8 hours 45 min ago
Joined: 03/19/2016 - 11:57
Posts: 2888
Location: Central IL

WTF wrote:
I’m not sure how gchart is soldering his mcu’s without a hot plate or hot air station, that can’t be easy.

I’ve been using a hot plate. Not perfect, but better than just using an iron. I just ordered my first stencils, hopefully those will make these QFN chips easier.
gchart
gchart's picture
Offline
Last seen: 8 hours 45 min ago
Joined: 03/19/2016 - 11:57
Posts: 2888
Location: Central IL

Microa wrote:
Hi gchart,
How to wire the 412 for your RampingIOS ?
PIN 1 VCC
PIN 2 SW
PIN 3 —-
PIN 4 PWM
PIN 5 ATL
PIN 6 UPDI
PIN 7 —-
PIN 8 GND

This image is labeled for my current setup: http://budgetlightforum.com/comment/1464235#comment-1464235

Changing pins for PWM, Switch, and adding ALT PWM should all be doable in the tk-attiny.h file except for PWM output also needs to be enabled for specific pins at the top of int main(): set TCA0.SINGLE.CTRLB to enable the correct compare channel(s). You might need to reference the 402 datasheet to map the waveform/compare out to pin assignments (the 412 datasheet is missing some of these details).

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

WTF wrote:
I’m not sure how gchart is soldering his mcu’s without a hot plate or hot air station, that can’t be easy.

The 412 that qchart is using is not QFN package, it’s SOIC with legs.

WTF wrote:
Do you think putting some vias near the center of the chip to give excess solder a place to go would help?

I usually have a couple of vias in there, and paste does sip through, but I don’t know how helpful it is. I just do it for connection to GND plane.
gchart
gchart's picture
Offline
Last seen: 8 hours 45 min ago
Joined: 03/19/2016 - 11:57
Posts: 2888
Location: Central IL

Mike C wrote:

The 412 that qchart is using is not QFN package, it’s SOIC with legs.

True, but I’ve also been using the 416 and 817 which are both QFN.
Mike C
Mike C's picture
Offline
Last seen: 1 day 22 hours ago
Joined: 01/22/2014 - 08:03
Posts: 2487
Location: Sweden

gchart wrote:
True, but I’ve also been using the 416 and 817 which are both QFN.

Aha, alrighty. Using a hot plate.

I’ve been using stencils for a long time. I got sick of pasting by hand real fast. If I decided to work overtime the same amount of time I save with stencils, the stencils would pay for themselves multiple times over.

Tom E
Tom E's picture
Offline
Last seen: 10 hours 10 min ago
Joined: 08/19/2012 - 08:23
Posts: 13963
Location: LI NY

This is a great ref source for everything ATtiny: https://en.wikipedia.org/wiki/ATtiny_microcontroller_comparison_chart

You should add this in the OP.

 

gchart
gchart's picture
Offline
Last seen: 8 hours 45 min ago
Joined: 03/19/2016 - 11:57
Posts: 2888
Location: Central IL

Tom E wrote:

This is a great ref source for everything ATtiny: https://en.wikipedia.org/wiki/ATtiny_microcontroller_comparison_chart


You should add this in the OP.


Yeah, I’ve found that to be very helpful. I just added that and a couple other sources as a “Chip Information” section in the OP.
gchart
gchart's picture
Offline
Last seen: 8 hours 45 min ago
Joined: 03/19/2016 - 11:57
Posts: 2888
Location: Central IL

Well… at this point, I’ve ported RampingIOS to run on the Series-1 chips (ATtiny412 / 416 / 817 / etc). That was pretty easy as almost everything was pretty self-contained. And I’ve created a couple drivers from scratch using that setup with good luck.

But now it’s time to try and tackle to larger, but more popular options… Andúril/FSM and NarsilM, here we come! I dunno exactly when I’ll get around to porting the code, but I made a development board for the ATtiny816 (or 1616 / 3216). Basically the same at the 817 except it’s 20 pin instead of 24; I don’t plan on need 24 pins anytime soon. Instead of running through regulators or FETs, I’m just using the MCU output to run the LED (limited with resistors). Since this is just for testing, I don’t need it to be bright… actually, bright is bad because I’d just be blinding myself. Cool

 

DavidEF
DavidEF's picture
Offline
Last seen: 4 days 8 hours ago
Joined: 06/05/2014 - 06:00
Posts: 7699
Location: Salisbury, North Carolina, USA

Thanks for the post here. One more thing: Not sharing the new dev boards? Innocent

The Cycle of Goodness: “No one prospers without rendering benefit to others”
- The YKK Philosophy

gchart
gchart's picture
Offline
Last seen: 8 hours 45 min ago
Joined: 03/19/2016 - 11:57
Posts: 2888
Location: Central IL

I just noticed I forgot an aux LED. Updating the board in a little bit and will share it then.

gchart
gchart's picture
Offline
Last seen: 8 hours 45 min ago
Joined: 03/19/2016 - 11:57
Posts: 2888
Location: Central IL

Alrighty… Aux LED has been added and boards re-ordered. Linky

 

gchart
gchart's picture
Offline
Last seen: 8 hours 45 min ago
Joined: 03/19/2016 - 11:57
Posts: 2888
Location: Central IL

The dev board PCBs arrived today and I made one up tonight. Looks like I’ve got some programming to do!

I think I’ll start with RampingIOS to test out the board (since I already know that works) and will move up to NarsilM and Andúril.

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

I’ll chime in with a small update… I’ve been working a little with getting all functionality I need running on the 3217 for a specific project. I just got the last piece of the puzzle working, OTSM.

With a 100uF cap measuring off time in 0.125 second intervals with BOD fully enabled at 1.8V threshold I got about 11 seconds with the 1634. With this new 3217 I get about 35 seconds with the same setup. Then I tested using BOD in sampled mode and got just over a minute. In sampled mode it might even be reasonable to test OTSM with a 10uF cap.

gchart
gchart's picture
Offline
Last seen: 8 hours 45 min ago
Joined: 03/19/2016 - 11:57
Posts: 2888
Location: Central IL

Mike C wrote:
I’ll chime in with a small update…

Wowsers, that’s impressive!
gchart
gchart's picture
Offline
Last seen: 8 hours 45 min ago
Joined: 03/19/2016 - 11:57
Posts: 2888
Location: Central IL

Sometimes I like reading datasheets for fun and to see what unexplored features are out there. I've been using Timer Counter A every time I needed PWM, but these new 1-Series chips have multiple timers including one called Timer Counter D which is described as such in the datasheet:

The Timer/Counter type D (TCD) is a high performance waveform controller that consists
of an asynchronous counter, a prescaler, compare logic, capture logic, and control logic.
The purpose of the TCD is to control power applications like LED, motor control, 
H-bridge and power converters. The TCD contains a counter that can run on a clock which 
is asynchronous from the system clock.

In essence, this allows us to use a different clock for the system than what is being used for PWM. Without the TCD, to get high resolution PWM at a high frequency, you'd need to run the system clock at a high speed (like 20 MHz), but that can consume a non-trivial amount of power (10 mA) especially if you want to drive an LED at low power for a long time. By separating the system clock and the one used by PWM, we can use the Ultra-Low Power (ULP) 32 kHz clock for the system while using the 20 MHz clock for PWM only. This can save a decent amount of power (consumption < 1 mA). To prove this out, I used Atmel's ATtiny817 Xplained Mini dev board and set it up for current measurement (removing a single 0-Ohm resistor and forcing current to pass through my DMM as explained in the Xplained Mini User Guide). The DMM used in this test is my Aneng AN8008.

 

The code for the PWM current tests can be found here. After conducting the current tests, I tested out the TCD functionality for driving the Xplained's on-board LED. That code can be found here.

Note: default 1-Series main clock is 3.33 MHz (20 MHz oscillator with prescaler divisor of 6) 

  Clock Timer Timer Clock PWM Freq. Current
Test 1 3.33 MHz none -- -- 1.9 mA
Test 2 3.33 MHz TCA, 8 bit System (3.33 MHz) 13.02 kHz 2.0 mA
Test 3 3.33 MHz TCA, 10 bit System (3.33 MHz) 3.25 kHz 2.0 mA
Test 4 3.33 MHz TCA, 12 bit System (3.33 MHz) 814 Hz 2.0 mA
Test 5 10 Mhz none -- -- 5.4 mA
Test 6 10 Mhz TCA, 8 bit System (10 Mhz) 39.06 kHz 5.5 mA
Test 7 10 Mhz TCA, 10 bit System (10 Mhz) 9.77 kHz 5.5 mA
Test 8 10 Mhz TCA, 12 bit System (10 Mhz) 2.44 kHz 5.5 mA
Test 9 20 Mhz none -- -- 10.1 mA
Test 10 20 Mhz TCA, 8 bit System (20 Mhz) 78.13 kHz 10.6 mA
Test 11 20 Mhz TCA, 10 bit System (20 Mhz) 19.53 kHz 10.6 mA
Test 12 20 Mhz TCA, 12 bit System (20 Mhz) 4.88 kHz 10.6 mA
Test 13 32 kHz none -- -- 21 uA
Test 14 32 kHz TCD, 8 bit 20 MHz 78.13 kHz 973 uA
Test 15 32 kHz TCD, 10 bit 20 MHz 19.53 kHz 970 uA
Test 16 32 kHz TCD, 12 bit 20 MHz 4.88 kHz 967 uA
Test 17 32 kHz TCD, 8 bit 10 Mhz (Prescaler: 2) 39.06 kHz 708 uA
Test 18 32 kHz TCD, 10 bit 10 Mhz (Prescaler: 2) 9.77 kHz 705 uA
Test 19 32 kHz TCD, 12 bit 10 Mhz (Prescaler: 2) 2.44 kHz 704 uA
Test 20 32 kHz TCD, 8 bit 5 Mhz (Prescaler: 4) 19.53 kHz 576 uA
Test 21 32 kHz TCD, 10 bit 5 Mhz (Prescaler: 4) 4.88 kHz 574 uA
Test 22 32 kHz TCD, 12 bit 5 Mhz (Prescaler: 4) 1.22 kHz 574 uA
Test 23 32 kHz TCD, 8 bit 2.5 Mhz (Prescaler: 8) 9.77 kHz 508 uA
Test 24 32 kHz TCD, 10 bit 2.5 Mhz (Prescaler: 8) 2.44 kHz 507 uA
Test 25 32 kHz TCD, 12 bit 2.5 Mhz (Prescaler: 8) 610 Hz 507 uA
Mike C
Mike C's picture
Offline
Last seen: 1 day 22 hours ago
Joined: 01/22/2014 - 08:03
Posts: 2487
Location: Sweden

Interesting indeed. I’ve only used TCA and TCB myself, that might change now. Thanks for posting!

gchart
gchart's picture
Offline
Last seen: 8 hours 45 min ago
Joined: 03/19/2016 - 11:57
Posts: 2888
Location: Central IL

Agreed. I never saw the need for it before. But if you want high frequency and reduced consumption, it looks like a good option. I’m going to try and airwire a couple of my ’412 based drivers to get a real driver running with it.

Pages