cancel
Showing results for 
Search instead for 
Did you mean: 

GPIO Speed

Samuel1
Associate III

Hello everybody,

I have to generate a pulse with very narrow and different widths. The setting and procedure is as follows: Clock Freq = 16 Mhz, Prescaler = 1. off time should be 15 μs,  thuss = 15 μs * 16MHz / 2 = 120  Counts and with this logic for certain time on and off. Unfortunately it looks like sometimes this time is so fast for GPIO (see signal, signal2). Although I set  Cubemx the maximum output speed on very high(see pin_5) . do you have any suggestions to solve this? i have tried to change the PWM period but it did not work because i need different pulse width successively.

thanks

3 REPLIES 3

The Speed setting doesn't mean what you think it means. It is really a slew rate defining how much energy is dumped into the pin and the wires, and load attached to it.

For more precise placement you probably don't want to be faffing around with C and library code.

If you want to modulate PWM signals you'd want to use DMA, and a table the TIM can pull the next value from, via a TIM Update trigger. At high speeds interrupts become increasingly problematic both in terms of latency and saturation.

If I were driving several pins with complex patterns, I'd probably create a 32-bit wide pattern buffer that I'd DMA into GPIO->BSRR at a rate controller by a TIM trigger into the DMA unit/stream/channel.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
S.Ma
Principal

GPIO SPEED won't have significant effect for signals <1MHz, unless you drive a heavy RC filter out there.

Look at PWM example in Cube / Nucleo / Timer project examples and find one that looks similar to your needs. I would reccomend first output compare + interrupt, then you can control each edge up and down edges even if the period changes.

Samuel1
Associate III

Hello again ,

i tried it now with arbitrary waveform. But it did not work. I think it's up to the configuration because I can not program registr. I would be glad if someone could help me. I created a array of 6 words for two waveform patterns to be send to TIM2 channel 1 (TIM2_ARR, TIM2_RCR, TIM2_CCR1) This is how the basics look

uint32_t aSRC_Buffer[6] = { 2000,1,800,3000,2,200}; /// ARR, RCR, CCR1 x 2.  But i donot see any signal on the Oszi except one Signal because of this function  HAL_TIM_PWM_Start(&htim2,TIM_CHANNEL_1);.

Summary of the configuration:  i am using Nucleo STM32F767ZI board.0690X0000088tZsQAI.png

0690X0000088tZxQAI.png

0690X0000088taHQAQ.png

Timer clock = 64 MHz

clock source: internal

PWM generation CH1

Prescaler = 64

counter mode = Up

period = 50,000

- Pin PA8: TIM2_ch1_output

- Fashion: push pull

- Pull: pull-up

- Speed: high

 
uint32_t aSRC_Buffer[6] = { 2000,1,800,3000,2,200};
 
 
  /* USER CODE BEGIN 2 */
//HAL_TIM_PWM_Start(&htim2,TIM_CHANNEL_1);
HAL_TIM_DMABurst_WriteStart(&htim2,TIM_DMABASE_ARR, TIM_DMA_TRIGGER,
(uint32_t *)aSRC_Buffer, TIM_DMABURSTLENGTH_3TRANSFERS);
  /* USER CODE END 2 */

​@Community member​ @S.Ma​ #[STM32 MCUs]​ #DMA​