2021-09-13 21:04:42 +08:00
|
|
|
|
/******************************************************************************************************************************************
|
|
|
|
|
* 文件名称: SWM320_pwm.c
|
|
|
|
|
* 功能说明: SWM320单片机的PWM功能驱动库
|
|
|
|
|
* 技术支持: http://www.synwit.com.cn/e/tool/gbook/?bid=1
|
2021-05-06 10:10:29 +08:00
|
|
|
|
* 注意事项:
|
2021-09-13 21:04:42 +08:00
|
|
|
|
* 版本日期: V1.1.0 2017年10月25日
|
|
|
|
|
* 升级记录:
|
2021-02-18 13:29:12 +08:00
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*******************************************************************************************************************************************
|
|
|
|
|
* @attention
|
|
|
|
|
*
|
2021-09-13 21:04:42 +08:00
|
|
|
|
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH CODING INFORMATION
|
|
|
|
|
* REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. AS A RESULT, SYNWIT SHALL NOT BE HELD LIABLE
|
|
|
|
|
* FOR ANY DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT
|
2021-02-18 13:29:12 +08:00
|
|
|
|
* OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION CONTAINED HEREIN IN CONN-
|
|
|
|
|
* -ECTION WITH THEIR PRODUCTS.
|
|
|
|
|
*
|
2021-09-13 21:04:42 +08:00
|
|
|
|
* COPYRIGHT 2012 Synwit Technology
|
2021-02-18 13:29:12 +08:00
|
|
|
|
*******************************************************************************************************************************************/
|
|
|
|
|
#include "SWM320.h"
|
|
|
|
|
#include "SWM320_pwm.h"
|
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
|
2021-09-13 21:04:42 +08:00
|
|
|
|
/******************************************************************************************************************************************
|
|
|
|
|
* 函数名称: PWM_Init()
|
|
|
|
|
* 功能说明: PWM初始化
|
|
|
|
|
* 输 入: PWM_TypeDef * PWMx 指定要被设置的PWM,有效值包括PWM0、PWM1、PWM2、PWM3、PWM4、PWM5
|
|
|
|
|
* PWM_InitStructure * initStruct 包含PWM相关设定值的结构体
|
2021-05-06 10:10:29 +08:00
|
|
|
|
* 输 出: 无
|
|
|
|
|
* 注意事项: 无
|
2021-02-18 13:29:12 +08:00
|
|
|
|
******************************************************************************************************************************************/
|
2022-08-17 00:43:24 +08:00
|
|
|
|
void PWM_Init(PWM_TypeDef * PWMx, PWM_InitStructure * initStruct)
|
2021-02-18 13:29:12 +08:00
|
|
|
|
{
|
2021-05-06 10:42:41 +08:00
|
|
|
|
uint32_t bit_offset = 0;
|
|
|
|
|
|
|
|
|
|
SYS->CLKEN |= (0x01 << SYS_CLKEN_PWM_Pos);
|
|
|
|
|
|
|
|
|
|
SYS->CLKDIV &= ~SYS_CLKDIV_PWM_Msk;
|
|
|
|
|
SYS->CLKDIV |= (initStruct->clk_div << SYS_CLKDIV_PWM_Pos);
|
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
PWM_Stop(PWMx, 1, 1); //一些关键寄存器只能在PWM停止时设置
|
2021-05-06 10:42:41 +08:00
|
|
|
|
|
|
|
|
|
PWMx->MODE = initStruct->mode;
|
|
|
|
|
|
|
|
|
|
PWMx->PERA = initStruct->cycleA;
|
|
|
|
|
PWMx->HIGHA = initStruct->hdutyA;
|
|
|
|
|
PWMx->DZA = initStruct->deadzoneA;
|
|
|
|
|
|
|
|
|
|
PWMx->PERB = initStruct->cycleB;
|
|
|
|
|
PWMx->HIGHB = initStruct->hdutyB;
|
|
|
|
|
PWMx->DZB = initStruct->deadzoneB;
|
|
|
|
|
|
|
|
|
|
PWMx->INIOUT &= ~(PWM_INIOUT_PWMA_Msk | PWM_INIOUT_PWMB_Msk);
|
|
|
|
|
PWMx->INIOUT |= (initStruct->initLevelA << PWM_INIOUT_PWMA_Pos) |
|
|
|
|
|
(initStruct->initLevelB << PWM_INIOUT_PWMB_Pos);
|
|
|
|
|
|
|
|
|
|
PWMG->IM = 0x00000000;
|
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
switch((uint32_t)PWMx)
|
2021-05-06 10:42:41 +08:00
|
|
|
|
{
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM0):
|
2021-05-06 10:42:41 +08:00
|
|
|
|
bit_offset = 0;
|
|
|
|
|
break;
|
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM1):
|
2021-05-06 10:42:41 +08:00
|
|
|
|
bit_offset = 2;
|
|
|
|
|
break;
|
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM2):
|
2021-05-06 10:42:41 +08:00
|
|
|
|
bit_offset = 4;
|
|
|
|
|
break;
|
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM3):
|
2021-05-06 10:42:41 +08:00
|
|
|
|
bit_offset = 6;
|
|
|
|
|
break;
|
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM4):
|
2021-05-06 10:42:41 +08:00
|
|
|
|
bit_offset = 8;
|
|
|
|
|
break;
|
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM5):
|
2021-05-06 10:42:41 +08:00
|
|
|
|
bit_offset = 10;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
PWMG->IRS = ((0x01 << bit_offset) | (0x01 << (bit_offset+1)) | (0x01 << (bit_offset+12)) | (0x01 << (bit_offset+13))); //清除中断标志
|
|
|
|
|
PWMG->IE &= ~((0x01 << bit_offset) | (0x01 << (bit_offset+1)) | (0x01 << (bit_offset+12)) | (0x01 << (bit_offset+13)));
|
|
|
|
|
PWMG->IE |= (initStruct->NCycleAIEn << bit_offset) | (initStruct->NCycleBIEn << (bit_offset+1)) |
|
|
|
|
|
(initStruct->HEndAIEn << (bit_offset+12)) | (initStruct->HEndBIEn << (bit_offset+13));
|
2021-05-06 10:42:41 +08:00
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
if(initStruct->NCycleAIEn | initStruct->NCycleBIEn | initStruct->HEndAIEn | initStruct->HEndBIEn)
|
2021-05-06 10:42:41 +08:00
|
|
|
|
{
|
|
|
|
|
NVIC_EnableIRQ(PWM_IRQn);
|
|
|
|
|
}
|
2022-08-17 00:43:24 +08:00
|
|
|
|
else if((PWMG->IE & (~((0x01 << bit_offset) | (0x01 << (bit_offset+1)) | (0x01 << (bit_offset+12)) | (0x01 << (bit_offset+13))))) == 0)
|
2021-05-06 10:42:41 +08:00
|
|
|
|
{
|
|
|
|
|
NVIC_DisableIRQ(PWM_IRQn);
|
|
|
|
|
}
|
2021-02-18 13:29:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-13 21:04:42 +08:00
|
|
|
|
/******************************************************************************************************************************************
|
|
|
|
|
* 函数名称: PWM_Start()
|
|
|
|
|
* 功能说明: 启动PWM,开始PWM输出
|
|
|
|
|
* 输 入: PWM_TypeDef * PWMx 指定要被设置的PWM,有效值包括PWM0、PWM1、PWM2、PWM3、PWM4、PWM5
|
|
|
|
|
* uint32_t chA 0 通道A不启动 1 通道A启动
|
|
|
|
|
* uint32_t chB 0 通道B不启动 1 通道B启动
|
2021-05-06 10:10:29 +08:00
|
|
|
|
* 输 出: 无
|
|
|
|
|
* 注意事项: 无
|
2021-02-18 13:29:12 +08:00
|
|
|
|
******************************************************************************************************************************************/
|
2022-08-17 00:43:24 +08:00
|
|
|
|
void PWM_Start(PWM_TypeDef * PWMx, uint32_t chA, uint32_t chB)
|
2021-02-18 13:29:12 +08:00
|
|
|
|
{
|
2022-08-17 00:43:24 +08:00
|
|
|
|
switch((uint32_t)PWMx)
|
2021-05-06 10:42:41 +08:00
|
|
|
|
{
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM0):
|
2021-05-06 10:42:41 +08:00
|
|
|
|
PWMG->CHEN |= (chA << PWMG_CHEN_PWM0A_Pos) | (chB << PWMG_CHEN_PWM0B_Pos);
|
|
|
|
|
break;
|
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM1):
|
2021-05-06 10:42:41 +08:00
|
|
|
|
PWMG->CHEN |= (chA << PWMG_CHEN_PWM1A_Pos) | (chB << PWMG_CHEN_PWM1B_Pos);
|
|
|
|
|
break;
|
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM2):
|
2021-05-06 10:42:41 +08:00
|
|
|
|
PWMG->CHEN |= (chA << PWMG_CHEN_PWM2A_Pos) | (chB << PWMG_CHEN_PWM2B_Pos);
|
|
|
|
|
break;
|
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM3):
|
2021-05-06 10:42:41 +08:00
|
|
|
|
PWMG->CHEN |= (chA << PWMG_CHEN_PWM3A_Pos) | (chB << PWMG_CHEN_PWM3B_Pos);
|
|
|
|
|
break;
|
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM4):
|
2021-05-06 10:42:41 +08:00
|
|
|
|
PWMG->CHEN |= (chA << PWMG_CHEN_PWM4A_Pos) | (chB << PWMG_CHEN_PWM4B_Pos);
|
|
|
|
|
break;
|
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM5):
|
2021-05-06 10:42:41 +08:00
|
|
|
|
PWMG->CHEN |= (chA << PWMG_CHEN_PWM5A_Pos) | (chB << PWMG_CHEN_PWM5B_Pos);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2021-02-18 13:29:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-13 21:04:42 +08:00
|
|
|
|
/******************************************************************************************************************************************
|
|
|
|
|
* 函数名称: PWM_Stop()
|
|
|
|
|
* 功能说明: 关闭PWM,停止PWM输出
|
|
|
|
|
* 输 入: PWM_TypeDef * PWMx 指定要被设置的PWM,有效值包括PWM0、PWM1、PWM2、PWM3、PWM4、PWM5
|
|
|
|
|
* uint32_t chA 0 通道A不关闭 1 通道A关闭
|
|
|
|
|
* uint32_t chB 0 通道B不关闭 1 通道B关闭
|
2021-05-06 10:10:29 +08:00
|
|
|
|
* 输 出: 无
|
|
|
|
|
* 注意事项: 无
|
2021-02-18 13:29:12 +08:00
|
|
|
|
******************************************************************************************************************************************/
|
2022-08-17 00:43:24 +08:00
|
|
|
|
void PWM_Stop(PWM_TypeDef * PWMx, uint32_t chA, uint32_t chB)
|
2021-02-18 13:29:12 +08:00
|
|
|
|
{
|
2022-08-17 00:43:24 +08:00
|
|
|
|
switch((uint32_t)PWMx)
|
2021-05-06 10:42:41 +08:00
|
|
|
|
{
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM0):
|
2021-05-06 10:42:41 +08:00
|
|
|
|
PWMG->CHEN &= ~((chA << PWMG_CHEN_PWM0A_Pos) | (chB << PWMG_CHEN_PWM0B_Pos));
|
|
|
|
|
break;
|
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM1):
|
2021-05-06 10:42:41 +08:00
|
|
|
|
PWMG->CHEN &= ~((chA << PWMG_CHEN_PWM1A_Pos) | (chB << PWMG_CHEN_PWM1B_Pos));
|
|
|
|
|
break;
|
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM2):
|
2021-05-06 10:42:41 +08:00
|
|
|
|
PWMG->CHEN &= ~((chA << PWMG_CHEN_PWM2A_Pos) | (chB << PWMG_CHEN_PWM2B_Pos));
|
|
|
|
|
break;
|
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM3):
|
2021-05-06 10:42:41 +08:00
|
|
|
|
PWMG->CHEN &= ~((chA << PWMG_CHEN_PWM3A_Pos) | (chB << PWMG_CHEN_PWM3B_Pos));
|
|
|
|
|
break;
|
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM4):
|
2021-05-06 10:42:41 +08:00
|
|
|
|
PWMG->CHEN &= ~((chA << PWMG_CHEN_PWM4A_Pos) | (chB << PWMG_CHEN_PWM4B_Pos));
|
|
|
|
|
break;
|
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM5):
|
2021-05-06 10:42:41 +08:00
|
|
|
|
PWMG->CHEN &= ~((chA << PWMG_CHEN_PWM5A_Pos) | (chB << PWMG_CHEN_PWM5B_Pos));
|
|
|
|
|
break;
|
|
|
|
|
}
|
2021-02-18 13:29:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-13 21:04:42 +08:00
|
|
|
|
/******************************************************************************************************************************************
|
|
|
|
|
* 函数名称: PWM_SetCycle()
|
|
|
|
|
* 功能说明: 设置周期
|
|
|
|
|
* 输 入: PWM_TypeDef * PWMx 指定要被设置的PWM,有效值包括PWM0、PWM1、PWM2、PWM3、PWM4、PWM5
|
|
|
|
|
* uint32_t chn 选择要设置哪个通道,有效值:PWM_CH_A、PWM_CH_B
|
|
|
|
|
* uint16_t cycle 要设定的周期值
|
2021-05-06 10:10:29 +08:00
|
|
|
|
* 输 出: 无
|
|
|
|
|
* 注意事项: 无
|
2021-02-18 13:29:12 +08:00
|
|
|
|
******************************************************************************************************************************************/
|
2022-08-17 00:43:24 +08:00
|
|
|
|
void PWM_SetCycle(PWM_TypeDef * PWMx, uint32_t chn, uint16_t cycle)
|
2021-02-18 13:29:12 +08:00
|
|
|
|
{
|
2022-08-17 00:43:24 +08:00
|
|
|
|
if(chn == PWM_CH_A)
|
2021-05-06 10:42:41 +08:00
|
|
|
|
PWMx->PERA = cycle;
|
2022-08-17 00:43:24 +08:00
|
|
|
|
else if(chn == PWM_CH_B)
|
2021-05-06 10:42:41 +08:00
|
|
|
|
PWMx->PERB = cycle;
|
2021-02-18 13:29:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-13 21:04:42 +08:00
|
|
|
|
/******************************************************************************************************************************************
|
|
|
|
|
* 函数名称: PWM_GetCycle()
|
|
|
|
|
* 功能说明: 获取周期
|
|
|
|
|
* 输 入: PWM_TypeDef * PWMx 指定要被设置的PWM,有效值包括PWM0、PWM1、PWM2、PWM3、PWM4、PWM5
|
|
|
|
|
* uint32_t chn 选择要查询哪个通道,有效值:PWM_CH_A、PWM_CH_B
|
|
|
|
|
* 输 出: uint16_t 获取到的周期值
|
2021-05-06 10:10:29 +08:00
|
|
|
|
* 注意事项: 无
|
2021-02-18 13:29:12 +08:00
|
|
|
|
******************************************************************************************************************************************/
|
2022-08-17 00:43:24 +08:00
|
|
|
|
uint16_t PWM_GetCycle(PWM_TypeDef * PWMx, uint32_t chn)
|
2021-02-18 13:29:12 +08:00
|
|
|
|
{
|
2021-05-06 10:42:41 +08:00
|
|
|
|
uint16_t cycle = 0;
|
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
if(chn == PWM_CH_A)
|
2021-05-06 10:42:41 +08:00
|
|
|
|
cycle = PWMx->PERA;
|
2022-08-17 00:43:24 +08:00
|
|
|
|
else if(chn == PWM_CH_B)
|
2021-05-06 10:42:41 +08:00
|
|
|
|
cycle = PWMx->PERB;
|
|
|
|
|
|
|
|
|
|
return cycle;
|
2021-02-18 13:29:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-13 21:04:42 +08:00
|
|
|
|
/******************************************************************************************************************************************
|
|
|
|
|
* 函数名称: PWM_SetHDuty()
|
|
|
|
|
* 功能说明: 设置高电平时长
|
|
|
|
|
* 输 入: PWM_TypeDef * PWMx 指定要被设置的PWM,有效值包括PWM0、PWM1、PWM2、PWM3、PWM4、PWM5
|
|
|
|
|
* uint32_t chn 选择要设置哪个通道,有效值:PWM_CH_A、PWM_CH_B
|
|
|
|
|
* uint16_t hduty 要设定的高电平时长
|
2021-05-06 10:10:29 +08:00
|
|
|
|
* 输 出: 无
|
|
|
|
|
* 注意事项: 无
|
2021-02-18 13:29:12 +08:00
|
|
|
|
******************************************************************************************************************************************/
|
2022-08-17 00:43:24 +08:00
|
|
|
|
void PWM_SetHDuty(PWM_TypeDef * PWMx, uint32_t chn, uint16_t hduty)
|
2021-02-18 13:29:12 +08:00
|
|
|
|
{
|
2022-08-17 00:43:24 +08:00
|
|
|
|
if(chn == PWM_CH_A)
|
2021-05-06 10:42:41 +08:00
|
|
|
|
PWMx->HIGHA = hduty;
|
2022-08-17 00:43:24 +08:00
|
|
|
|
else if(chn == PWM_CH_B)
|
2021-05-06 10:42:41 +08:00
|
|
|
|
PWMx->HIGHB = hduty;
|
2021-02-18 13:29:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-13 21:04:42 +08:00
|
|
|
|
/******************************************************************************************************************************************
|
|
|
|
|
* 函数名称: PWM_GetHDuty()
|
2021-05-06 10:10:29 +08:00
|
|
|
|
* 功能说明: 获取高电平时长
|
2021-09-13 21:04:42 +08:00
|
|
|
|
* 输 入: PWM_TypeDef * PWMx 指定要被设置的PWM,有效值包括PWM0、PWM1、PWM2、PWM3、PWM4、PWM5
|
|
|
|
|
* uint32_t chn 选择要查询哪个通道,有效值:PWM_CH_A、PWM_CH_B
|
|
|
|
|
* 输 出: uint16_t 获取到的高电平时长
|
2021-05-06 10:10:29 +08:00
|
|
|
|
* 注意事项: 无
|
2021-02-18 13:29:12 +08:00
|
|
|
|
******************************************************************************************************************************************/
|
2022-08-17 00:43:24 +08:00
|
|
|
|
uint16_t PWM_GetHDuty(PWM_TypeDef * PWMx, uint32_t chn)
|
2021-02-18 13:29:12 +08:00
|
|
|
|
{
|
2021-05-06 10:42:41 +08:00
|
|
|
|
uint16_t hduty = 0;
|
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
if(chn == PWM_CH_A)
|
2021-05-06 10:42:41 +08:00
|
|
|
|
hduty = PWMx->HIGHA;
|
2022-08-17 00:43:24 +08:00
|
|
|
|
else if(chn == PWM_CH_B)
|
2021-05-06 10:42:41 +08:00
|
|
|
|
hduty = PWMx->HIGHB;
|
|
|
|
|
|
|
|
|
|
return hduty;
|
2021-02-18 13:29:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-13 21:04:42 +08:00
|
|
|
|
/******************************************************************************************************************************************
|
|
|
|
|
* 函数名称: PWM_SetDeadzone()
|
|
|
|
|
* 功能说明: 设置死区时长
|
|
|
|
|
* 输 入: PWM_TypeDef * PWMx 指定要被设置的PWM,有效值包括PWM0、PWM1、PWM2、PWM3、PWM4、PWM5
|
|
|
|
|
* uint32_t chn 选择要设置哪个通道,有效值:PWM_CH_A、PWM_CH_B
|
|
|
|
|
* uint8_t deadzone 要设定的死区时长
|
2021-05-06 10:10:29 +08:00
|
|
|
|
* 输 出: 无
|
|
|
|
|
* 注意事项: 无
|
2021-02-18 13:29:12 +08:00
|
|
|
|
******************************************************************************************************************************************/
|
2022-08-17 00:43:24 +08:00
|
|
|
|
void PWM_SetDeadzone(PWM_TypeDef * PWMx, uint32_t chn, uint8_t deadzone)
|
2021-02-18 13:29:12 +08:00
|
|
|
|
{
|
2022-08-17 00:43:24 +08:00
|
|
|
|
if(chn == PWM_CH_A)
|
2021-05-06 10:42:41 +08:00
|
|
|
|
PWMx->DZA = deadzone;
|
2022-08-17 00:43:24 +08:00
|
|
|
|
else if(chn == PWM_CH_B)
|
2021-05-06 10:42:41 +08:00
|
|
|
|
PWMx->DZB = deadzone;
|
2021-02-18 13:29:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-13 21:04:42 +08:00
|
|
|
|
/******************************************************************************************************************************************
|
|
|
|
|
* 函数名称: PWM_GetDeadzone()
|
2021-05-06 10:10:29 +08:00
|
|
|
|
* 功能说明: 获取死区时长
|
2021-09-13 21:04:42 +08:00
|
|
|
|
* 输 入: PWM_TypeDef * PWMx 指定要被设置的PWM,有效值包括PWM0、PWM1、PWM2、PWM3、PWM4、PWM5
|
|
|
|
|
* uint32_t chn 选择要查询哪个通道,有效值:PWM_CH_A、PWM_CH_B
|
|
|
|
|
* 输 出: uint8_t 获取到的死区时长
|
2021-05-06 10:10:29 +08:00
|
|
|
|
* 注意事项: 无
|
2021-02-18 13:29:12 +08:00
|
|
|
|
******************************************************************************************************************************************/
|
2022-08-17 00:43:24 +08:00
|
|
|
|
uint8_t PWM_GetDeadzone(PWM_TypeDef * PWMx, uint32_t chn)
|
2021-02-18 13:29:12 +08:00
|
|
|
|
{
|
2021-05-06 10:42:41 +08:00
|
|
|
|
uint8_t deadzone = 0;
|
2021-02-18 13:29:12 +08:00
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
if(chn == PWM_CH_A)
|
2021-05-06 10:42:41 +08:00
|
|
|
|
deadzone = PWMx->DZA;
|
2022-08-17 00:43:24 +08:00
|
|
|
|
else if(chn == PWM_CH_B)
|
2021-05-06 10:42:41 +08:00
|
|
|
|
deadzone = PWMx->DZB;
|
|
|
|
|
|
|
|
|
|
return deadzone;
|
|
|
|
|
}
|
2021-02-18 13:29:12 +08:00
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
|
2021-09-13 21:04:42 +08:00
|
|
|
|
/******************************************************************************************************************************************
|
|
|
|
|
* 函数名称: PWM_IntNCycleEn()
|
2021-05-06 10:10:29 +08:00
|
|
|
|
* 功能说明: 新周期开始中断使能
|
2021-09-13 21:04:42 +08:00
|
|
|
|
* 输 入: PWM_TypeDef * PWMx 指定要被设置的PWM,有效值包括PWM0、PWM1、PWM2、PWM3、PWM4、PWM5
|
|
|
|
|
* uint32_t chn 选择要设置哪个通道,有效值:PWM_CH_A、PWM_CH_B
|
2021-05-06 10:10:29 +08:00
|
|
|
|
* 输 出: 无
|
|
|
|
|
* 注意事项: 无
|
2021-02-18 13:29:12 +08:00
|
|
|
|
******************************************************************************************************************************************/
|
2022-08-17 00:43:24 +08:00
|
|
|
|
void PWM_IntNCycleEn(PWM_TypeDef * PWMx, uint32_t chn)
|
2021-02-18 13:29:12 +08:00
|
|
|
|
{
|
2022-08-17 00:43:24 +08:00
|
|
|
|
switch((uint32_t)PWMx)
|
2021-05-06 10:42:41 +08:00
|
|
|
|
{
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM0):
|
|
|
|
|
if(chn == PWM_CH_A) PWMG->IE |= (0x01 << PWMG_IE_NEWP0A_Pos);
|
|
|
|
|
else PWMG->IE |= (0x01 << PWMG_IE_NEWP0B_Pos);
|
2021-05-06 10:42:41 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM1):
|
|
|
|
|
if(chn == PWM_CH_A) PWMG->IE |= (0x01 << PWMG_IE_NEWP1A_Pos);
|
|
|
|
|
else PWMG->IE |= (0x01 << PWMG_IE_NEWP1B_Pos);
|
2021-05-06 10:42:41 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM2):
|
|
|
|
|
if(chn == PWM_CH_A) PWMG->IE |= (0x01 << PWMG_IE_NEWP2A_Pos);
|
|
|
|
|
else PWMG->IE |= (0x01 << PWMG_IE_NEWP2B_Pos);
|
2021-05-06 10:42:41 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM3):
|
|
|
|
|
if(chn == PWM_CH_A) PWMG->IE |= (0x01 << PWMG_IE_NEWP3A_Pos);
|
|
|
|
|
else PWMG->IE |= (0x01 << PWMG_IE_NEWP3B_Pos);
|
2021-05-06 10:42:41 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM4):
|
|
|
|
|
if(chn == PWM_CH_A) PWMG->IE |= (0x01 << PWMG_IE_NEWP4A_Pos);
|
|
|
|
|
else PWMG->IE |= (0x01 << PWMG_IE_NEWP4B_Pos);
|
2021-05-06 10:42:41 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM5):
|
|
|
|
|
if(chn == PWM_CH_A) PWMG->IE |= (0x01 << PWMG_IE_NEWP5A_Pos);
|
|
|
|
|
else PWMG->IE |= (0x01 << PWMG_IE_NEWP5B_Pos);
|
2021-05-06 10:42:41 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
2021-02-18 13:29:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-13 21:04:42 +08:00
|
|
|
|
/******************************************************************************************************************************************
|
|
|
|
|
* 函数名称: PWM_IntNCycleDis()
|
2021-05-06 10:10:29 +08:00
|
|
|
|
* 功能说明: 新周期开始中断禁能
|
2021-09-13 21:04:42 +08:00
|
|
|
|
* 输 入: PWM_TypeDef * PWMx 指定要被设置的PWM,有效值包括PWM0、PWM1、PWM2、PWM3、PWM4、PWM5
|
|
|
|
|
* uint32_t chn 选择要设置哪个通道,有效值:PWM_CH_A、PWM_CH_B
|
2021-05-06 10:10:29 +08:00
|
|
|
|
* 输 出: 无
|
|
|
|
|
* 注意事项: 无
|
2021-02-18 13:29:12 +08:00
|
|
|
|
******************************************************************************************************************************************/
|
2022-08-17 00:43:24 +08:00
|
|
|
|
void PWM_IntNCycleDis(PWM_TypeDef * PWMx, uint32_t chn)
|
2021-02-18 13:29:12 +08:00
|
|
|
|
{
|
2022-08-17 00:43:24 +08:00
|
|
|
|
switch((uint32_t)PWMx)
|
2021-05-06 10:42:41 +08:00
|
|
|
|
{
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM0):
|
|
|
|
|
if(chn == PWM_CH_A) PWMG->IE &= ~(0x01 << PWMG_IE_NEWP0A_Pos);
|
|
|
|
|
else PWMG->IE &= ~(0x01 << PWMG_IE_NEWP0B_Pos);
|
2021-05-06 10:42:41 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM1):
|
|
|
|
|
if(chn == PWM_CH_A) PWMG->IE &= ~(0x01 << PWMG_IE_NEWP1A_Pos);
|
|
|
|
|
else PWMG->IE &= ~(0x01 << PWMG_IE_NEWP1B_Pos);
|
2021-05-06 10:42:41 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM2):
|
|
|
|
|
if(chn == PWM_CH_A) PWMG->IE &= ~(0x01 << PWMG_IE_NEWP2A_Pos);
|
|
|
|
|
else PWMG->IE &= ~(0x01 << PWMG_IE_NEWP2B_Pos);
|
2021-05-06 10:42:41 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM3):
|
|
|
|
|
if(chn == PWM_CH_A) PWMG->IE &= ~(0x01 << PWMG_IE_NEWP3A_Pos);
|
|
|
|
|
else PWMG->IE &= ~(0x01 << PWMG_IE_NEWP3B_Pos);
|
2021-05-06 10:42:41 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM4):
|
|
|
|
|
if(chn == PWM_CH_A) PWMG->IE &= ~(0x01 << PWMG_IE_NEWP4A_Pos);
|
|
|
|
|
else PWMG->IE &= ~(0x01 << PWMG_IE_NEWP4B_Pos);
|
2021-05-06 10:42:41 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM5):
|
|
|
|
|
if(chn == PWM_CH_A) PWMG->IE &= ~(0x01 << PWMG_IE_NEWP5A_Pos);
|
|
|
|
|
else PWMG->IE &= ~(0x01 << PWMG_IE_NEWP5B_Pos);
|
2021-05-06 10:42:41 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
2021-02-18 13:29:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-13 21:04:42 +08:00
|
|
|
|
/******************************************************************************************************************************************
|
|
|
|
|
* 函数名称: PWM_IntNCycleClr()
|
2021-05-06 10:10:29 +08:00
|
|
|
|
* 功能说明: 新周期开始中断标志清除
|
2021-09-13 21:04:42 +08:00
|
|
|
|
* 输 入: PWM_TypeDef * PWMx 指定要被设置的PWM,有效值包括PWM0、PWM1、PWM2、PWM3、PWM4、PWM5
|
|
|
|
|
* uint32_t chn 选择要设置哪个通道,有效值:PWM_CH_A、PWM_CH_B
|
2021-05-06 10:10:29 +08:00
|
|
|
|
* 输 出: 无
|
|
|
|
|
* 注意事项: 无
|
2021-02-18 13:29:12 +08:00
|
|
|
|
******************************************************************************************************************************************/
|
2022-08-17 00:43:24 +08:00
|
|
|
|
void PWM_IntNCycleClr(PWM_TypeDef * PWMx, uint32_t chn)
|
2021-02-18 13:29:12 +08:00
|
|
|
|
{
|
2022-08-17 00:43:24 +08:00
|
|
|
|
switch((uint32_t)PWMx)
|
2021-05-06 10:42:41 +08:00
|
|
|
|
{
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM0):
|
|
|
|
|
if(chn == PWM_CH_A) PWMG->IRS = (0x01 << PWMG_IRS_NEWP0A_Pos);
|
|
|
|
|
else PWMG->IRS = (0x01 << PWMG_IRS_NEWP0B_Pos);
|
2021-05-06 10:42:41 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM1):
|
|
|
|
|
if(chn == PWM_CH_A) PWMG->IRS = (0x01 << PWMG_IRS_NEWP1A_Pos);
|
|
|
|
|
else PWMG->IRS = (0x01 << PWMG_IRS_NEWP1B_Pos);
|
2021-05-06 10:42:41 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM2):
|
|
|
|
|
if(chn == PWM_CH_A) PWMG->IRS = (0x01 << PWMG_IRS_NEWP2A_Pos);
|
|
|
|
|
else PWMG->IRS = (0x01 << PWMG_IRS_NEWP2B_Pos);
|
2021-05-06 10:42:41 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM3):
|
|
|
|
|
if(chn == PWM_CH_A) PWMG->IRS = (0x01 << PWMG_IRS_NEWP3A_Pos);
|
|
|
|
|
else PWMG->IRS = (0x01 << PWMG_IRS_NEWP3B_Pos);
|
2021-05-06 10:42:41 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM4):
|
|
|
|
|
if(chn == PWM_CH_A) PWMG->IRS = (0x01 << PWMG_IRS_NEWP4A_Pos);
|
|
|
|
|
else PWMG->IRS = (0x01 << PWMG_IRS_NEWP4B_Pos);
|
2021-05-06 10:42:41 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM5):
|
|
|
|
|
if(chn == PWM_CH_A) PWMG->IRS = (0x01 << PWMG_IRS_NEWP5A_Pos);
|
|
|
|
|
else PWMG->IRS = (0x01 << PWMG_IRS_NEWP5B_Pos);
|
2021-05-06 10:42:41 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
2021-02-18 13:29:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-13 21:04:42 +08:00
|
|
|
|
/******************************************************************************************************************************************
|
|
|
|
|
* 函数名称: PWM_IntNCycleStat()
|
2021-05-06 10:10:29 +08:00
|
|
|
|
* 功能说明: 新周期开始中断是否发生
|
2021-09-13 21:04:42 +08:00
|
|
|
|
* 输 入: PWM_TypeDef * PWMx 指定要被设置的PWM,有效值包括PWM0、PWM1、PWM2、PWM3、PWM4、PWM5
|
|
|
|
|
* uint32_t chn 选择要设置哪个通道,有效值:PWM_CH_A、PWM_CH_B
|
|
|
|
|
* 输 出: uint32_t 1 新周期开始中断已发生 0 新周期开始中断未发生
|
2021-05-06 10:10:29 +08:00
|
|
|
|
* 注意事项: 无
|
2021-02-18 13:29:12 +08:00
|
|
|
|
******************************************************************************************************************************************/
|
2022-08-17 00:43:24 +08:00
|
|
|
|
uint32_t PWM_IntNCycleStat(PWM_TypeDef * PWMx, uint32_t chn)
|
2021-02-18 13:29:12 +08:00
|
|
|
|
{
|
2021-05-06 10:42:41 +08:00
|
|
|
|
uint32_t int_stat = 0;
|
2021-02-18 13:29:12 +08:00
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
switch((uint32_t)PWMx)
|
2021-05-06 10:42:41 +08:00
|
|
|
|
{
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM0):
|
|
|
|
|
if(chn == PWM_CH_A) int_stat = (PWMG->IF & PWMG_IF_NEWP0A_Msk);
|
|
|
|
|
else int_stat = (PWMG->IF & PWMG_IF_NEWP0B_Msk);
|
2021-05-06 10:42:41 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM1):
|
|
|
|
|
if(chn == PWM_CH_A) int_stat = (PWMG->IF & PWMG_IF_NEWP1A_Msk);
|
|
|
|
|
else int_stat = (PWMG->IF & PWMG_IF_NEWP1B_Msk);
|
2021-05-06 10:42:41 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM2):
|
|
|
|
|
if(chn == PWM_CH_A) int_stat = (PWMG->IF & PWMG_IF_NEWP2A_Msk);
|
|
|
|
|
else int_stat = (PWMG->IF & PWMG_IF_NEWP2B_Msk);
|
2021-05-06 10:42:41 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM3):
|
|
|
|
|
if(chn == PWM_CH_A) int_stat = (PWMG->IF & PWMG_IF_NEWP3A_Msk);
|
|
|
|
|
else int_stat = (PWMG->IF & PWMG_IF_NEWP3B_Msk);
|
2021-05-06 10:42:41 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM4):
|
|
|
|
|
if(chn == PWM_CH_A) int_stat = (PWMG->IF & PWMG_IF_NEWP4A_Msk);
|
|
|
|
|
else int_stat = (PWMG->IF & PWMG_IF_NEWP4B_Msk);
|
2021-05-06 10:42:41 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM5):
|
|
|
|
|
if(chn == PWM_CH_A) int_stat = (PWMG->IF & PWMG_IF_NEWP5A_Msk);
|
|
|
|
|
else int_stat = (PWMG->IF & PWMG_IF_NEWP5B_Msk);
|
2021-05-06 10:42:41 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return int_stat;
|
|
|
|
|
}
|
2021-02-18 13:29:12 +08:00
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
|
2021-09-13 21:04:42 +08:00
|
|
|
|
/******************************************************************************************************************************************
|
|
|
|
|
* 函数名称: PWM_IntHEndEn()
|
2021-05-06 10:10:29 +08:00
|
|
|
|
* 功能说明: 高电平结束中断使能
|
2021-09-13 21:04:42 +08:00
|
|
|
|
* 输 入: PWM_TypeDef * PWMx 指定要被设置的PWM,有效值包括PWM0、PWM1、PWM2、PWM3、PWM4、PWM5
|
|
|
|
|
* uint32_t chn 选择要设置哪个通道,有效值:PWM_CH_A、PWM_CH_B
|
2021-05-06 10:10:29 +08:00
|
|
|
|
* 输 出: 无
|
|
|
|
|
* 注意事项: 无
|
2021-02-18 13:29:12 +08:00
|
|
|
|
******************************************************************************************************************************************/
|
2022-08-17 00:43:24 +08:00
|
|
|
|
void PWM_IntHEndEn(PWM_TypeDef * PWMx, uint32_t chn)
|
2021-02-18 13:29:12 +08:00
|
|
|
|
{
|
2022-08-17 00:43:24 +08:00
|
|
|
|
switch((uint32_t)PWMx)
|
2021-05-06 10:42:41 +08:00
|
|
|
|
{
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM0):
|
|
|
|
|
if(chn == PWM_CH_A) PWMG->IE |= (0x01 << PWMG_IE_HEND0A_Pos);
|
|
|
|
|
else PWMG->IE |= (0x01 << PWMG_IE_HEND0B_Pos);
|
2021-05-06 10:42:41 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM1):
|
|
|
|
|
if(chn == PWM_CH_A) PWMG->IE |= (0x01 << PWMG_IE_HEND1A_Pos);
|
|
|
|
|
else PWMG->IE |= (0x01 << PWMG_IE_HEND1B_Pos);
|
2021-05-06 10:42:41 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM2):
|
|
|
|
|
if(chn == PWM_CH_A) PWMG->IE |= (0x01 << PWMG_IE_HEND2A_Pos);
|
|
|
|
|
else PWMG->IE |= (0x01 << PWMG_IE_HEND2B_Pos);
|
2021-05-06 10:42:41 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM3):
|
|
|
|
|
if(chn == PWM_CH_A) PWMG->IE |= (0x01 << PWMG_IE_HEND3A_Pos);
|
|
|
|
|
else PWMG->IE |= (0x01 << PWMG_IE_HEND3B_Pos);
|
2021-05-06 10:42:41 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM4):
|
|
|
|
|
if(chn == PWM_CH_A) PWMG->IE |= (0x01 << PWMG_IE_HEND4A_Pos);
|
|
|
|
|
else PWMG->IE |= (0x01 << PWMG_IE_HEND4B_Pos);
|
2021-05-06 10:42:41 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM5):
|
|
|
|
|
if(chn == PWM_CH_A) PWMG->IE |= (0x01 << PWMG_IE_HEND5A_Pos);
|
|
|
|
|
else PWMG->IE |= (0x01 << PWMG_IE_HEND5B_Pos);
|
2021-05-06 10:42:41 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
2021-02-18 13:29:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-13 21:04:42 +08:00
|
|
|
|
/******************************************************************************************************************************************
|
|
|
|
|
* 函数名称: PWM_IntHEndDis()
|
2021-05-06 10:10:29 +08:00
|
|
|
|
* 功能说明: 高电平结束中断禁能
|
2021-09-13 21:04:42 +08:00
|
|
|
|
* 输 入: PWM_TypeDef * PWMx 指定要被设置的PWM,有效值包括PWM0、PWM1、PWM2、PWM3、PWM4、PWM5
|
|
|
|
|
* uint32_t chn 选择要设置哪个通道,有效值:PWM_CH_A、PWM_CH_B
|
2021-05-06 10:10:29 +08:00
|
|
|
|
* 输 出: 无
|
|
|
|
|
* 注意事项: 无
|
2021-02-18 13:29:12 +08:00
|
|
|
|
******************************************************************************************************************************************/
|
2022-08-17 00:43:24 +08:00
|
|
|
|
void PWM_IntHEndDis(PWM_TypeDef * PWMx, uint32_t chn)
|
2021-02-18 13:29:12 +08:00
|
|
|
|
{
|
2022-08-17 00:43:24 +08:00
|
|
|
|
switch((uint32_t)PWMx)
|
2021-05-06 10:42:41 +08:00
|
|
|
|
{
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM0):
|
|
|
|
|
if(chn == PWM_CH_A) PWMG->IE &= ~(0x01 << PWMG_IE_HEND0A_Pos);
|
|
|
|
|
else PWMG->IE &= ~(0x01 << PWMG_IE_HEND0B_Pos);
|
2021-05-06 10:42:41 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM1):
|
|
|
|
|
if(chn == PWM_CH_A) PWMG->IE &= ~(0x01 << PWMG_IE_HEND1A_Pos);
|
|
|
|
|
else PWMG->IE &= ~(0x01 << PWMG_IE_HEND1B_Pos);
|
2021-05-06 10:42:41 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM2):
|
|
|
|
|
if(chn == PWM_CH_A) PWMG->IE &= ~(0x01 << PWMG_IE_HEND2A_Pos);
|
|
|
|
|
else PWMG->IE &= ~(0x01 << PWMG_IE_HEND2B_Pos);
|
2021-05-06 10:42:41 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM3):
|
|
|
|
|
if(chn == PWM_CH_A) PWMG->IE &= ~(0x01 << PWMG_IE_HEND3A_Pos);
|
|
|
|
|
else PWMG->IE &= ~(0x01 << PWMG_IE_HEND3B_Pos);
|
2021-05-06 10:42:41 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM4):
|
|
|
|
|
if(chn == PWM_CH_A) PWMG->IE &= ~(0x01 << PWMG_IE_HEND4A_Pos);
|
|
|
|
|
else PWMG->IE &= ~(0x01 << PWMG_IE_HEND4B_Pos);
|
2021-05-06 10:42:41 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM5):
|
|
|
|
|
if(chn == PWM_CH_A) PWMG->IE &= ~(0x01 << PWMG_IE_HEND5A_Pos);
|
|
|
|
|
else PWMG->IE &= ~(0x01 << PWMG_IE_HEND5B_Pos);
|
2021-05-06 10:42:41 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
2021-02-18 13:29:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-13 21:04:42 +08:00
|
|
|
|
/******************************************************************************************************************************************
|
|
|
|
|
* 函数名称: PWM_IntHEndClr()
|
2021-05-06 10:10:29 +08:00
|
|
|
|
* 功能说明: 高电平结束中断标志清除
|
2021-09-13 21:04:42 +08:00
|
|
|
|
* 输 入: PWM_TypeDef * PWMx 指定要被设置的PWM,有效值包括PWM0、PWM1、PWM2、PWM3、PWM4、PWM5
|
|
|
|
|
* uint32_t chn 选择要设置哪个通道,有效值:PWM_CH_A、PWM_CH_B
|
2021-05-06 10:10:29 +08:00
|
|
|
|
* 输 出: 无
|
|
|
|
|
* 注意事项: 无
|
2021-02-18 13:29:12 +08:00
|
|
|
|
******************************************************************************************************************************************/
|
2022-08-17 00:43:24 +08:00
|
|
|
|
void PWM_IntHEndClr(PWM_TypeDef * PWMx, uint32_t chn)
|
2021-02-18 13:29:12 +08:00
|
|
|
|
{
|
2022-08-17 00:43:24 +08:00
|
|
|
|
switch((uint32_t)PWMx)
|
2021-05-06 10:42:41 +08:00
|
|
|
|
{
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM0):
|
|
|
|
|
if(chn == PWM_CH_A) PWMG->IRS = (0x01 << PWMG_IRS_HEND0A_Pos);
|
|
|
|
|
else PWMG->IRS = (0x01 << PWMG_IRS_HEND0B_Pos);
|
2021-05-06 10:42:41 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM1):
|
|
|
|
|
if(chn == PWM_CH_A) PWMG->IRS = (0x01 << PWMG_IRS_HEND1A_Pos);
|
|
|
|
|
else PWMG->IRS = (0x01 << PWMG_IRS_HEND1B_Pos);
|
2021-05-06 10:42:41 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM2):
|
|
|
|
|
if(chn == PWM_CH_A) PWMG->IRS = (0x01 << PWMG_IRS_HEND2A_Pos);
|
|
|
|
|
else PWMG->IRS = (0x01 << PWMG_IRS_HEND2B_Pos);
|
2021-05-06 10:42:41 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM3):
|
|
|
|
|
if(chn == PWM_CH_A) PWMG->IRS = (0x01 << PWMG_IRS_HEND3A_Pos);
|
|
|
|
|
else PWMG->IRS = (0x01 << PWMG_IRS_HEND3B_Pos);
|
2021-05-06 10:42:41 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM4):
|
|
|
|
|
if(chn == PWM_CH_A) PWMG->IRS = (0x01 << PWMG_IRS_HEND4A_Pos);
|
|
|
|
|
else PWMG->IRS = (0x01 << PWMG_IRS_HEND4B_Pos);
|
2021-05-06 10:42:41 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM5):
|
|
|
|
|
if(chn == PWM_CH_A) PWMG->IRS = (0x01 << PWMG_IRS_HEND5A_Pos);
|
|
|
|
|
else PWMG->IRS = (0x01 << PWMG_IRS_HEND5B_Pos);
|
2021-05-06 10:42:41 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
2021-02-18 13:29:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-13 21:04:42 +08:00
|
|
|
|
/******************************************************************************************************************************************
|
|
|
|
|
* 函数名称: PWM_IntHEndStat()
|
2021-05-06 10:10:29 +08:00
|
|
|
|
* 功能说明: 高电平结束中断是否发生
|
2021-09-13 21:04:42 +08:00
|
|
|
|
* 输 入: PWM_TypeDef * PWMx 指定要被设置的PWM,有效值包括PWM0、PWM1、PWM2、PWM3、PWM4、PWM5
|
|
|
|
|
* uint32_t chn 选择要设置哪个通道,有效值:PWM_CH_A、PWM_CH_B
|
|
|
|
|
* 输 出: uint32_t 1 高电平结束中断已发生 0 高电平结束中断未发生
|
2021-05-06 10:10:29 +08:00
|
|
|
|
* 注意事项: 无
|
2021-02-18 13:29:12 +08:00
|
|
|
|
******************************************************************************************************************************************/
|
2022-08-17 00:43:24 +08:00
|
|
|
|
uint32_t PWM_IntHEndStat(PWM_TypeDef * PWMx, uint32_t chn)
|
2021-02-18 13:29:12 +08:00
|
|
|
|
{
|
2021-05-06 10:42:41 +08:00
|
|
|
|
uint32_t int_stat = 0;
|
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
switch((uint32_t)PWMx)
|
2021-05-06 10:42:41 +08:00
|
|
|
|
{
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM0):
|
|
|
|
|
if(chn == PWM_CH_A) int_stat = (PWMG->IF & PWMG_IF_HEND0A_Msk);
|
|
|
|
|
else int_stat = (PWMG->IF & PWMG_IF_HEND0B_Msk);
|
2021-05-06 10:42:41 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM1):
|
|
|
|
|
if(chn == PWM_CH_A) int_stat = (PWMG->IF & PWMG_IF_HEND1A_Msk);
|
|
|
|
|
else int_stat = (PWMG->IF & PWMG_IF_HEND1B_Msk);
|
2021-05-06 10:42:41 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM2):
|
|
|
|
|
if(chn == PWM_CH_A) int_stat = (PWMG->IF & PWMG_IF_HEND2A_Msk);
|
|
|
|
|
else int_stat = (PWMG->IF & PWMG_IF_HEND2B_Msk);
|
2021-05-06 10:42:41 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM3):
|
|
|
|
|
if(chn == PWM_CH_A) int_stat = (PWMG->IF & PWMG_IF_HEND3A_Msk);
|
|
|
|
|
else int_stat = (PWMG->IF & PWMG_IF_HEND3B_Msk);
|
2021-05-06 10:42:41 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM4):
|
|
|
|
|
if(chn == PWM_CH_A) int_stat = (PWMG->IF & PWMG_IF_HEND4A_Msk);
|
|
|
|
|
else int_stat = (PWMG->IF & PWMG_IF_HEND4B_Msk);
|
2021-05-06 10:42:41 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2022-08-17 00:43:24 +08:00
|
|
|
|
case((uint32_t)PWM5):
|
|
|
|
|
if(chn == PWM_CH_A) int_stat = (PWMG->IF & PWMG_IF_HEND5A_Msk);
|
|
|
|
|
else int_stat = (PWMG->IF & PWMG_IF_HEND5B_Msk);
|
2021-05-06 10:42:41 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return int_stat;
|
2021-02-18 13:29:12 +08:00
|
|
|
|
}
|