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

📄 stm32f10x_tim1.lst

📁 STM32利用正交编码器实现电机的控制
💻 LST
📖 第 1 页 / 共 5 页
字号:
    832          *                       - TIM1_IT_Update: TIM1 update Interrupt source
    833          *                       - TIM1_IT_CC1: TIM1 Capture Compare 1 Interrupt source
    834          *                       - TIM1_IT_CC2: TIM1 Capture Compare 2 Interrupt source
    835          *                       - TIM1_IT_CC3: TIM1 Capture Compare 3 Interrupt source
    836          *                       - TIM1_IT_CC4: TIM1 Capture Compare 4 Interrupt source
    837          *                       - TIM1_IT_CCUpdate: TIM1 Capture Compare Update Interrupt
    838          *                         source
    839          *                       - TIM1_IT_Trigger: TIM1 Trigger Interrupt source
    840          *                       - TIM1_IT_Break: TIM1 Break Interrupt source
    841          *                  - Newstate: new state of the TIM1 interrupts.
    842          *                    This parameter can be: ENABLE or DISABLE.
    843          * Output         : None
    844          * Return         : None
    845          *******************************************************************************/
    846          void TIM1_ITConfig(u16 TIM1_IT, FunctionalState NewState)
    847          {
    848            /* Check the parameters */
    849            assert(IS_TIM1_IT(TIM1_IT));
    850            assert(IS_FUNCTIONAL_STATE(NewState));
    851          
    852            if (NewState == ENABLE)
    853            {
    854              /* Enable the Interrupt sources */
    855              TIM1->DIER |= TIM1_IT;
    856            }
    857            else
    858            {
    859              /* Disable the Interrupt sources */
    860              TIM1->DIER &= (u16)~TIM1_IT;
    861            }
    862          }
    863          
    864          /*******************************************************************************
    865          * Function Name  : TIM1_DMAConfig
    866          * Description    : Configures the TIM1抯 DMA interface.
    867          * Input          : - TIM1_DMABase: DMA Base address.
    868          *                    This parameter can be one of the following values:
    869          *                       - TIM1_DMABase_CR1, TIM1_DMABase_CR2, TIM1_DMABase_SMCR,
    870          *                         TIM1_DMABase_DIER, TIM1_DMABase_SR, TIM1_DMABase_EGR,
    871          *                         TIM1_DMABase_CCMR1, TIM1_DMABase_CCMR2, TIM1_DMABase_CCER,
    872          *                         TIM1_DMABase_CNT, TIM1_DMABase_PSC, TIM1_DMABase_ARR,
    873          *                         TIM1_DMABase_RCR, TIM1_DMABase_CCR1, TIM1_DMABase_CCR2,
    874          *                         TIM1_DMABase_CCR3, TIM1_DMABase_CCR4, TIM1_DMABase_BDTR,
    875          *                         TIM1_DMABase_DCR.
    876          *                   - TIM1_DMABurstLength: DMA Burst length.
    877          *                     This parameter can be one value between:
    878          *                     TIM1_DMABurstLength_1Byte and TIM1_DMABurstLength_18Bytes.
    879          * Output         : None
    880          * Return         : None
    881          *******************************************************************************/
    882          void TIM1_DMAConfig(u16 TIM1_DMABase, u16 TIM1_DMABurstLength)
    883          {
    884            u32 tmpdcr = 0;
    885          
    886            /* Check the parameters */
    887            assert(IS_TIM1_DMA_BASE(TIM1_DMABase));
    888            assert(IS_TIM1_DMA_LENGTH(TIM1_DMABurstLength));
    889          
    890            tmpdcr = TIM1->DCR;
    891          
    892            /* Reset the DBA and the DBL Bits */
    893            tmpdcr &= DCR_DMA_Mask;
    894          
    895            /* Set the DMA Base and the DMA Burst Length */
    896            tmpdcr |= TIM1_DMABase | TIM1_DMABurstLength;
    897          
    898            TIM1->DCR = (u16)tmpdcr;
    899          }
    900          
    901          /*******************************************************************************
    902          * Function Name  : TIM1_DMACmd
    903          * Description    : Enables or disables the TIM1抯 DMA Requests.
    904          * Input          : - TIM1_DMASources: specifies the DMA Request sources.
    905          *                    This parameter can be any combination of the following values:
    906          *                       - TIM1_DMA_Update: TIM1 update Interrupt source
    907          *                       - TIM1_DMA_CC1: TIM1 Capture Compare 1 DMA source
    908          *                       - TIM1_DMA_CC2: TIM1 Capture Compare 2 DMA source
    909          *                       - TIM1_DMA_CC3: TIM1 Capture Compare 3 DMA source
    910          *                       - TIM1_DMA_CC4: TIM1 Capture Compare 4 DMA source
    911          *                       - TIM1_DMA_COM: TIM1 Capture Compare Update DMA
    912          *                         source
    913          *                       - TIM1_DMA_Trigger: TIM1 Trigger DMA source
    914          *                  - Newstate: new state of the DMA Request sources.
    915          *                    This parameter can be: ENABLE or DISABLE.
    916          * Output         : None
    917          * Return         : None
    918          *******************************************************************************/
    919          void TIM1_DMACmd(u16 TIM1_DMASource, FunctionalState Newstate)
    920          {
    921            u32 tmpdier = 0;
    922          
    923            /* Check the parameters */
    924            assert(IS_TIM1_DMA_SOURCE(TIM1_DMASource));
    925            assert(IS_FUNCTIONAL_STATE(Newstate));
    926          
    927            tmpdier = TIM1->DIER;
    928          
    929            if (Newstate == ENABLE)
    930            {
    931              /* Enable the DMA sources */
    932              tmpdier |= TIM1_DMASource;
    933            }
    934            else
    935            {
    936              /* Disable the DMA sources */
    937              tmpdier &= (u16)~TIM1_DMASource;
    938            }
    939            TIM1->DIER = (u16)tmpdier;
    940          }
    941          
    942          /*******************************************************************************
    943          * Function Name  : TIM1_InternalClockConfig
    944          * Description    : Configures the TIM1 interrnal Clock
    945          * Input          : None
    946          * Output         : None
    947          * Return         : None
    948          *******************************************************************************/
    949          void TIM1_InternalClockConfig(void)
    950          {
    951            /* Disable slave mode to clock the prescaler directly with the internal clock */
    952            TIM1->SMCR &=  SMCR_SMS_Mask;
    953          }
    954          /*******************************************************************************
    955          * Function Name  : TIM1_ETRClockMode1Config
    956          * Description    : Configures the TIM1 External clock Mode1
    957          * Input          : - TIM1_ExtTRGPrescaler: The external Trigger Prescaler.
    958          *                    It can be one of the following values:
    959          *                       - TIM1_ExtTRGPSC_OFF
    960          *                       - TIM1_ExtTRGPSC_DIV2
    961          *                       - TIM1_ExtTRGPSC_DIV4
    962          *                       - TIM1_ExtTRGPSC_DIV8.
    963          *                  - TIM1_ExtTRGPolarity: The external Trigger Polarity.
    964          *                    It can be one of the following values:
    965          *                       - TIM1_ExtTRGPolarity_Inverted
    966          *                       - TIM1_ExtTRGPolarity_NonInverted
    967          *                  - ExtTRGFilter: External Trigger Filter.
    968          *                    This parameter must be a value between 0x00 and 0x0F
    969          * Output         : None
    970          * Return         : None
    971          *******************************************************************************/
    972          void TIM1_ETRClockMode1Config(u16 TIM1_ExtTRGPrescaler, u16 TIM1_ExtTRGPolarity,
    973                                       u16 ExtTRGFilter)
    974          {
    975            /* Check the parameters */
    976            assert(IS_TIM1_EXT_PRESCALER(TIM1_ExtTRGPrescaler));
    977            assert(IS_TIM1_EXT_POLARITY(TIM1_ExtTRGPolarity));
    978          
    979            /* Configure the ETR Clock source */
    980            TIM1_ETRConfig(TIM1_ExtTRGPrescaler, TIM1_ExtTRGPolarity, ExtTRGFilter);
    981          
    982            /* Select the External clock mode1 */
    983            TIM1->SMCR &= SMCR_SMS_Mask;
    984            TIM1->SMCR |= TIM1_SlaveMode_External1;
    985            
    986            /* Select the Trigger selection : ETRF */
    987            TIM1->SMCR &= SMCR_TS_Mask;
    988            TIM1->SMCR |= TIM1_TS_ETRF;
    989          }
    990          
    991          /*******************************************************************************
    992          * Function Name  : TIM1_ETRClockMode2Config
    993          * Description    : Configures the TIM1 External clock Mode2
    994          * Input          : - TIM1_ExtTRGPrescaler: The external Trigger Prescaler.
    995          *                    It can be one of the following values:
    996          *                       - TIM1_ExtTRGPSC_OFF
    997          *                       - TIM1_ExtTRGPSC_DIV2
    998          *                       - TIM1_ExtTRGPSC_DIV4
    999          *                       - TIM1_ExtTRGPSC_DIV8
   1000          *                  - TIM1_ExtTRGPolarity: The external Trigger Polarity.
   1001          *                    It can be one of the following values:
   1002          *                       - TIM1_ExtTRGPolarity_Inverted
   1003          *                       - TIM1_ExtTRGPolarity_NonInverted
   1004          *                  - ExtTRGFilter: External Trigger Filter.
   1005          *                    This parameter must be a value between 0x00 and 0x0F
   1006          * Output         : None
   1007          * Return         : None
   1008          *******************************************************************************/
   1009          void TIM1_ETRClockMode2Config(u16 TIM1_ExtTRGPrescaler, u16 TIM1_ExtTRGPolarity,
   1010                                       u16 ExtTRGFilter)
   1011          {
   1012            /* Check the parameters */
   1013            assert(IS_TIM1_EXT_PRESCALER(TIM1_ExtTRGPrescaler));
   1014            assert(IS_TIM1_EXT_POLARITY(TIM1_ExtTRGPolarity));
   1015          
   1016            /* Configure the ETR Clock source */
   1017            TIM1_ETRConfig(TIM1_ExtTRGPrescaler, TIM1_ExtTRGPolarity, ExtTRGFilter);
   1018          
   1019            /* Enable the External clock mode2 */
   1020            *(vu32 *) SMCR_ECE_BB = SMCR_ECE_Set;
   1021          }
   1022          
   1023          /*******************************************************************************
   1024          * Function Name  : TIM1_ETRConfig
   1025          * Description    : Configures the TIM1 External Trigger (ETR).
   1026          * Input          : - TIM1_ExtTRGPrescaler: The external Trigger Prescaler.
   1027          *                    This parameter can be one of the following values:
   1028          *                       - TIM1_ExtTRGPSC_OFF
   1029          *                       - TIM1_ExtTRGPSC_DIV2
   1030          *                       - TIM1_ExtTRGPSC_DIV4
   1031          *                       - TIM1_ExtTRGPSC_DIV8
   1032          *                  - TIM1_ExtTRGPolarity: The external Trigger Polarity.
   1033          *                    This parameter can be one of the following values:
   1034          *                       - TIM1_ExtTRGPolarity_Inverted
   1035          *                       - TIM1_ExtTRGPolarity_NonInverted
   1036          *                  - ExtTRGFilter: External Trigger Filter.
   1037          *                    This parameter must be a value between 0x00 and 0x0F.
   1038          * Output         : None
   1039          * Return         : None
   1040          *******************************************************************************/
   1041          void TIM1_ETRConfig(u16 TIM1_ExtTRGPrescaler, u16 TIM1_ExtTRGPolarity,
   1042                              u16 ExtTRGFilter)
   1043          {
   1044            u32 tmpsmcr = 0;
   1045          
   1046            tmpsmcr = TIM1->SMCR;
   1047          
   1048            /* Set the Prescaler, the Filter value and the Polarity */
   1049            tmpsmcr &= SMCR_ETR_Mask;
   1

⌨️ 快捷键说明

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