野火电子论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10805|回复: 3

PWM互补输出不接地一直是相同的波形,接地直接没波形,附上代码,求大牛帮帮忙看看

[复制链接]
发表于 2017-6-10 12:08:41 | 显示全部楼层 |阅读模式
#include "bsp_Advance_Tim.h"

static void Advance_TIM_GPIOConfig()
{
        GPIO_InitTypeDef  GPIO_TimStruct;
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
       
       
        GPIO_TimStruct.GPIO_Pin = GPIO_Pin_8;
        GPIO_TimStruct.GPIO_Mode = GPIO_Mode_Out_PP;
        GPIO_TimStruct.GPIO_Speed = GPIO_Speed_50MHz;
       
        GPIO_Init(GPIOA,&GPIO_TimStruct);
       
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
        GPIO_TimStruct.GPIO_Pin = GPIO_Pin_13;
        GPIO_TimStruct.GPIO_Mode = GPIO_Mode_Out_PP;
        GPIO_TimStruct.GPIO_Speed = GPIO_Speed_50MHz;
       
        GPIO_Init(GPIOB,&GPIO_TimStruct);
       
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
        GPIO_TimStruct.GPIO_Pin = GPIO_Pin_12;
        GPIO_TimStruct.GPIO_Mode = GPIO_Mode_Out_PP;
        GPIO_TimStruct.GPIO_Speed = GPIO_Speed_50MHz;
       
        GPIO_Init(GPIOB,&GPIO_TimStruct);
        GPIO_ResetBits(GPIOB,GPIO_Pin_12);
}

static void AdvanceTim_Config()
{
        TIM_TimeBaseInitTypeDef  Advance_TimBaseStruct;
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1,ENABLE);
       
        Advance_TimBaseStruct.TIM_ClockDivision = TIM_CKD_DIV1;
        Advance_TimBaseStruct.TIM_CounterMode = TIM_CounterMode_Up;
        Advance_TimBaseStruct.TIM_Period = (9 - 1);
        Advance_TimBaseStruct.TIM_Prescaler = (8 - 1);
        Advance_TimBaseStruct.TIM_RepetitionCounter = 4;
       
        TIM_TimeBaseInit(TIM1,&Advance_TimBaseStruct);
       
       
        TIM_OCInitTypeDef  AdvanceOC_TimStruct;
       
        AdvanceOC_TimStruct.TIM_OCIdleState = TIM_OCIdleState_Set;
        AdvanceOC_TimStruct.TIM_OCMode = TIM_OCMode_PWM1;
        AdvanceOC_TimStruct.TIM_OCNIdleState = TIM_OCNIdleState_Set;
        AdvanceOC_TimStruct.TIM_OCNPolarity = TIM_OCNPolarity_High;
        AdvanceOC_TimStruct.TIM_OCPolarity = TIM_OCPolarity_High;
        AdvanceOC_TimStruct.TIM_OutputNState = TIM_OutputNState_Enable;
        AdvanceOC_TimStruct.TIM_OutputState = TIM_OutputState_Enable;
        AdvanceOC_TimStruct.TIM_Pulse = TIM_OPMode_Single;
       
        TIM_OC1Init(TIM1,&AdvanceOC_TimStruct);
                TIM_OC1PreloadConfig(TIM1,TIM_OCPreload_Enable);
//        TIM_OC1PolarityConfig(TIM1,TIM_OCPolarity_High);
//        TIM_OC1NPolarityConfig(TIM1,TIM_OCNPolarity_High);
        TIM_CCxCmd(TIM1,TIM_Channel_1,TIM_CCx_Enable);



        TIM_BDTRInitTypeDef  AdvanceTimStruct;
       
        AdvanceTimStruct.TIM_AutomaticOutput = TIM_AutomaticOutput_Enable;
        AdvanceTimStruct.TIM_Break = TIM_Break_Enable;
        AdvanceTimStruct.TIM_BreakPolarity = TIM_BreakPolarity_Low;
        AdvanceTimStruct.TIM_DeadTime = 11;
        AdvanceTimStruct.TIM_LOCKLevel  = TIM_LOCKLevel_OFF;
        AdvanceTimStruct.TIM_OSSIState = TIM_OSSIState_Enable;
        AdvanceTimStruct.TIM_OSSRState = TIM_OSSRState_Enable;
       
        TIM_BDTRConfig(TIM1,&AdvanceTimStruct);
       
        TIM_Cmd(TIM1,ENABLE);
        TIM_ClearFlag(TIM1,TIM_FLAG_Break);
        TIM_CtrlPWMOutputs(TIM1,ENABLE);
       
       
}


void Advance_Tim_Init()
{
        Advance_TIM_GPIOConfig();
        AdvanceTim_Config();
}











不接地波形图 ,接地直接没波

不接地波形图 ,接地直接没波
回复

使用道具 举报

发表于 2017-6-10 14:28:36 | 显示全部楼层
AdvanceOC_TimStruct.TIM_OCNPolarity = TIM_OCNPolarity_High;
AdvanceOC_TimStruct.TIM_OCPolarity = TIM_OCPolarity_High;

这两个怎么配置成一样。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-6-10 18:03:21 | 显示全部楼层
本帖最后由 MUEar 于 2017-6-10 18:05 编辑
fire 发表于 2017-6-10 14:28
AdvanceOC_TimStruct.TIM_OCNPolarity = TIM_OCNPolarity_High;
AdvanceOC_TimStruct.TIM_OCPolarity = TI ...

火哥,我想这个是互补输出的极性,应该不影响,所以就配置成一样的,按道理说怎么出来的图形也应该是互补的。我刚才把
AdvanceOC_TimStruct.TIM_OCNPolarity = TIM_OCNPolarity_High;改成AdvanceOC_TimStruct.TIM_OCNPolarity = TIM_OCNPolarity_Low;还是不行,但是用你的代码都好着呢,附张我改后的波形图,几乎没波形的是接地测得的,有波形的是没接地的,求指导:

接地测

接地测

连线

连线

未接地

未接地
回复 支持 反对

使用道具 举报

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

本版积分规则

联系站长|手机版|野火电子官网|野火淘宝店铺|野火电子论坛 ( 粤ICP备14069197号 ) 大学生ARM嵌入式2群

GMT+8, 2024-11-24 06:48 , Processed in 0.028983 second(s), 26 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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