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

📄 stm32f10x_adc.lst

📁 STM32利用正交编码器实现电机的控制
💻 LST
📖 第 1 页 / 共 5 页
字号:
    625              tmpreg2 = (u32)SQR2_SQ_Set << (5 * (Rank - 7));
    626              /* Clear the old SQx bits for the selected rank */
    627              tmpreg1 &= ~tmpreg2;
    628              /* Calculate the mask to set */
    629              tmpreg2 = (u32)ADC_Channel << (5 * (Rank - 7));
    630              /* Set the SQx bits for the selected rank */
    631              tmpreg1 |= tmpreg2;
    632              /* Store the new register value */
    633              ADCx->SQR2 = tmpreg1;
    634            }
    635            /* For Rank 13 to 16 */
    636            else
    637            {
    638              /* Get the old register value */
    639              tmpreg1 = ADCx->SQR1;
    640              /* Calculate the mask to clear */
    641              tmpreg2 = (u32)SQR1_SQ_Set << (5 * (Rank - 13));
    642              /* Clear the old SQx bits for the selected rank */
    643              tmpreg1 &= ~tmpreg2;
    644              /* Calculate the mask to set */
    645              tmpreg2 = (u32)ADC_Channel << (5 * (Rank - 13));
    646              /* Set the SQx bits for the selected rank */
    647              tmpreg1 |= tmpreg2;
    648              /* Store the new register value */
    649              ADCx->SQR1 = tmpreg1;
    650            }
    651          }
    652          
    653          /*******************************************************************************
    654          * Function Name  : ADC_ExternalTrigConvCmd
    655          * Description    : Enables or disables the ADCx conversion through external trigger.
    656          * Input          : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
    657          *                  - NewState: new state of the selected ADC external trigger
    658          *                    start of conversion.
    659          *                    This parameter can be: ENABLE or DISABLE.
    660          * Output         : None
    661          * Return         : None
    662          *******************************************************************************/
    663          void ADC_ExternalTrigConvCmd(ADC_TypeDef* ADCx, FunctionalState NewState)
    664          {
    665            /* Check the parameters */
    666            assert(IS_FUNCTIONAL_STATE(NewState));
    667          
    668            if (NewState != DISABLE)
    669            {
    670              /* Enable the selected ADC conversion on external event */
    671              ADCx->CR2 |= CR2_EXTTRIG_Set;
    672            }
    673            else
    674            {
    675              /* Disable the selected ADC conversion on external event */
    676              ADCx->CR2 &= CR2_EXTTRIG_Reset;
    677            }
    678          }
    679          
    680          /*******************************************************************************
    681          * Function Name  : ADC_GetConversionValue
    682          * Description    : Returns the last ADCx conversion result data for regular channel.
    683          * Input          : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
    684          * Output         : None
    685          * Return         : The Data conversion value.
    686          *******************************************************************************/
    687          u16 ADC_GetConversionValue(ADC_TypeDef* ADCx)
    688          {
    689            /* Return the selected ADC conversion value */
    690            return (u16) ADCx->DR;
    691          }
    692          
    693          /*******************************************************************************
    694          * Function Name  : ADC_GetDualModeConversionValue
    695          * Description    : Returns the last ADCs conversion result data in dual mode.
    696          * Output         : None
    697          * Return         : The Data conversion value.
    698          *******************************************************************************/
    699          u32 ADC_GetDualModeConversionValue(void)
    700          {
    701            /* Return the dual mode conversion value */
    702            return ADC1->DR;
    703          }
    704          
    705          /*******************************************************************************
    706          * Function Name  : ADC_AutoInjectedConvCmd
    707          * Description    : Enables or disables the selected ADC automatic injected group
    708          *                  conversion after regular one.
    709          * Input          : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
    710          *                  - NewState: new state of the selected ADC auto injected
    711          *                    conversion
    712          *                    This parameter can be: ENABLE or DISABLE.
    713          * Output         : None
    714          * Return         : None
    715          *******************************************************************************/
    716          void ADC_AutoInjectedConvCmd(ADC_TypeDef* ADCx, FunctionalState NewState)
    717          {
    718            /* Check the parameters */
    719            assert(IS_FUNCTIONAL_STATE(NewState));
    720          
    721            if (NewState != DISABLE)
    722            {
    723              /* Enable the selected ADC automatic injected group conversion */
    724              ADCx->CR1 |= CR1_JAUTO_Set;
    725            }
    726            else
    727            {
    728              /* Disable the selected ADC automatic injected group conversion */
    729              ADCx->CR1 &= CR1_JAUTO_Reset;
    730            }
    731          }
    732          
    733          /*******************************************************************************
    734          * Function Name  : ADC_InjectedDiscModeCmd
    735          * Description    : Enables or disables the discontinuous mode for injected group
    736          *                  channel for the specified ADC
    737          * Input          : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
    738          *                  - NewState: new state of the selected ADC discontinuous mode
    739          *                    on injected group channel.
    740          *                    This parameter can be: ENABLE or DISABLE.
    741          * Output         : None
    742          * Return         : None
    743          *******************************************************************************/
    744          void ADC_InjectedDiscModeCmd(ADC_TypeDef* ADCx, FunctionalState NewState)
    745          {
    746            /* Check the parameters */
    747            assert(IS_FUNCTIONAL_STATE(NewState));
    748          
    749            if (NewState != DISABLE)
    750            {
    751              /* Enable the selected ADC injected discontinuous mode */
    752              ADCx->CR1 |= CR1_JDISCEN_Set;
    753            }
    754            else
    755            {
    756              /* Disable the selected ADC injected discontinuous mode */
    757              ADCx->CR1 &= CR1_JDISCEN_Reset;
    758            }
    759          }
    760          
    761          /*******************************************************************************
    762          * Function Name  : ADC_ExternalTrigInjectedConvConfig
    763          * Description    : Configures the ADCx external trigger for injected channels conversion.
    764          * Input          : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
    765          *                  - ADC_ExternalTrigInjecConv: specifies the ADC trigger to
    766          *                    start injected conversion. 
    767          *                    This parameter can be one of the following values:
    768          *                       - ADC_ExternalTrigInjecConv_T1_TRGO: Timer1 TRGO event 
    769          *                         selected
    770          *                       - ADC_ExternalTrigInjecConv_T1_CC4: Timer1 capture
    771          *                         compare4 selected
    772          *                       - ADC_ExternalTrigInjecConv_T2_TRGO: Timer2 TRGO event
    773          *                         selected
    774          *                       - ADC_External TrigInjecConv_T2_CC1: Timer2 capture
    775          *                         compare1 selected
    776          *                       - ADC_ExternalTrigInjecConv_T3_CC4: Timer3 capture
    777          *                         compare4 selected
    778          *                       - ADC_ExternalTrigInjecConv_T4_TRGO: Timer4 TRGO event
    779          *                         selected 
    780          *                       - ADC_ExternalTrigInjecConv_Ext_Interrupt15: External
    781          *                         interrupt 15 event selected
    782          *                       - ADC_ExternalTrigInjecConv_None: Injected conversion
    783          *                         started by software and not by external trigger
    784          * Output         : None
    785          * Return         : None
    786          *******************************************************************************/
    787          void ADC_ExternalTrigInjectedConvConfig(ADC_TypeDef* ADCx, u32 ADC_ExternalTrigInjecConv)
    788          {
    789            u32 tmpreg = 0;
    790          
    791            /* Check the parameters */
    792            assert(IS_ADC_EXT_INJEC_TRIG(ADC_ExternalTrigInjecConv));
    793          
    794            /* Get the old register value */
    795            tmpreg = ADCx->CR2;
    796            /* Clear the old external event selection for injected group */
    797            tmpreg &= CR2_JEXTSEL_Reset;
    798            /* Set the external event selection for injected group */
    799            tmpreg |= ADC_ExternalTrigInjecConv;
    800            /* Store the new register value */
    801            ADCx->CR2 = tmpreg;
    802          }
    803          
    804          /*******************************************************************************
    805          * Function Name  : ADC_ExternalTrigInjectedConvCmd
    806          * Description    : Enables or disables the ADCx injected channels conversion
    807          *                  through external trigger
    808          * Input          : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
    809          *                  - NewState: new state of the selected ADC external trigger
    810          *                    start of injected conversion.
    811          *                    This parameter can be: ENABLE or DISABLE.
    812          * Output         : None
    813          * Return         : None
    814          *******************************************************************************/
    815          void ADC_ExternalTrigInjectedConvCmd(ADC_TypeDef* ADCx, FunctionalState NewState)
    816          {
    817            /* Check the parameters */
    818            assert(IS_FUNCTIONAL_STATE(NewState));
    819          
    820            if (NewState != DISABLE)
    821            {
    822              /* Enable the selected ADC external event selection for injected group */
    823              ADCx->CR2 |= CR2_JEXTTRIG_Set;
    824            }
    825            else
    826            {
    827              /* Disable the selected ADC external event selection for injected group */
    828              ADCx->CR2 &= CR2_JEXTTRIG_Reset;
    829            }
    830          }
    831          
    832          /*******************************************************************************
    833          * Function Name  : ADC_SoftwareStartInjectedConvCmd
    834          * Description    : Enables or disables the selected ADC start of the injected 
    835          *                  channels conversion.
    836          * Input          : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
    837          *                  - NewState: new state of the selected ADC software start
    838          *                    injected conversion.
    839          *                    This parameter can be: ENABLE or DISABLE.
    840          * Output         : None
    841          * Return         : None
    842          *******************************************************************************/
    843          void ADC_SoftwareStartInjectedConvCmd(ADC_TypeDef* ADCx, FunctionalState NewState)
    844          {
    845            /* Check the parameters */
    846            assert(IS_FUNCTIONAL_STATE(NewState));
    847          

⌨️ 快捷键说明

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