Looking for MCU with many timers - Page 1
Forum section: electronics / general

author: ubbut
author_rank: Regular Contributor
timestamp: August 17, 2019, 10:56:26 am
content: Hi,in a design I need a small (20-32) pin QFN µC with:- at least 6x 16bit timers that can be used for frequency generation (50% duty cycle is sufficient, no pwm)- 5V compatible(removed this requirement, because I released I can get away with 3.3V)- 4x ADC- Internal RC oscillator, at least 16Mhz- cheap: < $1- bonus points: programmable logicI looked at the usual suspects: STM, Microchip (booth PIC and AVR), NXP ... however was not able to find anything suitable.The search is more complicated by the fact, that a parametric search might show 9x 16 bit timers, but according to the datasheet, only 3 can be used for frequency generation.In one case (ATTINY417), the parametric search returns 6 x 16bit timers, but according to the datasheet, this is just incorrect.So If any of you know a suitable part, please let me know!very much appreciatedthanks!

author: Brutte
author_rank: Frequent Contributor
timestamp: August 17, 2019, 11:41:59 am
content: That is difficult because you want QFN32 and 6 independent 16-bit pwm frequencies. So you need at least 6 timers, 16-bit each and such timers typically have 2-4 outputs, out of which you are going to use one.

author: Whales
author_rank: Super Contributor
timestamp: August 17, 2019, 11:47:30 am
content: Any reason you can't go for an array of (eg 8-pin) cheap micros? Even if you need a single master controlling several slaves.

author: nctnico
author_rank: Super Contributor
timestamp: August 17, 2019, 11:50:54 am
content: What kind of frequency range do you need to generate?

author: digsys
author_rank: Unknown
timestamp: August 17, 2019, 12:08:57 pm
content: I've been using Silicon labs stuff for many years - packed with I/O function blocks -https://www.silabs.com/products/mcuMight be worth a look

author: wraper
author_rank: Unknown
timestamp: August 17, 2019, 12:19:22 pm
content: EFM8LB10F16 has six 16 bit timers/ six PWM outputs and cost less than $1. Most of pins are 5V tolerant.

author: rhodges
author_rank: Frequent Contributor
timestamp: August 17, 2019, 12:31:47 pm
content: STM8 (eg, stm8s003, stm8s103) has TIM1 with 4 output channels and TIM2 with 3. You would have to catch the interrupts and reload the 16-bit capture value for each one, though.example: CAPTURE = CAPTURE + INTERVAL

author: Jeroen3
author_rank: Super Contributor
timestamp: August 17, 2019, 12:49:32 pm
content: I can get 16 output compares over 6 timers with 4 ADC channels in STM32G431K6Ux UFQFPN32.One of the channels is inverted though. And not all channels are independent, but you didn't specify anything about that.It's not <$1, but it does have an cortex m4 at 170mhz!QuoteOutputs are never 5V tolerant, so you will need to find level converters, luckilyNexperamakes a lot of those for in smartphones in an incredibly tiny footprint. So that isn't a problem.

author: wraper
author_rank: Unknown
timestamp: August 17, 2019, 01:12:17 pm
content: Quote from: Jeroen3 on August 17, 2019, 12:49:32 pmThey are in a sense that you can use external pull up and setting output to Hi-Z state.

author: ubbut
author_rank: Regular Contributor
timestamp: August 17, 2019, 01:20:58 pm
content: Thanks for all your suggestions.Just realized I can get away with using a 3.3V part, this should simplify things(i did not mean 5V tolerant inputs, I meant 5V supply voltage compatible)

author: Jeroen3
author_rank: Super Contributor
timestamp: August 17, 2019, 01:37:21 pm
content: Quote from: wraper on August 17, 2019, 01:12:17 pmWhen you tie an output to a timer, you can't have the hardware put it in a high-z automatically. So you'd need the interrupt which might jitter.Some chips offer open-drain mode, that might work, if available together with timer output.Quote from: ubbut on August 17, 2019, 01:20:58 pmThat significantly reduces available candidates today.

author: nctnico
author_rank: Super Contributor
timestamp: August 17, 2019, 01:56:25 pm
content: It depends greatly on what kind of logic is at the output. If it is standard TTL compliant then Vih is 1.4V which is well below 3.3V.

author: SiliconWizard
author_rank: Super Contributor
timestamp: August 17, 2019, 02:21:14 pm
content: Just a thought, but you may not need as many timers as you think either.

author: nctnico
author_rank: Super Contributor
timestamp: August 17, 2019, 03:15:49 pm
content: And depending on the frequency requirement you might be able to do it in software too on a fast ARM controller.

author: NorthGuy
author_rank: Super Contributor
timestamp: August 17, 2019, 03:25:56 pm
content: Quote from: nctnico on August 17, 2019, 03:15:49 pmor in slow PIC alike.

author: errorprone
author_rank: Contributor
timestamp: August 18, 2019, 01:15:22 am
content: The pic32mm gpm series might be is interest. They have 6 single channel pwms, 3 multi channel pwms and is about $2Sent from my LG-H810 using Tapatalk

author: T3sl4co1l
author_rank: Super Contributor
timestamp: August 18, 2019, 01:35:22 am
content: Also consider tone generator ICs, which it sounds very much like what you may be doing?A far out possibility is emulating timers partly in software; you can calculate the time until the next transition, set a timer for that (one-shot, interrupt), and toggle the respective pin. The jitter will probably be pretty awful, but the spectral purity may still be good enough for some RF or control applications, and most likely is for audio purposes. (I've done the simplest version of this before, a timed interrupt on a Z80 platform; it generated a single tone at a time and didn't sound any different depending on what the main loop was up to.)Taking this even further, CPUs in the ~100MHz range (most second-lowest tier ARMs, say) have more than enough power to simply emulate a synth directly. That is, generating audio a sample at a time, stepping an array of DDSs and, say, running them through wavetables and envelope generators before driving a DAC (or a PWM channel to the same end). If you still need independent square wave channels, you could still do this but output packed binary to a GPIO port, instead of proportional (digitally coded analog) to a DAC; the sample rate does put a hard limit on how well timed the channels are, of course. Again, spectrum may be okay, but getting finer timing is less practical.Fast CPUs aren't really so much necessary, actually; a multi-channel synth has been demonstrated on an XT PC (8088 CPU), using the timer as a 1-bit DAC. Poor quality of course (~30kHx sample rate at 1 bit gives quite a lot of quantization noise!), but the sounds themselves are unlike almost anything else anyone's ever generated from a PC speaker before. Needless to say, this required heroic effort to pull off (the "8088 MPH" demo, the end of it namely), and I wouldn't expect anyone else to go to such lengths; rather, just to know that it's possible at all!Tim

author: westfw
author_rank: Super Contributor
timestamp: August 18, 2019, 01:48:11 am
content: Can you use a UART for some of the frequency generation? They usually have about a 16bit bitrate generator, and could generate a variety of 50% square waves at each bitrate (more if it doesn't need to be exactly 50%)At the expense of needing to reload the "output character"

author: ubbut
author_rank: Regular Contributor
timestamp: August 18, 2019, 06:54:51 am
content: Yes,I need that many timers, because doing it in software would have introduced too much jitter.Had considered a tone generator IC, but that would have meant I need a separate µC for ADC and control.Now found the STM32F051K6U6 which can even generate 7 independent frequencies. Costs about ~$0.50 at LCSCThanks for all the great input and help!

author: nctnico
author_rank: Super Contributor
timestamp: August 18, 2019, 09:19:46 am
content: Quote from: westfw on August 18, 2019, 01:48:11 amThis is also a good suggestion. DMA could be used to load the same character over and over without costing much CPU cycles. Come to think of it: in the past I have used a UART to generate a PWM signal for a crude NiCd backup battery charger. An SPI interface can also be used the same way.

author: Jeroen3
author_rank: Super Contributor
timestamp: August 18, 2019, 01:32:32 pm
content: Just bit bang the gpio with the dma. If you already consider degrading uart to a tone generator your requirements aren’t that tight.

author: janoc
author_rank: Super Contributor
timestamp: August 18, 2019, 01:48:13 pm
content: Quote from: SiliconWizard on August 17, 2019, 02:21:14 pmE.g. because on STM32s you have 4 outputcapturecompare units per timer (regardless of whether they are connected to actual I/O pins - you can always use interrupt or trigger DMA to twiddle some other pin), so you can effectively generate 4 different frequencies out of a single timer (assuming you can make do with a single prescaler value and timer clock, i.e. that the frequencies are not vastly different).

author: SiliconWizard
author_rank: Super Contributor
timestamp: August 18, 2019, 02:08:51 pm
content: Quote from: ubbut on August 18, 2019, 06:54:51 amUnless you're using "output compare" peripherals (which are not strictly timers, but sometimes linked to them), you're essentially doing it "in software". So you should look for that kind of peripherals instead of looking for timers.Now if there is no such peripheral and you're toggling an IO in a timer interrupt, you're already introducing some jitter (most MCUs take up to a few clock cycles to service an interrupt and it's not cycle-accurate). The whole point is just to make this negligible in your application (meaning the timer period should be long enough relative to the clock cycle).Now you can toggle several IOs instead of just one in just ONE ISR to generate different periods (obviously all multiple of the timer's period). Not excessively complicated. Of course for that approach to be usable, the different frequencies you need to generate must all be significantly lower than the CPU clock frequency.Some even suggested to do that without any interrupt. That's definitely doable especially if the MCU runs fast enough and is doing nothing else (so absolutely no interrupt enabled), using assembly would probably be required though.

author: NorthGuy
author_rank: Super Contributor
timestamp: August 18, 2019, 02:34:03 pm
content: Quote from: SiliconWizard on August 18, 2019, 02:08:51 pmI remember I did that once with PIC16 which had to drive 8 stepper controllers all running at different speeds and accelerations. I used 16kHz interrupt and the impact on the CPU was quite small.The range of desired frequencies determines what is the best model.

author: ubbut
author_rank: Regular Contributor
timestamp: August 18, 2019, 03:22:46 pm
content: The whole idea was to use 6 independent timers with output compare to generate frequencies directly. Using timer interrupts was never an option because of the relatively large jitter. (especially on ARMs)So one needs 6 independent timers. One timer with 6 output compare channels is not able to generate 6 different frequencies, just 6 different pulse widths.While I like to idea of using uart or spi it was never considered by me (because here the frequency resolution is limited by the number of prescalers available [usually not many])

author: nctnico
author_rank: Super Contributor
timestamp: August 18, 2019, 03:42:57 pm
content: Quote from: ubbut on August 18, 2019, 03:22:46 pmActually you can. Just set an interrupt for when the output compare triggers and update the compare register with the next trigger point in the interrupt service routine. The timer counter itself just runs freely and wraps back to zero.

author: andersm
author_rank: Super Contributor
timestamp: August 18, 2019, 03:55:48 pm
content: Renesas' RX series has lots of powerful timers, but I don't know offhand if they have anything that fit your package requirements.

author: rhodges
author_rank: Frequent Contributor
timestamp: August 18, 2019, 05:32:42 pm
content: @nctnico: Thanks, glad you spelled it out. Apparently, my post did not explain the idea properly.

author: PCB.Wiz
author_rank: Super Contributor
timestamp: August 18, 2019, 10:21:43 pm
content: Quote from: ubbut on August 17, 2019, 10:56:26 amWhat frequency range and granularity do you need ? Is internal or external oscillator needed ?eg the EFM8LB1 has programmable logic & 72MHz sysclk, so it can produce 16b to up to ~ 1100Hz, and the 6 channel PCA can use HSO mode to SW manage multiple frequencies, up to some SW-overhead limit.I'd expect something above 100kHz to be possible, via HSO and above 281KHz there is a 8b FreqOut mode, plus the programmable logic can toggle on any timer overflow.

author: andyturk
author_rank: Frequent Contributor
timestamp: August 20, 2019, 04:47:40 pm
content: Take a look at Cypress PSoC 4200 (ARM Cortex M0). There are several hardware timer blocks as well as programmable digital blocks that can be turned into timers.

author: labnet
author_rank: Contributor
timestamp: September 03, 2019, 12:02:19 am
content: I would second Andy. PSOC5 has enough macro blocks to spin up all sorts of crazy custom hardware in a really easy to use IDE.