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

📄 stm32f10x_tim.lst

📁 STM32利用正交编码器实现电机的控制
💻 LST
📖 第 1 页 / 共 5 页
字号:
    179          *                  parameters in the TIM_OCInitStruct.
    180          * Input          : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
    181          *                  - TIM_OCInitStruct: pointer to a TIM_OCInitTypeDef structure
    182          *                    that contains the configuration information for the specified
    183          *                    TIM peripheral.
    184          * Output         : None
    185          * Return         : None
    186          *******************************************************************************/
    187          void TIM_OCInit(TIM_TypeDef* TIMx, TIM_OCInitTypeDef* TIM_OCInitStruct)
    188          {
    189            u32 tmpccmrx = 0, tmpccer = 0;
    190            
    191            /* Check the parameters */
    192            assert(IS_TIM_OC_MODE(TIM_OCInitStruct->TIM_OCMode));
    193            assert(IS_TIM_CHANNEL(TIM_OCInitStruct->TIM_Channel));
    194            assert(IS_TIM_OC_POLARITY(TIM_OCInitStruct->TIM_OCPolarity));
    195          
    196            tmpccer = TIMx->CCER;
    197          
    198            if ((TIM_OCInitStruct->TIM_Channel == (u16)TIM_Channel_1) ||
    199                (TIM_OCInitStruct->TIM_Channel == (u16)TIM_Channel_2))
    200            {
    201              tmpccmrx = TIMx->CCMR1;
    202              
    203              /* Reset the Output Compare Bits */
    204              tmpccmrx &= Tab_OCModeMask[TIM_OCInitStruct->TIM_Channel];
    205          
    206              /* Set the Output Polarity level */
    207              tmpccer &= Tab_PolarityMask[TIM_OCInitStruct->TIM_Channel];
    208          
    209              if (TIM_OCInitStruct->TIM_Channel == TIM_Channel_1)
    210              {
    211                /* Disable the Channel 1: Reset the CCE Bit */
    212                TIMx->CCER &= CCER_CC1E_Reset;
    213          
    214                /* Select the Output Compare Mode */
    215                tmpccmrx |= TIM_OCInitStruct->TIM_OCMode;
    216          
    217                /* Set the Capture Compare Register value */
    218                TIMx->CCR1 = TIM_OCInitStruct->TIM_Pulse;
    219          
    220                /* Set the Capture Compare Enable Bit */
    221                if (TIM_OCInitStruct->TIM_OCMode != TIM_OCMode_Timing) // D.JIANG
    222                  tmpccer |= CCER_CC1E_Set;
    223          
    224                /* Set the Capture Compare Polarity */
    225                tmpccer |= TIM_OCInitStruct->TIM_OCPolarity;
    226              }
    227              else /* TIM_Channel_2 */
    228              {
    229                /* Disable the Channel 2: Reset the CCE Bit */
    230                TIMx->CCER &= CCER_CC2E_Reset;
    231          
    232                /* Select the Output Compare Mode */
    233                tmpccmrx |= (u32)TIM_OCInitStruct->TIM_OCMode << 8;
    234          
    235                /* Set the Capture Compare Register value */
    236                TIMx->CCR2 = TIM_OCInitStruct->TIM_Pulse;
    237          
    238                /* Set the Capture Compare Enable Bit */
    239                if (TIM_OCInitStruct->TIM_OCMode != TIM_OCMode_Timing) // D.JIANG
    240                  tmpccer |= CCER_CC2E_Set;
    241          
    242                /* Set the Capture Compare Polarity */
    243                tmpccer |= (u32)TIM_OCInitStruct->TIM_OCPolarity << 4;
    244              }
    245          
    246              TIMx->CCMR1 = (u16)tmpccmrx;
    247            }
    248            else 
    249            {
    250              if ((TIM_OCInitStruct->TIM_Channel == TIM_Channel_3) ||
    251                  (TIM_OCInitStruct->TIM_Channel == TIM_Channel_4))
    252              { 
    253                tmpccmrx = TIMx->CCMR2;
    254          
    255                /* Reset the Output Compare Bits */
    256                tmpccmrx &= Tab_OCModeMask[TIM_OCInitStruct->TIM_Channel];
    257          
    258                /* Set the Output Polarity level */
    259                tmpccer &= Tab_PolarityMask[TIM_OCInitStruct->TIM_Channel];
    260          
    261                if (TIM_OCInitStruct->TIM_Channel == TIM_Channel_3)
    262                {
    263                  /* Disable the Channel 3: Reset the CCE Bit */
    264                  TIMx->CCER &= CCER_CC3E_Reset;
    265          
    266                  /* Select the Output Compare Mode */
    267                  tmpccmrx |= TIM_OCInitStruct->TIM_OCMode;
    268          
    269                  /* Set the Capture Compare Register value */
    270                  TIMx->CCR3 = TIM_OCInitStruct->TIM_Pulse;
    271          
    272                  /* Set the Capture Compare Enable Bit */
    273                  if (TIM_OCInitStruct->TIM_OCMode != TIM_OCMode_Timing) // D.JIANG
    274                    tmpccer |= CCER_CC3E_Set;
    275          
    276                  /* Set the Capture Compare Polarity */
    277                  tmpccer |= (u32)TIM_OCInitStruct->TIM_OCPolarity << 8;
    278                }
    279                else  /* TIM_Channel_4 */
    280                {
    281                  /* Disable the Channel 4: Reset the CCE Bit */
    282                  TIMx->CCER &= CCER_CC4E_Reset;
    283          
    284                 /* Select the Output Compare Mode */
    285                  tmpccmrx |= (u32)TIM_OCInitStruct->TIM_OCMode << 8;
    286          
    287                  /* Set the Capture Compare Register value */
    288                  TIMx->CCR4 = TIM_OCInitStruct->TIM_Pulse;
    289          
    290                  /* Set the Capture Compare Enable Bit */
    291                  if (TIM_OCInitStruct->TIM_OCMode != TIM_OCMode_Timing) // D.JIANG
    292                    tmpccer |= CCER_CC4E_Set;
    293          
    294                  /* Set the Capture Compare Polarity */
    295                  tmpccer |= (u32)TIM_OCInitStruct->TIM_OCPolarity << 12;
    296                }
    297          
    298                TIMx->CCMR2 = (u16)tmpccmrx;
    299              }
    300            }
    301            
    302            TIMx->CCER = (u16)tmpccer;
    303          }
    304          
    305          /*******************************************************************************
    306          * Function Name  : TIM_ICInit
    307          * Description    : Initializes the TIMx peripheral according to the specified
    308          *                  parameters in the TIM_ICInitStruct.
    309          * Input          : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
    310          *                  - TIM_ICInitStruct: pointer to a TIM_ICInitTypeDef structure
    311          *                    that contains the configuration information for the specified
    312          *                    TIM peripheral.
    313          * Output         : None
    314          * Return         : None
    315          *******************************************************************************/
    316          void TIM_ICInit(TIM_TypeDef* TIMx, TIM_ICInitTypeDef* TIM_ICInitStruct)
    317          {
    318            /* Check the parameters */
    319            assert(IS_TIM_IC_MODE(TIM_ICInitStruct->TIM_ICMode));
    320            assert(IS_TIM_CHANNEL(TIM_ICInitStruct->TIM_Channel));
    321            assert(IS_TIM_IC_POLARITY(TIM_ICInitStruct->TIM_ICPolarity));
    322            assert(IS_TIM_IC_SELECTION(TIM_ICInitStruct->TIM_ICSelection));
    323            assert(IS_TIM_IC_PRESCALER(TIM_ICInitStruct->TIM_ICPrescaler));
    324            assert(IS_TIM_IC_FILTER(TIM_ICInitStruct->TIM_ICFilter));
    325            
    326            if (TIM_ICInitStruct->TIM_ICMode == TIM_ICMode_ICAP)
    327            {
    328              if (TIM_ICInitStruct->TIM_Channel == TIM_Channel_1)
    329              {
    330                /* TI1 Configuration */
    331                TI1_Config(TIMx, TIM_ICInitStruct->TIM_ICPolarity,
    332                           TIM_ICInitStruct->TIM_ICSelection,
    333                           TIM_ICInitStruct->TIM_ICFilter);
    334          
    335                /* Set the Input Capture Prescaler value */
    336                TIM_SetIC1Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler);
    337              }
    338              else if (TIM_ICInitStruct->TIM_Channel == TIM_Channel_2)
    339              {
    340                /* TI2 Configuration */
    341                TI2_Config(TIMx, TIM_ICInitStruct->TIM_ICPolarity,
    342                           TIM_ICInitStruct->TIM_ICSelection,
    343                           TIM_ICInitStruct->TIM_ICFilter);
    344          
    345                /* Set the Input Capture Prescaler value */
    346                TIM_SetIC2Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler);
    347              }
    348              else if (TIM_ICInitStruct->TIM_Channel == TIM_Channel_3)
    349              {
    350                /* TI3 Configuration */
    351                TI3_Config(TIMx, TIM_ICInitStruct->TIM_ICPolarity,
    352                           TIM_ICInitStruct->TIM_ICSelection,
    353                           TIM_ICInitStruct->TIM_ICFilter);
    354          
    355                /* Set the Input Capture Prescaler value */
    356                TIM_SetIC3Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler);
    357              }
    358              else /* TIM_Channel_4 */
    359              {
    360                /* TI4 Configuration */
    361                TI4_Config(TIMx, TIM_ICInitStruct->TIM_ICPolarity,
    362                           TIM_ICInitStruct->TIM_ICSelection,
    363                           TIM_ICInitStruct->TIM_ICFilter);
    364          
    365                /* Set the Input Capture Prescaler value */
    366                TIM_SetIC4Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler);
    367              }
    368            }
    369            else
    370            {
    371              PWMI_Config(TIMx, TIM_ICInitStruct);
    372            }
    373          }
    374          
    375          /*******************************************************************************
    376          * Function Name  : TIM_TimeBaseStructInit
    377          * Description    : Fills each TIM_TimeBaseInitStruct member with its default value.
    378          * Input          : - TIM_TimeBaseInitStruct: pointer to a TIM_TimeBaseInitTypeDef
    379          *                    structure which will be initialized.
    380          * Output         : None
    381          * Return         : None
    382          *******************************************************************************/
    383          void TIM_TimeBaseStructInit(TIM_TimeBaseInitTypeDef* TIM_TimeBaseInitStruct)
    384          {
    385            /* Set the default configuration */
    386            TIM_TimeBaseInitStruct->TIM_Period = TIM_Period_Reset_Mask;
    387            TIM_TimeBaseInitStruct->TIM_Prescaler = TIM_Prescaler_Reset_Mask;
    388            TIM_TimeBaseInitStruct->TIM_ClockDivision = TIM_CKD_DIV1;
    389            TIM_TimeBaseInitStruct->TIM_CounterMode = TIM_CounterMode_Up;
    390          }
    391          
    392          /*******************************************************************************
    393          * Function Name  : TIM_OCStructInit
    394          * Description    : Fills each TIM_OCInitStruct member with its default value.
    395          * Input          : - TIM_OCInitStruct: pointer to a TIM_OCInitTypeDef structure
    396          *                    which will be initialized.
    397          * Output         : None
    398          * Return         : None
    399          *******************************************************************************/
    400          void TIM_OCStructInit(TIM_OCInitTypeDef* TIM_OCInitStruct)
    401          {

⌨️ 快捷键说明

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