你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

6步PWM波形奇异的事情

[复制链接]
Extrao 提问时间:2019-10-17 16:36 /
在用官方例程里面的输出6-PWM时发现一个问题(我用的是H-PWM,L-ON),就是上桥的输出波形右下角,这里的引脚好像没有马上关断,
电压是缓慢下降的,并且,这个异常的出现是有规律的,每间隔6个PWM-ON出现一次异常波形,然后每隔1个PWM-ON出现,然后再隔4个PWM-ON出现一次。  我不知道是线间干扰,还是有寄生电容,还是代码写的有问题,我想这样来驱动电机势必出现混乱,心里十分不安,希望前辈指点。

波形右下角

波形右下角

波形右下角

波形右下角


定时器配置代码:

复制代码
中断函数代码


  1. /* Includes ------------------------------------------------------------------*/
  2. #include "stm32f4xx_it.h"
  3. //#include "main.h"

  4. /** @addtogroup Template_Project
  5.   * @{
  6.   */

  7. /* Private typedef -----------------------------------------------------------*/
  8. /* Private define ------------------------------------------------------------*/
  9. /* Private macro -------------------------------------------------------------*/
  10. /* Private variables ---------------------------------------------------------*/
  11. __IO uint32_t uwStep = 0;


  12. /* Private function prototypes -----------------------------------------------*/
  13. /* Private functions ---------------------------------------------------------*/

  14. /******************************************************************************/
  15. /*            Cortex-M4 Processor Exceptions Handlers                         */
  16. /******************************************************************************/

  17. /**
  18.   * @brief  This function handles NMI exception.
  19.   * @param  None
  20.   * @retval None
  21.   */
  22. void NMI_Handler(void)
  23. {
  24. }

  25. /**
  26.   * @brief  This function handles Hard Fault exception.
  27.   * @param  None
  28.   * @retval None
  29.   */
  30. void HardFault_Handler(void)
  31. {
  32.   /* Go to infinite loop when Hard Fault exception occurs */
  33.   while (1)
  34.   {
  35.   }
  36. }

  37. /**
  38.   * @brief  This function handles Memory Manage exception.
  39.   * @param  None
  40.   * @retval None
  41.   */
  42. void MemManage_Handler(void)
  43. {
  44.   /* Go to infinite loop when Memory Manage exception occurs */
  45.   while (1)
  46.   {
  47.   }
  48. }

  49. /**
  50.   * @brief  This function handles Bus Fault exception.
  51.   * @param  None
  52.   * @retval None
  53.   */
  54. void BusFault_Handler(void)
  55. {
  56.   /* Go to infinite loop when Bus Fault exception occurs */
  57.   while (1)
  58.   {
  59.   }
  60. }

  61. /**
  62.   * @brief  This function handles Usage Fault exception.
  63.   * @param  None
  64.   * @retval None
  65.   */
  66. void UsageFault_Handler(void)
  67. {
  68.   /* Go to infinite loop when Usage Fault exception occurs */
  69.   while (1)
  70.   {
  71.   }
  72. }

  73. /**
  74.   * @brief  This function handles SVCall exception.
  75.   * @param  None
  76.   * @retval None
  77.   */
  78. void SVC_Handler(void)
  79. {
  80. }

  81. /**
  82.   * @brief  This function handles Debug Monitor exception.
  83.   * @param  None
  84.   * @retval None
  85.   */
  86. void DebugMon_Handler(void)
  87. {
  88. }

  89. /**
  90.   * @brief  This function handles PendSVC exception.
  91.   * @param  None
  92.   * @retval None
  93.   */
  94. void PendSV_Handler(void)
  95. {
  96. }

  97. /**
  98.   * @brief  ADC1 的看门狗中断.
  99.   * @param  None
  100.   * @retval None
  101.   */
  102. void ADC_IRQHandler(void)
  103. {
  104.        
  105.         ADC_ITConfig(ADC1, ADC_IT_AWD, DISABLE);
  106.        
  107.         if(SET == ADC_GetFlagStatus(ADC1, ADC_FLAG_AWD))
  108.         {
  109.                 ADC_ClearFlag(ADC1, ADC_FLAG_AWD);
  110.                 ADC_ClearITPendingBit(ADC1, ADC_IT_AWD);
  111.                
  112.                 GPIO_SetBits(GPIOD, GPIO_Pin_8);
  113.                 GPIO_ResetBits(GPIOD, GPIO_Pin_9);
  114.         }
  115.        
  116.         ADC_ITConfig(ADC1, ADC_IT_AWD, ENABLE);
  117.        
  118. }

  119. /**
  120.   * @brief  This function handles SysTick Handler.
  121.   * @param  None
  122.   * @retval None
  123.   */
  124. void SysTick_Handler(void)
  125. {
  126.   TIM_GenerateEvent(TIM1, TIM_EventSource_COM);
  127. }

  128. /******************************************************************************/
  129. /*                 STM32F4xx Peripherals Interrupt Handlers                   */
  130. /*  Add here the Interrupt Handler for the used peripheral(s) (PPP), for the  */
  131. /*  available peripheral interrupt handler's name please refer to the startup */
  132. /*  file (startup_stm32f4xx.s).                                               */
  133. /******************************************************************************/

  134. /**
  135.   * @brief  This function handles TIM1 Trigger and commutation and TIM11
  136.   *         global interrupts requests.
  137.   * @param  None
  138.   * @retval None
  139.   */


  140. void TIM1_TRG_COM_TIM11_IRQHandler(void)
  141. {
  142.   /* Clear TIM1 COM pending bit */
  143.   TIM_ClearITPendingBit(TIM1, TIM_IT_COM);

  144.   if (uwStep == 1)
  145.   {
  146.     /* Next step: Step 2 Configuration -------------------------------------- */
  147.     TIM_CCxCmd(TIM1, TIM_Channel_3, TIM_CCx_Disable);
  148.     TIM_CCxNCmd(TIM1, TIM_Channel_3, TIM_CCxN_Disable);
  149.   
  150.     TIM_SelectOCxM(TIM1, TIM_Channel_1, TIM_OCMode_PWM1);
  151.     TIM_CCxCmd(TIM1, TIM_Channel_1, TIM_CCx_Enable);
  152.     TIM_CCxNCmd(TIM1, TIM_Channel_1, TIM_CCxN_Disable);

  153.     TIM_ForcedOC2Config(TIM1, TIM_ForcedAction_Active);
  154.     TIM_CCxCmd(TIM1, TIM_Channel_2, TIM_CCx_Disable);
  155.     TIM_CCxNCmd(TIM1, TIM_Channel_2, TIM_CCxN_Enable);
  156.                
  157.     uwStep++;
  158.   }
  159.   else if (uwStep == 2)
  160.   {
  161.     /* Next step: Step 3 Configuration -------------------------------------- */
  162.     TIM_ForcedOC2Config(TIM1, TIM_ForcedAction_Active);
  163.     TIM_CCxCmd(TIM1, TIM_Channel_2, TIM_CCx_Disable);
  164.     TIM_CCxNCmd(TIM1, TIM_Channel_2, TIM_CCxN_Enable);
  165.    
  166.     TIM_SelectOCxM(TIM1, TIM_Channel_3, TIM_OCMode_PWM1);
  167.     TIM_CCxCmd(TIM1, TIM_Channel_3, TIM_CCx_Enable);
  168.     TIM_CCxNCmd(TIM1, TIM_Channel_3, TIM_CCxN_Disable);

  169.     TIM_CCxCmd(TIM1, TIM_Channel_1, TIM_CCx_Disable);
  170.     TIM_CCxNCmd(TIM1, TIM_Channel_1, TIM_CCxN_Disable);
  171.                
  172.     uwStep++;
  173.   }
  174.   else if (uwStep == 3)
  175.   {
  176.     /* Next step: Step 4 Configuration -------------------------------------- */
  177.     TIM_SelectOCxM(TIM1, TIM_Channel_3, TIM_OCMode_PWM1);
  178.     TIM_CCxCmd(TIM1, TIM_Channel_3, TIM_CCx_Enable);
  179.     TIM_CCxNCmd(TIM1, TIM_Channel_3, TIM_CCxN_Disable);

  180.     TIM_CCxCmd(TIM1, TIM_Channel_2, TIM_CCx_Disable);
  181.     TIM_CCxNCmd(TIM1, TIM_Channel_2, TIM_CCxN_Disable);

  182.     TIM_ForcedOC1Config(TIM1, TIM_ForcedAction_Active);
  183.     TIM_CCxCmd(TIM1, TIM_Channel_1, TIM_CCx_Disable);
  184.     TIM_CCxNCmd(TIM1, TIM_Channel_1, TIM_CCxN_Enable);
  185.                
  186.     uwStep++;
  187.   }
  188.   else if (uwStep == 4)
  189.   {
  190.     /* Next step: Step 5 Configuration -------------------------------------- */
  191.     TIM_CCxCmd(TIM1, TIM_Channel_3, TIM_CCx_Disable);
  192.     TIM_CCxNCmd(TIM1, TIM_Channel_3, TIM_CCxN_Disable);

  193.     TIM_ForcedOC1Config(TIM1, TIM_ForcedAction_Active);
  194.     TIM_CCxCmd(TIM1, TIM_Channel_1, TIM_CCx_Disable);
  195.     TIM_CCxNCmd(TIM1, TIM_Channel_1, TIM_CCxN_Enable);

  196.     TIM_SelectOCxM(TIM1, TIM_Channel_2, TIM_OCMode_PWM1);
  197.     TIM_CCxCmd(TIM1, TIM_Channel_2, TIM_CCx_Enable);
  198.     TIM_CCxNCmd(TIM1, TIM_Channel_2, TIM_CCxN_Disable);
  199.                
  200.     uwStep++;
  201.   }
  202.   else if (uwStep == 5)
  203.   {
  204.     /* Next step: Step 6 Configuration -------------------------------------- */
  205.     TIM_ForcedOC3Config(TIM1, TIM_ForcedAction_Active);
  206.     TIM_CCxCmd(TIM1, TIM_Channel_3, TIM_CCx_Disable);
  207.     TIM_CCxNCmd(TIM1, TIM_Channel_3, TIM_CCxN_Enable);

  208.     TIM_CCxCmd(TIM1, TIM_Channel_1, TIM_CCx_Disable);
  209.     TIM_CCxNCmd(TIM1, TIM_Channel_1, TIM_CCxN_Disable);
  210.                
  211.     TIM_SelectOCxM(TIM1, TIM_Channel_2, TIM_OCMode_PWM1);
  212.     TIM_CCxCmd(TIM1, TIM_Channel_2, TIM_CCx_Enable);
  213.     TIM_CCxNCmd(TIM1, TIM_Channel_2, TIM_CCxN_Disable);
  214.                
  215.     uwStep++;
  216.   }
  217.   else
  218.   {
  219.     /* Next step: Step 1 Configuration -------------------------------------- */
  220.     TIM_SelectOCxM(TIM1, TIM_Channel_1, TIM_OCMode_PWM1);
  221.     TIM_CCxCmd(TIM1, TIM_Channel_1, TIM_CCx_Enable);
  222.     TIM_CCxNCmd(TIM1, TIM_Channel_1, TIM_CCxN_Disable);
  223.                
  224.                 TIM_ForcedOC3Config(TIM1, TIM_ForcedAction_Active);
  225.     TIM_CCxCmd(TIM1, TIM_Channel_3, TIM_CCx_Disable);
  226.     TIM_CCxNCmd(TIM1, TIM_Channel_3, TIM_CCxN_Enable);
  227.                
  228.     TIM_CCxCmd(TIM1, TIM_Channel_2, TIM_CCx_Disable);
  229.     TIM_CCxNCmd(TIM1, TIM_Channel_2, TIM_CCxN_Disable);
  230.    
  231.     uwStep = 1;
  232.   }
  233. }







  234. /**
  235.   * @}
  236.   */


  237. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
复制代码



收藏 1 评论5 发布时间:2019-10-17 16:36

举报

5个回答
Extrao 回答时间:2019-10-17 16:37:38
  1. 定时器配置代码:

  2. #define rsp_tim_GLOBAL

  3. #include "rsp_tim.h"

  4. //static uint8_t Conversion_SW = 1;
  5. static void SysTickConfig(void);
  6. static void TIMx_MODE_Config(void);
  7. static void TIMx_GPIO_Config(void);

  8. void TIMx_GPIO_Config(void)
  9. {
  10.         GPIO_InitTypeDef GPIO_InitStructure;
  11.         NVIC_InitTypeDef NVIC_InitStructure;
  12.        
  13.         RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE);  
  14.         // 开启定时器时钟,即内部时钟CK_INT,等于168M
  15.   RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);

  16.        
  17.         /* 定时器功能引脚初始化 */       
  18.         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;   
  19.         GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  20.         GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  21.         GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  22.         /* 上桥 */
  23.         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_11 | GPIO_Pin_13;// | GPIO_Pin_14;       
  24.         GPIO_Init(GPIOE, &GPIO_InitStructure);
  25.   /* 下桥 */
  26.         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_10 | GPIO_Pin_12;       
  27.         GPIO_Init(GPIOE, &GPIO_InitStructure);
  28.   /* 刹车 */
  29.   //GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
  30.         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;       
  31.         GPIO_Init(GPIOE, &GPIO_InitStructure);
  32.        
  33.        
  34.         /* 指定引脚复用功能 */
  35.         GPIO_PinAFConfig(GPIOE, GPIO_PinSource9,  GPIO_AF_TIM1);   //TIM1_CH1
  36.         GPIO_PinAFConfig(GPIOE, GPIO_PinSource11, GPIO_AF_TIM1);   //TIM1_CH2
  37.         GPIO_PinAFConfig(GPIOE, GPIO_PinSource13, GPIO_AF_TIM1);   //TIM1_CH3
  38.         //GPIO_PinAFConfig(GPIOE, GPIO_PinSource14, GPIO_AF_TIM1);   //TIM1_CH4
  39.        
  40.         GPIO_PinAFConfig(GPIOE, GPIO_PinSource8,  GPIO_AF_TIM1);   //TIM1_CH1N
  41.         GPIO_PinAFConfig(GPIOE, GPIO_PinSource10, GPIO_AF_TIM1);   //TIM1_CH2N
  42.         GPIO_PinAFConfig(GPIOE, GPIO_PinSource12, GPIO_AF_TIM1);   //TIM1_CH3N
  43.         GPIO_PinAFConfig(GPIOE, GPIO_PinSource15, GPIO_AF_TIM1);   //TIM1_BKIN
  44.        
  45.         /* Enable the TIM1 Trigger and commutation interrupt */
  46.         NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
  47.         NVIC_InitStructure.NVIC_IRQChannel = TIM1_TRG_COM_TIM11_IRQn;
  48.   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  49.   NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  50.   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  51.   NVIC_Init(&NVIC_InitStructure);   
  52. }

  53. void TIMx_MODE_Config(void)
  54. {
  55.         TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
  56.   TIM_OCInitTypeDef        TIM_OCInitStructure;
  57.         TIM_BDTRInitTypeDef      TIM_BDTRInitStructure;
  58.        
  59.        
  60.         /* Time Base configuration */
  61.         /* 预分频器不分频 */
  62.   TIM_TimeBaseStructure.TIM_Prescaler = 1-1;
  63.         /* 向上计数 */
  64.   TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
  65.         /* PWM周期 */
  66.   TIM_TimeBaseStructure.TIM_Period = 8400-1;
  67.         /* 分频因子 */
  68.   TIM_TimeBaseStructure.TIM_ClockDivision = 0;
  69.         /* 不使用重复计数器 */
  70.   TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
  71.   TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);

  72.        
  73.   /* Channel 1, 2,3 and 4 Configuration in PWM mode */
  74.         /* 输出比较模式 */
  75.         TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Timing;
  76.         /* 主、互输出使能 */
  77.   TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
  78.   TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable;
  79.         /* 主、互输出,高为有效电平 */
  80.   TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
  81.   TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High;
  82.         /* 主、互输出被禁止时的电平状态 */
  83.   TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Reset;
  84.   TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCNIdleState_Reset;
  85.        
  86.         /* 输出比较1占空比 */
  87.   TIM_OCInitStructure.TIM_Pulse = 1600;
  88.   TIM_OC1Init(TIM1, &TIM_OCInitStructure);
  89.        
  90.   TIM_OCInitStructure.TIM_Pulse = 1600;
  91.   TIM_OC2Init(TIM1, &TIM_OCInitStructure);

  92.   TIM_OCInitStructure.TIM_Pulse = 1600;
  93.   TIM_OC3Init(TIM1, &TIM_OCInitStructure);

  94.   /* Automatic Output enable, Break, dead time and lock configuration*/
  95.         /* 运、空模式下关闭状态的选择 */
  96.   TIM_BDTRInitStructure.TIM_OSSRState = TIM_OSSRState_Enable;
  97.   TIM_BDTRInitStructure.TIM_OSSIState = TIM_OSSIState_Enable;
  98.         /* 锁定配置 */
  99.   TIM_BDTRInitStructure.TIM_LOCKLevel = TIM_LOCKLevel_OFF;
  100.         /* 死区时间 */
  101.   TIM_BDTRInitStructure.TIM_DeadTime = 9;
  102.         /* 刹车使能 */
  103.   TIM_BDTRInitStructure.TIM_Break = TIM_Break_Enable;
  104.         /* Break引脚为高电平,禁止输出 */
  105.   TIM_BDTRInitStructure.TIM_BreakPolarity = TIM_BreakPolarity_High;
  106.         /* 自动输出 */
  107.   TIM_BDTRInitStructure.TIM_AutomaticOutput = TIM_AutomaticOutput_Enable;

  108.   TIM_BDTRConfig(TIM1, &TIM_BDTRInitStructure);

  109.   TIM_CCPreloadControl(TIM1, ENABLE);

  110.   TIM_ITConfig(TIM1, TIM_IT_COM, ENABLE);

  111.   /* TIM1 counter enable */
  112.   TIM_Cmd(TIM1, ENABLE);

  113.   /* Main Output Enable */
  114.   TIM_CtrlPWMOutputs(TIM1, ENABLE);
  115. }

  116. void TIMx_Config(void)
  117. {
  118.         SysTickConfig();
  119.         TIMx_GPIO_Config();
  120.         TIMx_MODE_Config();
  121. }

  122. static void SysTickConfig(void)
  123. {
  124.   /* Setup SysTick Timer for 100 msec interrupts  */
  125.   if (SysTick_Config((SystemCoreClock) / 190))//166))//165))
  126.   {
  127.     /* Capture error */
  128.     while (1);
  129.   }

  130.   NVIC_SetPriority(SysTick_IRQn, 0);
  131. }
复制代码
子曰好人 回答时间:2019-10-18 09:01:19
截图截长一点吧,这个有点短,不过你这个MOS这么长时间才完全关断确实有些问题,你把MCU发出的PWM和gate driver输出的信号放在一起对比,看一下是不是driver输出信号不正常。MOS关断不完全有可能是gate driver设计的问题。
mikecai 回答时间:2019-10-18 09:18:39
断开负载和藕和电路,看波形输出是否还这样,如若无,那是负载和藕和电路不合理,如有,改引脚的输出控制试试。

评分

参与人数 1蝴蝶豆 +2 收起 理由
STMCU + 2

查看全部评分

Extrao 回答时间:2019-10-18 17:05:30
找到问题了,下面这句dai ma的问题,系统滴答定时器,如果不传入能够被168000000(系统时钟)整除的数给计数器,

就会出现问题。很无奈,不知道里面是什么构造,是什么原理。

if (SysTick_Config(840000))//(SystemCoreClock) / 200))//190))//166))//165))

感谢:子曰好人麦克凯


20191018165558.png

(可以结贴了吗?)
herman2019 回答时间:2019-10-18 20:05:53
很赞

所属标签

相似问题

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
13245底部标题123相同标题
12底部标题123相同标题
33333底部标题123相同序号
3435底部标题-无链接
关注我们
st-img 微信公众号
st-img 手机版