2010-12-26 08:08 AM
predefined number of PWM output pulses
2011-05-17 05:19 AM
2011-05-17 05:19 AM
You may be able to use TIMx_RCR, the repetition counter register.
2011-05-17 05:19 AM
How fast are your pulses? If slow enough you could monitor TIMx_RCR in an ISR. If fast you may need external hardware and one or two extra pins. If you use external h/w you might consider doing your PWM pulse train entirely in external h/w.
For stuff like this and the proprietary LAN I want to do I wish for a Cortex-M3 with Xllinx like peripherals. (Looks around a bit - Actel, now MicroSemi - has smart fusion. It can run the internal ‘M3 at 80 or 100MHz but looking deeper it’s likely that STM32 @72MHZ is faster than the 80MHz - flash ROM wait states. At 100MHz their flash ROM takes additional wait states.)2011-05-17 05:19 AM
Two remarks
1) Now I have three step motors that I configure each to work 20 Hz, which is 6 [rpm], which is very slow. I understand that in that case I dont have to use TIMx_RCR, and I even may monitor each pulse with ISR. But in the case that I do want to use TIMx_RCR as you suggest, I did not see that timers other than TIM1 have this functionality. Am I right? 2) later those motors may work in a speed of 1600 rpm which is 5 [KHz], and then I have to use at least TIMx_RCR solution. The problem again that only TIm1 supports that (if I understand correctly)2011-05-17 05:19 AM
Warning: I have not done PWM output direct motor control on any processor. Many years ago I used 8051 parts preprogrammed as stepper controllers. But that’s it. See http://hmtown.com/amat.htm (middle two links) for context. You should be able to find my contact info if you want it.
A little spreadsheet arithmetic shows that your 1600 RPM needs 5333.33 Hz which with an STM32 at 72 MHz is 13500 processor clocks. Depending on what else the processor is doing you may be able to connect your PWM output to a counter input. Then interrupt on the 16-bit counter when the count expires. Set count on rising or falling edge as needed for your application. Consider stopping PWM by setting the duty cycle to zero. This should finish the current PWM cycle cleanly. I would try to use a logic analyzer to debug the details. A GPIO debug output from your ISR may prove useful. (Please forgive if this next sentence says what you already know.) Stop the PWM with power to the stepper coils to prevent mechanical load from pushing back on the motors.