找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

帖子
查看: 2487|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

STM32 tim8 pb1輸出不了pwm pc7 正常輸出?

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
#include "xctim.h"

void cxtim_init(void)
{
        GPIO_InitTypeDef                gpio_struct;
        TIM_TimeBaseInitTypeDef         tim_struct;
        TIM_OCInitTypeDef               tim_ocstruct;
        TIM_OCInitTypeDef               tim_ocstruct2;
        
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC |
                                RCC_APB2Periph_TIM8,ENABLE);
        
        //gpiob   1
        gpio_struct.GPIO_Pin            =       GPIO_Pin_1;
        gpio_struct.GPIO_Mode           =       GPIO_Mode_AF_PP;
        gpio_struct.GPIO_Speed          =       GPIO_Speed_50MHz;
        GPIO_Init(GPIOB,&gpio_struct);
        //gpioc    7
        gpio_struct.GPIO_Pin            =       GPIO_Pin_7;
        gpio_struct.GPIO_Mode           =       GPIO_Mode_AF_PP;
        gpio_struct.GPIO_Speed          =       GPIO_Speed_50MHz;
        GPIO_Init(GPIOC,&gpio_struct);
        
        tim_struct.TIM_Period           =       255;
        tim_struct.TIM_Prescaler        =       (72-1);
        tim_struct.TIM_CounterMode      =       TIM_CounterMode_Up;
        TIM_TimeBaseInit(TIM8,&tim_struct);
        
        tim_ocstruct.TIM_OCMode         =       TIM_OCMode_PWM1;
        tim_ocstruct.TIM_OutputState    =       TIM_OutputState_Enable;
        tim_ocstruct.TIM_OCPolarity     =       TIM_OCPolarity_High;
        tim_ocstruct.TIM_OCIdleState    =       TIM_OCIdleState_Reset;
        tim_ocstruct.TIM_Pulse          =       20;
        TIM_OC2Init(TIM8,&tim_ocstruct);

        tim_ocstruct2.TIM_OCMode         =       TIM_OCMode_PWM1;
        tim_ocstruct2.TIM_OutputNState   =       TIM_OutputNState_Enable;
        tim_ocstruct2.TIM_OCNPolarity    =       TIM_OCNPolarity_High;
        tim_ocstruct2.TIM_OCNIdleState   =       TIM_OCNIdleState_Reset;
        tim_ocstruct2.TIM_Pulse          =       20;
        TIM_OC3Init(TIM8,&tim_ocstruct2);
        
        TIM_CtrlPWMOutputs(TIM8,ENABLE);
        
        TIM_OC2PreloadConfig(TIM8,TIM_OCPreload_Enable);
        TIM_OC3PreloadConfig(TIM8,TIM_OCPreload_Enable);
        
        TIM_ARRPreloadConfig(TIM8,ENABLE);
        
        TIM_Cmd(TIM8,ENABLE);
        
}


8b37c3e0705ef65c5d2cc091dd3d3ca.png (41.44 KB, 下載次數(shù): 63)

8b37c3e0705ef65c5d2cc091dd3d3ca.png
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表