在用官方例程里面的输出6-PWM时发现一个问题(我用的是H-PWM,L-ON),就是上桥的输出波形右下角,这里的引脚好像没有马上关断,
电压是缓慢下降的,并且,这个异常的出现是有规律的,每间隔6个PWM-ON出现一次异常波形,然后每隔1个PWM-ON出现,然后再隔4个PWM-ON出现一次。 我不知道是线间干扰,还是有寄生电容,还是代码写的有问题,我想这样来驱动电机势必出现混乱,心里十分不安,希望前辈指点。
波形右下角
波形右下角
定时器配置代码:
中断函数代码
- /* Includes ------------------------------------------------------------------*/
- #include "stm32f4xx_it.h"
- //#include "main.h"
- /** @addtogroup Template_Project
- * @{
- */
- /* Private typedef -----------------------------------------------------------*/
- /* Private define ------------------------------------------------------------*/
- /* Private macro -------------------------------------------------------------*/
- /* Private variables ---------------------------------------------------------*/
- __IO uint32_t uwStep = 0;
- /* Private function prototypes -----------------------------------------------*/
- /* Private functions ---------------------------------------------------------*/
- /******************************************************************************/
- /* Cortex-M4 Processor Exceptions Handlers */
- /******************************************************************************/
- /**
- * @brief This function handles NMI exception.
- * @param None
- * @retval None
- */
- void NMI_Handler(void)
- {
- }
- /**
- * @brief This function handles Hard Fault exception.
- * @param None
- * @retval None
- */
- void HardFault_Handler(void)
- {
- /* Go to infinite loop when Hard Fault exception occurs */
- while (1)
- {
- }
- }
- /**
- * @brief This function handles Memory Manage exception.
- * @param None
- * @retval None
- */
- void MemManage_Handler(void)
- {
- /* Go to infinite loop when Memory Manage exception occurs */
- while (1)
- {
- }
- }
- /**
- * @brief This function handles Bus Fault exception.
- * @param None
- * @retval None
- */
- void BusFault_Handler(void)
- {
- /* Go to infinite loop when Bus Fault exception occurs */
- while (1)
- {
- }
- }
- /**
- * @brief This function handles Usage Fault exception.
- * @param None
- * @retval None
- */
- void UsageFault_Handler(void)
- {
- /* Go to infinite loop when Usage Fault exception occurs */
- while (1)
- {
- }
- }
- /**
- * @brief This function handles SVCall exception.
- * @param None
- * @retval None
- */
- void SVC_Handler(void)
- {
- }
- /**
- * @brief This function handles Debug Monitor exception.
- * @param None
- * @retval None
- */
- void DebugMon_Handler(void)
- {
- }
- /**
- * @brief This function handles PendSVC exception.
- * @param None
- * @retval None
- */
- void PendSV_Handler(void)
- {
- }
- /**
- * @brief ADC1 的看门狗中断.
- * @param None
- * @retval None
- */
- void ADC_IRQHandler(void)
- {
-
- ADC_ITConfig(ADC1, ADC_IT_AWD, DISABLE);
-
- if(SET == ADC_GetFlagStatus(ADC1, ADC_FLAG_AWD))
- {
- ADC_ClearFlag(ADC1, ADC_FLAG_AWD);
- ADC_ClearITPendingBit(ADC1, ADC_IT_AWD);
-
- GPIO_SetBits(GPIOD, GPIO_Pin_8);
- GPIO_ResetBits(GPIOD, GPIO_Pin_9);
- }
-
- ADC_ITConfig(ADC1, ADC_IT_AWD, ENABLE);
-
- }
- /**
- * @brief This function handles SysTick Handler.
- * @param None
- * @retval None
- */
- void SysTick_Handler(void)
- {
- TIM_GenerateEvent(TIM1, TIM_EventSource_COM);
- }
- /******************************************************************************/
- /* STM32F4xx Peripherals Interrupt Handlers */
- /* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */
- /* available peripheral interrupt handler's name please refer to the startup */
- /* file (startup_stm32f4xx.s). */
- /******************************************************************************/
- /**
- * @brief This function handles TIM1 Trigger and commutation and TIM11
- * global interrupts requests.
- * @param None
- * @retval None
- */
- void TIM1_TRG_COM_TIM11_IRQHandler(void)
- {
- /* Clear TIM1 COM pending bit */
- TIM_ClearITPendingBit(TIM1, TIM_IT_COM);
- if (uwStep == 1)
- {
- /* Next step: Step 2 Configuration -------------------------------------- */
- TIM_CCxCmd(TIM1, TIM_Channel_3, TIM_CCx_Disable);
- TIM_CCxNCmd(TIM1, TIM_Channel_3, TIM_CCxN_Disable);
-
- 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);
- TIM_ForcedOC2Config(TIM1, TIM_ForcedAction_Active);
- TIM_CCxCmd(TIM1, TIM_Channel_2, TIM_CCx_Disable);
- TIM_CCxNCmd(TIM1, TIM_Channel_2, TIM_CCxN_Enable);
-
- uwStep++;
- }
- else if (uwStep == 2)
- {
- /* Next step: Step 3 Configuration -------------------------------------- */
- TIM_ForcedOC2Config(TIM1, TIM_ForcedAction_Active);
- TIM_CCxCmd(TIM1, TIM_Channel_2, TIM_CCx_Disable);
- TIM_CCxNCmd(TIM1, TIM_Channel_2, TIM_CCxN_Enable);
-
- 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);
- TIM_CCxCmd(TIM1, TIM_Channel_1, TIM_CCx_Disable);
- TIM_CCxNCmd(TIM1, TIM_Channel_1, TIM_CCxN_Disable);
-
- uwStep++;
- }
- else if (uwStep == 3)
- {
- /* Next step: Step 4 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);
- TIM_CCxCmd(TIM1, TIM_Channel_2, TIM_CCx_Disable);
- TIM_CCxNCmd(TIM1, TIM_Channel_2, TIM_CCxN_Disable);
- TIM_ForcedOC1Config(TIM1, TIM_ForcedAction_Active);
- TIM_CCxCmd(TIM1, TIM_Channel_1, TIM_CCx_Disable);
- TIM_CCxNCmd(TIM1, TIM_Channel_1, TIM_CCxN_Enable);
-
- uwStep++;
- }
- else if (uwStep == 4)
- {
- /* Next step: Step 5 Configuration -------------------------------------- */
- TIM_CCxCmd(TIM1, TIM_Channel_3, TIM_CCx_Disable);
- TIM_CCxNCmd(TIM1, TIM_Channel_3, TIM_CCxN_Disable);
- TIM_ForcedOC1Config(TIM1, TIM_ForcedAction_Active);
- TIM_CCxCmd(TIM1, TIM_Channel_1, TIM_CCx_Disable);
- TIM_CCxNCmd(TIM1, TIM_Channel_1, TIM_CCxN_Enable);
- 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);
-
- uwStep++;
- }
- else if (uwStep == 5)
- {
- /* Next step: Step 6 Configuration -------------------------------------- */
- TIM_ForcedOC3Config(TIM1, TIM_ForcedAction_Active);
- TIM_CCxCmd(TIM1, TIM_Channel_3, TIM_CCx_Disable);
- TIM_CCxNCmd(TIM1, TIM_Channel_3, TIM_CCxN_Enable);
- TIM_CCxCmd(TIM1, TIM_Channel_1, TIM_CCx_Disable);
- TIM_CCxNCmd(TIM1, TIM_Channel_1, TIM_CCxN_Disable);
-
- 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);
-
- uwStep++;
- }
- else
- {
- /* Next step: Step 1 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);
-
- TIM_ForcedOC3Config(TIM1, TIM_ForcedAction_Active);
- TIM_CCxCmd(TIM1, TIM_Channel_3, TIM_CCx_Disable);
- TIM_CCxNCmd(TIM1, TIM_Channel_3, TIM_CCxN_Enable);
-
- TIM_CCxCmd(TIM1, TIM_Channel_2, TIM_CCx_Disable);
- TIM_CCxNCmd(TIM1, TIM_Channel_2, TIM_CCxN_Disable);
-
- uwStep = 1;
- }
- }
- /**
- * @}
- */
- /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
复制代码
|
评分
查看全部评分
就会出现问题。很无奈,不知道里面是什么构造,是什么原理。
if (SysTick_Config(840000))//(SystemCoreClock) / 200))//190))//166))//165))
感谢:子曰好人,麦克凯
(可以结贴了吗?)