Need help choosing microcontroller, going crazy (two channels wav playback) - Page 1
Forum section: electronics / projects

author: alexanderbrevig
author_rank: Frequent Contributor
timestamp: January 17, 2017, 09:50:34 am
content: So, I've tried to use parametric search for the vendors I have  experience with (atmel, nxp, texas instruments, renesas, ST micro) but I can't seem to find anything I think is suitable.I'm just done with my previous paid project and it got way out of hand in terms of specs as the client wanted something totally illogical (javascript interpreter for an "iot" temperature sensor). Anyways, I'm tired of working with hardware that iswayover engineered.My question should you choose to care:Which part would you choose if you wanted to make a product that plays two stereo 24bit@44.1kHz.wavfiles that should be uploaded to the device through USB?My current thinking is that I need two I2S peripherals, one USB Mass Storage Class compliant host peripheral, and a good way to store audio. SD Card with SDIO or SPI mode? Internal FLASH IC?I'm going crazy and have a hard time figuring out what is a good way to go. Anyone with experience playing audio off of SD? Is it fast enough in SPI mode?Any replies are happily received!

author: Fungus
author_rank: Super Contributor
timestamp: January 17, 2017, 10:01:35 am
content: Quote from: alexanderbrevig on January 17, 2017, 09:50:34 amhttp://www.ebay.com/itm/171764616814Edit: I just noticed those things claim to have a 24 bit DAC so there you go.But... 24bits? What for?

author: alexanderbrevig
author_rank: Frequent Contributor
timestamp: January 17, 2017, 10:41:49 am
content: Tanks for the replyOn the phone so having a hard time trying to update the previous post. Here are some qualifiers:I don't need a codec as I can parse the wav files to get the PCM.I want to be in control of the DACs as I'm going for phase coherency on the two streams.Need at least 4GB storage.24bit to meet a spec and fit in a prosumer/audio market.

author: Psi
author_rank: Super Contributor
timestamp: January 17, 2017, 10:55:23 am
content: stm32 and a good quality stereo DAC is where i would start.You want to use the STM32 DMA controller to do the data transfer to the DAC.Use the stm32 usb mass storage example code to read the usb file system.the STM32F103 is probably all you need and is very common/cheapBut you could probably do it with the cheaper STM32F0x2 to keep costs as low as possible

author: alexanderbrevig
author_rank: Frequent Contributor
timestamp: January 17, 2017, 10:57:08 am
content: My current mcus in the lead are; STM32 as my last project used an F103 and the PSoC 5 because I love them.I'd not go for the F1 though I think..Edit: saw you mention the exact same part I've been using. Maybe I should make it easy for myself and just reuse my knowledge...

author: Psi
author_rank: Super Contributor
timestamp: January 17, 2017, 11:00:12 am
content: STM32F4x7 have got stupid amounts of power, if you think you may need itBut that's probably way overkill.Just get a stm32 that has USB and two dma controllers, one for each stereo DAC IC

author: bktemp
author_rank: Super Contributor
timestamp: January 17, 2017, 11:13:51 am
content: If you really need to upload the files over USB using the microcontroller, get one having HS-USB. Using FS-USB it will take forever to transfer 4GB.

author: alexanderbrevig
author_rank: Frequent Contributor
timestamp: January 17, 2017, 12:08:34 pm
content: Thanks for getting me down the STM path (I was a bit tired of them and wanted to learn something new, but it's better to bank on my experience I think for this...)!After looking through my box of devkits I actually found one for STM32F4 and it has a Cirrus DAC close to the one I've been looking for (as far as control and interface goes):Also this:I think I will go for the STM32F429 series.Huge bonus with all the example code, design resources and all the jazz TI does!Between those I can test both I2S and running an LCD directly.I guess this would kind of count as over engineering, but I like the fact it has support for everything I want. Even HS USBWhat do you guys think?Stop pondering and get dirty?

author: bobaruni
author_rank: Regular Contributor
timestamp: January 17, 2017, 12:17:42 pm
content: Excellent choice, I'm using the same board (STM32F407) to play 24 bit 96K WAV / FLAC to I2s ES9018K2M DAC and onboard CODEC simultaneously from a USB stick and am loving how it sounds.It will do 192K but only on external DAC as onboard CODEC can only do 96K.Just be aware that you will need an external phy chip for USB HS, both boards can only do USB FS.

author: FreddyVictor
author_rank: Regular Contributor
timestamp: January 17, 2017, 12:36:35 pm
content: Quote from: bobaruni on January 17, 2017, 12:17:42 pmactually, he's not quite, he's got the very similar but cheaper STM32F401 version (should be fine tho')Quote from: bobaruni on January 17, 2017, 12:17:42 pmsounds interesting

author: bobaruni
author_rank: Regular Contributor
timestamp: January 17, 2017, 12:49:13 pm
content: Quote from: FreddyVictor on January 17, 2017, 12:36:35 pmAhh, yes agreed should be fine but may or may not do 192K on WAV and may or may not do 96K on FLAC.

author: alexanderbrevig
author_rank: Frequent Contributor
timestamp: January 17, 2017, 01:50:11 pm
content: Thanks for the input everyone! I realize I need a ULPI between the connector and the chip. Sounds about right?Funny you should say that about the USB stick, as I've had a chat here and changed the spec. Audio will now be played off of a usb thumb driveI think 44.1 is fine for the application. I might even do 16 bit over 24. The device will be used in a live audio/concert setting, so...Currently planning on the F429 over the F401 because I cant seem to find any evidence 401 supports USB-HS (not in datasheet, and not in cubemx).

author: alexanderbrevig
author_rank: Frequent Contributor
timestamp: January 17, 2017, 02:05:12 pm
content: aaaand as I've never used USB Host for anything I'm suddenly unsure if it's at all possible to get access in a random access fashion so I can stream two files!?Going to get my reading (writing) glasses on and have at it!

author: bktemp
author_rank: Super Contributor
timestamp: January 17, 2017, 02:18:11 pm
content: ST uses this FAT filesystem driver:http://elm-chan.org/fsw/ff/00index_e.htmlIt supports unlimited number of files open at the same time (until you run out of memory for all the file objects).Random access for reading shouldn't be a problem, because flash memory is fast. When reading, read the file in large blocks (4-32kBytes).If you want to write at the same time while streaming audio, you need a large buffer because wear leveling during writing can take a couple of seconds for slow devices.

author: bobaruni
author_rank: Regular Contributor
timestamp: January 17, 2017, 02:19:05 pm
content: Yes, you can stream multiple files using Chan's FatFS when configured correctly but remember you are limited to USB FS and then there's the overhead of the file system....I suggest you start with the STM32 Cube HAL (Projects\STM32F401-Discovery\Applications\Audio\Audio_playback_and_record)....it's limited to 16 bit files and the CODEC clock setting is way off due to a bug but it's a good starting point, otherwise you are in for quite some work without the example.

author: alexanderbrevig
author_rank: Frequent Contributor
timestamp: January 17, 2017, 03:15:06 pm
content: Thanks for the FAT reference! Already playing with the record/play example. I've changed the PLLs to get a more satisfying and appropriate setup for me (I started from "scratch" with CubeMX and pasted in what I wanted from the example). Audio is playing! WOHO

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: January 17, 2017, 03:33:27 pm
content: PIC32MZ may be worth a look ( the more recent EF ones with the less ridiculous errrata list). One big advantage is thay have tons of RAM -up to 512K - you may need a fair bit for buffering USB lumpinessThey have 4-6 SPI ports which have I2S support ( I think on all of them), as well as HS USB Host, and come in sensible QFP packages.

author: amyk
author_rank: Super Contributor
timestamp: January 18, 2017, 03:38:26 am
content: Funny you talk about overengineering and then look at many of the replies here... I'd go with one of those USB 8051s with built-in DAC. The Chinese have preprogrammed single-chip solutions for this --- search "SD card MP3 player" or similar (they can not only play MP3, but usually WAV, WMV, OGG, and a few others.)

author: krho
author_rank: Regular Contributor
timestamp: January 18, 2017, 06:34:03 am
content: Quote from: blueskull on January 17, 2017, 11:10:37 amKnow of any cheap and readily available even in small quantities? Microchip has a bunch of cheap! 2$ even in 10QTY e.g USB2244 Hi-Speed card readers, but you can't control any of the remaining GPIOs, where you could switch the mux when connected to the usb DATA port.So on arm side only some LPC M3 remains for such task, SDIO + USB Hi-Speed which is too expensive for a device we are building.

author: JPortici
author_rank: Super Contributor
timestamp: January 18, 2017, 06:42:12 am
content: Quote from: Fungus on January 17, 2017, 10:01:35 amthey actually achieve the dynamic range needed for 16 bits (check)they are a cheaper and more available than equivalent 16 bit parts (check)and I2S don't care as you send 32 bit words per channel anyway

author: krho
author_rank: Regular Contributor
timestamp: January 18, 2017, 04:27:13 pm
content: GL3233 is not available at EU distributors, also using stolen firmware is a no go, sorry EU is no China where everybody copies everybody and gets away with it..

author: alexanderbrevig
author_rank: Frequent Contributor
timestamp: January 18, 2017, 10:16:51 pm
content: Quote from: mikeselectricstuff on January 17, 2017, 03:33:27 pmI have never tried any PIC, maybe it's time? Any recommendation for a good devkit?http://store.digilentinc.com/chipkit-wi-fire-wifi-enabled-mz-microcontroller-board/don't really need wifi though...

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: January 18, 2017, 11:12:19 pm
content: I'd start with the Microchip ones as they will have example code ready to run on them - saves a lot of time for something complicated like USB if you can start with something that already does something.Also makes it quick to evaluate performance.

author: Fungus
author_rank: Super Contributor
timestamp: January 19, 2017, 11:40:28 am
content: Quote from: alexanderbrevig on January 17, 2017, 10:41:49 amHaving it all pre-built doesn't hurt.Quote from: alexanderbrevig on January 17, 2017, 10:41:49 amI'm sure the DACs will be perfectly in phase on that chip.Quote from: alexanderbrevig on January 17, 2017, 10:41:49 amYou can attach an external SPI flash chip to that module, choose your own memory size:http://www.ebay.com/itm/171764616814Or get a modules with SD card reader. Have a poke around eBay, there's lots to choose from.eg.http://www.ebay.com/itm/131577755212Most of the adverts tell you the chipset on the board. You can use that info and google for datasheets, build your own module if you want to.

author: amyk
author_rank: Super Contributor
timestamp: January 19, 2017, 12:07:41 pm
content: Quote from: blueskull on January 19, 2017, 02:13:36 amThis is why Chinese parts are so successful. Even if they officially supply info under NDA, they pay very little attention to you redistributing it, because it gives them more sales. They use NDAs to go after competitors, not customers.

author: alexanderbrevig
author_rank: Frequent Contributor
timestamp: January 19, 2017, 01:58:59 pm
content: Just to get the idea of what I'm after I'll post this here:I will make at least 100 units so I'm not looking to cobble some modules together. My ultimate goal is to have zero wire harnesses and to minimize manual labor to attaching the display and the ~20 screws for the connectors and panels onto the enclosure. I'll rather spend a few dollars in more expensive parts that fit my design criteria than spend a few minutes cutting and soldering cables - per board. I'll rather make three PCB revisions than having to do manual bodges on everything.Thanks for all the input guys! Thanks to your input I've got a proto now.

author: nctnico
author_rank: Super Contributor
timestamp: January 19, 2017, 02:07:41 pm
content: Did you look at NXP's LPC1700 series? AFAIK these should fit the bill. USB host capability (LUFA USB stack provided by NXP), real SD card interface and I2S interface. Ofcourse it has a DMA engine to offload the CPU from dealing with all the data transfers.

author: alexanderbrevig
author_rank: Frequent Contributor
timestamp: January 19, 2017, 08:59:13 pm
content: Quote from: mikeselectricstuff on January 18, 2017, 11:12:19 pmJust spent half an hour pulling down MPLAB X and Harmony and I've got to say it's looking good! For some reason I've always shied away from PICs but I see that's probably been a mistake.About to press order on this;http://www.microchip.com/Developmenttools/ProductDetails.aspx?PartNO=DM320007Would be very grateful if someone could say "do it" or "why don't you tryinstead?"!So far it seems like a nice environment, good documentation and all in all a nice powerful package!EDIT: No, I've not had a close look at the NXP. I like STM and apparently MPLAB is very nice too! So I think the first decision has been made for me. It will be either an STM32F4 or a PIC32mz

author: bobaruni
author_rank: Regular Contributor
timestamp: January 20, 2017, 06:26:20 am
content: Do It: PIC32MZ uses MIPS32 core which is a very nice but old microarchitecture to use (at least with ASM).Don't do it: You are at the mercy of Microchip who are possibly the only vendor using a MIPS32 core whereas the STM32 has many upgrade, downgrade possibilities and heaps of other vendors with similar Cortex M microcontrollers.Having said this, before I moved to 32bit Cortex M, I was using Atmel AVRs and of course was locked in for years as no other vendors make an AVR equivalent.At the end of the day, which chip will let you do everything you want to do (or at least not prevent you from doing so)?Me personally, I chose STM32 for a similar project because I had them here, they are very cheap, easy to get, tons of examples and resources and I have written a collection of libraries that I reuse and also especially because I know there are future chips coming that will be an easy upgrade path (STM32H7 400MHZ Cortex M7), I did also consider PIC32MZ but the long ISR latency and DEV board price scared me away.On the down side to STM32, I find the examples are somewhat buggy and or incomplete and the community forum is very quiet.You decide

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: January 20, 2017, 09:06:45 am
content: Quote from: bobaruni on January 20, 2017, 06:26:20 am"At the mercy" how exactly? Microchip have the best record in the industry of not obsoleting parts, and also have several pin-compatible variants to provide alternatives if there is a short-term supply issue.The core does nit matter at all - it's all about the IO. There's more similarity between 16 and 32 bit PICs than ARM devices from different manufacturers.QuoteIf devboard cost is a factor in choosing a chip you are not a serious user.

author: alexanderbrevig
author_rank: Frequent Contributor
timestamp: January 20, 2017, 09:34:49 am
content: Thanks for the input guys!I see no direct objections on my choice of dev board so it's now ordered!Which part I'll choose for this project is still undecided but I figure I should at least give the PIC a fair chance. Along my previous statements I might as well add; I'll rather spend tenfold on a devkit that works from the get-go, rather than a cheapo that needs a few hours of frustration. It's still true - time is money!All that said, I like the excuse to get a new dev kit. Who doesn't?

author: JPortici
author_rank: Super Contributor
timestamp: January 20, 2017, 09:44:29 am
content: Quote from: bobaruni on January 20, 2017, 06:26:20 amas if you didn't have to rewrite almost all the code anyway because peripherals behave differently, are named differently and use a totally different API (USB for example)Quoteas if cortex didn't have its fair amount of interrupt latency and pipeline interlock tooAlso dev tools are always pricey. Talking about boards with everything already mounted and working, with a working software already on.. and you just write your routines while the hardware is being designed. IMHO Microchip excel at those, their example just works, provided you have the correct compiler installed. The same can't be said for ST and i think arm in general. Go on, open an example project from ST and tell me how it went.If you meant that microchip doesn't have a simple board with MCU and onboard programming in the 10-20 euro range (maybe even 'duino compatible for the joy of makers) you are wrong. Olimex makes those (wish there was some cheaper/simpler like the VLDiscovery but you can't have everything)

author: bobaruni
author_rank: Regular Contributor
timestamp: January 20, 2017, 09:57:05 am
content: Quote from: mikeselectricstuff on January 20, 2017, 09:06:45 amA serious user? or perhaps I can do the same thing with something that is 1/10th the cost.The cost or how much money I have has no bearing on how serious I am.

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: January 20, 2017, 10:10:12 am
content: Quote from: bobaruni on January 20, 2017, 09:57:05 amThe cost of the devboard is insignificant compared to other costs for anything but a hobbyist project.

author: Fungus
author_rank: Super Contributor
timestamp: January 20, 2017, 10:15:02 am
content: Quote from: mikeselectricstuff on January 20, 2017, 09:06:45 amOr maybe they are not a serious chip seller.

author: bobaruni
author_rank: Regular Contributor
timestamp: January 20, 2017, 10:15:15 am
content: Quote from: mikeselectricstuff on January 20, 2017, 10:10:12 amYou're absolutely right, but picture a scenario where you design something that you would like to share with the wider community, shouldn't you base it on a board that many more people can afford?

author: JPortici
author_rank: Super Contributor
timestamp: January 20, 2017, 10:16:07 am
content: a devboard will always cost less than me having to spend a morning researching for one, an afternoon assembling one and the eventual one two three following days of troubleshootinga devboard =/= a chip with a power supply and programmer on a breakout board. and there are these, cheaper ones for microchip. again, look at olimex

author: JPortici
author_rank: Super Contributor
timestamp: January 20, 2017, 10:17:10 am
content: Quote from: Fungus on January 20, 2017, 10:15:02 amthat's a good one, i genuinely laughed

author: Fungus
author_rank: Super Contributor
timestamp: January 20, 2017, 10:25:32 am
content: Quote from: JPortici on January 20, 2017, 10:17:10 amOK, that was the wrong word. I meant everything else they do will also be a paid service. They won't be interested in you unless you're a "serious" customer ordering a million chips on a corporate account.

author: Howardlong
author_rank: Super Contributor
timestamp: January 20, 2017, 10:29:31 am
content: Quote from: alexanderbrevig on January 18, 2017, 10:16:51 pmI have that WiFire board. For serious projects, you'll want to populate the ICD header and use a debugger with it: out of the box it just offers the ability to self-upload flash images. Although it is supported by Harmony (which you have little choice but to use if you're using USB) and there is a board support package for it, there are not many examples at present that actually use it, and certainly not for all those peripherals. It's good hardware with plenty of peripherals, but lacks an onboard debugger.Another option might be the very recently shipping PIC32MZ EF Curiosity board DM320104 but you'll possibly want the audio daughter board and a MikroBus SD card adapter.I would take a look at the Harmony help file and check which boards support which example applications. By far the best supported board is the PIC32MZ EF starter kit DM320007 (or DM320007-C which has the crypto enabled), which includes and integrated debugger and host, device and OTG HS USB. You will want some means of adding an SD card, with a MEB II DM320005-2 being the best supported. Unfortunately, neither the PIC32MZ SK nor the MEB II are cheap options, but they will be the easiest to get yourself up and running as there is already an application written for this combination for audio and SD card access. If you value your time, PIC32MZ EF SK + MEB II is the way to go as other alternatives will mean a fair bit of learning especially if you are new to Harmony.BTW, PIC32MZ doesn't support SD card SDIO mode, it's SPI mode only.

author: bobaruni
author_rank: Regular Contributor
timestamp: January 20, 2017, 10:32:24 am
content: Quote from: mikeselectricstuff on January 20, 2017, 09:06:45 amAgain, you are absolutely right, It doesn't matter with modern compilers but I still like to get my hands dirty and code in pure ASM and the MIPS32 core is my favorite to this day.It seems I have ruffled some feathers by suggesting STM32 over PIC32MZ, perhaps I failed to mention I use both, as well as NXP Cortex M, Kinetis Cortex M, AVR, PIC16....and so onAll I'm saying is that in ONE particular application which is very similar to the OP's, I chose the STM32 as it ticked more boxes than any other chips at the time I started the design process.My current thinking is to also try the Cypress PSOC 5LP as I have one here and have never used it and would like to explore the CPLD-like programmable logic which would be nice for SPDIF In / Out.It's my opinion only as I'm sure your/others criteria/specifications and allegiance to a particular vendor (I don't have one) may be different.

author: nctnico
author_rank: Super Contributor
timestamp: January 20, 2017, 10:33:36 am
content: Quote from: JPortici on January 20, 2017, 09:44:29 amST is a pretty bad example when it comes to compatibility between the various devices which has turned me away from ST's ARM controllers every time. NXP's LPC series ARM controllers is much better in that respect so you don't need any HAL to make your code portable between devices.Regarding dev boards: I always liked to roll my own based on schematics from existing boards. That way I add things I like and catch things which can go wrong on a prototype early.

author: bobaruni
author_rank: Regular Contributor
timestamp: January 20, 2017, 10:44:05 am
content: Quote from: nctnico on January 20, 2017, 10:33:36 amYes I like to roll my own except for when the package is BGA....just can't do it....yet.Speaking of NXP, the LPC Link 2 is a pretty unique board with it's 80MSPS 12 bit ADC built in, nice little oscilloscope project for a little over $25

author: JPortici
author_rank: Super Contributor
timestamp: January 20, 2017, 10:45:35 am
content: Quote from: Fungus on January 20, 2017, 10:25:32 amas for lately, i'd tend to agree with you. though this still happens: a genuine programmer breaks down? out of warranty? nonsense. a new one will be delivered to you for free.just an example..bug aknowledgement and responsiveness is on par if not better with other manufacturers i uselet me remind you of the st forum, i find the microchip one to be betteror nxp community.. official nxp support will tell you to first post your question to the community (where their account will only post automatically generated bullshit comments of reading the FAQs)and then you're on your own, that platform is just awful.

author: bobaruni
author_rank: Regular Contributor
timestamp: January 20, 2017, 11:04:25 am
content: Quote from: JPortici on January 20, 2017, 10:45:35 amThere is a new forum It's still rubbish and the links to other forum replies are all broken, absolutely useless.

author: alexanderbrevig
author_rank: Frequent Contributor
timestamp: January 31, 2017, 05:55:51 am
content: Allright people! I've come to a decision for nowI've made the choice to go STM32 for this one but I'll definitively check out that PIC32MZ*EF for my next educational project!Theroughlayout has started:I'm well on my way, and will continue to document my process.The blog is mostly for myself. Just in case anyone has interest:https://livearmada.wordpress.com/there's also a post there aboutall this mcu selection stuff!

author: hans
author_rank: Super Contributor
timestamp: January 31, 2017, 09:27:27 am
content: The STM32F4 is more than capable of doing this. I made a dual stereo USB soundcard with the STM32F411, which is a simpler slower chip without the LCD and lacks some of the interconnectivity peripherals. It is more than capable of driving both audio channels,as wellas doing software mixing of a center and a subwoofer (IIR low-pass filter at 48kHz) channel, using hardware floating point. I haven't fussed with the USB enumeration profiles to make do some more sophisticated stuff I had planned, but it goes to show there is plenty of room to spare.Moreover, the I2S peripheral also has DMA which I haven't used yet. So this chip is also serving 4x 48kHz interrupts at this moment, which is very wasteful but it works.It shows how much room is left for processing other stuff like LCDs, even at 100MHz. But if you can budget in a STM32F42x or STM32F43x, you can do some wicked stuff at 180MHz and it's DMA2D engine.You don't need much buffers at all for USB audio. Audio is sent using USB isochronous transfers, which are only 192 bytes (2 channels x 16-bit x 48 samples) in size in my case. 44.1kHz is annoying to deal with because it's a non-multiple of 1000, so rather pick 48kHz. The USB sends Isochronous packets at 1kHz and synchronizes it using SOF tokens on the bus. SOF is a cheap 1kHz time base for USB, and is used to latch the buffer to the audio codec. This is useful because there will always be clock differences even when using the I2S PLL, and if your word sample frequency is off by 1-2Hz that means you're dropping (or interpolating) 1-2 samples each second. For me this is inaudible and just a consequence of dealing with USB.I've first tried finishing off the buffer and then swapping to the new buffer at the audio codec level, but that had some audio distortion that only popped up every minute or so. I think it was because the sample clock was a few Hz to slow, and so eventually it was 1 complete buffer of 48 samples behind which was eventually completely dropped.I can say the ST code examples were helpful, but because I was in a hurry I also borrowed some parts ofthis project

author: alexanderbrevig
author_rank: Frequent Contributor
timestamp: January 31, 2017, 11:08:50 am
content: Hi there hans!Cool project you've got going thereJust in case it's unclear. I'm not streaming off of USB. It's off of the SD card. Also I'll be using STM32F103 which looks to be about 50% cheaperI was concerned about that 44.1 thing myself, but I see they have a 9 bit prescaler named 44K (I've checked, it is actually 44.1) so I'm hoping I'll be in good hands. If not I could always demand 48k but I'd prefer not to.Jitter won't be too much of an issue for me as I can get samples on demand. I will select a very precise oscillator (can't remember the different ones) but I want be as close to 44.1 as I can.DMA is a thing I know I'll have to use, but up until now I really have not had any hand-on playtime with it. I'm hoping it's not as scary as I feel it is