AVR Configurable Custom Logic As A Frequency Divider At 4x Chip’s Clock Speed

What a time to be alive when you can find inexpensive microcontrollers that come with programmable(ish) logic that can operate independently of the system clock. [David Johnson-Davies] recently built a proof of concept using the Configurable Custom Logic (CCL) that is available in some of the newer AVR microcontroller designs. It’s a simple implementation, a set of frequency dividers that blink three LEDs with up to a 90 MHz input signal. But the simplicity is the reason to love his write-up — you can wrap your head around it right away.

There are four lookup table (LUTs) used to form the frequency divider. Think of these like a NAND or XOR gate, but you get to decide how the output truth tables will perform. The output is fed into a sequencer which can be configured as a D/JK flip-flop or a D/RS latch, plus you can specify the signal edge, and of course define the clock source. An interesting trick here is to hold the G input of both D flip-flops high by feeding them LUTs set to all ones. Note that the output of the first divider (PA3) is feeding the external input (PD2) of the second divider.

While the CCL is configured using the C code you flash to the microcontroller, it’s a hardware peripheral capable of operating independent of the chip’s system clock. The AVR128DA28 that’s used here tops out at 24 MHz (double that if you use the PLL) but [David] got reliable results from his clock divider feeding a signal as high as 90 MHz to the input pin. Of course you have the option of feeding internal clock signals to the CCL, but that wouldn’t seem nearly as interesting here. For the demo, [David] is actually toggling an IO pin which is connected to PA2 as the external input for the logic. Make sure you click through to his write-up linked above as he does an excellent job of walking through the sample code (just a couple-dozen lines to set this all up). Here’s the datasheet for this chip (PDF, page 447 for pertinent registers) and for a deeper dive the appnote on CCL (PDF).

So what is this all good for? We already saw an answer to that question back in January when [SM6VFZ] used the CCL peripheral to build a software-defined switch-mode converter. How awesome is that?

HackadayU Announces Rhino, Mech Eng, And AVR Classes During Winter Session

The winter lineup of HackadayU courses has just been announced, get your tickets now!

Spend those indoor hours leveling up your skills — on offer are classes to learn how to prototype like a mechanical engineer, how to create precision 3D models in Rhino, or how to dive through abstraction for total control of AVR microcontrollers. Each course is led by an expert instructor over five classes held live via weekly video chats, plus a set of office hours for further interaction.

  • Introduction to 3D using Rhino
    • Instructor: James McBennett
    • Course overview: Introduces students to Rhino3D, a NURBS based 3D software that contains a little of everything, making it James’ favorite software to introduce students to 3D. Classes are on Tuesdays at 6pm EST beginning January 26th
  • Prototyping in Mechanical Engineering
    • Instructor: Will Fischer
    • Course overview: The tips and tricks from years of prototyping and mechanical system design will help you learn to think about the world as a mechanical engineer does. Classes are on Tuesdays at 1pm EST beginning January 26th
  • AVR: Architecture, Assembly, & Reverse Engineering
    • Instructor: Uri Shaked
    • Course overview: Explore the internals of AVR architecture; reverse engineer the code generated by the compiler, learn the AVR assembly language, and look at the different peripherals and the registers that control their behavior. Classes are on Wednesdays at 2pm EST beginning January 27th

Consider becoming an Engineering Liaison for HackadayU. These volunteers help keep the class humming along for the best experience for students and instructors alike. Liaison applications are now open.

HackadayU courses are “pay-as-you-wish” with a $10 suggested donation; all proceeds go to charity with 2019 contributions topping $10,100 going to STEAM:CODERS. There is a $1 minimum to help ensure the live seats don’t go to waste. Intro videos for each course from the instructors themselves are found below, and don’t forget to check out the excellent HackadayU courses from 2020.

Continue reading “HackadayU Announces Rhino, Mech Eng, And AVR Classes During Winter Session”

AVR Microcontroller Doubles Up As A Switching Regulator

[SM6VFZ] designed, built and tested a switched-mode DC-DC boost regulator using the core independent peripherals (CIP) of an ATtiny214 micro-controller as a proof of concept, and it looks pretty promising!

A Buck, Boost, or Buck-Boost switching regulator topology usually consists of a diode, a switching element (MOSFET) and an energy storage device (inductor/capacitor) in the power path, and a controller that can measure the output voltage, control the switching element and add safety features such as current limiting and temperature shutdown. A search for switching regulators or controllers throws up thousands of parts, and it’s possible to select one specifically well suited for any desired application. Even so, the ability to use the micro-controller itself as the regulator can have several use cases. Such an implementation allows for a software configurable switch-mode regulator and easy topology changes (boost, buck, fly back etc.).

The “Getting Started with Core Independent Peripherals on AVR®” application note is a good place to get an overview of how the CIP functionality works. Configurable Custom Logic (CCL) is among one of the powerful CIP peripherals. Think of CCL as a rudimentary CPLD — a programmable logic peripheral, which can be connected to a wide range of internal and external inputs such as device pins, events, or other internal peripherals. The CCL can serve as “glue logic” between the device peripherals and external devices. The CCL peripheral offers two LookUp Tables (LUT). Each LUT consists of three inputs, a truth table, a synchronizer, a filter, and an edge detector. Each LUT can generate an output as a user programmable logic expression with three inputs and any device that have CCL peripherals will have a minimum of two LUTs available.

This napkinCAD sketch shows how [SM6VFZ] implemented the boost regulator in the ATtiny214. The AND gate is formed using one of the CCL LUT’s. The first “timer 1” on the left, connected to one input of the AND gate, is free running and set at 33 kHz. The analog comparator compares the boosted output voltage against an internally generated reference voltage derived from the DAC. The output of the comparator then “gates” timer 1 signal to trigger the second “timer 2” — which is a mono-shot timer set to max out at 15 us. This makes sure there is enough time left for the inductor to completely release its energy before the next cycle starts. You can check out the code that [SM6VFZ] used to built this prototype, and his generous amounts of commenting makes it easy to figure out how it works.

Based on this design, the prototype that he built delivers 12 V at about 200 mA with an 85% efficiency, which compares pretty well against regular switching regulators. Keep in mind that this is more of a proof-of-concept (that actually works), and there is a lot of scope for improvement in terms of noise, efficiency and other parameters, so everyone’s comments are welcome.

In an earlier blog post, we looked at how ATmegas with Programmable Logic came about with this feature that is usually found in PIC micro-controllers, thanks to Microchip’s acquisition of Atmel a few years back. But we haven’t seen any practical example of the CCL peripheral in an Atmel chip up until now.

Minimal TinyAVR 0 Programming

When [Alain] wanted to use some of the new TinyAVR 0 chips — specifically, the Attiny406 — it seemed overkill to use the Windows IDE. There are plenty of sources of information on programming other AVR chips using simple command line tools, but not for these newer 0-series parts which use a new programming protocol known as UPDI. That led to a deep diving into how to program a TinyAVR 0 with a text editor, makefile, and USB-to-serial cable.

The Attiny406 has 4K of flash, 256 bytes of RAM and can run at 20 MHz with no external clock. You might think programming would be similar to a regular AVR part, but these tiny devices use UPDI (Unified Programming and Debug Interface) which uses 3 pins for programming. Older devices used different protocols.

It is very easy to create a UPDI programmer. A USB to logic-level serial cable and a 4.7K resistor is all it takes. There’s Python code that knows how to drive the protocol, too. You can also use the logic-level serial port on the Raspberry Pi with some device tree modifications explained in the code’s documentation.

[Alain] made a nice breakout board for the device. It fits a breadboard, allows for 5V or 3.3V operation, and has an LED and switch. Nothing fancy, but handy. Once you know how to ship a hex file to the chip, the rest is pretty standard. While the AVR version of gcc doesn’t cross-compile for the ATTiny out of the box, there is a device pack from Microchip that enables that feature.

The trend is to go to bigger processors, not smaller, but when you need to cram something in a small space, save a few pennies per unit, or draw very little power, these tiny processors can be just the ticket. The processors may be small, but if you work you can do some pretty big things with them.

AVR Multi-Tool Learns The Latest Tricks

Like many of us who fiddle with microcontrollers, [Mike] and [Brian] often found themselves using an ISP programmer and a USB-to-serial adapter. But when they started working on the latest generation of ATtiny chips, they found themselves in need of a Unified Program, and Debug Interface (UPDI) programmer as well. So they decided to wrap all three functions into one handy open hardware gadget.

They call their creation the AVR General Purpose Programmer, or AVRgpp for short. It runs on an ATmega328P with a Pro Mini bootloader, which means that the programmer itself is fully compatible with the Arduino IDE. USB-to-serial capability is provided by a CH330N, and a MC14053 digital switch IC is used to select between talking to the AVRgpp’s onboard MCU or the target device.

A 128 x 32 I2C OLED and two push buttons are used to select the device’s current mode, and there’s a physical switch to select between 5 V or 3.3 V power for the target. There’s also a ST662 12 V regulator, as UPDI targets occasionally need a high voltage pulse to switch into programming mode. Everything is packaged up in a pocket-sized laser cut enclosure that you can easily toss in your bag.

[Mike] and [Brian] say they are considering putting the AVRgpp into small scale production if there’s enough interest, so let them know if you’d like to get one without having to build it yourself.

AVRO’s Project 1794: A Canadian Flying Saucer

If you ask those of us who grew up somewhere in the 1950s to 1970s what our car would be like in the year 2020, we might have described an Avrocar. This top secret vehicle from Canadian Avro was part hovercraft and part jet-powered vertical takeoff vehicle. There were two prototypes actually made and [Real Engineering] has a short video on how the prototypes worked, how the real design might have worked, and even has a lot of footage of the actual devices. You can see the video below.

The designer, [Jack Frost], experimented with ground effect and the Coanda effect. The Canadian branch of Avro, a British company, worked with the U.S. military and if you look at it, you wonder how many UFO sightings it caused. Nothing like a flying disk 18 feet in diameter going over your backyard to make you call the newspapers. On second thought, it probably never got enough altitude for that to happen.

Continue reading “AVRO’s Project 1794: A Canadian Flying Saucer”

A Lightweight AVR IDE

It’s entirely possible to do your coding in vim or emacs, hammering out hotkeys to drive the interface and bring your code to life. While working in such a way has its charms, it can be confronting to new coders, and that’s before even considering trying to understand command line compiler settings. The greenhorn coder may find themselves more at home in the warm embrace of an IDE, and [morrows_end] has now built one for those working with AVR assembly code.

The IDE goes by the name of Simple AVR IDE, or savr_ide for short. Programmed in C++ with the FLTK widget library, [morrows_end] has tested it on Windows XP, but notes that it should successfully compile for Linux, Unix, and even MacOS too.

All the basic features are there – there’s syntax highlighting, as well as integration with the AVRA assembler and AVRDUDE for programming chips. It’s a tool that could make taking the leap into assembly code just that little bit easier.  For another taste of bare metal coding, check out [Ben Jojo]’s discussion of x86 bootloaders.