📄 91x_mc.c
字号:
if(MC_InitStruct->MC_PolarityWH == MC_Polarity_Inverted)
{
MC->PSR |= MC_PWH_Set;
}
else
{
MC->PSR &= MC_PWH_Reset;
}
}
default:
break;
}
}
/*******************************************************************************
* Function Name : MC_StructInit
* Description : Fills each MC_InitStruct member with its default value.
* Input : MC_InitStruct : pointer to a MC_InitTypeDef structure which
* will be initialized.
* Output : None
* Return : None.
*******************************************************************************/
void MC_StructInit(MC_InitTypeDef* MC_InitStruct)
{
u16 temp;
temp=MC->ECR;
temp &= MC_PWM_Counter ;
MC_InitStruct->MC_OperatingMode = MC_HardwareOperating_Mode;
MC_InitStruct->MC_TachoMode = MC_TachoContinuous_Mode;
MC_InitStruct->MC_TachoEvent_Mode = MC_TachoEvent_Hardware_Mode;
MC_InitStruct->MC_Prescaler = 0x00;
MC_InitStruct->MC_TachoPrescaler = 0x0000;
MC_InitStruct->MC_PWMMode = MC_PWMClassical_Mode;
MC_InitStruct->MC_Complementary = MC_Complementary_Enable;
MC_InitStruct->MC_Emergency = MC_Emergency_Disable;
MC_InitStruct->MC_ForcedPWMState = 0x003F;
MC_InitStruct->MC_Period = 0x0000;
MC_InitStruct->MC_TachoPeriod = 0x00FF;
MC_InitStruct->MC_Channel = MC_Channel_ALL;
MC_InitStruct->MC_PulseU = 0x0000;
MC_InitStruct->MC_PulseV = 0x0000;
MC_InitStruct->MC_PulseW = 0x0000;
MC_InitStruct->MC_PolarityUL = MC_Polarity_NonInverted;
MC_InitStruct->MC_PolarityUH = MC_Polarity_NonInverted;
MC_InitStruct->MC_PolarityVL = MC_Polarity_NonInverted;
MC_InitStruct->MC_PolarityVH = MC_Polarity_NonInverted;
MC_InitStruct->MC_PolarityWL = MC_Polarity_NonInverted;
MC_InitStruct->MC_PolarityWH = MC_Polarity_NonInverted;
MC_InitStruct->MC_TachoPolarity = MC_TachoEventEdge_RisingFalling;
if(temp==0)
{
MC_InitStruct->MC_DeadTime = 0x003F;
}
else
{
MC_InitStruct->MC_DeadTime = 0x03FF;
}
MC_InitStruct->MC_RepetitionCounter = 0x0000;
}
/*******************************************************************************
* Function Name : MC_Cmd
* Description : Enables or disables the MC peripheral.
* Input : Newstate: new state of the MC peripheral.
* This parameter can be: ENABLE or DISABLE.
* Output : None
* Return : None
*******************************************************************************/
void MC_Cmd(FunctionalState NewState)
{
if(NewState == ENABLE)
{
/* Enable the PWM counter */
MC->PCR0 |= MC_PCE_Set;
/* Enable the Tacho counter */
MC->PCR0 |= MC_TCE_Set;
/* Enable the Dead Time counter */
MC->PCR0 |= MC_DTE_Set;
}
else
{
/* Disable the PWM counter */
MC->PCR0 &= MC_PCE_Reset;
/* Disable the Tacho counter */
MC->PCR0 &= MC_TCE_Reset;
/* Disable the Dead counter */
MC->PCR0 &= MC_DTE_Reset;
}
}
/*******************************************************************************
* Function Name : MC_ClearPWMCounter
* Description : Clears the MC PWM counter.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void MC_ClearPWMCounter(void)
{
/* Clear the PWM counter */
MC->PCR0 |= MC_CPC_Set;
}
/*******************************************************************************
* Function Name : MC_ClearTachoCounter
* Description : Clears the MC Tacho counter.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void MC_ClearTachoCounter(void)
{
/* Clear the Tacho counter */
MC->PCR0 |= MC_CTC_Set;
}
/*******************************************************************************
* Function Name : MC_CtrlPWMOutputs
* Description : Enables or disables MC peripheral Main Outputs.
* Input : Newstate: new state of the MC peripheral Main Outputs.
* This parameter can be: ENABLE or DISABLE.
* Output : None
* Return : None
*******************************************************************************/
void MC_CtrlPWMOutputs(FunctionalState Newstate)
{
if(Newstate == ENABLE)
{
/* Enable the dead time generator data */
MC->OPR &= MC_ODS_Reset;
}
else
{
/* Enable the default state data */
MC->OPR |= MC_ODS_Set;
}
}
/*******************************************************************************
* Function Name : MC_ITConfig
* Description : Enables or disables the MC interrupts.
* Input : - MC_IT: specifies the MC interrupts sources to be enabled
* or disabled.
* This parameter can be any combination of the following values:
* - MC_IT_CMPW: Compare W Interrupt.
* - MC_IT_CMPV: Compare V Interrupt.
* - MC_IT_CMPU: Compare U Interrupt.
* - MC_IT_ZPC: Zero of PWM counter Interrupt.
* - MC_IT_ADT: Automatic Data Transfer Interrupt.
* - MC_IT_OTC: Overflow of Tacho counter Interrupt.
* - MC_IT_CPT: Capture of Tacho counter Interrupt.
* - MC_IT_CM0: Compare 0 Interrupt.
* - Newstate: new state of IMC interrupts.
* This parameter can be: ENABLE or DISABLE.
* Output : None
* Return : None
*******************************************************************************/
void MC_ITConfig(u16 MC_IT, FunctionalState NewState)
{
if(NewState == ENABLE)
{
/* Enable the specific interrupt source */
MC->IMR |= MC_IT;
/* Enable the global peripheral interrupt sources */
MC->PCR2 |= MC_GPI_Set;
}
else
{
/* Disable the specific interrupt source */
MC->IMR &= ~MC_IT;
/* Disable the global peripheral interrupt sources */
MC->PCR2 &= MC_GPI_Reset;
}
}
/*******************************************************************************
* Function Name : MC_SetPrescaler
* Description : Sets the MC prescaler value.
* Input : MC_Prescaler: MC prescaler new value.
* Output : None
* Return : None
*******************************************************************************/
void MC_SetPrescaler(u8 MC_Prescaler)
{
/* Set the Prescaler Register value */
MC->CPRS = MC_Prescaler;
}
/*******************************************************************************
* Function Name : MC_SetPeriod
* Description : Sets the MC period value.
* Input : MC_Period: MC period new value.
* Output : None
* Return : None
*******************************************************************************/
void MC_SetPeriod(u16 MC_Period)
{
/* Set the Period Register value */
MC->CMP0 = MC_Period;
}
/*******************************************************************************
* Function Name : MC_SetPulseU
* Description : Sets the MC pulse U value.
* Input : MC_PulseU: MC pulse U new value.
* Output : None
* Return : None
*******************************************************************************/
void MC_SetPulseU(u16 MC_PulseU)
{
/* Set the Pulse U Register value */
MC->CMPU = MC_PulseU;
}
/*******************************************************************************
* Function Name : MC_SetPulseV
* Description : Sets the MC pulse V value.
* Input : MC_PulseV: MC pulse V new value.
* Output : None
* Return : None
*******************************************************************************/
void MC_SetPulseV(u16 MC_PulseV)
{
/* Set the Pulse V Register value */
MC->CMPV = MC_PulseV;
}
/*******************************************************************************
* Function Name : MC_SetPulseW
* Description : Sets the MC pulse W value.
* Input : MC_PulseW: MC pulse W new value.
* Output : None
* Return : None
*******************************************************************************/
void MC_SetPulseW(u16 MC_PulseW)
{
/* Set the Pulse W Register value */
MC->CMPW = MC_PulseW;
}
/*******************************************************************************
* Function Name : MC_PWMModeConfig
* Description : Selects the MC PWM counter Mode.
* Input : MC_PWMMode: MC PWM counter Mode.
* Output : None
* Return : None
*******************************************************************************/
void MC_PWMModeConfig(u16 MC_PWMMode)
{
/* Select the MC PWM counter Mode */
if(MC_PWMMode == MC_PWMZeroCentered_Mode)
{
MC->PCR0 |= MC_CMS_Set;
}
else
{
MC->PCR0 &= MC_CMS_Reset;
}
}
/*******************************************************************************
* Function Name : MC_SetDeadTime
* Description : Sets the MC dead time value.
* Input : MC_DeadTime: MC dead time new value.
* Output : None
* Return : None
*******************************************************************************/
void MC_SetDeadTime(u16 MC_DeadTime)
{
/* Set the dead time Register value */
MC->DTG = MC_DeadTime;
}
/*******************************************************************************
* Function Name : MC_SetTachoCompare
* Description : Sets the MC Tacho Compare Register value.
* Input : MC_Compare: MC Tacho compare new value.
* Output : None
* Return : None
*******************************************************************************/
void MC_SetTachoCompare(u8 MC_Compare)
{
/* Sets the Tacho Compare Register value */
MC->TCMP = MC_Compare;
}
/*******************************************************************************
* Function Name : MC_EmergencyCmd
* Description : Enables or disables the MC emergency feauture.
* Input : Newstate: new state of the MC peripheral Emergency.
* This parameter can be: ENABLE or DISABLE.
* Output : None
* Return : None
*******************************************************************************/
void MC_EmergencyCmd(FunctionalState NewState)
{
if(NewState == ENABLE)
{
/* Reset the DISEST Bit in the PCR1 Register to enable the emergency stop input */
MC->PCR1 &= MC_DISEST_Reset;
}
else
{
/* Set the DISEST Bit in the PCR1 Register to disable the emergency stop input */
MC->PCR1 |= MC_DISEST_Reset;
}
}
/*******************************************************************************
* Function Name : MC_EmergencyClear
* Description : Clears the MC Emergency Register.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void MC_EmergencyClear(void)
{
MC->ECR |= 0x0100;
/* Clear EST bit */
MC->ESC = MC_ESC_Clear;
}
/*******************************************************************************
* Function Name : MC_GetPeriod
* Description : Gets the MC period value.
* Input : None
* Output : None
* Return : MC period value.
*******************************************************************************/
u16 MC_GetPeriod(void)
{
/* Return the PWM signal period value */
return MC->CMP0;
}
/*******************************************************************************
* Function Name : MC_GetPulseU
* Description : Gets the MC pulse U value.
* Input : None
* Output : None
* Return : MC pulse U value.
*******************************************************************************/
u16 MC_GetPulseU(void)
{
/* Return the PWM pulse U Register value */
return MC->CMPU;
}
/*******************************************************************************
* Function Name : MC_GetPulseV
* Description : Gets the MC pulse V value.
* Input : None
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -