Small and cheap MCU with DAC - Page 1
Forum section: electronics / projects

author: Unixon
author_rank: Frequent Contributor
timestamp: December 16, 2018, 02:02:50 pm
content: Hi,Can anyone suggest a cheap MCU with a single DAC channel capable of about 30-50kSPS for sound playback.Small SMD package in range SOT23-SO8-QFN20 is preferred, TSSOP20 and alike is nearly largest acceptable package.

author: technix
author_rank: Super Contributor
timestamp: December 16, 2018, 03:20:11 pm
content: Quote from: Unixon on December 16, 2018, 02:02:50 pmAre you okay with two-chip solutions? If so, there are multiple I2S DAC in MSOP-8 or smaller packages that can go along with a STM32F030 or STM32F042 in TSSOP-20 or QFN-28. Those runs at least 48ksps, often 96ksps.

author: Wimberleytech
author_rank: Super Contributor
timestamp: December 16, 2018, 03:35:42 pm
content: Quote from: Unixon on December 16, 2018, 02:02:50 pmSiLabs C8051F411 has two current DACs and comes in a 20 pin QFN package.

author: wraper
author_rank: Unknown
timestamp: December 16, 2018, 03:44:33 pm
content: Most of Silabs EFM8 laser bee family have 2/4 12 bit 200ksps voltage DACs. EFM8BB3 series have them too. They also should have ARM with more advanced DACs as well. Their MCUs are pretty good in analog part.

author: technix
author_rank: Super Contributor
timestamp: December 16, 2018, 03:46:11 pm
content: Quote from: Wimberleytech on December 16, 2018, 03:35:42 pmIs that thing fast enough though... And it is a 12-bit job.

author: Wimberleytech
author_rank: Super Contributor
timestamp: December 16, 2018, 03:59:40 pm
content: Quote from: technix on December 16, 2018, 03:46:11 pmIt has an internal 25MHz clock source, runs most instructions in one or two clock cycles. Can use an external 50MHz clock source.You do not need to drive the DAC with 12 bits. Just drive the upper 8 bits. Whether it is fast enough depends on your code overhead...prolly needs some analysis to be sure.

author: Unixon
author_rank: Frequent Contributor
timestamp: December 16, 2018, 04:12:48 pm
content: Quote from: technix on December 16, 2018, 03:20:11 pmI'm totally OK with that, but the total price tag will be out of range probably.Out of well known AVR/STM32 series I see a tiniest MCU with DAC will make $0.5-$1 by itself which is already at the top.ATTINY212 started family and STM32F031/F032-s are both pretty good MCUs with remarkably different performance.I'm just curious what else good alternative to these low-end MCUs are in other popular families...Well, I think the software will also be the limiting factor here so I can't really tell if an MCU fits unless I know the firmware requirements.

author: wraper
author_rank: Unknown
timestamp: December 16, 2018, 04:19:00 pm
content: What exactly is that audio? EFM8BB3 is among the cheapest with DAC.https://eu.mouser.com/ProductDetail/Silicon-Labs/EFM8BB31F16I-B-4QFN24?qs=sGAEpiMZZMve4%2fbfQkoj%252bFTsmtn1iS1fkue2JzQjlAw%3d

author: Unixon
author_rank: Frequent Contributor
timestamp: December 16, 2018, 04:25:06 pm
content: Quote from: Wimberleytech on December 16, 2018, 03:35:42 pmUnfortunately, this one is an order of magnitude out of price range.Quote from: wraper on December 16, 2018, 03:44:33 pmEFM8LB1x and EFM8BB3 looks good, thanks, I'll save that for alternative solution.These are computationally more powerful than STM32F03x but more expensive at the same time.

author: Unixon
author_rank: Frequent Contributor
timestamp: December 16, 2018, 04:34:49 pm
content: Quote from: wraper on December 16, 2018, 04:19:00 pmOh, I'm sorry, I wasn't clear on that. I need a tiny sound effect generator/player and I'm looking for a MCU+DAC+firmware type of solution.The sound quality is not a big question, from LPF filtered PWM to 8bit will probably be too harsh, but at least 12bit at 48kSPS is already OK.

author: wraper
author_rank: Unknown
timestamp: December 16, 2018, 04:36:05 pm
content: Quote from: Unixon on December 16, 2018, 04:25:06 pmThey are 8 bit, so generally they are slower than STM32F03x for computations. EFM8BB3 is 1.5-2x cheaper than STM32F03x depending on quantity.

author: Unixon
author_rank: Frequent Contributor
timestamp: December 16, 2018, 04:39:59 pm
content: Quote from: wraper on December 16, 2018, 04:36:05 pmOh sh*... I was looking at MHz column aloneWell, then STM32F03x beats them on price and may very well beat them on performance.

author: wraper
author_rank: Unknown
timestamp: December 16, 2018, 05:05:17 pm
content: Quote from: Unixon on December 16, 2018, 04:39:59 pmWhere it beats them in price? STM32F03x is more expensive.

author: Wimberleytech
author_rank: Super Contributor
timestamp: December 16, 2018, 05:12:12 pm
content: Quote from: Unixon on December 16, 2018, 04:34:49 pmhttp://keterex.com/pubs/kx1400br.pdf

author: Unixon
author_rank: Frequent Contributor
timestamp: December 16, 2018, 05:31:09 pm
content: Quote from: wraper on December 16, 2018, 05:05:17 pmAt my local supplier, however, this strongly depends on which chip it is, price ratio could go both ways.STM32F031F4P6 is about $1-$1.5 in volume other chips range up to $2-3.EFM8BB31* well ... is about the same range in volume.For low quantities locals want like 5-10 times of volume price for top of the line chips.

author: wraper
author_rank: Unknown
timestamp: December 16, 2018, 05:34:06 pm
content: Quote from: Unixon on December 16, 2018, 05:31:09 pmDid you actually check mouser link? And who the hell uses local supplier when price is concern?

author: SiliconWizard
author_rank: Super Contributor
timestamp: December 16, 2018, 05:51:47 pm
content: Quote from: Unixon on December 16, 2018, 04:34:49 pmAlright. So if I get it well, you need an MCU under $1, small package, with a 12-bit DAC output and fast enough to generate sound effects at 48kSps...Some suggestions:* ATSAMD10D14: if the limited RAM/Flash and 10-bit DAC is ok* EFM8BB3 family

author: Unixon
author_rank: Frequent Contributor
timestamp: December 16, 2018, 05:55:22 pm
content: Quote from: wraper on December 16, 2018, 05:34:06 pmYes, I've checked that. We're in a little different location to mouser, so...Generally speaking, for small quantities needed for development purposes shipping costs and time often outweighs low unit prices.As for large quantities and production runs... I'm not really sure why manufacturing people don't like buying from mouser, probably there are some problems with importing stuff or maybe they just want to offload these issues of legal fighting with customs to big local suppliers and just get parts quickly on demand.

author: SiliconWizard
author_rank: Super Contributor
timestamp: December 16, 2018, 06:01:36 pm
content: The EFM8BB31F16G-B-QFN24 is available at mouser for $0.78 per 1.

author: Unixon
author_rank: Frequent Contributor
timestamp: December 16, 2018, 06:05:10 pm
content: Quote from: SiliconWizard on December 16, 2018, 05:51:47 pmYes, this is correct.Quote from: SiliconWizard on December 16, 2018, 05:51:47 pmLooks like this MCU is comparable to STM32F03x series, thanks, I will keep it as another good alternative.

author: wraper
author_rank: Unknown
timestamp: December 16, 2018, 06:11:45 pm
content: Quote from: Unixon on December 16, 2018, 05:55:22 pmSo what? Depending on where you are located $50-200 order value will give free shipping and they'll do customs for you. Where are you located BTW?

author: 0xdeadbeef
author_rank: Super Contributor
timestamp: December 16, 2018, 06:27:40 pm
content: For the record: the NXP LPC802/LPC804 also come with a DAC and are available down to TSSOP20 packages. Price for a single LPC802 is $1,12 at Mouser.

author: nick_d
author_rank: Regular Contributor
timestamp: December 18, 2018, 05:27:05 am
content: Can I ask what is going to happen to the DAC signal, will it go to some kind of power amp IC or even an op-amp to drive a speaker? And, another question, is power consumption an issue? If it is something like a children's toy then power consumption is a big issue, but I can't see why this would need 12 bit accuracy at such a high sample rate?The reason I ask is that if cost is the only consideration then much can be done by bit-banging or using timer channels. For example, in one project I had 8 spare outputs and a slow ADC available. So I created a resistive ladder with 8 bits of precision (256 levels basically) and on each power up I calibrated it using the ADC to determine the exact resistor values. If I then ran at 16x the rate I could get 12 bits.Another thing to keep in mind is oversampling and digital signal processing. See, if you want 20 kHz output from a 1-bit DAC at 12 bit precision, you might think that you need 20 x 4096 kHz = 8 MHz output rate, but that's NOT correct. For a very slow moving signal, true, to control the average over a 50us period (20 kHz) you do need 4096 individual outputs so that you can set the correct number of them to be "1". BUT, for a fast-moving signal a "1" at time t has a very different effect than a "1" at time t+1, so by taking into account the timing of your output pulses rather than just which 20us period they fall into, you can get very accurate reproduction.To do this requires sigma-delta modulation, and it costs you CPU time and power, hence why I ask about your budget, but it can be done with a low parts count. Bear in mind also that a 1-bit DAC is only stable over a small part of its output range, this can be improved a lot using more levels. I think a good compromise may be a 3-level DAC using the average or difference of 2 digital output pins. This can be achieved with clever connections to your output op-amp if any.cheers, Nick

author: Unixon
author_rank: Frequent Contributor
timestamp: December 18, 2018, 10:35:36 am
content: Quote from: nick_d on December 18, 2018, 05:27:05 amYes, it will. This must be a simple module playing a predefined sound sample when triggered.Quote from: nick_d on December 18, 2018, 05:27:05 amI think it's not an issue, but the device low power anyway. Considering the resolution and sample rate... well, I'm not sure beforehand what will it sound like, so probably I'm searching for more than would be enough for the job. May be even 8bit with half of mentioned sample rate would be OK, I just don't know at the moment.

author: technix
author_rank: Super Contributor
timestamp: December 18, 2018, 10:45:00 am
content: Quote from: Unixon on December 18, 2018, 10:35:36 amIf that is the case there are dedicated MP3 playback chips. You may need an SPI Flash to go with it, but otherwise it runs on its internal mask ROM firmware.

author: nick_d
author_rank: Regular Contributor
timestamp: December 18, 2018, 11:24:14 am
content: QuoteIn that case, little more needs to be said I think. I thought of a design for you and I went to check the part numbers (looked at a circuit one of my clients gave me, he said it was the cheapest MCU he could find of any stripe)... and found it's already been recommended to you, the EFM Sleepy Bee device. Mind you, the one my client uses is cheaper at Digikey than the options already mentioned in this thread... see this link:https://www.digikey.com/product-detail/en/silicon-labs/EFM8SB10F2G-A-QFN20/336-3170-5-ND/511572755c each in quantity 100. It doesn't have a DAC, but it has the timer PWM channel. You can get 10 bit accuracy at 16 kHz, by running your device at 16 MHz and setting the timer PWM for a period of 1024. This is totally good enough for playing a simple sound. Bear in mind that after output filtering, it would be impossible for anyone to tell how many levels your DAC has, you will just get a nice smooth audio signal regardless.A problem you may run into is that the EFM8SB1 has only 8 kBytes of Flash, so with uncompressed audio you can store 0.5s of 8 bits/sample mono audio at 16 kHz (less however much space you use for code). You will want to look into compression. Using ADPCM you could probably expand this to 5s without much effort. Audio quality will suffer a bit. If you want to do an advanced codec, there's huge room for improvement. Also, depending on the type of sound, you could synthesize it on the fly. This is difficult for speech, but for simple chimes, etc, it's very easy.Regarding your output filter, to get top quality audio from this cheap and crappy PWM DAC at a low bit-accuracy, what you need is a nice sharp cutoff, just before the Nyquist frequency of 8 kHz. The best way to do this is with a single op-amp and a Sallen and Key low-pass filter. See section 6 of this referencehttp://www.ti.com/lit/an/sloa049b/sloa049b.pdffor the circuit. If you wish, use two Sallen and Key filters in series. Choose your response, Butterworth would be fine. Then see section 9 of the reference for how to compute the component values. Use the order=2 or the order=4 section depending on whether you're implementing just one Sallen and Key filter, or two Sallen and Key in series.cheers, Nick

author: Miyuki
author_rank: Frequent Contributor
timestamp: December 19, 2018, 12:33:16 pm
content: Hialso ATtiny417 / ATtiny814 / ATtiny816 / ATtiny817 series have 8bit DAC and are cheap

author: Unixon
author_rank: Frequent Contributor
timestamp: December 21, 2018, 10:15:23 pm
content: Quote from: Miyuki on December 19, 2018, 12:33:16 pmYeah, good old AVRsI like them.A little time ago I've managed to get my hands on a big bunch of ATtiny841's for just $0.4 (I guess they were reselling free samples or something like that), unfortunately, 841's don't carry a DAC around, but they carry hardware I2C slave which maybe very useful. Now every AVR of this class is at minimum about $1.5 or so at 1K pcs

author: Wimberleytech
author_rank: Super Contributor
timestamp: December 21, 2018, 11:18:16 pm
content: Quote from: Unixon on December 21, 2018, 10:15:23 pmMy vote is for the Silabs MCUs...but...then...I am partial...being their father...

author: nick_d
author_rank: Regular Contributor
timestamp: December 22, 2018, 12:26:04 am
content: So DaddyIs it true that the cheaper family members omit the DAC, this seems to be so based on the different posts here but I did not do a thorough survey.Also, why choose 8051, the memory model seems a bit unfriendly to my modern C-oriented eye but perhaps there are good reasons for this? Or is it due to commercial reasons such as compatibility, licensing, availability of an in-house 1T 8051 core?Do you design the core or is it more of a matter of integrating IP blocks via a standard bus structure?Do you use a HDL, such as Verilog or VHDL? What about simulation, are gate level and transistor level sims done before masks are ordered? Do you use expensive proprietary layout and routing tools?Getting back to the topic: I would like to know the duration of audio and its nature: chimes, speech, music, ...? Reason is it affects choice of MCU... amount of Flash or possibly the use of a cheap outboard SPI Flash.Regarding ADPCM compression I was overly optimistic in a previous post. I suggested 8kbyte Flash could hold 0.5s uncompressed or 5s compressed. I looked into it further and discovered that the common way to do it is to compress 8 bit A-law or mu-law samples into 4-bit ADPCM nibbles. So the cheap cheap Sleepy Bee suggested by me can do 1.0s.As it turns out I have several experimental compressors that can improve this, without requiring hefty DSP as MP3 does. This might be an application for one of them, but it depends on the type of audio to be played.cheers, Nick

author: Wimberleytech
author_rank: Super Contributor
timestamp: December 22, 2018, 01:27:09 am
content: Quote from: nick_d on December 22, 2018, 12:26:04 amAt the time, it was all about die size...getting the cost down. Same with the ADC. Had to go with an 8-bit to save area.QuoteGood question. You may not like the answer. We knew of a good core at a good price so we bought it and ultimately bought the group that made the core. Simple as that.QuoteTotally custom from the bottom up.QuoteVerilog. Syopsys and Cadence tools. A very refined methodology to ensure accuracy. In the later days, we did top-level simulations only to ensure blocks were connected properly (pch bias current to nch mirror...stuff like that)We were taping out a new core every four months with heavy reuse. Virtually all of the products are still selling...18 years later.

author: Unixon
author_rank: Frequent Contributor
timestamp: December 22, 2018, 02:31:20 pm
content: BTW, why so many microcontrollers that have a built-in ADC consisting of a DAC and a comparator circuit don't offer a buffered output from this internal DAC?

author: Wimberleytech
author_rank: Super Contributor
timestamp: December 22, 2018, 03:11:43 pm
content: Quote from: Unixon on December 22, 2018, 02:31:20 pmI would say that most DACs used in SAR ADCs are charge-scaling. These do not work as static DACs.The 12-bit ADC on the early Silabs MCUs is a combination voltage-scaling/charge-scaling DAC. The voltage-scaling portion could be used as a stand-alone DAC. The Silabs 8-bit DAC is totally charge-scaling (for all the early ones).