Author Topic: Choosing a Microcontroller  (Read 2958 times)

0 Members and 1 Guest are viewing this topic.

Offline wmdunnTopic starter

  • Newbie
  • Posts: 6
  • Country: us
Choosing a Microcontroller
« on: December 14, 2023, 11:16:55 pm »
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!
 

Offline moffy

  • Super Contributor
  • ***
  • Posts: 1894
  • Country: au
Re: Choosing a Microcontroller
« Reply #1 on: December 15, 2023, 12:58:30 am »
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.pdf
The 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-KE16Z
Hope that helps. :)
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 12976
Re: Choosing a Microcontroller
« Reply #2 on: December 15, 2023, 01:28:02 am »
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!
Microchip 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.
 

Offline Andy Chee

  • Frequent Contributor
  • **
  • Posts: 774
  • Country: au
Re: Choosing a Microcontroller
« Reply #3 on: December 15, 2023, 03:10:02 am »
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.
 

Online peter-h

  • Super Contributor
  • ***
  • Posts: 3780
  • Country: gb
  • Doing electronics since the 1960s...
Re: Choosing a Microcontroller
« Reply #4 on: December 15, 2023, 12:23:53 pm »
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.
Z80 Z180 Z280 Z8 S8 8031 8051 H8/300 H8/500 80x86 90S1200 32F417
 

Offline mariush

  • Super Contributor
  • ***
  • Posts: 5105
  • Country: ro
  • .
Re: Choosing a Microcontroller
« Reply #5 on: December 15, 2023, 12:55:06 pm »
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/12807575

PIC16F15223 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/12807224


But 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) or https://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 them
 
MSP430 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


 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 17881
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: Choosing a Microcontroller
« Reply #6 on: December 15, 2023, 01:32:17 pm »
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.
 

Offline tooki

  • Super Contributor
  • ***
  • Posts: 12033
  • Country: ch
Re: Choosing a Microcontroller
« Reply #7 on: December 15, 2023, 03:20:10 pm »
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.
Given 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 code worse than the compiler’s…
 
The following users thanked this post: TomWinTejas

Offline Doctorandus_P

  • Super Contributor
  • ***
  • Posts: 3554
  • Country: nl
Re: Choosing a Microcontroller
« Reply #8 on: December 15, 2023, 03:38:42 pm »
Recently I had a brief look into the datasheet of an attiny3226

It 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 out :) but 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.
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 17881
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: Choosing a Microcontroller
« Reply #9 on: December 15, 2023, 03:39:41 pm »
Assembler is the last thing anyone should be using unless it can only be done in assembler.
 
The following users thanked this post: tooki

Offline Simon

  • Global Moderator
  • *****
  • Posts: 17881
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: Choosing a Microcontroller
« Reply #10 on: December 15, 2023, 03:42:58 pm »
Recently I had a brief look into the datasheet of an attiny3226

It 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.


That 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.
 

Offline bson

  • Supporter
  • ****
  • Posts: 2311
  • Country: us
Re: Choosing a Microcontroller
« Reply #11 on: December 15, 2023, 07:49:41 pm »
A very important selection for me is if it is compatible with GCC. Does MSP430 do GCC?
Yes, 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.)
 

Offline Andy Chee

  • Frequent Contributor
  • **
  • Posts: 774
  • Country: au
Re: Choosing a Microcontroller
« Reply #12 on: December 15, 2023, 09:10:59 pm »
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.
Given 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 code worse than the compiler’s…
My 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.

 

Offline mariush

  • Super Contributor
  • ***
  • Posts: 5105
  • Country: ro
  • .
Re: Choosing a Microcontroller
« Reply #13 on: December 15, 2023, 09:59:18 pm »
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
 

Offline tooki

  • Super Contributor
  • ***
  • Posts: 12033
  • Country: ch
Re: Choosing a Microcontroller
« Reply #14 on: December 15, 2023, 11:39:13 pm »
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.
Given 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 code worse than the compiler’s…
My Arduino Uno version of "Hello World!" HD44780, complies larger than my 16F628 assembly version of the same thing.
Different 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…
 

Offline nigelwright7557

  • Frequent Contributor
  • **
  • Posts: 697
  • Country: gb
    • Electronic controls
Re: Choosing a Microcontroller
« Reply #15 on: December 16, 2023, 12:13:12 am »
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.

 

Offline PCB.Wiz

  • Super Contributor
  • ***
  • Posts: 1670
  • Country: au
Re: Choosing a Microcontroller
« Reply #16 on: December 16, 2023, 05:58:54 am »
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 ADC

Lcsc have STC8H8K64U-45I-SOP16 for 28c/100

addit:
Quote
This works on an Arduino UNO, however I'd like to stay away from ATMEGAs as I don't think they're manufactured anymore.
The 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 Nuvoton

Quote
Introducing the New Nuvoton N76S003 Series!
Newly upgraded from the N76E003 series, the specifications are consistent, allowing you to easily transfer.
。    Lower Power Consumption: Under 2 mA @ normal mode
。    New Encryption Protection Function: SPROM Flash for security code
。    Increased SRAM: XRAM area extended to 1 KB (18kFlash)
22c ea TSSOP20 / QFN20

If you want smaller, Silabs have EFM8BB50 series, in 2x2 and 2.5x2.5mm QFN as well as a very easy SO16N
« Last Edit: December 17, 2023, 08:58:05 pm by PCB.Wiz »
 

Online DavidAlfa

  • Super Contributor
  • ***
  • Posts: 6082
  • Country: es
Re: Choosing a Microcontroller
« Reply #17 on: December 16, 2023, 06:53:31 am »
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.

My Arduino Uno version of "Hello World!" HD44780, complies larger than my 16F628 assembly version of the same thing.
Comparing Arduino vs assembler makes no sense, not even to a properly optimized C program...
« Last Edit: December 16, 2023, 10:43:59 pm by DavidAlfa »
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 17881
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: Choosing a Microcontroller
« Reply #18 on: December 16, 2023, 09:00:52 am »
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.
Given 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 code worse than the compiler’s…
My 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.



Remember 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.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf