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

📄 91x_mc.c

📁 万利ARM9的STR912开发板配套资料和源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
     case MC_Channel_ALL:
     {
       MC->CMPU = MC_InitStruct->MC_PulseU;
       MC->CMPV = MC_InitStruct->MC_PulseV;
       MC->CMPW = MC_InitStruct->MC_PulseW;
       
       if(MC_InitStruct->MC_PolarityUL == MC_Polarity_Inverted)
       {
       	 MC->PSR |= MC_PUL_Set;
       }
       else
       {
         MC->PSR &= MC_PUL_Reset;
       }
       if(MC_InitStruct->MC_PolarityUH == MC_Polarity_Inverted)
       {
       	 MC->PSR |= MC_PUH_Set;
       }
       else
       {
         MC->PSR &= MC_PUH_Reset;
       }

       if(MC_InitStruct->MC_PolarityVL == MC_Polarity_Inverted)
       {
       	 MC->PSR |= MC_PVL_Set;
       }
       else
       {
         MC->PSR &= MC_PVL_Reset;
       }
       if(MC_InitStruct->MC_PolarityVH == MC_Polarity_Inverted)
       {
       	 MC->PSR |= MC_PVH_Set;
       }
       else
       {
         MC->PSR &= MC_PVH_Reset;
       }

       if(MC_InitStruct->MC_PolarityWL == MC_Polarity_Inverted)
       {
       	 MC->PSR |= MC_PWL_Set;
       }
       else
       {
         MC->PSR &= MC_PWL_Reset;
       }
       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)
{
  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;
  MC_InitStruct->MC_DeadTime = 0x003F;
  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
*******************************************************************************/

⌨️ 快捷键说明

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