Skip to main content
JJ..1
Associate II
February 2, 2020
Solved

Salutations! I need guidance to choose a micro controller that can communicate with STM32F103VCT6 at the same speed through UART and has 36 PWN pins. Thank You J.

  • February 2, 2020
  • 8 replies
  • 3749 views

This topic has been closed for replies.
Best answer by berendi

Let's say you have 4 outputs for starters, PB0 needs 80% duty cycle, PB1 50%, PB2 10%, and PB3 100% (always on). So you have to output the following sequence of bits repeated on each pin (of course you can shift the phase too by shifting the bits around)

PB0 1111111100
PB1 1111100000
PB2 1000000000
PB3 1111111111

turn the above table 90 degrees clockwise, you get a list of binary numbers

uint16_t pb_pattern = {
 0b1111,
 0b1011,
 0b1011,
 0b1011,
 0b1011,
 0b1001,
 0b1001,
 0b1001,
 0b1000,
 0b1000
};

This is just a simplified example, you can use full 16 bit values to output on PB0-PB15 simultaneously.

Now you can set up a timer to 10 times the PWM frequency, and a DMA channel that transfers 10 halfwords in circular mode from the buffer above to GPIOB->ODR, on each timer period. If more than 10% precision is needed, use a longer table and adjust the timer period.

It can then be extended to more GPIO banks, using more timer and DMA channels, for 32, 48, etc PWM signals.

It might even be possible to do it on the controlling MCU if there are enough pins and RAM available, maybe replacing it with a 144-pin STM32F103 variant with some more RAM.

If the two MCUs have to be separate, calculate the memory requirements based on the required PWM precision, and chose the cheapest MCU that has enough pins and RAM.

8 replies

berendi
Principal
February 2, 2020

STM32G474 has 7 regular timers with 4 PWM channels each, one with two PWMs and two timers with one PWM each, a high-resolution timer with 10 PWM outputs, and there is a low power timer with a single PWM output. That's 43.

JJ..1
JJ..1Author
Associate II
February 2, 2020

Thank You so much for your help. If only its not much of a trouble could you please guide me how did you selected and found this MCU? I was not able to find it on the STM website with their filter criteria. Thank You

berendi
Principal
February 2, 2020

My job includes selecting and recommending MCUs for new products, so I have to be up to date regarding their capabilities, subscribed and actually reading product announcements, new datasheets etc. I knew that a HR timer has lots of PWM channels (but I had to look up exactly how many), but it's a separate item on their (broken as designed) product selector, both online and offline.

JJ..1
JJ..1Author
Associate II
February 2, 2020
berendi
Principal
February 2, 2020

There is some work left for you, I've only looked at the one with the highest pin count.

JJ..1
JJ..1Author
Associate II
February 2, 2020

Thank you

Tesla DeLorean
Guru
February 2, 2020

Perhaps you can do better with a small CPLD/FPGA?

You can drive all kinds of patterns to the STM32 GPIO via TIM+DMA

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
JJ..1
JJ..1Author
Associate II
February 2, 2020

Do you mean to say that I use the digital outputs with a timer and fast switch it 'ON' and 'OFF' according to the desired PWN signal I require?

Tesla DeLorean
Guru
February 2, 2020

PWN? You mean PWM or something else?

GPIO's are in bank of 16, you can drive the states via a 32-bit wide pattern buffer to the GPIO->BSRR register.

Providing for fast, and complex signal generation.

3 banks could do 48 servos

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
JJ..1
JJ..1Author
Associate II
February 10, 2020

Hello,

1) Can STM32G474 with 43 PWN pins to control 36 solenoid PWM outputs independently? all of them work without affecting the operation of the rest outputs.All outputs receive different PWN signals and different period of time.

2)Another issue is that, under volting the solenoid coil through PWN signals is causing a high pitch noise(low volume) at 33.33% PWM of 12V i.e equivalent to 4V is supplied to solenoids. The mechanical components are removed then also the noise persists. The noise doesn't come if i give a linear power supply of 4V to the solenoid.

Kindly advice.

Thank you

berendi
Principal
February 10, 2020

1) No. PWM frequencies are not all independent. Regular timer units support a single frequency with 4 independent duty cycles, HRTIM supports 6 independent frequencies. There is no MCU in the STM32 series with 36 completely independent PWM outputs.

2) Try increasing the PWM frequency and/or adjust the low pass filters on the outputs (or add one to each when there isn't any).

3) Check total current ratings in the datasheet.

JJ..1
JJ..1Author
Associate II
February 10, 2020

There are 2 cases :

CASE 1:

These are the list of 6 PWN signals of 12 V that are in use.

1) 100% i.e 12V equivalent

2) 75% i.e 9V equivalent

3) 50% i.e 6V equivalent

4) 41.66% i.e 5V equivalent

5) 33.3% i.e 4V equivalent

6) 25V% i.e 3V equivalent

There are 36 Outputs.

1) 1 output would only receive 3V to 5V equivalent PWN signa, which ever is called for

2) 1 Output would only receive 6V to 12V equivalent PWN signal, which ever is called for

3) 34 Outputs receive 100% or 33.3% PWM independently. First 100% for 100ms to turn on then 33.3% to remain ON.

CASE 2:

I can even work with 2 PWM signals

1) 100%

2) 33.3%

This will be used for 34 outputs. Outputs receive 100% or 33.3% PWM independently. First 100% for 100ms to turn on then 33.3% to remain ON.

Are any of the cases possible?

berendi
Principal
February 10, 2020

Previously you've written that each period is different. Now you are implying that the period doesn't really matter (maybe the faster the better), you just want to control the output voltage by means of the duty cycle in 12 steps.

Using the same timer period on all pwm channels would of course work with any combination of timers, and it would simplify the DMA controlled GPIO solution above, which works on any STM32 MCU (requiring only 3*4*12=144 bytes of memory for the DMA buffers).

JJ..1
JJ..1Author
Associate II
February 10, 2020

Apologies for not being able to explain well. I would like to elaborate on the last statement you wrote, just so that i make myself clear and I understand well.

if code says turn ON output 1 : then 100% is given to 1 for 100 ms then it drops to 33% PWM. This will be continuously ON.

while it is on a code could ask output 2 to be ON: then 100% is given to output 2 for 100ms(while other output 1 at 33% isn't affected) after that only 33% is send to output 2.

likewise there are 34 outputs.

(optinal if possible) other 2 outputs can receive any of the below mentioned PWM

1) 100% i.e 12V equivalent

2) 75% i.e 9V equivalent

3) 50% i.e 6V equivalent

4) 41.66% i.e 5V equivalent

5) 33.3% i.e 4V equivalent

6) 25V% i.e 3V equivalent.

So can this work?

Piranha
Principal III
February 10, 2020

Maybe it's easier to introduce two supply voltage levels for solenoids and add some simple delay circuit consisting from resistor, capacitor, transistor and probably diode to each solenoid control logic in a way that at turning on it turns on the higher voltage for some time and then drops to a lower "hold" voltage. Just an idea to think of... :)

JJ..1
JJ..1Author
Associate II
February 11, 2020

Yes, but that would require double the number of MOSFETs so that would increase the board size and costs . That is the final last option. Thus trying for PWN the the recommended MCU first