Ejemplo n.º 1
0
/**
  * @brief  Initializes the TIM3 peripheral according to the specified parameters.
  * @param    TIM3_Channel specifies the Input Capture Channel from @ref TIM3_Channel_TypeDef.
  * @param   TIM3_ICPolarity specifies the Input Capture Polarity from @ref TIM3_ICPolarity_TypeDef.
  * @param   TIM3_ICSelection specifies the Input Capture Selection from @ref TIM3_ICSelection_TypeDef.
  * @param   TIM3_ICPrescaler specifies the Input Capture Prescaler from @ref TIM3_ICPSC_TypeDef.
  * @param   TIM3_ICFilter specifies the Input Capture Filter value (value can be an integer from 0x00 to 0x0F).
  * @retval None
  */
void TIM3_ICInit(TIM3_Channel_TypeDef TIM3_Channel,
                 TIM3_ICPolarity_TypeDef TIM3_ICPolarity,
                 TIM3_ICSelection_TypeDef TIM3_ICSelection,
                 TIM3_ICPSC_TypeDef TIM3_ICPrescaler,
                 uint8_t TIM3_ICFilter)
{
    /* Check the parameters */
    assert_param(IS_TIM3_CHANNEL_OK(TIM3_Channel));
    assert_param(IS_TIM3_IC_POLARITY_OK(TIM3_ICPolarity));
    assert_param(IS_TIM3_IC_SELECTION_OK(TIM3_ICSelection));
    assert_param(IS_TIM3_IC_PRESCALER_OK(TIM3_ICPrescaler));
    assert_param(IS_TIM3_IC_FILTER_OK(TIM3_ICFilter));

    if (TIM3_Channel != TIM3_CHANNEL_2)
    {
        /* TI1 Configuration */
        TI1_Config((uint8_t)TIM3_ICPolarity,
                   (uint8_t)TIM3_ICSelection,
                   (uint8_t)TIM3_ICFilter);

        /* Set the Input Capture Prescaler value */
        TIM3_SetIC1Prescaler(TIM3_ICPrescaler);
    }
    else
    {
        /* TI2 Configuration */
        TI2_Config((uint8_t)TIM3_ICPolarity,
                   (uint8_t)TIM3_ICSelection,
                   (uint8_t)TIM3_ICFilter);

        /* Set the Input Capture Prescaler value */
        TIM3_SetIC2Prescaler(TIM3_ICPrescaler);
    }
}
Ejemplo n.º 2
0
/**
  * @brief  Initializes the TIM3 peripheral according to the specified parameters.
  * @param  TIM3_Channel : This parameter can be any member of the @Ref TIM3_Channel_TypeDef enumeration.
  * @param  TIM3_ICPolarity : This parameter can be any member of the @Ref TIM3_ICPolarity_TypeDef enumeration.
  * @param  TIM3_ICSelection : This parameter can be any member of the @Ref TIM3_ICSelection_TypeDef enumeration.
  * @param  TIM3_ICPrescaler : This parameter can be any member of the @Ref TIM3_ICPSC_TypeDef enumeration.
  * @param  TIM3_ICFilter : This parameter must be a value between 0x00 and 0x0F.
  * @retval None
  */
void TIM3_ICInit(TIM3_Channel_TypeDef TIM3_Channel,
                 TIM3_ICPolarity_TypeDef TIM3_ICPolarity,
                 TIM3_ICSelection_TypeDef TIM3_ICSelection,
                 TIM3_ICPSC_TypeDef TIM3_ICPrescaler,
                 uint8_t TIM3_ICFilter)
{
  /* Check the parameters */
  assert_param(IS_TIM3_CHANNEL(TIM3_Channel));

  if (TIM3_Channel == TIM3_Channel_1)
  {
    /* TI1 Configuration */
    TI1_Config(TIM3_ICPolarity, TIM3_ICSelection, TIM3_ICFilter);

    /* Set the Input Capture Prescaler value */
    TIM3_SetIC1Prescaler(TIM3_ICPrescaler);
  }
  else /* if (TIM3_Channel == TIM3_Channel_2) */
  {
    /* TI2 Configuration */
    TI2_Config(TIM3_ICPolarity, TIM3_ICSelection, TIM3_ICFilter);
    /* Set the Input Capture Prescaler value */
    TIM3_SetIC2Prescaler(TIM3_ICPrescaler);
  }
}
Ejemplo n.º 3
0
/**
  * @brief  Configures the TIM3 peripheral in PWM Input Mode according to the specified parameters.
  * @param    TIM3_Channel specifies the Input Capture Channel from @ref TIM3_Channel_TypeDef.
  * @param   TIM3_ICPolarity specifies the Input Capture Polarity from @ref TIM3_ICPolarity_TypeDef.
  * @param   TIM3_ICSelection specifies the Input Capture Selection from @ref TIM3_ICSelection_TypeDef.
  * @param   TIM3_ICPrescaler specifies the Input Capture Prescaler from @ref TIM3_ICPSC_TypeDef.
  * @param   TIM3_ICFilter specifies the Input Capture Filter value (value can be an integer from 0x00 to 0x0F).
  * @retval None
  */
void TIM3_PWMIConfig(TIM3_Channel_TypeDef TIM3_Channel,
                     TIM3_ICPolarity_TypeDef TIM3_ICPolarity,
                     TIM3_ICSelection_TypeDef TIM3_ICSelection,
                     TIM3_ICPSC_TypeDef TIM3_ICPrescaler,
                     uint8_t TIM3_ICFilter)
{
    uint8_t icpolarity = (uint8_t)TIM3_ICPOLARITY_RISING;
    uint8_t icselection = (uint8_t)TIM3_ICSELECTION_DIRECTTI;

    /* Check the parameters */
    assert_param(IS_TIM3_PWMI_CHANNEL_OK(TIM3_Channel));
    assert_param(IS_TIM3_IC_POLARITY_OK(TIM3_ICPolarity));
    assert_param(IS_TIM3_IC_SELECTION_OK(TIM3_ICSelection));
    assert_param(IS_TIM3_IC_PRESCALER_OK(TIM3_ICPrescaler));

    /* Select the Opposite Input Polarity */
    if (TIM3_ICPolarity != TIM3_ICPOLARITY_FALLING)
    {
        icpolarity = (uint8_t)TIM3_ICPOLARITY_FALLING;
    }
    else
    {
        icpolarity = (uint8_t)TIM3_ICPOLARITY_RISING;
    }

    /* Select the Opposite Input */
    if (TIM3_ICSelection == TIM3_ICSELECTION_DIRECTTI)
    {
        icselection = (uint8_t)TIM3_ICSELECTION_INDIRECTTI;
    }
    else
    {
        icselection = (uint8_t)TIM3_ICSELECTION_DIRECTTI;
    }

    if (TIM3_Channel != TIM3_CHANNEL_2)
    {
        /* TI1 Configuration */
        TI1_Config((uint8_t)TIM3_ICPolarity, (uint8_t)TIM3_ICSelection,
                   (uint8_t)TIM3_ICFilter);

        /* Set the Input Capture Prescaler value */
        TIM3_SetIC1Prescaler(TIM3_ICPrescaler);

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

        /* Set the Input Capture Prescaler value */
        TIM3_SetIC2Prescaler(TIM3_ICPrescaler);
    }
    else
    {
        /* TI2 Configuration */
        TI2_Config((uint8_t)TIM3_ICPolarity, (uint8_t)TIM3_ICSelection,
                   (uint8_t)TIM3_ICFilter);

        /* Set the Input Capture Prescaler value */
        TIM3_SetIC2Prescaler(TIM3_ICPrescaler);

        /* TI1 Configuration */
        TI1_Config(icpolarity, icselection, TIM3_ICFilter);

        /* Set the Input Capture Prescaler value */
        TIM3_SetIC1Prescaler(TIM3_ICPrescaler);
    }
}
Ejemplo n.º 4
0
/**
  * @brief  Configures the TIM3 peripheral in PWM Input Mode according to the
  * specified parameters.
  * @param  TIM3_Channel : This parameter can be any member of the @Ref TIM3_Channel_TypeDef enumeration.
  * @param  TIM3_ICPolarity : This parameter can be any member of the @Ref TIM3_ICPolarity_TypeDef enumeration.
  * @param  TIM3_ICSelection : This parameter can be any member of the @Ref TIM3_ICSelection_TypeDef enumeration.
  * @param  TIM3_ICPrescaler : This parameter can be any member of the @Ref TIM3_ICPSC_TypeDef enumeration.
  * @param  TIM3_ICFilter : This parameter must be a value between 0x00 and 0x0F.
  * @retval None
  */
void TIM3_PWMIConfig(TIM3_Channel_TypeDef TIM3_Channel,
                     TIM3_ICPolarity_TypeDef TIM3_ICPolarity,
                     TIM3_ICSelection_TypeDef TIM3_ICSelection,
                     TIM3_ICPSC_TypeDef TIM3_ICPrescaler,
                     uint8_t TIM3_ICFilter)
{
  uint8_t icpolarity = TIM3_ICPolarity_Rising;
  uint8_t icselection = TIM3_ICSelection_DirectTI;

  /* Check the parameters */
  assert_param(IS_TIM3_CHANNEL(TIM3_Channel));

  /* Select the Opposite Input Polarity */
  if (TIM3_ICPolarity == TIM3_ICPolarity_Rising)
  {
    icpolarity = TIM3_ICPolarity_Falling;
  }
  else
  {
    icpolarity = TIM3_ICPolarity_Rising;
  }

  /* Select the Opposite Input */
  if (TIM3_ICSelection == TIM3_ICSelection_DirectTI)
  {
    icselection = TIM3_ICSelection_IndirectTI;
  }
  else
  {
    icselection = TIM3_ICSelection_DirectTI;
  }

  if (TIM3_Channel == TIM3_Channel_1)
  {
    /* TI1 Configuration */
    TI1_Config(TIM3_ICPolarity, TIM3_ICSelection, TIM3_ICFilter);

    /* Set the Input Capture Prescaler value */
    TIM3_SetIC1Prescaler(TIM3_ICPrescaler);

    /* TI2 Configuration */
    TI2_Config((TIM3_ICPolarity_TypeDef)icpolarity, (TIM3_ICSelection_TypeDef)icselection, TIM3_ICFilter);

    /* Set the Input Capture Prescaler value */
    TIM3_SetIC2Prescaler(TIM3_ICPrescaler);
  }
  else
  {
    /* TI2 Configuration */
    TI2_Config(TIM3_ICPolarity, TIM3_ICSelection, TIM3_ICFilter);

    /* Set the Input Capture Prescaler value */
    TIM3_SetIC2Prescaler(TIM3_ICPrescaler);

    /* TI1 Configuration */
    TI1_Config((TIM3_ICPolarity_TypeDef)icpolarity, (TIM3_ICSelection_TypeDef)icselection, TIM3_ICFilter);

    /* Set the Input Capture Prescaler value */
    TIM3_SetIC1Prescaler(TIM3_ICPrescaler);
  }
}