這篇文章主要為大家展示了“如何解決STM32普通定時(shí)器配置PWM的問(wèn)題”,內(nèi)容簡(jiǎn)而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“如何解決STM32普通定時(shí)器配置PWM的問(wèn)題”這篇文章吧。
我們提供的服務(wù)有:成都網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì)、微信公眾號(hào)開發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認(rèn)證、海陽(yáng)ssl等。為1000多家企事業(yè)單位解決了網(wǎng)站和推廣的問(wèn)題。提供周到的售前咨詢和貼心的售后服務(wù),是有科學(xué)管理、有技術(shù)的海陽(yáng)網(wǎng)站制作公司
oid TIM3_Init(void) { TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_OCInitTypeDef TIM_OCInitStructure; /* PWM信號(hào)電平跳變值 */ // u16 CCR1= 36000; // u16 CCR2= 36000; /*PCLK1經(jīng)過(guò)2倍頻后作為TIM3的時(shí)鐘源等于72MHz*/ RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); /* Time base configuration */ TIM_TimeBaseStructure.TIM_Period =1599; //計(jì)數(shù)周期1600 TIM_TimeBaseStructure.TIM_Prescaler = 1; //設(shè)置預(yù)分頻:預(yù)分頻=2,即為72/3=24MHz TIM_TimeBaseStructure.TIM_ClockDivision = 0; //設(shè)置時(shí)鐘分頻系數(shù):不分頻 TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //向上計(jì)數(shù)溢出模式 TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure); /* PWM1 Mode configuration: Channel1 */ TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; //配置為PWM模式1 TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_Pulse =600; //設(shè)置跳變值,當(dāng)計(jì)數(shù)器計(jì)數(shù)到這個(gè)值時(shí),電平發(fā)生跳變 TIM_OCInitStructure.TIM_OCPolarity =TIM_OCPolarity_Low; //當(dāng)定時(shí)器計(jì)數(shù)值小于CCR1時(shí)為高電平 TIM_OC1Init(TIM3, &TIM_OCInitStructure); //使能通道1 TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Enable); /* PWM1 Mode configuration: Channel2 */ TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_Pulse = 300; //設(shè)置通道2的電平跳變值,輸出另外一個(gè)占空比的PWM TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; //當(dāng)定時(shí)器計(jì)數(shù)值小于CCR2時(shí)為低電平 TIM_OC2Init(TIM3, &TIM_OCInitStructure); //使能通道2 TIM_OC2PreloadConfig(TIM3, TIM_OCPreload_Enable); TIM_ARRPreloadConfig(TIM3, ENABLE); //使能TIM3重載寄存器ARR /* TIM3 enable counter */ TIM_Cmd(TIM3, ENABLE); Delay_8ms(); TIM_Cmd(TIM3, DISABLE); }
以上是“如何解決STM32普通定時(shí)器配置PWM的問(wèn)題”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!