3 ms·
AVR gives up on core/SRAM and instead offers incredible peripherals. While AVR DA, DB, DD, EA, and EB chips can serve as replacements to ATmega (albeit with new
by dragontamer 2y ago
AVR gives up on core/SRAM and instead offers incredible peripherals. While AVR DA, DB, DD, EA, and EB chips can serve as replacements to ATmega (albeit with new pinouts), the newer chips are a completely different ballgame.
AVR DB has 3x OpAmps for free.
AVR EA and EB have differential 12-bit ADCs with programmable 1x to 16x gain. We're not just talking about measuring 4mA to 20mA protocol easily, but you can measure uA of current with reasonable accuracy with just a shunt-resistor + the AVR EA's ADC.
AVR DD has a dual power-supply with 1.8V to 5V support. That means that some pins can be on 3.3V logic while other pins are on 5V logic. IE: The AVR DD's job is to be a built-in full-and-proper level shifter.
Bonus points: All modern AVR chips (Dx and Ex) have an event-system to route events from any peripheral (Timers, Pins, UART, etc. etc.) to many other pins and even interrupts to the CPU. This combines with the CCL programmable logic unit (Four 3-LUTs + two 1-bit memory cells) to have an incredible amount of "glue logic" built into these chips.
Anyone who comes in this topic and talks about "But 32bit whatevers", ESP32 or about super-cheap RISC-V chips is missing the point of the AVR line. You're not really the ones in the market for this chip. Anyone who has to deal with a cheap design that manipulates a bit of analog sensors, or glue together logic... well... AVR is the right chip for these jobs.
----------
There's one problem. It means that you need to know the ins-and-outs of the peripherals that are offered on these chips. AVR DD cannot do the same current-measuring job that an AVR EA or AVR EB can do.
Mixed-signal Peripherals are so much harder to understand than MHz and SRAM. But for those who are "in the know", well... these are awesome peripherals. Its difficult to find competitors to these chips.
Indeed, a proper bidirectional 3.3V to 5V level shifter across 28 I/O pins alone would probably cost you more than the $1-ish AVR DD.
3x Rail-to-Rail OpAmps with programmable voltage-reference, a DAC and differential ADC is a *bargain* for the AVR DB's $2 price point.
---------
And the whole line offers like 5V and 50mA in/out on the GPIO. Its an extremely forgiving chip. The fun trick is to run Resistor+LED directly off of GPIO because... you can. (Typical LEDs are 20mA).
- kragen 2y agoi feel like the ch32v003 might plausibly be the right chip for these jobs, even though it's risc-v, because it's so much cheaper than the avrs. as a bonus, it's made by a chinese company, so you can use it even in contexts where foreign hardware isn't allowed (this has become a big deal as the usa has started ramping up its sanctions) in theory it's 12¢ each at lcsc, but it's out of stock, so that's only theoretical: https://www.lcsc.com/product-detail/Microcontroller-Units-MCUs-MPUs-SOCs_WCH-Jiangsu-Qin-Heng-CH32V003J4M6_C5346354.html https://www.lcsc.com/product-detail/Microcontroller-Units-MC... it's not competitive with the expensive avrs when it comes to mixed-signal peripherals and 1.8-volt support, but it does have some tasty stuff. you get 3.3 to 5 volts, a 10-bit adc (1.7 megasamples per second with a ±2% bandgap reference), and an op-amp (so you can do differential input to the adc and set its gain), a basic set of digital peripherals, and that's about it. that's still better than an atmega328 or an stm32f103 but not in the same league as the stuff you're talking about i haven't actually tried the chips myself, so i don't know if they're all they're cracked up to be, but except for a fatal problem with the spi peripheral in the smaller packages, other people seem to report good success, even without speaking chinese: https://hackaday.com/tag/ch32v003/ https://hackaday.com/tag/ch32v003/ in this price range, there's also the arm puya py32, and of course the padauk chips with their redoubtable multithreading so you can do your i/o from a separate hardware thread instead of from interrupt handlers
- dragontamer 2y ago> it's not competitive with the expensive avrs when it comes to mixed-signal peripherals and 1.8-volt support. you get 3.3 to 5 volts, a 10-bit adc (1.7 megasamples per second with a ±2% bandgap reference), and an op-amp (so you can do differential input to the adc and set its gain), a basic set of digital peripherals, and that's about it. that's still better than an atmega328 or an stm32f103 but not in the same league as the stuff you're talking about Yeah, the features you just talked about are definitely more akin to what AVR Dx or Ex have to offer (albeit the ch32v003 is cheaper and has less features). I do like this modern trend of making incredibly powerful peripherals that most mixed-signal designs need (ex: adding OpAmps to a device, or in the AVR case, adding Differential ADCs to explicitly support more use cases). This design trend didn't exist back in the day when ATMega328pb was designed however, so you don't get it with the old chip. ----------- OpAmps seem to be one magic device that really should be in more of these designs. There's so much you can add with one OpAmp (or a team of 3x OpAmps). So I love it when people point out chips with an OpAmp (or two or three) that come with a uC. I've seen some pretty silly designs, like using the OpAmps to sense Voltage (or current), hooking up the output of those OpAmps to the Analog Comparator that triggers an interrupt + internal state, and that state controls a Timer-waveform / PWM output that controls a Voltage-Controlled Current-Controlled battery charger that's feeding a MOSFET + inductor to create effectively a software-controlled buck-boost converter. I doubt its as good as any "real" solution, but if you've got a bunch of these uCs lying around, it might be a better solution than adding more SKUs of the specialized power chips. Just a hobbyist here btw. Not a real engineer. The real engineers might look at my previous paragraph with horror!
- kragen 2y agoyeah, i think software control of buck and boost converters is a mainstream thing to do at this point, and if you think about it, that's what you're doing every time you control a motor with a pwm signal, even if the motor's windings are the only inductor. building discrete dc-dc converters turns out to be the main purpose for the 184-picosecond-resolution high-resolution timer included in chips like the stm32g484. i was reading this appnote yesterday: https://www.st.com/resource/en/application_note/an4539-hrtim-cookbook-stmicroelectronics.pdf https://www.st.com/resource/en/application_note/an4539-hrtim... incidentally, even the old attiny chips that don't have adcs at all do have analog comparators, so you can do tricks like that with them too i'd be happier with the on-chip op-amps if they also included on-chip analog multiplexers, resistors, and capacitors sufficient to build something like a sallen–key filter in software, but so far only the cypress psoc line seems to be doing that, and it's probably a lot of chip real estate to sacrifice for an inferior version of a couple of 0.3¢ external components i'm not an ee either, i just play one in ngspice
- gsliepen 2y agoExactly this. Also, if it's anything like the ATmega, instruction timing will be very simple and deterministic. For some applications that matters a lot.