How to Select a Timer on AVR MCUs

2 years ago by dragontamer to c/ece

Modern AVR has a wide variety of Timers (TCA, TCB most commonly, but TCD, TCE, and TCF are uncommon and specific to particular AVR chips).

This can make choosing a AVR DD vs AVR EA vs AVR EB vs AVR DA a difficult choice, especially if you're trying to use timers to their greatest extent possible.

This blogpost covers a basic idea of what the different timers offer.


The blogpost is short enough. I feel like what I can add is to highlight the difference between:

  • Timers -- A background count++, a comparator of count vs some pre-configured values, and then likely an output pin that changes based off of these configurations. Consider this an MCU output. Almost everything listed can be used as a timer.

  • Counters -- Counter functionality is an MCU input. Many protocols, such as Servos, PWM, pulse-train decoding requires a variety of pulse-frequency-modulation, pulse-counting, or wide variety of other kinds of common tasks. "TCB" may be called a "Timer", but its really more of a counter-focused device which can more easily measure frequencies (for pulse-frequency-modulation). TCA and a few others can do some basic counting tasks, but usually not as well as TCB.

The other discussions in the blog are easy enough to understand IMO. This is all AVR specific, but some of the best material online are highly specialized articles like this, so I still feel like sharing.

henfredemars 2 points 2 years ago

Reminds me of my university days programming for this target which then exploded in popularity with Arduino and the maker movement.

path: 0 11464792, hotness: undefined, score: 2, children: 5
dragontamer 3 points 2 years ago

These new AVR DA / DB / DD / EA / EB series over the past couple of years is really excellent IMO.

I feel like "x16 Programmable Gain Differential 12-bit ADC" on the AVR EA should give you a reason to check things out! CCL (Four 3-LUTs + 2 1-bit memory cells) can operate while the processor is in sleep states, allowing for some customizable glue logic.

These timers today are certainly more powerful than what came out 15 years ago too.


Each AVR series has a "secret weapon" that's pretty cool. AVR DB has 3x OpAmps. EA is that x16 PGA Differential 12-bit ADC like I said. EB has these new waveforms.

This post: https://lemmy.world/post/16422711 shows off how to use Timers, CCL and the event system to create a bang-bang Boost converter that operates even under CPU sleep (since its all Timers / Peripherals).

With a more advanced timer like Timer E, that same design can upgrade to a nmos+pmos totem pole Boost Converter somewhat easily as well. (Replace the diode with a pmos + use TimerE to configure dead-time + complementary on/off signals that can operate all during standby-sleep).

path: 0 11464792 11465342, hotness: undefined, score: 3, children: 4
henfredemars 1 point 2 years ago

I find this especially interesting because a lot of cheap AVR cores are used to implement simple logic, so additional tools to do that efficiently meets pushes what’s possible in an application.

path: 0 11464792 11465342 11465819, hotness: undefined, score: 1, children: 3
dragontamer 2 points 2 years ago

The "Event System" is really good for that too.

The Event System (EVSYS) enables direct peripheral-to-peripheral signaling. It allows a change in one peripheral (the event generator) to trigger actions in other peripherals (the event users) through event channels, without using the CPU

The most simple of logic / signaling doesn't require the CPU anymore. Its truly a system where combinations of pieces leads to a large number of simple designs.

"Modern AVR" is very much about these peripherals. No, you don't get as much compute as the 32-bitters (Cortex M0+ or whatever). But by being able to do so much dumb logic without waking up, AVR reaches into absurdly low-power design spaces. There's just so much that can happen while sleeping now, its kind of insane.

simple logic

Alas, its not very easy to design like this. But that's what makes it a fun hobby at least! "Simple Logic" but... it ends up touching like 5 different peripherals tied together with the Event system in not the easiest to understand initialization code to write....

path: 0 11464792 11465342 11465819 11466414, hotness: undefined, score: 2, children: 2
henfredemars 1 point 2 years ago

I hate to say it but I never really got into the event system properly. It was quicker and easier to implement my solution using a traditional by the book approach with timers/interrupts. No, it wasn’t very power efficient, but it got the job done. Keep in mind I was using AVR in academics and home projects not in industry.

It does look really cool. I feel like high-quality firmware engineering is rarely seen in the field. I’ve pulled a lot of firmware and seen a lot of questionable practice, but the really good developers? It seems like they move into ASIC design or support higher end SoCs. Juicing an AVR for every drop of performance seems like a lost art from my vantage point in the same way that video games rarely use tricks to optimize for memory or storage because it doesn’t make a economic sense to do so.

We have the smart devices everywhere in their firmware is usually garbage.

path: 0 11464792 11465342 11465819 11466414 11466836, hotness: undefined, score: 1, children: 1
ece
ece

@lemmy.world

login for more options
3134
104
27

Electrical and computer engineering (ECE) community, for professionals and learners. Discuss ECE related topics here, for instance digital design, signal processing, circuit analysis, electromagnetics, microelectronics, power electronics, RF electronics, etc.

go to feed...