打印
[STM32F1]

STM32F103 6路互补信号中有三路PWM信号输出有间断

[复制链接]
899|18
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
probedog|  楼主 | 2023-6-26 10:14 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
我的STM32F103RCT6 tim8输出6路互补信号中有三路PWM信号输出有间断,请问可能是什么原因导致的,麻烦各位高人帮我看看.调了很久了,找不到原因.
以下贴出代码。

//初始化Tim8
void MotorLeft_Hw_PWM_Init(void)
{
    by_Direct = 0;
    by_Step = 0;
    w_PWM_Save = 0;

    GPIO_InitTypeDef        GPIO_InitStructure;
    NVIC_InitTypeDef        NVIC_InitStructure;
    TIM_OCInitTypeDef       TIM_OCInitStructure;
    TIM_BDTRInitTypeDef     TIM_BDTRInitStructure;
    TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;

    /* GPIOA Configuration: Channel 1, 2 and 3 as alternate function push-pull */
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOA, &GPIO_InitStructure);

    /* GPIOB Configuration: Channel 1N, 2N and 3N as alternate function push-pull */
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
    GPIO_Init(GPIOB, &GPIO_InitStructure);

    /* GPIOB Configuration: BKIN pin */
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    GPIO_Init(GPIOB, &GPIO_InitStructure);  


    /* Time Base configuration */
    TIM_TimeBaseStructure.TIM_Prescaler = 0;
    TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
    TIM_TimeBaseStructure.TIM_Period = 3499;
    TIM_TimeBaseStructure.TIM_ClockDivision = 0;
    TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;

    TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);

    /* Channel 1, 2,3 and 4 Configuration in PWM mode */
    TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
    TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
    TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable;
    TIM_OCInitStructure.TIM_Pulse = 0;
    TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;;
    TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High;
    TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Reset;
    TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCNIdleState_Reset;

    TIM_OC1Init(TIM1, &TIM_OCInitStructure);
    TIM_OC2Init(TIM1, &TIM_OCInitStructure);
    TIM_OC3Init(TIM1, &TIM_OCInitStructure);

    /* Automatic Output enable, Break, dead time and lock configuration*/
    TIM_BDTRInitStructure.TIM_OSSRState = TIM_OSSRState_Enable;
    TIM_BDTRInitStructure.TIM_OSSIState = TIM_OSSIState_Enable;
    TIM_BDTRInitStructure.TIM_LOCKLevel = TIM_LOCKLevel_OFF;
    TIM_BDTRInitStructure.TIM_DeadTime = 0xFF;
    TIM_BDTRInitStructure.TIM_Break = TIM_Break_Enable;
    TIM_BDTRInitStructure.TIM_BreakPolarity = TIM_BreakPolarity_High;
    TIM_BDTRInitStructure.TIM_AutomaticOutput = TIM_AutomaticOutput_Enable;
    TIM_BDTRConfig(TIM1, &TIM_BDTRInitStructure);

    TIM_ClearITPendingBit(TIM1, TIM_IT_Break);
    TIM_ITConfig(TIM1, TIM_IT_Break, ENABLE);

    TIM_CCPreloadControl(TIM1, ENABLE);
    TIM_ITConfig(TIM1, TIM_IT_COM, ENABLE);
    TIM_Cmd(TIM1, ENABLE);
    TIM_CtrlPWMOutputs(TIM1, ENABLE);


    NVIC_InitStructure.NVIC_IRQChannel = TIM1_TRG_COM_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x00;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);
}

使用特权

评论回复
沙发
probedog|  楼主 | 2023-6-26 10:16 | 只看该作者
//输出PWM
void MotorLeft_Hw_Hall_Int(UCHAR by_State)
{
    switch(by_Step)
    {
    case 5:
    default:
        MotorLeft_Hw_PWM(0, 1749);
        /* Next by_Step: by_Step 1 (A+,C-)Configuration ---------------------------- */
        /*  Channel2 configuration */
        TIM_CCxCmd(TIM1, TIM_Channel_2, TIM_CCx_Disable);
        TIM_CCxNCmd(TIM1, TIM_Channel_2, TIM_CCxN_Disable);

        /*  Channel1 configuration */
        TIM_SelectOCxM(TIM1, TIM_Channel_1, TIM_OCMode_PWM1);
        TIM_CCxCmd(TIM1, TIM_Channel_1, TIM_CCx_Enable);
        TIM_CCxNCmd(TIM1, TIM_Channel_1, TIM_CCxN_Disable);

        /*  Channel3 configuration */
        TIM_SelectOCxM(TIM1, TIM_Channel_3, TIM_OCMode_PWM1);
        TIM_CCxCmd(TIM1, TIM_Channel_3, TIM_CCx_Disable);
        TIM_CCxNCmd(TIM1, TIM_Channel_3, TIM_CCxN_Enable);
        by_Step = 4;
        break;
    case 4:
        /* Next by_Step: by_Step 2 (A+,B-)Configuration ---------------------------- */
        /*  Channel3 configuration */
        TIM_CCxCmd(TIM1, TIM_Channel_3, TIM_CCx_Disable);
        TIM_CCxNCmd(TIM1, TIM_Channel_3, TIM_CCxN_Disable);

        /*  Channel1 configuration */
        TIM_SelectOCxM(TIM1, TIM_Channel_1, TIM_OCMode_PWM1);
        TIM_CCxCmd(TIM1, TIM_Channel_1, TIM_CCx_Enable);
        TIM_CCxNCmd(TIM1, TIM_Channel_1, TIM_CCxN_Disable);

        /*  Channel2 configuration */
        TIM_SelectOCxM(TIM1, TIM_Channel_2, TIM_OCMode_PWM1 );
        TIM_CCxCmd(TIM1, TIM_Channel_2, TIM_CCx_Disable);
        TIM_CCxNCmd(TIM1, TIM_Channel_2, TIM_CCxN_Enable);
        by_Step = 6;
        break;
    case 6:
        /* Next by_Step: by_Step 3 (C+,B-)Configuration ---------------------------- */
        /*  Channel1 configuration */
        TIM_CCxCmd(TIM1, TIM_Channel_1, TIM_CCx_Disable);
        TIM_CCxNCmd(TIM1, TIM_Channel_1, TIM_CCxN_Disable);

        /*  Channel3 configuration */
        TIM_SelectOCxM(TIM1, TIM_Channel_3, TIM_OCMode_PWM1);
        TIM_CCxCmd(TIM1, TIM_Channel_3, TIM_CCx_Enable);
        TIM_CCxNCmd(TIM1, TIM_Channel_3, TIM_CCxN_Disable);

        /*  Channel2 configuration */
        TIM_SelectOCxM(TIM1, TIM_Channel_2, TIM_OCMode_PWM1);
        TIM_CCxCmd(TIM1, TIM_Channel_2, TIM_CCx_Disable);
        TIM_CCxNCmd(TIM1, TIM_Channel_2, TIM_CCxN_Enable);
        by_Step = 2;
        break;
    case 2:
        /* Next by_Step: by_Step 4 (C+,A-)Configuration ---------------------------- */
        /*  Channel2 configuration */
        TIM_CCxCmd(TIM1, TIM_Channel_2, TIM_CCx_Disable);
        TIM_CCxNCmd(TIM1, TIM_Channel_2, TIM_CCxN_Disable);

        /*  Channel3 configuration */
        TIM_SelectOCxM(TIM1, TIM_Channel_3, TIM_OCMode_PWM1);
        TIM_CCxCmd(TIM1, TIM_Channel_3, TIM_CCx_Enable);
        TIM_CCxNCmd(TIM1, TIM_Channel_3, TIM_CCxN_Disable);

        /*  Channel1 configuration */
        TIM_SelectOCxM(TIM1, TIM_Channel_1, TIM_OCMode_PWM1);
        TIM_CCxCmd(TIM1, TIM_Channel_1, TIM_CCx_Disable);
        TIM_CCxNCmd(TIM1, TIM_Channel_1, TIM_CCxN_Enable);
        by_Step = 3;
        break;
    case 3:
        /* Next by_Step: by_Step 5 (B+,A-)Configuration ---------------------------- */
        /*  Channel3 configuration */
        TIM_CCxCmd(TIM1, TIM_Channel_3, TIM_CCx_Disable);
        TIM_CCxNCmd(TIM1, TIM_Channel_3, TIM_CCxN_Disable);

        /*  Channel2 configuration */
        TIM_SelectOCxM(TIM1, TIM_Channel_2, TIM_OCMode_PWM1);
        TIM_CCxCmd(TIM1, TIM_Channel_2, TIM_CCx_Enable);
        TIM_CCxNCmd(TIM1, TIM_Channel_2, TIM_CCxN_Disable);

        /*  Channel1 configuration */
        TIM_SelectOCxM(TIM1, TIM_Channel_1, TIM_OCMode_PWM1);
        TIM_CCxCmd(TIM1, TIM_Channel_1, TIM_CCx_Disable);
        TIM_CCxNCmd(TIM1, TIM_Channel_1, TIM_CCxN_Enable);
        by_Step = 1;
        break;
    case 1:
        /* Next by_Step: by_Step 6 (B+,C-)Configuration ---------------------------- */
        /*  Channel1 configuration */
        TIM_CCxCmd(TIM1, TIM_Channel_1, TIM_CCx_Disable);
        TIM_CCxNCmd(TIM1, TIM_Channel_1, TIM_CCxN_Disable);

        /*  Channel2 configuration */
        TIM_SelectOCxM(TIM1, TIM_Channel_2, TIM_OCMode_PWM1);
        TIM_CCxCmd(TIM1, TIM_Channel_2, TIM_CCx_Enable);
        TIM_CCxNCmd(TIM1, TIM_Channel_2, TIM_CCxN_Disable);

        /*  Channel3 configuration */
        TIM_SelectOCxM(TIM1, TIM_Channel_3, TIM_OCMode_PWM1);
        TIM_CCxCmd(TIM1, TIM_Channel_3, TIM_CCx_Disable);
        TIM_CCxNCmd(TIM1, TIM_Channel_3, TIM_CCxN_Enable);
        by_Step = 5;
        break;
    }
}

使用特权

评论回复
板凳
香水城| | 2023-6-30 07:58 | 只看该作者
要是有图示说明就好了。

看你三对互不通道频繁切换开关动作,不知你的异常间断具体啥意思。

另外,死区先关闭测试下。

使用特权

评论回复
地板
Undshing| | 2023-7-1 23:14 | 只看该作者
没看懂描述

使用特权

评论回复
5
未说出口的像你| | 2023-7-13 22:19 | 只看该作者
估计被中断给影响了吧

使用特权

评论回复
6
失物招領| | 2023-7-14 01:24 | 只看该作者
你是不是在中断里做什么数据处理之类的了,耽误时间了?

使用特权

评论回复
7
白马过平川| | 2023-7-14 03:22 | 只看该作者
中断配置是不是有点问题啊

使用特权

评论回复
8
风凉| | 2023-7-14 06:12 | 只看该作者
你就复制之前的三路好使的呗

使用特权

评论回复
9
她已醉| | 2023-7-14 07:12 | 只看该作者
单独看这个看不出啊,你能不能用示波器把抓到的波形发出来看看

使用特权

评论回复
10
捧一束彼岸花| | 2023-7-14 08:11 | 只看该作者
建议楼主直接找个关于电机控制的例程,上面应该有三路互补输出的操作

使用特权

评论回复
11
在曼谷的春| | 2023-7-14 10:24 | 只看该作者
你说的间断,是随机的还是固定的?

使用特权

评论回复
12
我吃小朋友| | 2023-7-14 12:42 | 只看该作者
你程序里是不是有中断比PWM的优先级还高啊?

使用特权

评论回复
13
月亮一键变蓝| | 2023-7-14 15:33 | 只看该作者
你程序除了PWM之外,还有其他的逻辑程序么?

使用特权

评论回复
14
故意相遇| | 2023-7-14 21:45 | 只看该作者
大概就是有什么影响了你的PWM输出吧

使用特权

评论回复
15
SantaBunny| | 2023-10-27 09:52 | 只看该作者
检查一下是不是中断配置有点问题

使用特权

评论回复
16
周半梅| | 2023-12-1 07:32 | 只看该作者

首先是进行按比例和具体的施胶量进行混合操作

使用特权

评论回复
17
童雨竹| | 2023-12-1 08:25 | 只看该作者

将在原边形成电压尖峰,

使用特权

评论回复
18
Wordsworth| | 2023-12-1 09:28 | 只看该作者

使该元器件不超过正常值范围

使用特权

评论回复
19
Clyde011| | 2023-12-1 10:31 | 只看该作者

该电容可以存储高达8KV的电位

使用特权

评论回复
20
万图| | 2023-12-1 12:27 | 只看该作者

ESD静电保护器工作特性与TVS管一致。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

376

主题

2009

帖子

3

粉丝