Choosing a Microcontroller - Page 1
Forum section: electronics / projects

author: wmdunn
author_rank: Newbie
timestamp: December 14, 2023, 11:16:55 pm
content: Hey guys,I'm having trouble figuring out what specifications a microcontroller for my current project needs to have. The application: it sends a digital output to a transistor which acts as a switch to control a DC motor, and also reads a voltage from a pressure transducer and converts the voltage to a pressure value (via code I wrote) and displays it on an LCD.I think it needs at least 1 digital pin, an analog pin, an SCL pin, and an SDA pin. Must be powered by 5 volts. 8-bit. I'm unsure of what memory needs it has (RAM, EEPROM, ROM, Flash, etc.). The device I'm building is not battery powered, but low power consumption is always nice. Smaller size and surface mounted would also be nice as I'm designing a PCB to go along with it.Does anyone have have any corrects to my conjecture? Or any suggestions for a microcontroller? This works on an Arduino UNO, however I'd like to stay away from ATMEGAs as I don't think they're manufactured anymore. Thanks so much!

author: moffy
author_rank: Super Contributor
timestamp: December 15, 2023, 12:58:30 am
content: The first thought is a low power ARM M0 of some sort but the 5V is a bit unusual, so I did a quick search and came up with the NXP Kinetis KE1xZ which can run off 5V:https://au.mouser.com/datasheet/2/302/nxp_phgl-s-a0007665085-1-1750475.pdfThe NXP development environment is free with good examples and has a low cost development board available:https://www.nxp.com/design/design-center/development-boards/freedom-development-boards/mcu-boards/freedom-development-platform-for-48mhz-ke1xz64-32-mcus:FRDM-KE16ZHope that helps.

author: Ian.M
author_rank: Super Contributor
timestamp: December 15, 2023, 01:28:02 am
content: Quote from: wmdunn on December 14, 2023, 11:16:55 pmMicrochip bought Atmel. Microchip have a reputation for continuing to produce MCUs as long as there is any demand, (even though they'll often suggest a pin compatible alternative, with typically twice the memory and performance for half the price) long after other companies would have quit production.Also there's the Aries ATmega328P clone. Buy '328 based Arduinos or just the '328 chip, off Amazon, Ebay or any of the far east eBazaar sites and odds are you'll get a fake Atmel branded ATmega328P, with an Aries die inside it. As long as you don't need low power sleep, its such a good clone you'll be hard pressed to tell the difference.TLDR: The ATmega328P isn't going away for many years, maybe even several decades.OTOH it certainly doesn't offer the best value for money as there are plenty of other cheaper 8 bit MCUs suitable for your application. It all depends on the quantity you expect to build . . . <100 you'll never recover the cost of porting it to another MCU, >100000 and you'd be a fool not to, to reduce uniit cost.

author: Andy Chee
author_rank: Super Contributor
timestamp: December 15, 2023, 03:10:02 am
content: Incidentally, you may be able to get away with less memory RAM/ROM if you code in assembly, rather than compiled C. Your compiler should tell you how much memory your code requires.

author: peter-h
author_rank: Super Contributor
timestamp: December 15, 2023, 12:23:53 pm
content: This could be done with a very low-end CPU.I would say the key decision is what else will this chip be used for in the future. You do not want to re-learn everything.A 32F4xx (I use that) is about 10k times fast enough for this job. But at $5 (10k+) that probably doesn't matter.Try to think of features which the competition doesn't have. If the competition is chinese they tend to just do the minimum.

author: mariush
author_rank: Super Contributor
timestamp: December 15, 2023, 12:55:06 pm
content: Yeah... there's gonna be Atmega328p for decades, or chinese clones of it.But if you don't want to spend $1.5 for one, there's PIC chips at half the price (of course with less space and ram, but maybe you don't need that much storage and ram either way)For example PIC16F15245 (7.5KB code, 1 KB ram) is 0.8$ , 0.65$ if you get 100 :https://www.digikey.com/en/products/detail/microchip-technology/PIC16F15245T-I-SS/12807575PIC16F15223 with 3.5 KB code and 256 bytes of ram is half a dollar if you get 100 :https://www.digikey.com/en/products/detail/microchip-technology/PIC16F15223-I-MG/12807224But you could probably spend a few hours just looking through parameters to choose a pic with exactly the amount of io you need, maybe get one with lcd driver integrated if you plan to use a bare lcd display and not some i2c/serial/parallel alphanumeric display or seven-segment led display.The programmers are cheap, under 30-40$.Outside Microchip, if you don't want to get into 32 bit ARM and complex microcontrollers .... personally, I would like to try Silicon Labs EFM8 (busy bee 5v ) :https://www.digikey.com/en/products/detail/silicon-labs/EFM8BB51F8G-C-QFN20R/15276589(qfn) orhttps://www.digikey.com/en/products/detail/silicon-labs/EFM8BB51F8G-C-TSSOP20/15276611(tssop)but I'd be a bit worried about availability, otherwise the cores are ancient 8051 so shouldn't be that hard to code for themMSP430 could be interesting but afaik it's max 3.6v so you'd also need a ldo to reduce 5v to 3.6v and you may need a voltage translator from 3.3v/3.6v to 5v if it needs to interact with other devices.And again, there's the issue of availability .. for example :https://www.digikey.com/en/products/detail/texas-instruments/MSP430FR2110IRLLR/6572208

author: Simon
author_rank: Unknown
timestamp: December 15, 2023, 01:32:17 pm
content: If you want 5V and are doing something simple just grab any 8 bit micro that will do 5V, there are some around now that only go up to 3.3V. In ARM land the only one I know of is the SAMC21 but this is not a basic chip and a bit of a ballistic missile to crack a nut so not as easy to get running on as your bogo 8 bitters. On the other hand if you want something to grow into it's not a bad choice and has bigger brothers.

author: tooki
author_rank: Super Contributor
timestamp: December 15, 2023, 03:20:10 pm
content: Quote from: Andy Chee on December 15, 2023, 03:10:02 amGiven how extraordinary modern compilers are at optimization, the chances that someone who is still this much of a beginner (that they need help choosing an MCU) could do better than the compiler is slim. I mean, I know I’d end up creating machine codeworsethan the compiler’s…

author: Doctorandus_P
author_rank: Super Contributor
timestamp: December 15, 2023, 03:38:42 pm
content: Recently I had a brief look into the datasheet of an attiny3226It seems the tiny's are growing up now. It is a bit low on timers but got two uart (with SPI?) peripherals, and some extra things such LUT tables and pins can be mapped to another location, so you can have both an 8-bit port and uart running at the same time.It has 32kB flash. There are also 4, 8, and 16k versions, but they cost the same so why bother? They are all below EUR1.5 and that makes price irrelevant for all practical hobby purposes. The are around 1/3 the cost of the atmega328, but the annoyance is that you need yet another programmer to get started.There are also 14 pin and 24 pin versions, the 24 pin has a fine pitch package, which makes it less suitable for hobby, while the 14 & 20 pin packages are available in 1.27mm pitch, which even fits reasonably on perf board if you bend a few pins a bit. The 2.5mm length difference is also insignificant, so I'd go for the 20 pin variant. SOIC is small enough that size would hardly matter at all, and big enough for easy soldering / inspection / modifications / tinkering / etc.But more importantly. I don't choose microcontrollers on a project basis. I want to buy some stock so I can just grab an uC when want to do a project. At the moment I have atmega8 and atmega328 on stock (and a bunch of STM32Fxxxx). And I never liked their pinout. You can't have uart and an 8-bit port at the same time and that is a nuisance for me.A very important selection for me is if it is compatible with GCC. Does MSP430 do GCC? also have a few Cypress C7CY68013A chips, but these are a bit weird beasts. There is no flash to wear outbut they do need some other connection to get started. Normally they get their software (or should it still be called firmware?) over USB via DFU. But I never used them for anything different then a Logic Analyzer for Sigrok / Pulseview.

author: Simon
author_rank: Unknown
timestamp: December 15, 2023, 03:39:41 pm
content: Assembler is the last thing anyone should be using unless it can only be done in assembler.

author: Simon
author_rank: Unknown
timestamp: December 15, 2023, 03:42:58 pm
content: Quote from: Doctorandus_P on December 15, 2023, 03:38:42 pmThat is because all modern AVR's are based on the Xmega, microchip being microchip have fucked it up for everyone by using an old name for something new. They will be nothing like the old ATTiny's. To add insult to injury they then realized the mess they made and started to come out with new chips that are just like the new ATmega/ATtiny that are just like the old Xmega and just called them A, B, C, D like the bunch of useless assholes they are.

author: bson
author_rank: Unknown
timestamp: December 15, 2023, 07:49:41 pm
content: Quote from: Doctorandus_P on December 15, 2023, 03:38:42 pmYes, in fact TI supports gcc for the MSP430 - meaning they maintain the target support. TI's own compiler also implements most common gcc'isms, like attributes, builtins, inline asm syntax (same for their assembler, so no worries about inline asm), and if memory serves linker command files, and code usually just compiles and runs. It produces better code in many cases and the debugger is a little nicer than GDB form their IDE (but last I checked not quite as functional, you can't for example just call a function from it, which is one of the great features of GDB). It can sometimes also be worthwhile simply compiling with it since it can find issues that gcc won't, but it does have some differences in particular for C++ that tend towards the obscure. (Such as what specifically constitutes a constexpr when it knows a non-const value is never going to change due to inlining or template specialization.)

author: Andy Chee
author_rank: Super Contributor
timestamp: December 15, 2023, 09:10:59 pm
content: Quote from: tooki on December 15, 2023, 03:20:10 pmMy Arduino Uno version of "Hello World!" HD44780, complies larger than my 16F628 assembly version of the same thing.If this was a mass produced product and you wanted to choose the lower specced micro to save on product costs, then coding in assembler may be a strategy to realise that goal, depending of course on the complexity of your program code. However the unit sales might have to be in the 10,000s to make a noticeable difference between choosing a low spec over a high spec processor.For everyday hacking, cost is not an issue, so feel free to use a high spec processor beyond your actual design requirements.

author: mariush
author_rank: Super Contributor
timestamp: December 15, 2023, 09:59:18 pm
content: I was reminded by the long detailed article / website "The amazing 1$ microcontroller" by Jay Carlson :https://jaycarlson.net/microcontrollers/He runs 21 microcontrollers priced at that moment at around 1$ through various tests and compares their features and everything. Some micros may not be available anymore, others may have improved documentation or programming environments, the article is quite old, from around 2017, so sure to be much better microcontrollers at the 1$ threshold but still worth checking out the link

author: tooki
author_rank: Super Contributor
timestamp: December 15, 2023, 11:39:13 pm
content: Quote from: Andy Chee on December 15, 2023, 09:10:59 pmDifferent CPU architectures and instruction sets and toolchains, so can’t be compared directly. AVR is a RISC architecture, which typically requires more instructions (and thus larger code) to do the same thing.What would be more interesting is to write it in C in MPLAB X and compile it for your PIC.That or rewrite it in AVR assembly…

author: nigelwright7557
author_rank: Frequent Contributor
timestamp: December 16, 2023, 12:13:12 am
content: I tend to be a PIC man and there is vast choice to go at.Just make sure what you want is in stock first.

author: PCB.Wiz
author_rank: Super Contributor
timestamp: December 16, 2023, 05:58:54 am
content: If you need 5V, you could look at wide Vcc parts (sub 2v ~ 5.5V)You could also select by package.TSSOP20 is very common, and has broadly common pin outs.STC have USB MCU with 64kF and 8kR that has a wide package choice, and a clk PLL, & 12b ADCLcsc have STC8H8K64U-45I-SOP16 for 28c/100addit:QuoteThe Mega328 will still be available for some time, but they are at tail-end pricing.The newer AVRs have on chip regulators, so their MHz does not fall with Vcc.8bit MCUs are still active, I got this email from NuvotonQuoteIf you want smaller, Silabs have EFM8BB50 series, in 2x2 and 2.5x2.5mm QFN as well as a very easy SO16N

author: DavidAlfa
author_rank: Super Contributor
timestamp: December 16, 2023, 06:53:31 am
content: Any reason for 8bit and 5v requirements?Wouldn't be ok with 3.3V ldo and much better 32bit ARM?I keep recommending the $0.11 Puya PY32F002A, tssop-20.Quote from: Andy Chee on December 15, 2023, 09:10:59 pmComparing Arduino vs assembler makes no sense, not even to a properly optimized C program...

author: Simon
author_rank: Unknown
timestamp: December 16, 2023, 09:00:52 am
content: Quote from: Andy Chee on December 15, 2023, 09:10:59 pmRemember that when you make large volumes the prices drop dramatically anyway. Most of what you pay is distribution costs. People who have runs of chips made for them will be getting the lowest prices as they are sometimes the catalyst for the distributors getting any. Infineon BTS smart switches come to mind. Very automotive, quite expensive from distribution, but I bet AUDI does not pay anything like we pay to kit out an electronic relay box, they probably are the reason any are made at all.