PWM and interrupt on same timer

Post here all questions related to STM32 core if you can't find a relevant section!
Post Reply
User avatar
diydsp
Posts: 1
Joined: Thu Aug 20, 2020 10:10 pm

PWM and interrupt on same timer

Post by diydsp »

Hi all, using an STM32H7 here. Thank you so much for porting stm32duino to this hot-rod hardware.

I would like to configure PWM and trigger an interrupt at the end of each period. (for an H-Bridge driving a speaker(*)).
So far I set them up separately:
- PWM on D6 via analogWrite. This uses TIM1 internally.
- periodic interrupt via HardwareTimer on TIM2.
Both of these have been verified to work with scope and speaker/microphone/spectrogram.
It works ok-ish if the periodic interrupt and PWM period at not synced, but it renders lots of artifacts into the audible waveform, so therefore I'd like to have them synced together, coming from the same timer.

Before I dive too deep into this, are there any examples around? Is there already explicit support for this? I've been peeking at the source for
HardwareTimer, pwm_start, AttachInterrupt, etc. I think I might be able to see how to mix them together, but before engaging at that level, I'd like to see if anyone else has already gone through the effort!

Thank you,
DIYDSP

(*) using an H-Bridge as opposed to a traditional codec + linear amp combo so it works with a wiiide voltage range.
Post Reply

Return to “General discussion”