I needed something similar, In my case I solved using TIMER. Here my code:
[DEAD LINK /public/STe2ecommunities/mcu/Lists/ARM%20CortexM3%20STM32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/ARM CortexM3 STM32/fastest way to generate output waveform&FolderCTID=0x01200200770978C69A1141439FE559EB459D758000626BE2B829C32145B9EB5739142DC17E¤tviews=122]https://my.st.com/public/STe2ecommunities/mcu/Lists/ARM%20CortexM3%20STM32/Flat.aspx?RootFolder=%2fpublic%2fSTe2ecommunities%2fmcu%2fLists%2fARM%20CortexM3%20STM32%2ffastest%20way%20to%20generate%20output%20waveform&FolderCTID=0x01200200770978C69A1141439FE559EB459D758000626BE2B829C32145B9EB5739142DC17E¤tviews=122
I don't know if you have looked at the application note ''AN2820'' it is about: ''Driving bipolar stepper motors using a medium-density STM32F103xx microcontroller'' This is the link: http://www.st.com/mcu/familiesdocs-110.html Hope this helps. MCU Lüfter, be low power
Thanks for the reply, in your case, what you did is pwm where the duty cycle and period is set. My problem is to generate a specific number of pulses because my application is for stepper motor where I need to generate the precise number of steps. The PWM is not that important and relevant. Any tips or code on how to do it?
Thanks. I've already solved the problem, I've found a much easier way, alternating the GPIO pin as set and reset and by having a certain amount of delay for each is much easier. This way, I can control the duration of the pulse and how much pulse I wanted to produce by using for loop. If there's any question on how to do this, I'll be happy to post the code.