2022-10-19 22:44:15 +08:00

652 lines
23 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/******************************************************************************************************************************************
* <20>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>: SWM320_pwm.c
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: SWM320<32><30>Ƭ<EFBFBD><C6AC><EFBFBD><EFBFBD>PWM<57><4D><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <20><><EFBFBD><EFBFBD>֧<EFBFBD><D6A7>: http://www.synwit.com.cn/e/tool/gbook/?bid=1
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:
* <20><EFBFBD><E6B1BE><EFBFBD><EFBFBD>: V1.1.0 2017<31><37>10<31><30>25<32><35>
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼:
*
*
*******************************************************************************************************************************************
* @attention
*
* 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
* OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION CONTAINED HEREIN IN CONN-
* -ECTION WITH THEIR PRODUCTS.
*
* COPYRIGHT 2012 Synwit Technology
*******************************************************************************************************************************************/
#include "SWM320.h"
#include "SWM320_pwm.h"
/******************************************************************************************************************************************
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: PWM_Init()
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: PWM<57><4D>ʼ<EFBFBD><CABC>
* <20><> <20><>: PWM_TypeDef * PWMx ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>PWM<57><4D><EFBFBD><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>PWM0<4D><30>PWM1<4D><31>PWM2<4D><32>PWM3<4D><33>PWM4<4D><34>PWM5
* PWM_InitStructure * initStruct <09><><EFBFBD><EFBFBD>PWM<57><4D><EFBFBD><EFBFBD><EFBFBD>趨ֵ<E8B6A8>Ľṹ<C4BD><E1B9B9>
* <20><> <20><>: <20><>
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
******************************************************************************************************************************************/
void PWM_Init(PWM_TypeDef * PWMx, PWM_InitStructure * initStruct)
{
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);
PWM_Stop(PWMx, 1, 1); //һЩ<D2BB>ؼ<EFBFBD><D8BC>Ĵ<EFBFBD><C4B4><EFBFBD>ֻ<EFBFBD><D6BB><EFBFBD><EFBFBD>PWMֹͣʱ<D6B9><CAB1><EFBFBD><EFBFBD>
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;
switch((uint32_t)PWMx)
{
case((uint32_t)PWM0):
bit_offset = 0;
break;
case((uint32_t)PWM1):
bit_offset = 2;
break;
case((uint32_t)PWM2):
bit_offset = 4;
break;
case((uint32_t)PWM3):
bit_offset = 6;
break;
case((uint32_t)PWM4):
bit_offset = 8;
break;
case((uint32_t)PWM5):
bit_offset = 10;
break;
}
PWMG->IRS = ((0x01 << bit_offset) | (0x01 << (bit_offset+1)) | (0x01 << (bit_offset+12)) | (0x01 << (bit_offset+13))); //<2F><><EFBFBD><EFBFBD><EFBFBD>жϱ<D0B6>־
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));
if(initStruct->NCycleAIEn | initStruct->NCycleBIEn | initStruct->HEndAIEn | initStruct->HEndBIEn)
{
NVIC_EnableIRQ(PWM_IRQn);
}
else if((PWMG->IE & (~((0x01 << bit_offset) | (0x01 << (bit_offset+1)) | (0x01 << (bit_offset+12)) | (0x01 << (bit_offset+13))))) == 0)
{
NVIC_DisableIRQ(PWM_IRQn);
}
}
/******************************************************************************************************************************************
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: PWM_Start()
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: <09><><EFBFBD><EFBFBD>PWM<57><4D><EFBFBD><EFBFBD>ʼPWM<57><4D><EFBFBD><EFBFBD>
* <20><> <20><>: PWM_TypeDef * PWMx ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>PWM<57><4D><EFBFBD><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>PWM0<4D><30>PWM1<4D><31>PWM2<4D><32>PWM3<4D><33>PWM4<4D><34>PWM5
* uint32_t chA 0 ͨ<><CDA8>A<EFBFBD><41><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1 ͨ<><CDA8>A<EFBFBD><41><EFBFBD><EFBFBD>
* uint32_t chB 0 ͨ<><CDA8>B<EFBFBD><42><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1 ͨ<><CDA8>B<EFBFBD><42><EFBFBD><EFBFBD>
* <20><> <20><>: <20><>
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
******************************************************************************************************************************************/
void PWM_Start(PWM_TypeDef * PWMx, uint32_t chA, uint32_t chB)
{
switch((uint32_t)PWMx)
{
case((uint32_t)PWM0):
PWMG->CHEN |= (chA << PWMG_CHEN_PWM0A_Pos) | (chB << PWMG_CHEN_PWM0B_Pos);
break;
case((uint32_t)PWM1):
PWMG->CHEN |= (chA << PWMG_CHEN_PWM1A_Pos) | (chB << PWMG_CHEN_PWM1B_Pos);
break;
case((uint32_t)PWM2):
PWMG->CHEN |= (chA << PWMG_CHEN_PWM2A_Pos) | (chB << PWMG_CHEN_PWM2B_Pos);
break;
case((uint32_t)PWM3):
PWMG->CHEN |= (chA << PWMG_CHEN_PWM3A_Pos) | (chB << PWMG_CHEN_PWM3B_Pos);
break;
case((uint32_t)PWM4):
PWMG->CHEN |= (chA << PWMG_CHEN_PWM4A_Pos) | (chB << PWMG_CHEN_PWM4B_Pos);
break;
case((uint32_t)PWM5):
PWMG->CHEN |= (chA << PWMG_CHEN_PWM5A_Pos) | (chB << PWMG_CHEN_PWM5B_Pos);
break;
}
}
/******************************************************************************************************************************************
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: PWM_Stop()
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: <09>ر<EFBFBD>PWM<57><4D>ֹͣPWM<57><4D><EFBFBD><EFBFBD>
* <20><> <20><>: PWM_TypeDef * PWMx ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>PWM<57><4D><EFBFBD><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>PWM0<4D><30>PWM1<4D><31>PWM2<4D><32>PWM3<4D><33>PWM4<4D><34>PWM5
* uint32_t chA 0 ͨ<><CDA8>A<EFBFBD><41><EFBFBD>ر<EFBFBD> 1 ͨ<><CDA8>A<EFBFBD>ر<EFBFBD>
* uint32_t chB 0 ͨ<><CDA8>B<EFBFBD><42><EFBFBD>ر<EFBFBD> 1 ͨ<><CDA8>B<EFBFBD>ر<EFBFBD>
* <20><> <20><>: <20><>
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
******************************************************************************************************************************************/
void PWM_Stop(PWM_TypeDef * PWMx, uint32_t chA, uint32_t chB)
{
switch((uint32_t)PWMx)
{
case((uint32_t)PWM0):
PWMG->CHEN &= ~((chA << PWMG_CHEN_PWM0A_Pos) | (chB << PWMG_CHEN_PWM0B_Pos));
break;
case((uint32_t)PWM1):
PWMG->CHEN &= ~((chA << PWMG_CHEN_PWM1A_Pos) | (chB << PWMG_CHEN_PWM1B_Pos));
break;
case((uint32_t)PWM2):
PWMG->CHEN &= ~((chA << PWMG_CHEN_PWM2A_Pos) | (chB << PWMG_CHEN_PWM2B_Pos));
break;
case((uint32_t)PWM3):
PWMG->CHEN &= ~((chA << PWMG_CHEN_PWM3A_Pos) | (chB << PWMG_CHEN_PWM3B_Pos));
break;
case((uint32_t)PWM4):
PWMG->CHEN &= ~((chA << PWMG_CHEN_PWM4A_Pos) | (chB << PWMG_CHEN_PWM4B_Pos));
break;
case((uint32_t)PWM5):
PWMG->CHEN &= ~((chA << PWMG_CHEN_PWM5A_Pos) | (chB << PWMG_CHEN_PWM5B_Pos));
break;
}
}
/******************************************************************************************************************************************
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: PWM_SetCycle()
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <20><> <20><>: PWM_TypeDef * PWMx ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>PWM<57><4D><EFBFBD><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>PWM0<4D><30>PWM1<4D><31>PWM2<4D><32>PWM3<4D><33>PWM4<4D><34>PWM5
* uint32_t chn ѡ<><D1A1>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>ĸ<EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Чֵ<D0A7><D6B5>PWM_CH_A<5F><41>PWM_CH_B
* uint16_t cycle Ҫ<><EFBFBD><E8B6A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
* <20><> <20><>: <20><>
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
******************************************************************************************************************************************/
void PWM_SetCycle(PWM_TypeDef * PWMx, uint32_t chn, uint16_t cycle)
{
if(chn == PWM_CH_A)
PWMx->PERA = cycle;
else if(chn == PWM_CH_B)
PWMx->PERB = cycle;
}
/******************************************************************************************************************************************
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: PWM_GetCycle()
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: <09><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
* <20><> <20><>: PWM_TypeDef * PWMx ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>PWM<57><4D><EFBFBD><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>PWM0<4D><30>PWM1<4D><31>PWM2<4D><32>PWM3<4D><33>PWM4<4D><34>PWM5
* uint32_t chn ѡ<><D1A1>Ҫ<EFBFBD><D2AA>ѯ<EFBFBD>ĸ<EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Чֵ<D0A7><D6B5>PWM_CH_A<5F><41>PWM_CH_B
* <20><> <20><>: uint16_t <09><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
******************************************************************************************************************************************/
uint16_t PWM_GetCycle(PWM_TypeDef * PWMx, uint32_t chn)
{
uint16_t cycle = 0;
if(chn == PWM_CH_A)
cycle = PWMx->PERA;
else if(chn == PWM_CH_B)
cycle = PWMx->PERB;
return cycle;
}
/******************************************************************************************************************************************
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: PWM_SetHDuty()
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: <09><><EFBFBD>øߵ<C3B8>ƽʱ<C6BD><CAB1>
* <20><> <20><>: PWM_TypeDef * PWMx ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>PWM<57><4D><EFBFBD><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>PWM0<4D><30>PWM1<4D><31>PWM2<4D><32>PWM3<4D><33>PWM4<4D><34>PWM5
* uint32_t chn ѡ<><D1A1>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>ĸ<EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Чֵ<D0A7><D6B5>PWM_CH_A<5F><41>PWM_CH_B
* uint16_t hduty Ҫ<><EFBFBD>ĸߵ<C4B8>ƽʱ<C6BD><CAB1>
* <20><> <20><>: <20><>
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
******************************************************************************************************************************************/
void PWM_SetHDuty(PWM_TypeDef * PWMx, uint32_t chn, uint16_t hduty)
{
if(chn == PWM_CH_A)
PWMx->HIGHA = hduty;
else if(chn == PWM_CH_B)
PWMx->HIGHB = hduty;
}
/******************************************************************************************************************************************
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: PWM_GetHDuty()
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: <20><>ȡ<EFBFBD>ߵ<EFBFBD>ƽʱ<C6BD><CAB1>
* <20><> <20><>: PWM_TypeDef * PWMx ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>PWM<57><4D><EFBFBD><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>PWM0<4D><30>PWM1<4D><31>PWM2<4D><32>PWM3<4D><33>PWM4<4D><34>PWM5
* uint32_t chn ѡ<><D1A1>Ҫ<EFBFBD><D2AA>ѯ<EFBFBD>ĸ<EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Чֵ<D0A7><D6B5>PWM_CH_A<5F><41>PWM_CH_B
* <20><> <20><>: uint16_t <09><>ȡ<EFBFBD><C8A1><EFBFBD>ĸߵ<C4B8>ƽʱ<C6BD><CAB1>
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
******************************************************************************************************************************************/
uint16_t PWM_GetHDuty(PWM_TypeDef * PWMx, uint32_t chn)
{
uint16_t hduty = 0;
if(chn == PWM_CH_A)
hduty = PWMx->HIGHA;
else if(chn == PWM_CH_B)
hduty = PWMx->HIGHB;
return hduty;
}
/******************************************************************************************************************************************
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: PWM_SetDeadzone()
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
* <20><> <20><>: PWM_TypeDef * PWMx ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>PWM<57><4D><EFBFBD><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>PWM0<4D><30>PWM1<4D><31>PWM2<4D><32>PWM3<4D><33>PWM4<4D><34>PWM5
* uint32_t chn ѡ<><D1A1>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>ĸ<EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Чֵ<D0A7><D6B5>PWM_CH_A<5F><41>PWM_CH_B
* uint8_t deadzone Ҫ<><EFBFBD><E8B6A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
* <20><> <20><>: <20><>
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
******************************************************************************************************************************************/
void PWM_SetDeadzone(PWM_TypeDef * PWMx, uint32_t chn, uint8_t deadzone)
{
if(chn == PWM_CH_A)
PWMx->DZA = deadzone;
else if(chn == PWM_CH_B)
PWMx->DZB = deadzone;
}
/******************************************************************************************************************************************
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: PWM_GetDeadzone()
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
* <20><> <20><>: PWM_TypeDef * PWMx ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>PWM<57><4D><EFBFBD><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>PWM0<4D><30>PWM1<4D><31>PWM2<4D><32>PWM3<4D><33>PWM4<4D><34>PWM5
* uint32_t chn ѡ<><D1A1>Ҫ<EFBFBD><D2AA>ѯ<EFBFBD>ĸ<EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Чֵ<D0A7><D6B5>PWM_CH_A<5F><41>PWM_CH_B
* <20><> <20><>: uint8_t <09><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
******************************************************************************************************************************************/
uint8_t PWM_GetDeadzone(PWM_TypeDef * PWMx, uint32_t chn)
{
uint8_t deadzone = 0;
if(chn == PWM_CH_A)
deadzone = PWMx->DZA;
else if(chn == PWM_CH_B)
deadzone = PWMx->DZB;
return deadzone;
}
/******************************************************************************************************************************************
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: PWM_IntNCycleEn()
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: <20><><EFBFBD><EFBFBD><EFBFBD>ڿ<EFBFBD>ʼ<EFBFBD>ж<EFBFBD>ʹ<EFBFBD><CAB9>
* <20><> <20><>: PWM_TypeDef * PWMx ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>PWM<57><4D><EFBFBD><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>PWM0<4D><30>PWM1<4D><31>PWM2<4D><32>PWM3<4D><33>PWM4<4D><34>PWM5
* uint32_t chn ѡ<><D1A1>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>ĸ<EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Чֵ<D0A7><D6B5>PWM_CH_A<5F><41>PWM_CH_B
* <20><> <20><>: <20><>
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
******************************************************************************************************************************************/
void PWM_IntNCycleEn(PWM_TypeDef * PWMx, uint32_t chn)
{
switch((uint32_t)PWMx)
{
case((uint32_t)PWM0):
if(chn == PWM_CH_A) PWMG->IE |= (0x01 << PWMG_IE_NEWP0A_Pos);
else PWMG->IE |= (0x01 << PWMG_IE_NEWP0B_Pos);
break;
case((uint32_t)PWM1):
if(chn == PWM_CH_A) PWMG->IE |= (0x01 << PWMG_IE_NEWP1A_Pos);
else PWMG->IE |= (0x01 << PWMG_IE_NEWP1B_Pos);
break;
case((uint32_t)PWM2):
if(chn == PWM_CH_A) PWMG->IE |= (0x01 << PWMG_IE_NEWP2A_Pos);
else PWMG->IE |= (0x01 << PWMG_IE_NEWP2B_Pos);
break;
case((uint32_t)PWM3):
if(chn == PWM_CH_A) PWMG->IE |= (0x01 << PWMG_IE_NEWP3A_Pos);
else PWMG->IE |= (0x01 << PWMG_IE_NEWP3B_Pos);
break;
case((uint32_t)PWM4):
if(chn == PWM_CH_A) PWMG->IE |= (0x01 << PWMG_IE_NEWP4A_Pos);
else PWMG->IE |= (0x01 << PWMG_IE_NEWP4B_Pos);
break;
case((uint32_t)PWM5):
if(chn == PWM_CH_A) PWMG->IE |= (0x01 << PWMG_IE_NEWP5A_Pos);
else PWMG->IE |= (0x01 << PWMG_IE_NEWP5B_Pos);
break;
}
}
/******************************************************************************************************************************************
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: PWM_IntNCycleDis()
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: <20><><EFBFBD><EFBFBD><EFBFBD>ڿ<EFBFBD>ʼ<EFBFBD>жϽ<D0B6><CFBD><EFBFBD>
* <20><> <20><>: PWM_TypeDef * PWMx ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>PWM<57><4D><EFBFBD><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>PWM0<4D><30>PWM1<4D><31>PWM2<4D><32>PWM3<4D><33>PWM4<4D><34>PWM5
* uint32_t chn ѡ<><D1A1>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>ĸ<EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Чֵ<D0A7><D6B5>PWM_CH_A<5F><41>PWM_CH_B
* <20><> <20><>: <20><>
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
******************************************************************************************************************************************/
void PWM_IntNCycleDis(PWM_TypeDef * PWMx, uint32_t chn)
{
switch((uint32_t)PWMx)
{
case((uint32_t)PWM0):
if(chn == PWM_CH_A) PWMG->IE &= ~(0x01 << PWMG_IE_NEWP0A_Pos);
else PWMG->IE &= ~(0x01 << PWMG_IE_NEWP0B_Pos);
break;
case((uint32_t)PWM1):
if(chn == PWM_CH_A) PWMG->IE &= ~(0x01 << PWMG_IE_NEWP1A_Pos);
else PWMG->IE &= ~(0x01 << PWMG_IE_NEWP1B_Pos);
break;
case((uint32_t)PWM2):
if(chn == PWM_CH_A) PWMG->IE &= ~(0x01 << PWMG_IE_NEWP2A_Pos);
else PWMG->IE &= ~(0x01 << PWMG_IE_NEWP2B_Pos);
break;
case((uint32_t)PWM3):
if(chn == PWM_CH_A) PWMG->IE &= ~(0x01 << PWMG_IE_NEWP3A_Pos);
else PWMG->IE &= ~(0x01 << PWMG_IE_NEWP3B_Pos);
break;
case((uint32_t)PWM4):
if(chn == PWM_CH_A) PWMG->IE &= ~(0x01 << PWMG_IE_NEWP4A_Pos);
else PWMG->IE &= ~(0x01 << PWMG_IE_NEWP4B_Pos);
break;
case((uint32_t)PWM5):
if(chn == PWM_CH_A) PWMG->IE &= ~(0x01 << PWMG_IE_NEWP5A_Pos);
else PWMG->IE &= ~(0x01 << PWMG_IE_NEWP5B_Pos);
break;
}
}
/******************************************************************************************************************************************
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: PWM_IntNCycleClr()
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: <20><><EFBFBD><EFBFBD><EFBFBD>ڿ<EFBFBD>ʼ<EFBFBD>жϱ<D0B6>־<EFBFBD><D6BE><EFBFBD><EFBFBD>
* <20><> <20><>: PWM_TypeDef * PWMx ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>PWM<57><4D><EFBFBD><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>PWM0<4D><30>PWM1<4D><31>PWM2<4D><32>PWM3<4D><33>PWM4<4D><34>PWM5
* uint32_t chn ѡ<><D1A1>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>ĸ<EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Чֵ<D0A7><D6B5>PWM_CH_A<5F><41>PWM_CH_B
* <20><> <20><>: <20><>
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
******************************************************************************************************************************************/
void PWM_IntNCycleClr(PWM_TypeDef * PWMx, uint32_t chn)
{
switch((uint32_t)PWMx)
{
case((uint32_t)PWM0):
if(chn == PWM_CH_A) PWMG->IRS = (0x01 << PWMG_IRS_NEWP0A_Pos);
else PWMG->IRS = (0x01 << PWMG_IRS_NEWP0B_Pos);
break;
case((uint32_t)PWM1):
if(chn == PWM_CH_A) PWMG->IRS = (0x01 << PWMG_IRS_NEWP1A_Pos);
else PWMG->IRS = (0x01 << PWMG_IRS_NEWP1B_Pos);
break;
case((uint32_t)PWM2):
if(chn == PWM_CH_A) PWMG->IRS = (0x01 << PWMG_IRS_NEWP2A_Pos);
else PWMG->IRS = (0x01 << PWMG_IRS_NEWP2B_Pos);
break;
case((uint32_t)PWM3):
if(chn == PWM_CH_A) PWMG->IRS = (0x01 << PWMG_IRS_NEWP3A_Pos);
else PWMG->IRS = (0x01 << PWMG_IRS_NEWP3B_Pos);
break;
case((uint32_t)PWM4):
if(chn == PWM_CH_A) PWMG->IRS = (0x01 << PWMG_IRS_NEWP4A_Pos);
else PWMG->IRS = (0x01 << PWMG_IRS_NEWP4B_Pos);
break;
case((uint32_t)PWM5):
if(chn == PWM_CH_A) PWMG->IRS = (0x01 << PWMG_IRS_NEWP5A_Pos);
else PWMG->IRS = (0x01 << PWMG_IRS_NEWP5B_Pos);
break;
}
}
/******************************************************************************************************************************************
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: PWM_IntNCycleStat()
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: <20><><EFBFBD><EFBFBD><EFBFBD>ڿ<EFBFBD>ʼ<EFBFBD>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
* <20><> <20><>: PWM_TypeDef * PWMx ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>PWM<57><4D><EFBFBD><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>PWM0<4D><30>PWM1<4D><31>PWM2<4D><32>PWM3<4D><33>PWM4<4D><34>PWM5
* uint32_t chn ѡ<><D1A1>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>ĸ<EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Чֵ<D0A7><D6B5>PWM_CH_A<5F><41>PWM_CH_B
* <20><> <20><>: uint32_t 1 <20><><EFBFBD><EFBFBD><EFBFBD>ڿ<EFBFBD>ʼ<EFBFBD>ж<EFBFBD><D0B6>ѷ<EFBFBD><D1B7><EFBFBD> 0 <20><><EFBFBD><EFBFBD><EFBFBD>ڿ<EFBFBD>ʼ<EFBFBD>ж<EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD>
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
******************************************************************************************************************************************/
uint32_t PWM_IntNCycleStat(PWM_TypeDef * PWMx, uint32_t chn)
{
uint32_t int_stat = 0;
switch((uint32_t)PWMx)
{
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);
break;
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);
break;
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);
break;
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);
break;
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);
break;
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);
break;
}
return int_stat;
}
/******************************************************************************************************************************************
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: PWM_IntHEndEn()
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: <20>ߵ<EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>ʹ<EFBFBD><CAB9>
* <20><> <20><>: PWM_TypeDef * PWMx ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>PWM<57><4D><EFBFBD><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>PWM0<4D><30>PWM1<4D><31>PWM2<4D><32>PWM3<4D><33>PWM4<4D><34>PWM5
* uint32_t chn ѡ<><D1A1>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>ĸ<EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Чֵ<D0A7><D6B5>PWM_CH_A<5F><41>PWM_CH_B
* <20><> <20><>: <20><>
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
******************************************************************************************************************************************/
void PWM_IntHEndEn(PWM_TypeDef * PWMx, uint32_t chn)
{
switch((uint32_t)PWMx)
{
case((uint32_t)PWM0):
if(chn == PWM_CH_A) PWMG->IE |= (0x01 << PWMG_IE_HEND0A_Pos);
else PWMG->IE |= (0x01 << PWMG_IE_HEND0B_Pos);
break;
case((uint32_t)PWM1):
if(chn == PWM_CH_A) PWMG->IE |= (0x01 << PWMG_IE_HEND1A_Pos);
else PWMG->IE |= (0x01 << PWMG_IE_HEND1B_Pos);
break;
case((uint32_t)PWM2):
if(chn == PWM_CH_A) PWMG->IE |= (0x01 << PWMG_IE_HEND2A_Pos);
else PWMG->IE |= (0x01 << PWMG_IE_HEND2B_Pos);
break;
case((uint32_t)PWM3):
if(chn == PWM_CH_A) PWMG->IE |= (0x01 << PWMG_IE_HEND3A_Pos);
else PWMG->IE |= (0x01 << PWMG_IE_HEND3B_Pos);
break;
case((uint32_t)PWM4):
if(chn == PWM_CH_A) PWMG->IE |= (0x01 << PWMG_IE_HEND4A_Pos);
else PWMG->IE |= (0x01 << PWMG_IE_HEND4B_Pos);
break;
case((uint32_t)PWM5):
if(chn == PWM_CH_A) PWMG->IE |= (0x01 << PWMG_IE_HEND5A_Pos);
else PWMG->IE |= (0x01 << PWMG_IE_HEND5B_Pos);
break;
}
}
/******************************************************************************************************************************************
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: PWM_IntHEndDis()
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: <20>ߵ<EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD><EFBFBD>жϽ<D0B6><CFBD><EFBFBD>
* <20><> <20><>: PWM_TypeDef * PWMx ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>PWM<57><4D><EFBFBD><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>PWM0<4D><30>PWM1<4D><31>PWM2<4D><32>PWM3<4D><33>PWM4<4D><34>PWM5
* uint32_t chn ѡ<><D1A1>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>ĸ<EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Чֵ<D0A7><D6B5>PWM_CH_A<5F><41>PWM_CH_B
* <20><> <20><>: <20><>
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
******************************************************************************************************************************************/
void PWM_IntHEndDis(PWM_TypeDef * PWMx, uint32_t chn)
{
switch((uint32_t)PWMx)
{
case((uint32_t)PWM0):
if(chn == PWM_CH_A) PWMG->IE &= ~(0x01 << PWMG_IE_HEND0A_Pos);
else PWMG->IE &= ~(0x01 << PWMG_IE_HEND0B_Pos);
break;
case((uint32_t)PWM1):
if(chn == PWM_CH_A) PWMG->IE &= ~(0x01 << PWMG_IE_HEND1A_Pos);
else PWMG->IE &= ~(0x01 << PWMG_IE_HEND1B_Pos);
break;
case((uint32_t)PWM2):
if(chn == PWM_CH_A) PWMG->IE &= ~(0x01 << PWMG_IE_HEND2A_Pos);
else PWMG->IE &= ~(0x01 << PWMG_IE_HEND2B_Pos);
break;
case((uint32_t)PWM3):
if(chn == PWM_CH_A) PWMG->IE &= ~(0x01 << PWMG_IE_HEND3A_Pos);
else PWMG->IE &= ~(0x01 << PWMG_IE_HEND3B_Pos);
break;
case((uint32_t)PWM4):
if(chn == PWM_CH_A) PWMG->IE &= ~(0x01 << PWMG_IE_HEND4A_Pos);
else PWMG->IE &= ~(0x01 << PWMG_IE_HEND4B_Pos);
break;
case((uint32_t)PWM5):
if(chn == PWM_CH_A) PWMG->IE &= ~(0x01 << PWMG_IE_HEND5A_Pos);
else PWMG->IE &= ~(0x01 << PWMG_IE_HEND5B_Pos);
break;
}
}
/******************************************************************************************************************************************
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: PWM_IntHEndClr()
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: <20>ߵ<EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD><EFBFBD>жϱ<D0B6>־<EFBFBD><D6BE><EFBFBD><EFBFBD>
* <20><> <20><>: PWM_TypeDef * PWMx ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>PWM<57><4D><EFBFBD><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>PWM0<4D><30>PWM1<4D><31>PWM2<4D><32>PWM3<4D><33>PWM4<4D><34>PWM5
* uint32_t chn ѡ<><D1A1>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>ĸ<EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Чֵ<D0A7><D6B5>PWM_CH_A<5F><41>PWM_CH_B
* <20><> <20><>: <20><>
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
******************************************************************************************************************************************/
void PWM_IntHEndClr(PWM_TypeDef * PWMx, uint32_t chn)
{
switch((uint32_t)PWMx)
{
case((uint32_t)PWM0):
if(chn == PWM_CH_A) PWMG->IRS = (0x01 << PWMG_IRS_HEND0A_Pos);
else PWMG->IRS = (0x01 << PWMG_IRS_HEND0B_Pos);
break;
case((uint32_t)PWM1):
if(chn == PWM_CH_A) PWMG->IRS = (0x01 << PWMG_IRS_HEND1A_Pos);
else PWMG->IRS = (0x01 << PWMG_IRS_HEND1B_Pos);
break;
case((uint32_t)PWM2):
if(chn == PWM_CH_A) PWMG->IRS = (0x01 << PWMG_IRS_HEND2A_Pos);
else PWMG->IRS = (0x01 << PWMG_IRS_HEND2B_Pos);
break;
case((uint32_t)PWM3):
if(chn == PWM_CH_A) PWMG->IRS = (0x01 << PWMG_IRS_HEND3A_Pos);
else PWMG->IRS = (0x01 << PWMG_IRS_HEND3B_Pos);
break;
case((uint32_t)PWM4):
if(chn == PWM_CH_A) PWMG->IRS = (0x01 << PWMG_IRS_HEND4A_Pos);
else PWMG->IRS = (0x01 << PWMG_IRS_HEND4B_Pos);
break;
case((uint32_t)PWM5):
if(chn == PWM_CH_A) PWMG->IRS = (0x01 << PWMG_IRS_HEND5A_Pos);
else PWMG->IRS = (0x01 << PWMG_IRS_HEND5B_Pos);
break;
}
}
/******************************************************************************************************************************************
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: PWM_IntHEndStat()
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: <20>ߵ<EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
* <20><> <20><>: PWM_TypeDef * PWMx ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>PWM<57><4D><EFBFBD><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>PWM0<4D><30>PWM1<4D><31>PWM2<4D><32>PWM3<4D><33>PWM4<4D><34>PWM5
* uint32_t chn ѡ<><D1A1>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>ĸ<EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Чֵ<D0A7><D6B5>PWM_CH_A<5F><41>PWM_CH_B
* <20><> <20><>: uint32_t 1 <20>ߵ<EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6>ѷ<EFBFBD><D1B7><EFBFBD> 0 <20>ߵ<EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD>
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
******************************************************************************************************************************************/
uint32_t PWM_IntHEndStat(PWM_TypeDef * PWMx, uint32_t chn)
{
uint32_t int_stat = 0;
switch((uint32_t)PWMx)
{
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);
break;
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);
break;
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);
break;
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);
break;
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);
break;
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);
break;
}
return int_stat;
}