⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 91x_mc.c

📁 STR912的中断控制器的应用例子
💻 C
📖 第 1 页 / 共 3 页
字号:
* Output         : None
* Return         : MC pulse V value.
*******************************************************************************/
u16 MC_GetPulseV(void)
{
/* Return the PWM pulse V Register value */
  return MC->CMPV;
}

/*******************************************************************************
* Function Name  : MC_GetPulseW
* Description    : Gets the MC pulse W value.
* Input          : None
* Output         : None
* Return         : MC pulse W value.
*******************************************************************************/
u16 MC_GetPulseW(void)
{
/* Return the PWM pulse W Register value */
  return MC->CMPW;
}

/*******************************************************************************
* Function Name  : MC_GetTachoCapture
* Description    : Gets the MC Tacho period value.
* Input          : None
* Output         : None
* Return         : MC Tacho capture value.
*******************************************************************************/
u16 MC_GetTachoCapture(void)
{
/* Return the Tacho Capture Register value */
  return MC->TCPT;
}

/*******************************************************************************
* Function Name  : MC_ClearOnTachoCapture
* Description    : Enables or disables the the Clear on capture of tacho counter.
* Input          : Newstate: new state of the CCPT bit.
*                  This parameter can be: ENABLE or DISABLE.
* Output         : None
* Return         : None
*******************************************************************************/
void MC_ClearOnTachoCapture(FunctionalState NewState)
{
  if(NewState == ENABLE)
  {
    /* Enable the Clear on capture of tacho counter */
    MC->PCR1 |= MC_CCPT_Set;
  }
  else
  {   
    /* Disable the Clear on capture of tacho counter */
    MC->PCR1 &= MC_CCPT_Reset;
  }
}
/*******************************************************************************
* Function Name  : MC_ForceDataTransfer
* Description    : Sets the MC Outputs default states.
* Input          : MC_ForcedData: MC outputs new states.
* Output         : None
* Return         : None
*******************************************************************************/
void MC_ForceDataTransfer(u8 MC_ForcedData)
{
   /* Set the MC PWM Forced State */
   MC->OPR |= MC_ODS_Set;
   MC->OPR = (MC->OPR & MC_OPR_Mask) | MC_ForcedData;
}

/*******************************************************************************
* Function Name  : MC_PreloadConfig
* Description    : Enables the Software Data Transfer.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void MC_SoftwarePreloadConfig(void)
{
  /* Set the SDT: Software Data Transfer bit */
  MC->PCR2 |= MC_SDT_Set;
}

/*******************************************************************************
* Function Name  : MC_SoftwareTachoCapture
* Description    : Enables the Software Tacho Capture.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void MC_SoftwareTachoCapture(void)
{
  /* Set the STC: Software Tacho Capture bit */
  MC->PCR1 |= MC_STC_Set;
}

/*******************************************************************************
* Function Name  : MC_GetCountingStatus
* Description    : Checks whether the PWM Counter is counting Up or Down.
* Input          : None
* Output         : None
* Return         : The new state of the PWM Counter(DOWN or UP).
*******************************************************************************/
CountingStatus MC_GetCountingStatus(void)
{
  if((MC->PCR0 & MC_UDCS_Mask) != DOWN)
  {
    return UP;
  }
  else
  {
    return DOWN;
  }
}

/*******************************************************************************
* Function Name  : MC_GetFlagStatus
* Description    : Checks whether the specified MC flag is set or not.
* Input          : MC_FLAG: specifies the flag to check.
*                  This parameter can be one of the following values:
*                         - MC_FLAG_CMPW: Compare W Flag.
*                         - MC_FLAG_CMPV: Compare V Flag.
*                         - MC_FLAG_CMPU: Compare U Flag.
*                         - MC_FLAG_ZPC: Zero of PWM counter Flag.
*                         - MC_FLAG_ADT: Automatic Data Transfer Flag.
*                         - MC_FLAG_OTC: Overflow of Tacho counter Flag.
*                         - MC_FLAG_CPT: Capture of Tacho counter Flag.
*                         - MC_FLAG_CM0: Compare 0 Flag.
*                         - MC_FLAG_EST: Emergency Stop Flag.
* Output         : None
* Return         : The new state of the MC_FLAG(SET or RESET).
*******************************************************************************/
FlagStatus MC_GetFlagStatus(u16 MC_FLAG)
{
  if((MC->IPR & MC_FLAG) != RESET)
  {
    return SET;
  }
  else
  {
    return RESET;
  }
}

/*******************************************************************************
* Function Name  : MC_ClearFlag
* Description    : Clears the MC抯 pending flags.
* Input          : MC_FLAG: specifies the flag to clear.
*                  This parameter can be any combination of the following values:
*                         - MC_FLAG_CMPW: Compare W Flag.
*                         - MC_FLAG_CMPV: Compare V Flag.
*                         - MC_FLAG_CMPU: Compare U Flag.
*                         - MC_FLAG_ZPC: Zero of PWM counter Flag.
*                         - MC_FLAG_ADT: Automatic Data Transfer Flag.
*                         - MC_FLAG_OTC: Overflow of Tacho counter Flag.
*                         - MC_FLAG_CPT: Capture of Tacho counter Flag.
*                         - MC_FLAG_CM0: Compare 0 Flag.
* Output         : None
* Return         : None
*******************************************************************************/
void MC_ClearFlag(u16 MC_FLAG)
{
/* Clear the corresponding Flag */
  MC->IPR &= ~MC_FLAG;
}

/*******************************************************************************
* Function Name  : MC_GetITStatus
* Description    : Checks whether the MC interrupt has occurred or not.
* Input          : MC_IT: specifies the MC interrupt source to check.
*                  This parameter can be one 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.
* Output         : None
* Return         : The new state of the MC_IT(SET or RESET).
*******************************************************************************/
ITStatus MC_GetITStatus(u16 MC_IT)
{
  if((MC->IPR & MC_IT) && (MC->IMR & MC_IT))
  {
    return SET;
  }
  else
  {
    return RESET;
  }
}

/*******************************************************************************
* Function Name  : MC_ClearITPendingBit
* Description    : Clears the IMC's interrupt pending bits.
* Input          : MC_IT: specifies the pending bit to clear.
*                  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.
* Output         : None
* Return         : None
*******************************************************************************/
void MC_ClearITPendingBit(u16 MC_IT)
{
/* Clear the corresponding interrupt pending bit */ 
  MC->IPR &= ~MC_IT;
}


/*******************************************************************************
* Function Name  : MC_Lock
* Description    : Enables the lock of certain control register bits 
* Input          : - MC_LockLevel: Specifies the level to be locked.
*                  This parameter can be any combination of the following values:
*                         - MC_LockLevel4: Lock Dead Time Generator register.
*                         - MC_LockLevel3: Lock Output Peripheral Register.
*                         - MC_LockLevel2: Lock phase polarity bits.
*                         - MC_LockLevel1: Lock Emergency Stop Disable bit.
*                         - MC_LockLevel0: Dead Time Enable and Output  Dead Time
*                                          counter Selection bits.
* Output         : None
* Return         : None
*******************************************************************************/
void  MC_Lock(u16 MC_LockLevel)
{
  MC->LOK &= ~MC_LockLevel; 
  MC->LOK |= MC_LockLevel;
}

/******************************************************************************
* Function Name  :  MC_CounterModeConfig
* Description    : Enables the 10 bits mode for the dead time counter or enables
*                  the 16 bits mode for the PWM counter.
* Input          : - MC_Counter : Specifies the counter
*                  This parameter can be any combination of the following values:
*                         - MC_DT_Counter  : Dead Time Counter is in 10 bits mode.
*                         - MC_PWM_Counter : PWM_Counter is in 16 bits mode.
* Output         : None
* Return         : None
*******************************************************************************/
void MC_CounterModeConfig(u16 MC_Counter)
{ 
  MC->ECR &= ~MC_Counter; 
  MC->ECR |=  MC_Counter;               
}

/*******************************************************************************
* Function Name  : MC_DoubleUpdateMode
* Description    : Enables or disables the Double Update Mode for the MC
* Input          : - Newstate: New state of the double update mode.
*                  This parameter can be: ENABLE or DISABLE.
* Output         : None
* Return         : None
*******************************************************************************/
void MC_DoubleUpdateMode(FunctionalState NewState)
{
  if( NewState==ENABLE)
  { 
    MC->ECR |= MC_DUM;
  }
  else
  { 
    MC->ECR &= ~MC_DUM; 
  }
}

/*******************************************************************************
* Function Name  : MC_ADCTrigger
* Description    : Enables or disables the Triggers to the ADC conversion 
* Input          : IMC event : The IMC event to trigger the ADC conversion
*                  This parameter can be one of the following values:
*                          - MC_ZPC : When the PWM counter reaches zero.
*                          - MC_CM0 : When the PWM counter reaches its maximum 
*                                     count.
*                          - MC_ADT : When the PWM counter equals zero and the 
*                                     Repetition Down counter equals zero.
*                  - Newstate: New state of the ADC trigger event.
*                  This parameter can be: ENABLE or DISABLE.
* Output         : None
* Return         : None
*******************************************************************************/
void MC_ADCTrigger(u16 IMC_Event, FunctionalState NewState)
{
  MC->ECR &= 0x01F3;
  
  if( NewState==ENABLE)
  {
    MC->ECR |= IMC_Event;
  }
  else
  {
    MC->ECR &= ~IMC_Event; 
  }    
}


/*******************************************************************************
* Function Name  : MC_EnhancedStop
* Description    : Enables or disables an Enhanced Motor Stop feature.
* Input          : NewState : This pararameter can be ENABLE or DISABLE.
* Output         : None
* Return         : None
*******************************************************************************/
void MC_EnhancedStop(FunctionalState NewState)
{ 
  if( NewState==ENABLE)
  {
    MC->ECR |=  0x0040;
  }
  else
  {
    MC->ECR &= ~ 0x0040; 
  }
}
/*******************************************************************************
* Function Name  : MC_DebugOutputProtection
* Description    : Allows the output phases to follow the polarity set by PSR if 
*		   enabled or they remain in their last known state if disabled.
* Input          : NewState : This pararameter can be ENABLE or DISABLE.
* Output         : None
* Return         : None
*******************************************************************************/
void MC_DebugOutputProtection(FunctionalState NewState)
{ 
  if( NewState==ENABLE)
  {
    MC->ECR |= 0x0080;
  }
  else
  {
    MC->ECR &= ~0x0080; 
  }
}

/*******************************************************************************
* Function Name  : MC_EmergencyStopPolarity
* Description    : Enables or disables an Enhanced Stop Polarity feature.
* Input          : NewState : This pararameter can be ENABLE or DISABLE.
* Output         : None
* Return         : None
*******************************************************************************/
void MC_EmergencyStopPolarity(FunctionalState NewState)
{ 
  if( NewState==ENABLE)
  {
    MC->ECR |= 0x0002;
  }
  else
  {
    MC->ECR &= ~0x0002; 
  }
}
/******************* (C) COPYRIGHT 2007 STMicroelectronics *****END OF FILE****/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -