cancel
Showing results for 
Search instead for 
Did you mean: 

Pwm vs timer irq - slow 100khz max

oeliks
Senior

Hi ! Im generating pwm at 200khz with no problems. But when I use ​timer to generate interrupt I get max 100khz of pulse on pin. No matter if I use HAL_GPIO_Toggle/WritePin or just GPIOx->BSRR. No matter how low value of timer prescaller I use.

Output pin set to high speed.​ push pull. No pullup, no pulldown.

Why? Software or hardware limitations?

STM32f103c8 at 72 MHz of timer clock​.

1 ACCEPTED SOLUTION

Accepted Solutions

Would probably want to have the TIM trigger the ADC(s) directly. At higher speeds want the DMA to collect the ADC data. You could then toggle at DMA HT/TC interrupts at a slower rate, but could relate edge of that to TIM pin output.

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

View solution in original post

5 REPLIES 5
S.Ma
Principal

Why not describe what you want to achieve?

Are you trying to generate PWM by just timer interrupt? (both rise and fall edge? = 400 kHz interrupt if 50% duty cycle)?

You're going to run out of bandwidth. The interrupt has to push/pop context, and the flash memory is fairly slow. You're likely to saturate the processor as you interrupt above 100 KHz

For driving/modulating pulses at high speeds, use the TIM features, and DMA

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
oeliks
Senior

Thanks for answers 🙂

I wanted to generate a pulse to debug with scope.

​​

PWM_IT 200khz, ​generates interrupt (both rising and falling edge) that starts ADC and sets some output pin at the same time, when ADC is ready the pin is reset by ADC interrupt.

Wanted to have a visual interpretation of adc conversion time.​

Would probably want to have the TIM trigger the ADC(s) directly. At higher speeds want the DMA to collect the ADC data. You could then toggle at DMA HT/TC interrupts at a slower rate, but could relate edge of that to TIM pin output.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
oeliks
Senior

Thanks. I will try to use DMA. But while I wanted to collect an array of 20 samples at high pulse and 20 at low, and then replace first sample in array with another, than second etc. And avarage it. To get "walking" avarage. I think it will be more complicated than I think 🙂

​Or mabey take 20 samples, avarage it, take next 20 samples, avarage, and avarage this two avarages .... ohhh