OID Tim3_init (void)
{
Tim_timebaseinittypedef tim_timebasestructure;
Tim_ocinittypedef tim_ocinitstructure;
/* PWM signal level hopping value */
U16 ccr1= 36000;
U16 Ccr2= 36000;
/*pclk1 after twice octave as TIM3 clock source equals 72mhz*/
Rcc_apb1periphclockcmd (RCC_APB1PERIPH_TIM3, ENABLE);
/* Time Base configuration */
Tim_timebasestructure.tim_period = 1599; Counting Cycle 1600
Tim_timebasestructure.tim_prescaler = 1; Set Prescaler: Prescaler = 2, which is 72/3=24mhz
tim_timebasestructure.tim_clockdivision = 0; Set the clock divider factor: no crossover
Tim_timebasestructure.tim_countermode = tim_countermode_up; Count overflow mode up
Tim_timebaseinit (TIM3, &tim_timebasestructure);
/* PWM1 Mode Configuration:channel1 */
Tim_ocinitstructure.tim_ocmode = TIM_OCMODE_PWM1; configured for PWM mode 1
Tim_ocinitstructure.tim_outputstate = tim_outputstate_enable;
Tim_ocinitstructure.tim_pulse = 600; Set the jump value, when the counter is counted to this value, the level of the transition occurs
Tim_ocinitstructure.tim_ocpolarity =tim_ocpolarity_low; High when the timer count value is less than CCR1
Tim_oc1init (TIM3, &tim_ocinitstructure); Enable Channel 1
Tim_oc1preloadconfig (TIM3, tim_ocpreload_enable);
/* PWM1 Mode Configuration:channel2 */
Tim_ocinitstructure.tim_outputstate = tim_outputstate_enable;
Tim_ocinitstructure.tim_pulse = 300; Set the level hopping value of Channel 2 and output the PWM of another duty-free ratio
tim_ocinitstructure.tim_ocpolarity = Tim_ocpolarity_high; Low when the timer count value is less than CCR2
Tim_oc2init (TIM3, &tim_ocinitstructure); Enable Channel 2
Tim_oc2preloadconfig (TIM3, tim_ocpreload_enable);
Tim_arrpreloadconfig (TIM3, ENABLE); Enable TIM3 Reload Register arr
/* TIM3 Enable counter */
Tim_cmd (TIM3, ENABLE);
Delay_8ms ();
Tim_cmd (TIM3, DISABLE);
}
STM32 General Timer Configuration PWM problem