EEVblog Electronics Community Forum

Electronics => Microcontrollers => Topic started by: jmaja on November 28, 2022, 09:14:42 am

Title: Chip shortage, which microcontroller to choose
Post by: jmaja on November 28, 2022, 09:14:42 am
I make high precision sensors in low volume (20-100/year) for global market. I need to make a new model, since the actual sensor chip I have used is out off production. I checked through the BOM of the current model and it seems to be totally impossible to get most of the active components I have used before.

So let's start with the microcontroller. I have used AVR XMega, which seems to have totally disappeared from the vendors. Last time I ordered these in Summer 2021 I still could find a drop in replacement, although not exactly the same I used before. Now there is nothing.

What would be a good option, which would likely be available now and for the coming about 10 years or so (the two current sensors I produce were designed in 2007 and 2013)? XMega has been easily fast enough (actually run at 4 MHz) and has enough ports (would need to have 1-2 SPI and 1 UART, maybe USB). I prefer to use GCC. 3.3 VCC would be easiest.
Title: Re: Chip shortage, which microcontroller to choose
Post by: mino-fm on November 28, 2022, 10:15:04 am
Just buy 10k of RP2040 so they will help you the next 10 years ;-)
Title: Re: Chip shortage, which microcontroller to choose
Post by: jmaja on November 28, 2022, 10:32:28 am
Just buy 10k of RP2040 so they will help you the next 10 years ;-)
Seems to be in stock and cheap (1 €), but not cheap enough to by 10k of them. Never heard of that one before, but seems to be an ARM Cortex-M0. Is that a good option? I have used SAMD21 in one project. Basically the same?

One thing I forgot to spec is a package somehow suitable for hand soldering or a heat gun. So far I have used outsourced reflow for one model and hand soldered the other. For both hand soldered the prototype. The RP2040 package looks a bit difficult for hand soldering, but maybe manageable.
Title: Re: Chip shortage, which microcontroller to choose
Post by: T3sl4co1l on November 28, 2022, 10:50:54 am
If you're used to AVR, the AVR-Dx would seem the next logical step.  Peripherals are different from both MEGA and XMEGA so there's some getting used to.  I would rate them comparable or more powerful than XMEGA, largely because of the peripherals which are more configurable than ever (thanks to even more event sources/sinks plus CCL).  Last I checked, they were moderately available, though I'm sure the exact supply varies (i.e., 100s available here or there across the family).  Maybe they're all unusually short at the moment, I don't know.

RP2040 is certainly not a SAMD21... but if you're doing mostly CPU functions, it might not matter.  Point in case, it's all about the peripherals, everyone and their uncle makes ARM chips but it's what they hang off them that makes all the difference.

Tim
Title: Re: Chip shortage, which microcontroller to choose
Post by: mino-fm on November 28, 2022, 10:55:33 am
Seems to be in stock and cheap (1 €), but not cheap enough to by 10k of them.

So take 100 as a first step instead.

Quote
One thing I forgot to spec is a package somehow suitable for hand soldering or a heat gun.

Look for Raspberry Pi Pico-Board using RP2040 priced arround $5. It's very easy to handle if you got enough space.
Let me show you one application of mine:
Title: Re: Chip shortage, which microcontroller to choose
Post by: RoGeorge on November 28, 2022, 11:14:01 am
Just buy 10k of RP2040 so they will help you the next 10 years ;-)
Seems to be in stock and cheap (1 €), but not cheap enough to by 10k of them.

10kpcs would be the stock for 100 years.  :)
10 years at 100pcs/year is only 1kpcs, or 200pcs for the minimum estimated in the OP.
Title: Re: Chip shortage, which microcontroller to choose
Post by: jmaja on November 28, 2022, 11:51:29 am
If you're used to AVR, the AVR-Dx would seem the next logical step.
Could be. Haven't really been following the new models, since I have been perfectly happy with XMega. Didn't even know about this. Seems to be released 2020. There were a lot of bugs in the early XMega revisions. Are the AVR-Dx already about bug free?

What might be the reason for XMega being totally out of stock, but AVR-Dx seems to have good stocks?  E.g. at Digi-Key only 2 of 224 normally stocked XMega's in stock vs 78 out of 171 for AVR-Dx.
Title: Re: Chip shortage, which microcontroller to choose
Post by: woofy on November 28, 2022, 03:51:15 pm
Unless this is an open source project, forget RP2040 - no code protection.

This one any good?
https://www.digikey.co.uk/en/products/detail/microchip-technology/ATXMEGA8E5-AN/5235860 (https://www.digikey.co.uk/en/products/detail/microchip-technology/ATXMEGA8E5-AN/5235860)
Title: Re: Chip shortage, which microcontroller to choose
Post by: T3sl4co1l on November 28, 2022, 04:02:17 pm
My guess, other than general popularity -- I'm guessing XMEGAs aren't actually all that much in demand? But, that's entirely a guess -- the -Dx are modern process node so pack a lot more in a smaller die.  They apparently have a low voltage regulator internal, no external bypass capacitor needed.  Hence the fine pitch process and modest clock frequency, despite the 5V IO capability.

Tim
Title: Re: Chip shortage, which microcontroller to choose
Post by: jmaja on November 28, 2022, 04:21:08 pm
Unless this is an open source project, forget RP2040 - no code protection.

This one any good?
https://www.digikey.co.uk/en/products/detail/microchip-technology/ATXMEGA8E5-AN/5235860 (https://www.digikey.co.uk/en/products/detail/microchip-technology/ATXMEGA8E5-AN/5235860)

Not an open source project, but I don't think my customers nor competitors would copy my design, thus not really a big issue. But what do you mean by "no code protection"? You are required to publish your code or that hex can be copied out from Flash? RP2040 seems to use an external Flash (or USB).

8 kB Flash is not enough. I'm currently using a 64 kB model, maybe 32 kB would still be OK.
Title: Re: Chip shortage, which microcontroller to choose
Post by: jmaja on November 28, 2022, 04:27:40 pm
the -Dx are modern process node so pack a lot more in a smaller die.  They apparently have a low voltage regulator internal, no external bypass capacitor needed.  Hence the fine pitch process and modest clock frequency, despite the 5V IO capability.
Doesn't seem to have an USB. So far I have used a FTDI USB module, but have thought about using XMega USB instead. Not a deal breaker, but adds some cost and space.
Title: Re: Chip shortage, which microcontroller to choose
Post by: RoGeorge on November 28, 2022, 04:37:09 pm
No code protection usually means the MCU doesn't have any physical lock-bits protection, or other physical mechanism in place (serial number, encryption, etc.) against stealing the binary firmware from an already programmed MCU.

It's about securing the firmware by hardware mechanisms, not about licensing or other written agreements.
Title: Re: Chip shortage, which microcontroller to choose
Post by: jmaja on November 28, 2022, 05:10:51 pm
No code protection usually means the MCU doesn't have any physical lock-bits protection, or other physical mechanism in place (serial number, encryption, etc.) against stealing the binary firmware from an already programmed MCU.

That's what I thought in this case. Since RP2040 doesn't have an internal FLASH, I guess no code protection comes from the design. Or is there a way to protect even the external FLASH somehow.

I have used lock-bits for disabling code download from XMega, but as said it's not that important to me. But I don't want to share my C-code.
Title: Re: Chip shortage, which microcontroller to choose
Post by: mariush on November 28, 2022, 05:44:49 pm
It would help to know what specifications you need... how much mips etc etc ... and your budget.

Digikey has lots of PIC16F and PIC18F with or without USB and 32K+ of flash in thousands or tens of thousands in stock, at 1-5$ if you buy just one... better prices in quantity.

For sure there's some ARM chips under 2-3$ each with 32 KB of memory.  ex STM32G030 with 64 KB flash and 8 KB ram (no usb) is 2.14$ at Digikey in 1 piece, $1.5 at 100 pcs : https://www.digikey.com/en/products/detail/stmicroelectronics/STM32G030K8T6/10326689 (https://www.digikey.com/en/products/detail/stmicroelectronics/STM32G030K8T6/10326689)

Some PIC24 chips have 128 KB of flash but not usb... but you say you use ftdi for usb ... so it's just some low speed serial / virtual com as usb ?
Title: Re: Chip shortage, which microcontroller to choose
Post by: NorthGuy on November 28, 2022, 06:16:01 pm
What would be a good option, which would likely be available now and for the coming about 10 years or so (the two current sensors I produce were designed in 2007 and 2013)? XMega has been easily fast enough (actually run at 4 MHz) and has enough ports (would need to have 1-2 SPI and 1 UART, maybe USB). I prefer to use GCC. 3.3 VCC would be easiest.

Very strange specification. If you need USB, then only MCUs with USB will do. This restricts the choice. If you don't need USB, then almost anything will do. You need to make up your mind first on that subject.

With your volume, I would buy 500 and that would be enough for a long long time, and you would get some volume break. There's always a danger that what you buy may not work for some reason, but if you were to develop and test everything only to find out that the your chip vanished out of stock, it would be a bummer.
Title: Re: Chip shortage, which microcontroller to choose
Post by: NorthGuy on November 28, 2022, 06:50:30 pm
Doesn't seem to have an USB. So far I have used a FTDI USB module, but have thought about using XMega USB instead. Not a deal breaker, but adds some cost and space.

If you buy 500 or 1000, using a USB-capable chip may save you $1000 or even more. The more you buy, the more important is the price.
Title: Re: Chip shortage, which microcontroller to choose
Post by: jmaja on November 28, 2022, 07:12:49 pm
Very strange specification. If you need USB, then only MCUs with USB will do. This restricts the choice. If you don't need USB, then almost anything will do. You need to make up your mind first on that subject.

When I started using XMega 10+ years ago I didn't really care about the USB it had. Later I thought I would use that in the next project, since it had it and was quite cheap (2-3 €). I can continue with FTDI providing USB, if that makes life easier.

This is not a  very price sensitive project. Thus I don't really care that much if the MCU costs 1 or 10 € as long as it works well and can be bought later as well. I don't want to spent 10 k€ beforehand. The sensors chip, enclosure etc are more expensive and the selling price orders of magnitude more due to design, calibration process and software.
Title: Re: Chip shortage, which microcontroller to choose
Post by: jmaja on November 28, 2022, 07:24:02 pm
It would help to know what specifications you need... how much mips etc etc ... and your budget.

Digikey has lots of PIC16F and PIC18F with or without USB and 32K+ of flash in thousands or tens of thousands in stock, at 1-5$ if you buy just one... better prices in quantity.

MIPS is not a problem most likely. As said I have run XMega at only 4 MHz. There will be some floating point calculations including trigonometric functions, but that has not been a problem at all for XMega at 4 MHz outputting data up to 50 Hz. Probably no problem having 2 MHz SPI and 115200 bps UART, at least with hardware UART/SPI of XMega.

As said USB would be a nice to have option, but I can continue with FTDI.

For some reason I don't like PIC. Haven't ever used them, thus really no reason.

Budget up to 10 €/each.

Low component count is a plus. I have liked the internal accurate enough oscillator.
Title: Re: Chip shortage, which microcontroller to choose
Post by: SiliconWizard on November 28, 2022, 07:29:06 pm
You could consider the STM32G0 line in this price range. You have a selection of parts supporting USB starting at about $2.
Title: Re: Chip shortage, which microcontroller to choose
Post by: hans on November 28, 2022, 08:10:33 pm
No code protection usually means the MCU doesn't have any physical lock-bits protection, or other physical mechanism in place (serial number, encryption, etc.) against stealing the binary firmware from an already programmed MCU.

That's what I thought in this case. Since RP2040 doesn't have an internal FLASH, I guess no code protection comes from the design. Or is there a way to protect even the external FLASH somehow.

I have used lock-bits for disabling code download from XMega, but as said it's not that important to me. But I don't want to share my C-code.

Some MCUs have on the fly decryption for code of external memories. That way only the plain binary is only accessible from inside the chip regions, similar to FLASH code protection.

I'm not going to argue whether you need code protection. If you decide on not needing it, then that's clear. However, as a default stance in any commercial product, I do recommended using it. That's why I wouldn't consider a RP2040 as a good choice for a commercial project. RPi is about education and accessibility after all.

ESP32s are also affordable and available, etc., and I've seen the datasheet/user manual mention it can protect the binary that's stored in external FLASH. How so: no idea, never done it.


Another option to consider is perhaps the PIC24s. The PIC24FJ64GB004 has USB and internal oscillator that's accurate enough for it. It's a different architecture than 8-bit PICs and in that regard quite similar to AVRs. Although, I do wonder: have you used the XMEGA with MPLAB X or Atmel Studio? Some toolchains tend to lead to quite strong opinions, besides how the chip and architecture may operate.
Title: Re: Chip shortage, which microcontroller to choose
Post by: jmaja on November 28, 2022, 08:44:33 pm
Although, I do wonder: have you used the XMEGA with MPLAB X or Atmel Studio? Some toolchains tend to lead to quite strong opinions, besides how the chip and architecture may operate.

Neither. I do have Atmel Studio, but have used GCC directly with my own Makefiles from command line (CygWin + X) and using Emacs as an editor. I hate using Atmel Studio, but sometimes it is necessary to use it due to simulator etc. I also hate the code Atmel Studio procuces and is used in all tuturials and libraries. My code is very different looking and doesn't use the long function call chains used in tutorials.

Never heard of MPLAB X.

I guess I would need to use Atmel Studio for USB, since that would not be worth while coding from scratch.
Title: Re: Chip shortage, which microcontroller to choose
Post by: wek on November 28, 2022, 09:22:59 pm
You could consider the STM32G0 line in this price range. You have a selection of parts supporting USB starting at about $2.
STM32G0xx don't have USB (except 'G0Bx/'G0C1). Most of them has support for USBC-PD, and that is not USB.

JW
Title: Re: Chip shortage, which microcontroller to choose
Post by: robint91 on November 28, 2022, 11:48:15 pm
Nowadays I just use a ESP32S3-FN8.

- Cheap 2.4€/pcs
- internal flash, 8MBytes
- Decent amount of RAM
- manageable peripherals
- ESP-IDF is quite good, "batteries included" but still low level enough.
- Has USB
- Has secure options
- Has WiFi/ble

I find it really difficult to find a use for other brands when you aren't IO bound.
Title: Re: Chip shortage, which microcontroller to choose
Post by: westfw on November 29, 2022, 02:47:50 am
Quote
Never heard of [Rp2040]
Haven't really been following the new [AVR] models, since I have been perfectly happy with XMega.
Never heard of MPLAB X.
Umm.  You should probably pay more attention to ... things in general.

The AVR-Dx are sort of xmega-lite.  They have rich peripherals similar to xmega, but no DMA and no USB (so far.)

Quote
Are the AVR-Dx already about bug free?
Alas, not.  Relatively long errata, which you should check out before trying to use them.

Quote
totally impossible to get most of the active components
Yeah, the current chip shortage is pretty sucky and unpredictable, especially in the quantity range you mentioned.
For all we know, the xMegas might come back before the rest of the components you need. :-(
Title: Re: Chip shortage, which microcontroller to choose
Post by: nctnico on November 29, 2022, 02:52:51 am
Nowadays I just use a ESP32S3-FN8.

I find it really difficult to find a use for other brands when you aren't IO bound.
That is a good option. Has a Risc-V core if I'm not mistaken. Chips designed in / from China have been surprisingly available despite the shortages.
Title: Re: Chip shortage, which microcontroller to choose
Post by: RoGeorge on November 29, 2022, 08:48:28 am
Chips designed in / from China have been surprisingly available despite the shortages.

China might not be a reliable source of MCU either.

Social media tells a rebellion is spreading through China right now, people gathering, demonstrating and fighting with police because they can not take any more the fake virus story, and its zero covid measures.  There was a fire in one of their sealed building, and people burnt alive because they couldn't get out of the building.  Complete isolation there means no way to go out, all the doors are locked and welded, by welders.  Or at least that's what social media shows.
Title: Re: Chip shortage, which microcontroller to choose
Post by: nctnico on November 29, 2022, 05:27:46 pm
Chips designed in / from China have been surprisingly available despite the shortages.

China might not be a reliable source of MCU either.

Social media tells a rebellion is spreading through China right now, people gathering, demonstrating and fighting with police
That is not going to affect production in any way. In the US people actually stormed and occupied the capitol building where the nation's top ranking politicians 'work'. That didn't have any effect on the country's productivity either.
Title: Re: Chip shortage, which microcontroller to choose
Post by: Doctorandus_P on November 29, 2022, 11:22:09 pm
... AVR-Dx would seem the next logical step.  Peripherals are different from both MEGA and XMEGA so there's some getting used to. 


Huh what?
They've done it again?

I was already annoyed by peripheral incompatibilities between the Mega's and the tinies. At some point I was interested in a faster uC, mainly for TFT LCD's, and I had a look at the Xmega's, and then I learned they were so dissimilar that I might as wel go to a completely different uC family, and I settled on STM32. The main reasons for that were the blue pills (which had a real STM back then) , the pretty nice ST-Link V2 clones, (with an upgrade path to the Open Soure Black Magic Probe, and the GCC copiler and pretty open development tools.

These day's I only use the old atmega's for the projects where they "fit", because I have no interest to buy a new programmer every 5 year because they changed the programming interface again.
Title: Re: Chip shortage, which microcontroller to choose
Post by: westfw on November 29, 2022, 11:35:50 pm
Quote
They've done it again?
I was already annoyed by peripheral incompatibilities between the Mega's and the tinies.
Yep.  Not only different peripherals, but a whole new way of accessing them (now structure-based rather than individual registers.)

On the bright side, I think the new Tinies and Megas are more compatible with each other than they've been in the past.

Title: Re: Chip shortage, which microcontroller to choose
Post by: nctnico on November 30, 2022, 01:09:01 am
Quote
They've done it again?
I was already annoyed by peripheral incompatibilities between the Mega's and the tinies.
Yep.  Not only different peripherals, but a whole new way of accessing them (now structure-based rather than individual registers.)
Using structs and a typedef to access peripheral registers is standard nowadays. It takes some getting used to and you can argue it is syntactic sugar coating. OTOH in many cases modern day microcontrollers have several identical peripherals and having a pointer to a struct makes it easier to deal with a peripheral. You can have functions that accept a pointer to such a struct and deal with a peripheral in a unified way. Instead of copying the same code over and over with different register names.

Not so long ago I rewrote my UART handling abstration layer to use an array with pointers to structeres with the registers. The interrupt handler calls a function with the pointer for the particular UART. Works nicely for NXP and ST ARM microcontrollers.
Title: Re: Chip shortage, which microcontroller to choose
Post by: T3sl4co1l on November 30, 2022, 11:10:11 am
Quote
They've done it again?
I was already annoyed by peripheral incompatibilities between the Mega's and the tinies.
Yep.  Not only different peripherals, but a whole new way of accessing them (now structure-based rather than individual registers.)

On the bright side, I think the new Tinies and Megas are more compatible with each other than they've been in the past.

Well, that was introduced with the XMEGAs, but they carry on.  DA is based on xmega2 core, I think ("AVRxt" in the instruction datasheet).

The weirdest syntactical thing about that, I think, is the TCA is written as a union even.  So you have to specify TCA0.SINGLE.BLAH or .SPLIT. every single time.  But eh, it's just for a little IO, and toss it in a macro if you find it annoying.


I found the TCD docs highly confusing, and TCA a bit hard to parse but not quite as bad, and TCB factually wrong on a certain aspect (when they say it's "stopped", in applicable states, they really mean it doesn't count when CNT = 0 or CMP or whatever; likewise, you can force a reset by setting CNT = CMP or MAX; the text implies additional internal states, but in fact, as far as I can tell, it's strictly the count compared to other registers, and decision logic so you aren't required to use an event to trigger/stop it).  I think everything else is pretty much as it says, as you'd expect?  Again, check the errata of course.  I didn't discover any device errata (doc errata I would argue so), but confirmed a few, they're not too bad.

Going from MEGA to XMEGA/Dx will be a minor culture shock because of the syntax, yeah; from XMEGA to Dx, almost nothing.  PORT, USART, SPI, DAC and probably others will be familiar from XMEGA; ADC is... kind of hybrid I'd say, some XMEGA features (and yes it's 12 real bits, and the internal refs aren't bad), but stripped down a bit (no auto sequenced mux, have to service that from interrupt).

At least, that was the DA I used most recently, perhaps more advanced peripherals (bring back XMEGA ADC? etc.) go on the later series, I haven't checked.

If you're particularly slow at reading peripherals docs*, by all means invest in something much more powerful, and potentially more consistent across the series / families.  (I don't know much detail offhand about STM32s, I would guess they do a mix of both [keeping and changing things] too?)

(*Not a knock, just an honest self assessment.  I feel like my own reading comprehension has dropped a bit over the years.  Not enough to be a problem, but I feel slower I mean.  If you're much slower still, or more error prone, indeed it would be a good investment to commit to studying, in as much detail as you can force yourself through, a platform more powerful than you will usually need, so you aren't stuck poring over datasheets of myriad smaller chips, but also bigger chips, on the occasion you would otherwise need to use them.  The cost is easily justifiable as long as quantities are small (sub 1000s?).  Or, also a possibility in this sort of case, you could have [late onset?] ADHD, and treatment may be available; in any case, whatever works for you. :-+ )


These day's I only use the old atmega's for the projects where they "fit", because I have no interest to buy a new programmer every 5 year because they changed the programming interface again.

FYI, if you have like a AVRISPMKII or newer, PDI is supported, which means XMEGA is available.  The Dx use UPDI, but UPDI doesn't even need a programmer as such, you can do it from any old serial port (logic level) with a resistor.  I literally use a FTDI TTL-232R-3V3 and adapter cable.  Be sure to get the latest version AVRDude to support it.  But yeah, notwithstanding the above. :)

Tim