2018-03-26 10:56 PM
Hello everyone,
I am just new to stm32 microcontroller. I am starting my first project of stm32 using “STM32F030C6T6� MCU. My project is to drive a “high speed solenoid valve driver�. In which I have to drive a mosfet with PWM of duty cycle 15%@40Khz. Till this point it is not a problem. but there is a twist that first pulse of PWM output must be of 500ms period i.e. 2Hz with approx. 80% duty cycle means 80%@2Hz. From 2nd pulse it should be then 15%@40Khz Just Summarizing here:__1st pulse : Freq. 2Hz, Period 500ms, duty cycle appr. 99%
2nd pulse: Freq. 40KHz, Period .025ms, duty cycle appr. 15% 3rd pulse: Freq. 40KHz, Period .025ms, duty cycle appr. 15% | | | last pulse: Freq. 40KHz, Period .025ms, duty cycle appr. 15%Note: Toff of all pulse from first to last should be same.__
Can any one help me how it can be done with timer or how to configure timer for it.
You feedback and suggestions will be highly appreciated. Thanks in advance.2018-03-27 12:44 AM
Set both TIMx_ARR and TIMx_CCRy to preloaded (TIMx_CR1.ARR=1, TIMx_CCMRz.OCyPE=1). Set TIMx_CCMRz to required output mode and enable in TIMx_CCER . Set TIMx_PSC, TIMx_ARR and TIMx_CCRy for the first pulse and set TIMx_EGR.UG to generate an update to make those settings active. Now set TIMx_PSC, TIMx_ARR and TIMx_CCRy for the subsequent pulses - these will get active only after the first cycle is finished and next Update is generated during the run of timer. Now enable the timer by TIMx_CR1.CEN.
If the desired number of pulses is below 256, you can use TIM1 and its repetition counter (TIM1_RCR) and one-pulse mode (TIM1_CR1.OPM) to automatically stop the timer after the set number of pulses; but in TIM1 also don't forget to set TIM1_BDTR.MOE to enable outputs. Otherwise, you'd need to stop the timer in software when the required number of pulses elapsed (using an interrupt).
JW
2018-03-27 03:56 AM
Thank you so much dear for your immediate reply. I got your suggestion, I will do it in my code and will let you know if I encounter any problem.
By the way one mistake I have done while putting this question, that the frequency for first pulse is 2.0khz not 2hz. But no a problem I will calculate values as per this and will write the code.
Once again thank you so much.