OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 2506|回复: 0

tim8 pb1 输出不了pwm pc7 正常输出

[复制链接]

8

主题

30

帖子

0

精华

高级会员

Rank: 4

积分
666
金钱
666
注册时间
2020-7-2
在线时间
77 小时
发表于 2020-7-9 16:20:16 | 显示全部楼层 |阅读模式
#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);
        
}



正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-6-29 15:38

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表