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

📄 stm32f10x_adc.lst

📁 STM32利用正交编码器实现电机的控制
💻 LST
📖 第 1 页 / 共 5 页
字号:
    848            if (NewState != DISABLE)
    849            {
    850              /* Enable the selected ADC external event selection for injected group */
    851              /* Starts the selected ADC injected conversion */
    852              ADCx->CR2 |= CR2_JEXTTRIG_JSWSTRT_Set;
    853            }
    854            else
    855            {
    856              /* Stops the selected ADC injected conversion */
    857              /* Disable the selected ADC external event selection for injected group */
    858          	ADCx->CR2 &= CR2_JEXTTRIG_JSWSTRT_Reset;
    859            }
    860          }
    861          
    862          /*******************************************************************************
    863          * Function Name  : ADC_GetSoftwareStartInjectedConvCmdStatus
    864          * Description    : Gets the selected ADC Software start injected conversion Status.
    865          * Input          : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
    866          * Output         : None
    867          * Return         : The new state of ADC software start injected conversion (SET or RESET).
    868          *******************************************************************************/
    869          FlagStatus ADC_GetSoftwareStartInjectedConvCmdStatus(ADC_TypeDef* ADCx)
    870          {
    871            FlagStatus bitstatus = RESET;
    872          
    873            /* Check the status of JSWSTRT bit */
    874            if ((ADCx->CR2 & CR2_JSWSTRT_Set) != (u32)RESET)
    875            {
    876              /* JSWSTRT bit is set */
    877              bitstatus = SET;
    878            }
    879            else
    880            {
    881              /* JSWSTRT bit is reset */
    882              bitstatus = RESET;
    883            }
    884            /* Return the JSWSTRT bit status */
    885            return  bitstatus;
    886          }
    887          
    888          /*******************************************************************************
    889          * Function Name  : ADC_InjectedChannelConfig
    890          * Description    : Configures for the selected ADC injected channel its corresponding
    891          *                  rank in the sequencer and its sample time.
    892          * Input          : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
    893          *                  - ADC_Channel: the ADC channel to configure. 
    894          *                    This parameter can be one of the following values:
    895          *                       - ADC_Channel_0: ADC Channel0 selected
    896          *                       - ADC_Channel_1: ADC Channel1 selected
    897          *                       - ADC_Channel_2: ADC Channel2 selected
    898          *                       - ADC_Channel_3: ADC Channel3 selected
    899          *                       - ADC_Channel_4: ADC Channel4 selected
    900          *                       - ADC_Channel_5: ADC Channel5 selected
    901          *                       - ADC_Channel_6: ADC Channel6 selected
    902          *                       - ADC_Channel_7: ADC Channel7 selected
    903          *                       - ADC_Channel_8: ADC Channel8 selected
    904          *                       - ADC_Channel_9: ADC Channel9 selected
    905          *                       - ADC_Channel_10: ADC Channel10 selected
    906          *                       - ADC_Channel_11: ADC Channel11 selected
    907          *                       - ADC_Channel_12: ADC Channel12 selected
    908          *                       - ADC_Channel_13: ADC Channel13 selected
    909          *                       - ADC_Channel_14: ADC Channel14 selected
    910          *                       - ADC_Channel_15: ADC Channel15 selected
    911          *                       - ADC_Channel_16: ADC Channel16 selected
    912          *                       - ADC_Channel_17: ADC Channel17 selected
    913          *                  - Rank: The rank in the injected group sequencer. This parameter
    914          *                    must be between 1 to 4.
    915          *                  - ADC_SampleTime: The sample time value to be set for the
    916          *                    selected channel. 
    917          *                    This parameter can be one of the following values:
    918          *                       - ADC_SampleTime_1Cycles5: Sample time equal to 1.5 cycles
    919          *                       - ADC_SampleTime_7Cycles5: Sample time equal to 7.5 cycles
    920          *                       - ADC_SampleTime_13Cycles5: Sample time equal to 13.5 cycles
    921          *                       - ADC_SampleTime_28Cycles5: Sample time equal to 28.5 cycles	
    922          *                       - ADC_SampleTime_41Cycles5: Sample time equal to 41.5 cycles	
    923          *                       - ADC_SampleTime_55Cycles5: Sample time equal to 55.5 cycles	
    924          *                       - ADC_SampleTime_71Cycles5: Sample time equal to 71.5 cycles	
    925          *                       - ADC_SampleTime_239Cycles5: Sample time equal to 239.5 cycles	
    926          * Output         : None
    927          * Return         : None
    928          *******************************************************************************/
    929          void ADC_InjectedChannelConfig(ADC_TypeDef* ADCx, u8 ADC_Channel, u8 Rank, u8 ADC_SampleTime)
    930          {
    931            u32 tmpreg1 = 0, tmpreg2 = 0;
    932            u8 tmpreg3 = 0;
    933          
    934            /* Check the parameters */
    935            assert(IS_ADC_CHANNEL(ADC_Channel));
    936            assert(IS_ADC_INJECTED_RANK(Rank));
    937            assert(IS_ADC_SAMPLE_TIME(ADC_SampleTime));
    938          
    939            /* if ADC_Channel_10 ... ADC_Channel_17 is selected */
    940            if (ADC_Channel > ADC_Channel_9)
    941            {
    942              /* Get the old register value */
    943              tmpreg1 = ADCx->SMPR1;
    944              /* Calculate the mask to clear */
    945              tmpreg2 = (u32)SMPR1_SMP_Set << (3*(ADC_Channel - 10));
    946              /* Clear the old discontinuous mode channel count */
    947              tmpreg1 &= ~tmpreg2;
    948              /* Calculate the mask to set */
    949              tmpreg2 = (u32)ADC_SampleTime << (3*(ADC_Channel - 10));
    950              /* Set the discontinuous mode channel count */
    951              tmpreg1 |= tmpreg2;
    952              /* Store the new register value */
    953              ADCx->SMPR1 = tmpreg1;
    954            }
    955            else /* ADC_Channel include in ADC_Channel_[0..9] */
    956            {
    957              /* Get the old register value */
    958              tmpreg1 = ADCx->SMPR2;
    959              /* Calculate the mask to clear */
    960              tmpreg2 = (u32)SMPR2_SMP_Set << (3 * ADC_Channel);
    961              /* Clear the old discontinuous mode channel count */
    962              tmpreg1 &= ~tmpreg2;
    963              /* Calculate the mask to set */
    964              tmpreg2 = (u32)ADC_SampleTime << (3 * ADC_Channel);
    965              /* Set the discontinuous mode channel count */
    966              tmpreg1 |= tmpreg2;
    967              /* Store the new register value */
    968              ADCx->SMPR2 = tmpreg1;
    969            }
    970          
    971            /* Rank configuration */
    972            /* Get the old register value */
    973            tmpreg1 = ADCx->JSQR;
    974            /* Get JL value: Number = JL+1 */
    975            tmpreg3 =  (u8)((tmpreg1 & (u32)~JSQR_JL_Reset)>> 20);
    976            /* Calculate the mask to clear: ((Rank-1)+(4-JL-1)) */
    977            tmpreg2 = (u32)JSQR_JSQ_Set << (5 * ((Rank + 3) - (tmpreg3 + 1)));
    978            /* Clear the old JSQx bits for the selected rank */
    979            tmpreg1 &= ~tmpreg2;
    980            /* Calculate the mask to set: ((Rank-1)+(4-JL-1)) */
    981            tmpreg2 = (u32)ADC_Channel << (5 * ((Rank + 3) - (tmpreg3 + 1)));
    982            /* Set the JSQx bits for the selected rank */
    983            tmpreg1 |= tmpreg2;
    984            /* Store the new register value */
    985            ADCx->JSQR = tmpreg1;
    986          }
    987          
    988          /*******************************************************************************
    989          * Function Name  : ADC_InjectedSequencerLengthConfig
    990          * Description    : Configures the sequencer length for injected channels
    991          * Input          : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
    992          *                  - Length: The sequencer length. 
    993          *                    This parameter must be a number between 1 to 4.
    994          * Output         : None
    995          * Return         : None
    996          *******************************************************************************/
    997          void ADC_InjectedSequencerLengthConfig(ADC_TypeDef* ADCx, u8 Length)
    998          {
    999            u32 tmpreg1 = 0;
   1000            u8 tmpreg2 = 0;
   1001          
   1002            /* Check the parameters */
   1003            assert(IS_ADC_INJECTED_LENGTH(Length));
   1004            
   1005            /* Get the old register value */
   1006            tmpreg1 = ADCx->JSQR;
   1007            /* Clear the old injected sequnence lenght JL bits */
   1008            tmpreg1 &= JSQR_JL_Reset;
   1009            /* Set the injected sequnence lenght JL bits */
   1010            tmpreg2 = Length - 1; 
   1011            tmpreg1 |= (u32)tmpreg2 << 20;
   1012            /* Store the new register value */
   1013            ADCx->JSQR = tmpreg1;
   1014          }
   1015          
   1016          /*******************************************************************************
   1017          * Function Name  : ADC_SetInjectedOffset
   1018          * Description    : Set the injected channels conversion value offset
   1019          * Input          : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
   1020          *                  - ADC_InjectedChannel: the ADC injected channel to set its
   1021          *                    offset. 
   1022          *                    This parameter can be one of the following values:
   1023          *                       - ADC_InjectedChannel_1: Injected Channel1 selected
   1024          *                       - ADC_InjectedChannel_2: Injected Channel2 selected
   1025          *                       - ADC_InjectedChannel_3: Injected Channel3 selected
   1026          *                       - ADC_InjectedChannel_4: Injected Channel4 selected
   1027          *                  - Offset: the offset value for the selected ADC injected channel
   1028          *                    This parameter must be a 12bit value.
   1029          * Output         : None
   1030          * Return         : None
   1031          *******************************************************************************/
   1032          void ADC_SetInjectedOffset(ADC_TypeDef* ADCx, u8 ADC_InjectedChannel, u16 Offset)
   1033          {
   1034            /* Check the parameters */
   1035            assert(IS_ADC_INJECTED_CHANNEL(ADC_InjectedChannel));
   1036            assert(IS_ADC_OFFSET(Offset));  
   1037          
   1038            /* Set the selected injected channel data offset */
   1039            *((u32 *)((*(u32*)&ADCx) + ADC_InjectedChannel)) = (u32)Offset;
   1040          }
   1041          
   1042          /*******************************************************************************
   1043          * Function Name  : ADC_GetInjectedConversionValue
   1044          * Description    : Returns the ADC injected channel conversion result
   1045          * Input          : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
   1046          *                  - ADC_InjectedChannel: the converted ADC injected channel.
   1047          *                    This parameter can be one of the following values:
   1048          *                       - ADC_InjectedChannel_1: Injected Channel1 selected
   1049          *                       - ADC_InjectedChannel_2: Injected Channel2 selected
   1050          *                       - ADC_InjectedChannel_3: Injected Channel3 selected
   1051          *                       - ADC_InjectedChannel_4: Injected Channel4 selected
   1052          * Output         : None
   1053          * Return         : The Data conversion value.
   1054          *******************************************************************************/
   1055          u16 ADC_GetInjectedConversionValue(ADC_TypeDef* ADCx, u8 ADC_InjectedChannel)
   1056          {
   1057            /* Check the parameters */
   1058            assert(IS_ADC_INJECTED_CHANNEL(ADC_InjectedChannel));
   1059          
   1060            /* Returns the selected injected channel conversion data value */
   1061            return (u16) (*(u32*) (((*(u32*)&ADCx) + ADC_InjectedChannel + JDR_Offset)));
   1062          }
   1063          
   1064          /*******************************************************************************
   1065          * Function Name  : ADC_AnalogWatchdogCmd
   1066          * Description    : Enables or disables the

⌨️ 快捷键说明

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