Exemplo n.º 1
0
/**
  * @brief  Initializes the TIM2 peripheral according to the specified parameters.
  * @param  TIM2_Channel : This parameter can be any member of the @Ref TIM2_Channel_TypeDef enumeration.
  * @param  TIM2_ICPolarity : This parameter can be any member of the @Ref TIM2_ICPolarity_TypeDef enumeration.
  * @param  TIM2_ICSelection : This parameter can be any member of the @Ref TIM2_ICSelection_TypeDef enumeration.
  * @param  TIM2_ICPrescaler : This parameter can be any member of the @Ref TIM2_ICPSC_TypeDef enumeration.
  * @param  TIM2_ICFilter : This parameter must be a value between 0x00 and 0x0F.
  * @retval None
  */
void TIM2_ICInit(TIM2_Channel_TypeDef TIM2_Channel,
                 TIM2_ICPolarity_TypeDef TIM2_ICPolarity,
                 TIM2_ICSelection_TypeDef TIM2_ICSelection,
                 TIM2_ICPSC_TypeDef TIM2_ICPrescaler,
                 uint8_t TIM2_ICFilter)
{
  /* Check the parameters */
  assert_param(IS_TIM2_CHANNEL(TIM2_Channel));

  if (TIM2_Channel == TIM2_Channel_1)
  {
    /* TI1 Configuration */
    TI1_Config(TIM2_ICPolarity, TIM2_ICSelection, TIM2_ICFilter);

    /* Set the Input Capture Prescaler value */
    TIM2_SetIC1Prescaler(TIM2_ICPrescaler);
  }
  else /* if (TIM2_Channel == TIM2_Channel_2) */
  {
    /* TI2 Configuration */
    TI2_Config(TIM2_ICPolarity, TIM2_ICSelection, TIM2_ICFilter);

    /* Set the Input Capture Prescaler value */
    TIM2_SetIC2Prescaler(TIM2_ICPrescaler);
  }
}
Exemplo n.º 2
0
/**
  * @brief  Initializes the TIM2 peripheral according to the specified parameters.
  * @param    TIM2_Channel specifies the Input Capture Channel from @ref TIM2_Channel_TypeDef.
  * @param   TIM2_ICPolarity specifies the Input Capture Polarity from @ref TIM2_ICPolarity_TypeDef.
  * @param   TIM2_ICSelection specifies the Input Capture Selection from @ref TIM2_ICSelection_TypeDef.
  * @param   TIM2_ICPrescaler specifies the Input Capture Prescaler from @ref TIM2_ICPSC_TypeDef.
  * @param   TIM2_ICFilter specifies the Input Capture Filter value (value can be an integer from 0x00 to 0x0F).
  * @retval None
  */
void TIM2_ICInit(TIM2_Channel_TypeDef TIM2_Channel,
                 TIM2_ICPolarity_TypeDef TIM2_ICPolarity,
                 TIM2_ICSelection_TypeDef TIM2_ICSelection,
                 TIM2_ICPSC_TypeDef TIM2_ICPrescaler,
                 uint8_t TIM2_ICFilter)
{
    /* Check the parameters */
    assert_param(IS_TIM2_CHANNEL_OK(TIM2_Channel));
    assert_param(IS_TIM2_IC_POLARITY_OK(TIM2_ICPolarity));
    assert_param(IS_TIM2_IC_SELECTION_OK(TIM2_ICSelection));
    assert_param(IS_TIM2_IC_PRESCALER_OK(TIM2_ICPrescaler));
    assert_param(IS_TIM2_IC_FILTER_OK(TIM2_ICFilter));

    if (TIM2_Channel == TIM2_CHANNEL_1)
    {
        /* TI1 Configuration */
        TI1_Config((uint8_t)TIM2_ICPolarity,
                   (uint8_t)TIM2_ICSelection,
                   (uint8_t)TIM2_ICFilter);

        /* Set the Input Capture Prescaler value */
        TIM2_SetIC1Prescaler(TIM2_ICPrescaler);
    }
    else if (TIM2_Channel == TIM2_CHANNEL_2)
    {
        /* TI2 Configuration */
        TI2_Config((uint8_t)TIM2_ICPolarity,
                   (uint8_t)TIM2_ICSelection,
                   (uint8_t)TIM2_ICFilter);

        /* Set the Input Capture Prescaler value */
        TIM2_SetIC2Prescaler(TIM2_ICPrescaler);
    }
    else
    {
        /* TI3 Configuration */
        TI3_Config((uint8_t)TIM2_ICPolarity,
                   (uint8_t)TIM2_ICSelection,
                   (uint8_t)TIM2_ICFilter);

        /* Set the Input Capture Prescaler value */
        TIM2_SetIC3Prescaler(TIM2_ICPrescaler);
    }
}
Exemplo n.º 3
0
/**
  * @brief  Configures the TIM2 peripheral in PWM Input Mode according to the
  * specified parameters.
  * @param  TIM2_Channel : This parameter can be any member of the @Ref TIM2_Channel_TypeDef enumeration.
  * @param  TIM2_ICPolarity : This parameter can be any member of the @Ref TIM2_ICPolarity_TypeDef enumeration.
  * @param  TIM2_ICSelection : This parameter can be any member of the @Ref TIM2_ICSelection_TypeDef enumeration.
  * @param  TIM2_ICPrescaler : This parameter can be any member of the @Ref TIM2_ICPSC_TypeDef enumeration.
  * @param  TIM2_ICFilter : This parameter must be a value between 0x00 and 0x0F.
  * @retval None
  */
void TIM2_PWMIConfig(TIM2_Channel_TypeDef TIM2_Channel,
                     TIM2_ICPolarity_TypeDef TIM2_ICPolarity,
                     TIM2_ICSelection_TypeDef TIM2_ICSelection,
                     TIM2_ICPSC_TypeDef TIM2_ICPrescaler,
                     uint8_t TIM2_ICFilter)
{
  uint8_t icpolarity = TIM2_ICPolarity_Rising;
  uint8_t icselection = TIM2_ICSelection_DirectTI;

  /* Check the parameters */
  assert_param(IS_TIM2_CHANNEL(TIM2_Channel));

  /* Select the Opposite Input Polarity */
  if (TIM2_ICPolarity == TIM2_ICPolarity_Rising)
  {
    icpolarity = TIM2_ICPolarity_Falling;
  }
  else
  {
    icpolarity = TIM2_ICPolarity_Rising;
  }

  /* Select the Opposite Input */
  if (TIM2_ICSelection == TIM2_ICSelection_DirectTI)
  {
    icselection = TIM2_ICSelection_IndirectTI;
  }
  else
  {
    icselection = TIM2_ICSelection_DirectTI;
  }

  if (TIM2_Channel == TIM2_Channel_1)
  {
    /* TI1 Configuration */
    TI1_Config(TIM2_ICPolarity, TIM2_ICSelection,
               TIM2_ICFilter);

    /* Set the Input Capture Prescaler value */
    TIM2_SetIC1Prescaler(TIM2_ICPrescaler);

    /* TI2 Configuration */
    TI2_Config((TIM2_ICPolarity_TypeDef)icpolarity, (TIM2_ICSelection_TypeDef)icselection, TIM2_ICFilter);

    /* Set the Input Capture Prescaler value */
    TIM2_SetIC2Prescaler(TIM2_ICPrescaler);
  }
  else
  {
    /* TI2 Configuration */
    TI2_Config(TIM2_ICPolarity, TIM2_ICSelection,
               TIM2_ICFilter);

    /* Set the Input Capture Prescaler value */
    TIM2_SetIC2Prescaler(TIM2_ICPrescaler);

    /* TI1 Configuration */
    TI1_Config((TIM2_ICPolarity_TypeDef)icpolarity, (TIM2_ICSelection_TypeDef)icselection, TIM2_ICFilter);

    /* Set the Input Capture Prescaler value */
    TIM2_SetIC1Prescaler(TIM2_ICPrescaler);
  }
}
Exemplo n.º 4
0
/**
  * @brief  Configures the TIM2 peripheral in PWM Input Mode according to the specified parameters.
    * @param    TIM2_Channel specifies the Input Capture Channel from @ref TIM2_Channel_TypeDef.
  * @param   TIM2_ICPolarity specifies the Input Capture Polarity from @ref TIM2_ICPolarity_TypeDef.
  * @param   TIM2_ICSelection specifies the Input Capture Selection from @ref TIM2_ICSelection_TypeDef.
  * @param   TIM2_ICPrescaler specifies the Input Capture Prescaler from @ref TIM2_ICPSC_TypeDef.
  * @param   TIM2_ICFilter specifies the Input Capture Filter value (value can be an integer from 0x00 to 0x0F).
  * @retval None
  */
void TIM2_PWMIConfig(TIM2_Channel_TypeDef TIM2_Channel,
                     TIM2_ICPolarity_TypeDef TIM2_ICPolarity,
                     TIM2_ICSelection_TypeDef TIM2_ICSelection,
                     TIM2_ICPSC_TypeDef TIM2_ICPrescaler,
                     uint8_t TIM2_ICFilter)
{
    uint8_t icpolarity = (uint8_t)TIM2_ICPOLARITY_RISING;
    uint8_t icselection = (uint8_t)TIM2_ICSELECTION_DIRECTTI;

    /* Check the parameters */
    assert_param(IS_TIM2_PWMI_CHANNEL_OK(TIM2_Channel));
    assert_param(IS_TIM2_IC_POLARITY_OK(TIM2_ICPolarity));
    assert_param(IS_TIM2_IC_SELECTION_OK(TIM2_ICSelection));
    assert_param(IS_TIM2_IC_PRESCALER_OK(TIM2_ICPrescaler));

    /* Select the Opposite Input Polarity */
    if (TIM2_ICPolarity != TIM2_ICPOLARITY_FALLING)
    {
        icpolarity = (uint8_t)TIM2_ICPOLARITY_FALLING;
    }
    else
    {
        icpolarity = (uint8_t)TIM2_ICPOLARITY_RISING;
    }

    /* Select the Opposite Input */
    if (TIM2_ICSelection == TIM2_ICSELECTION_DIRECTTI)
    {
        icselection = (uint8_t)TIM2_ICSELECTION_INDIRECTTI;
    }
    else
    {
        icselection = (uint8_t)TIM2_ICSELECTION_DIRECTTI;
    }

    if (TIM2_Channel == TIM2_CHANNEL_1)
    {
        /* TI1 Configuration */
        TI1_Config((uint8_t)TIM2_ICPolarity, (uint8_t)TIM2_ICSelection,
                   (uint8_t)TIM2_ICFilter);

        /* Set the Input Capture Prescaler value */
        TIM2_SetIC1Prescaler(TIM2_ICPrescaler);

        /* TI2 Configuration */
        TI2_Config(icpolarity, icselection, TIM2_ICFilter);

        /* Set the Input Capture Prescaler value */
        TIM2_SetIC2Prescaler(TIM2_ICPrescaler);
    }
    else
    {
        /* TI2 Configuration */
        TI2_Config((uint8_t)TIM2_ICPolarity, (uint8_t)TIM2_ICSelection,
                   (uint8_t)TIM2_ICFilter);

        /* Set the Input Capture Prescaler value */
        TIM2_SetIC2Prescaler(TIM2_ICPrescaler);

        /* TI1 Configuration */
        TI1_Config((uint8_t)icpolarity, icselection, (uint8_t)TIM2_ICFilter);

        /* Set the Input Capture Prescaler value */
        TIM2_SetIC1Prescaler(TIM2_ICPrescaler);
    }
}