STM32 General Timer Configuration PWM problem

Source: Internet
Author: User


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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.