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

📄 75x_adc.c

📁 STR750的所有库文件(头文件和源文件)
💻 C
📖 第 1 页 / 共 3 页
字号:
    return SET;
  }
  else
  {
    /* Return RESET if ADC Conversion is stopped */
    return RESET;
  }
}

/*******************************************************************************
* Function Name  : ADC_Cmd
* Description    : Enables the ADC peripheral or puts it in power down mode.
*                  - NewState: new state of the ADC peripheral. 
*                    This parameter can be: ENABLE or DISABLE.
* Output         : None  
* Return         : None.
*******************************************************************************/
void ADC_Cmd(FunctionalState NewState)
{
  if (NewState == DISABLE)
  {
    /* Enable ADC Power Down Mode */
    ADC->CLR4 |= ADC_PowerDown_Enable;
  }
  else
  {
    /* Disable ADC Power Down Mode */
    ADC->CLR4 &= ADC_PowerDown_Disable;
  }
}

/*******************************************************************************
* Function Name  : ADC_AutoClockOffConfig                                
* Description    : Enables or disables the Auto clock off feature.
*                  - NewState: new state of the Auto clock off feature. This 
*                    parameter can be: ENABLE or DISABLE.  
* Output         : None   
* Return         : None.                                                 
*******************************************************************************/
void ADC_AutoClockOffConfig(FunctionalState NewState)
{
  if (NewState == ENABLE)
  {
    /* Enable ADC Auto Clock Off */
    ADC->CLR4 |= ADC_AutoClockOff_Enable;
  }
  else
  {
    /* Disable ADC Auto Clock Off */
    ADC->CLR4 &= ADC_AutoClockOff_Disable;
  }
}

/*******************************************************************************
* Function Name  : ADC_AnalogWatchdogConfig                                       
* Description    : Configures the analog input channel to be used for the selected
*                  Analog Watchdog and defines its corresponding High and Low 
*                  threshold values.               
* Input          : - ADC_AnalogWatchdog: specifies the analog watchdog which will
*                    be affected to the desired converted channel. This parameter
*                    can be one of the following values: 
*                     - ADC_AnalogWatchdog0: select analog watchdog 0
*                     - ADC_AnalogWatchdog1: select analog watchdog 1
*                     - ADC_AnalogWatchdog2: select analog watchdog 2
*                     - ADC_AnalogWatchdog3: select analog watchdog 3
*                  - ADC_CHANNEL: specifies the channel linked to the selected 
*                    analog watchdog. This parameter can be ADC_CHANNELx where x 
*                    can be (0..15)                    
*                  - LowThreshold: Low Threshold for the selected Analog watchdog
*                  - HighThreshold: High Threshold for the selected Analog watchdog
* Output         : None
* Return         : None
*******************************************************************************/
void ADC_AnalogWatchdogConfig(u16 ADC_AnalogWatchdog, u8 ADC_CHANNEL, 
                              u16 LowThreshold, u16 HighThreshold)
{
  switch (ADC_AnalogWatchdog)
  {
    /* Set the selected channel and their corresponding High and Low thresholds */
    case ADC_AnalogWatchdog0 :
      ADC->TRA0 = (ADC->TRA0 & ADC_AnalogWatchdogChannel_Mask) | ((u16) ADC_CHANNEL<<10);
      ADC->TRA0 = (ADC->TRA0 & ADC_Threshold_Mask) |  HighThreshold;
      ADC->TRB0 = (ADC->TRB0 & ADC_Threshold_Mask) |  LowThreshold;
      break;

    case ADC_AnalogWatchdog1 :
      ADC->TRA1 = (ADC->TRA1 & ADC_AnalogWatchdogChannel_Mask) | ((u16) ADC_CHANNEL<<10);
      ADC->TRA1 = (ADC->TRA1 & ADC_Threshold_Mask) |  HighThreshold;
      ADC->TRB1 = (ADC->TRB1 & ADC_Threshold_Mask) |  LowThreshold;
      break;

    case ADC_AnalogWatchdog2 :
      ADC->TRA2 = (ADC->TRA2 & ADC_AnalogWatchdogChannel_Mask) | ((u16) ADC_CHANNEL<<10);
      ADC->TRA2 = (ADC->TRA2 & ADC_Threshold_Mask) |  HighThreshold;
      ADC->TRB2 = (ADC->TRB2 & ADC_Threshold_Mask) |  LowThreshold;
      break;

    case ADC_AnalogWatchdog3 :
      ADC->TRA3 = (ADC->TRA3 & ADC_AnalogWatchdogChannel_Mask) | ((u16) ADC_CHANNEL<<10);
      ADC->TRA3 = (ADC->TRA3 & ADC_Threshold_Mask) |  HighThreshold;
      ADC->TRB3 = (ADC->TRB3 & ADC_Threshold_Mask) |  LowThreshold;
      break;

    default:
      break; 
  }
}

/*******************************************************************************
* Function Name  : ADC_AnalogWatchdogCmd                                   
* Description    : Enables or disables the selected analog Watchdog.
* Input          : - ADC_AnalogWatchdog: specifies the analog watchdog to be 
*                    enabled or disabled. This parameter can be one of the 
*                    following values: 
*                     - ADC_AnalogWatchdog0: select analog watchdog 0
*                     - ADC_AnalogWatchdog1: select analog watchdog 1
*                     - ADC_AnalogWatchdog2: select analog watchdog 2
*                     - ADC_AnalogWatchdog3: select analog watchdog 3
*                  - NewState: new state of the specified analog watchdog.
*                    This parameter can be: ENABLE or DISABLE.
* Output         : None
* Return         : None.                                                   
*******************************************************************************/
void ADC_AnalogWatchdogCmd(u16 ADC_AnalogWatchdog, FunctionalState NewState)
{
  if (NewState == ENABLE)
  {
    /* Enable the selected ADC AnalogWatchdogx */
    switch (ADC_AnalogWatchdog)
    {
      case ADC_AnalogWatchdog0 : 
        ADC->TRB0 |= ADC_AnalogWatchdog_Enable;
        break;

      case ADC_AnalogWatchdog1 : 
        ADC->TRB1 |= ADC_AnalogWatchdog_Enable;  
        break;

      case ADC_AnalogWatchdog2 : 
        ADC->TRB2 |= ADC_AnalogWatchdog_Enable;  
        break;

      case ADC_AnalogWatchdog3 : 
        ADC->TRB3 |= ADC_AnalogWatchdog_Enable;  
        break;

      default:
        break; 
    }
  }
  else
  {
    /* Disable the selected ADC AnalogWatchdogx */
    switch (ADC_AnalogWatchdog)
    {
      case ADC_AnalogWatchdog0 : 
        ADC->TRB0 &= ADC_AnalogWatchdog_Disable;  
        break;

      case ADC_AnalogWatchdog1 : 
        ADC->TRB1 &= ADC_AnalogWatchdog_Disable;  
        break;

      case ADC_AnalogWatchdog2 : 
        ADC->TRB2 &= ADC_AnalogWatchdog_Disable;  
        break;

      case ADC_AnalogWatchdog3 : 
        ADC->TRB3 &= ADC_AnalogWatchdog_Disable;  
        break;

      default:
        break; 
    }
  }
}

/*******************************************************************************
* Function Name  : ADC_GetAnalogWatchdogResult
* Description    : Returns the comparison result of the selected analog watchdog.
* Input          : - ADC_AnalogWatchdog: specifies the analog watchdog channel 
*                    which its comparison result will be returned. This parameter
*                    can be one of the following values: 
*                     - ADC_AnalogWatchdog0: select analog watchdog 0
*                     - ADC_AnalogWatchdog1: select analog watchdog 1
*                     - ADC_AnalogWatchdog2: select analog watchdog 2
*                     - ADC_AnalogWatchdog3: select analog watchdog 3
* Output         : None
* Return         : The analog watchdog comparaison result value
*******************************************************************************/
u16 ADC_GetAnalogWatchdogResult(u16 ADC_AnalogWatchdog)
{
  /* Return the selected ADC AnalogWatchdogx comparaison result */
  switch(ADC_AnalogWatchdog)
  {
    case ADC_AnalogWatchdog0 :
      return ((ADC->PBR & ADC_AnalogWatchdog)>>4);

    case ADC_AnalogWatchdog1 :
      return ((ADC->PBR & ADC_AnalogWatchdog)>>6);

    case ADC_AnalogWatchdog2 :
      return ((ADC->PBR & ADC_AnalogWatchdog)>>8);

    case ADC_AnalogWatchdog3 :
      return ((ADC->PBR & ADC_AnalogWatchdog)>>10);

    default : return (0xFF);  /* if a wrong value of ADC_AnalogWatchdog is selected */
  }
}

/*******************************************************************************
* Function Name  : ADC_InjectedConversionConfig
* Description    : Configures the start trigger level for the injected channels 
*                  and the injected analog input channels to be converted. 
* Input          : - ADC_Injec_ExtTrigger: specifies the start trigger level.
*                    This parameter can be one of the following values:
*                         - ADC_Injec_ExtTrigger_Disable : external trigger disabled
*                         - ADC_Injec_ExtTrigger_RisingEdge: external trigger
*                           configured as rising edge of PWM Timer TRGO signal
*                         - ADC_Injec_ExtTrigger_FallingEdge: external trigger 
*                           configured as falling edge of PWM Timer TRGO signal 
*                  - FirstChannel: specifies the first injected channel to be
*                    converted. 
*                    This parameter can be ADC_CHANNELx  where x can be (0..15). 
*                  - ChannelNumber: specifies the Number of the injected channels 
*                    to be converted. This parameter can be a  value from 1 to 16.    
* Output         : None
* Return         : None
*******************************************************************************/
void ADC_InjectedConversionConfig(u16 ADC_Injec_ExtTrigger, u8 FirstChannel, u8 ChannelNumber)
{
  /* Configure the external start injected conversion trigger */
  switch (ADC_Injec_ExtTrigger)
  {
    case ADC_Injec_ExtTrigger_Disable  :
      /* Disable the external trigger and start the injected conversion by software */
      ADC->CLR3 &= ADC_Injec_ExtTrigger_Disable ;
      break;
    case ADC_Injec_ExtTrigger_RisingEdge :
      /* Start injected conversion on rising edge of the external trigger (PWM) */
      ADC->CLR3 |= ADC_Injec_ExtTrigger_RisingEdge;
      break;
    case ADC_Injec_ExtTrigger_FallingEdge :
      /* Start injected conversion on falling edge of the external trigger (PWM) */
      ADC->CLR3 |= ADC_Injec_ExtTrigger_Enable; 
      ADC->CLR3 &= ADC_Injec_ExtTrigger_FallingEdge;
      break;

    default:
      break;
  }
  
  /* Clear first injected channel to be converted JFCH[3:0] bits */
  ADC->CLR3 &= ADC_FirstChannel_Mask;
  /* Set the first injected channel to be converted */
  ADC->CLR3 |= FirstChannel;
  /* Clear number of injected channels to be converted JNCH[3:0] bits */
  ADC->CLR3 &= ADC_ChannelNumber_Mask;  
  /* Set the number of injected channels to be converted */
  ADC->CLR3 |= ((ChannelNumber-1)<<6);
}

/*******************************************************************************
* Function Name  : ADC_StartInjectedConversion
* Description    : Starts by software the conversion of the injected input channels.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void ADC_StartInjectedConversion(void)
{
  /* Start the injected ADC Conversion */
  ADC->CLR3 |= ADC_Injec_ConversionStart;
}

/*******************************************************************************
* Function Name  : ADC_GetConversionValue
* Description    : Reads the conversion result from the appropriate data register.
* Input          : - ADC_CHANNEL :specifies the ADC channel which its conversion 
*                    value have to be returned. This parameter can be ADC_CHANNELx
*                    where x can be (0..15) to select channelx  
* Output         : None
* Return         : The returned value holds the conversion result of the selected   
*                  channel.
*******************************************************************************/
u16 ADC_GetConversionValue(u8 ADC_CHANNEL)
{
  /* Return the conversion result of the selected channel */
  return *((u16 *)(ADC_BASE + ((ADC_CHANNEL<<2) + ADC_DataRegisterOffset)));

⌨️ 快捷键说明

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