Picproje Elektronik Sitesi

MİKRODENETLEYİCİLER => ARM => Cortex ARM => Konuyu başlatan: muhittin_kaplan - 16 Eylül 2013, 18:26:23

Başlık: input capture
Gönderen: muhittin_kaplan - 16 Eylül 2013, 18:26:23
Ultrasonic Sensör Ulaştı ELime, Çalışmasına baktım,
10us lik bir puls verdikten sonra echo çıkışından size uzaklıkla doğru orantılı Mantık 1 e çekilmiş sinyal gönderiyor.
STM32 ile input capture örneklerini inceledim. (input PWM leride inceledim.) kendi örneğindeki aşağıdaki örnek input PWM ve açıklamasında demişki "feq ve duty" verir.

  TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;
  TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
  TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
  TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
  TIM_ICInitStructure.TIM_ICFilter = 0x0;

  TIM_PWMIConfig(TIM3, &TIM_ICInitStructure);

  /* Select the TIM3 Input Trigger: TI2FP2 */
  TIM_SelectInputTrigger(TIM3, TIM_TS_TI2FP2);

  /* Select the slave Mode: Reset Mode */
  TIM_SelectSlaveMode(TIM3, TIM_SlaveMode_Reset);

  /* Enable the Master/Slave Mode */
  TIM_SelectMasterSlaveMode(TIM3, TIM_MasterSlaveMode_Enable);

  /* TIM enable counter */
  TIM_Cmd(TIM3, ENABLE);

  /* Enable the CC2 Interrupt Request */
  TIM_ITConfig(TIM3, TIM_IT_CC2, ENABLE);


anlamadığım şu Sadece yükselen kenarda tetiklenirse Duty yi nasıl bulur ?
  TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
Başlık: Ynt: input capture
Gönderen: Klein - 16 Eylül 2013, 18:34:37
oradaki polarite counter reset için gereken polarite.
Eğer düşen kenara ayarlarsan  ilk düşen kenarda  sayıcı sıfırlanır. Yükselen kenarda darbe genişliği bayrağı çekilir. diğer düşen kenarda tekrar sayıcı sıfırlanır.
Başlık: Ynt: input capture
Gönderen: muhittin_kaplan - 16 Eylül 2013, 18:37:51
void TIM3_IRQHandler(void)
{
  /* Clear TIM3 Capture compare interrupt pending bit */
  TIM_ClearITPendingBit(TIM3, TIM_IT_CC2);

  /* Get the Input Capture value */
  IC2Value = TIM_GetCapture2(TIM3);

  if (IC2Value != 0)
  {
    /* Duty cycle computation */
    DutyCycle = (TIM_GetCapture1(TIM3) * 100) / IC2Value;

    /* Frequency computation */
    Frequency = SystemCoreClock / IC2Value;
  }
  else
  {
    DutyCycle = 0;
    Frequency = 0;
  }

}
Başlık: Ynt: input capture
Gönderen: Klein - 16 Eylül 2013, 18:42:21
https://www.picproje.org/index.php/topic,37420.msg272070.html#msg272070 (https://www.picproje.org/index.php/topic,37420.msg272070.html#msg272070)
Başlık: Ynt: input capture
Gönderen: muhittin_kaplan - 16 Eylül 2013, 18:44:59
inceledim hocam, ama kütüphaneyle yapmak istedim.
Başlık: Ynt: input capture
Gönderen: Klein - 16 Eylül 2013, 18:52:48
Örneğin linkini verme nedenim periyot ve darbe genişliğini ayrı registerlerden alabileceğini gösternmek içindi.

oid TIM2_IRQHandler(){
    ccr1=TIM2->CCR1; // periyot
    ccr2=TIM2->CCR2; // darbe genişliği
TIM2->SR=0;   



mesaj birleştirme:: 16 Eylül 2013, 18:55:05

hmm. sen de ayrı gregisterlerden almışsın. hesabı görünce hesaplayarak buldun diye düşündüm.
Başlık: Ynt: input capture
Gönderen: muhittin_kaplan - 16 Eylül 2013, 18:55:35
/* Clear TIM3 Capture compare interrupt pending bit */
  TIM_ClearITPendingBit(TIM3, TIM_IT_CC2);

  /* Get the Input Capture value */
  IC2Value = TIM_GetCapture2(TIM3);

  if (IC2Value != 0)
  {
    /* Duty cycle computation */
    DutyCycle = (TIM_GetCapture1(TIM3) * 100) / IC2Value;

    /* Frequency computation */
    Frequency = SystemCoreClock / IC2Value;
  }
  else
  {
    DutyCycle = 0;
    Frequency = 0;
  }

}


Hocam Yukarda da aynısını Yapıyor.
  IC2Value = TIM_GetCapture2(TIM3); ile CCR2
TIM_GetCapture1(TIM3) ile CCR1 i alıyor. ama her ne hikmetse her defasında farklı sonuç çıkıyor.
Başlık: Ynt: input capture
Gönderen: Klein - 16 Eylül 2013, 18:58:53
CM3 ile hiç denemedim ama STM32F4 kiti üzerinde denemiştim. Çok düzgün sonuçlar aldım. Kendi filtresi olduğu için bu güne kadar çalıştığım IC modülleri içinde en iyisiydi.
Başlık: Ynt: input capture
Gönderen: muhittin_kaplan - 16 Eylül 2013, 19:00:01
/**
  ******************************************************************************
  * @file    TIM/PWM_Input/main.c
  * @author  MCD Application Team
  * @version V3.5.0
  * @date    08-April-2011
  * @brief   Main program body
  ******************************************************************************
  * @attention
  *
  * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  *
  * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  ******************************************************************************
  */

/* Includes ------------------------------------------------------------------*/
#include "stm32f10x.h"

/** @addtogroup STM32F10x_StdPeriph_Examples
  * @{
  */

/** @addtogroup TIM_PWM_Input
  * @{
  */

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/


/* Private function prototypes -----------------------------------------------*/
void RCC_Configuration(void);
void GPIO_Configuration(void);
void NVIC_Configuration(void);

/* Private functions ---------------------------------------------------------*/




/**
  * @brief   Main program
  * @param  None
  * @retval None
  */


GPIO_InitTypeDef GPIO_InitStructure;
TIM_ICInitTypeDef  TIM_ICInitStructure;



int IC2Value = 0;
int DutyCycle = 0;
int Frequency = 0;


void TIM3_IRQHandler(void)
{
  /* Clear TIM3 Capture compare interrupt pending bit */
  TIM_ClearITPendingBit(TIM3, TIM_IT_CC2);

  /* Get the Input Capture value */
  IC2Value = TIM_GetCapture2(TIM3);

  if (IC2Value != 0)
  {
    /* Duty cycle computation */
    DutyCycle = (TIM_GetCapture1(TIM3) * 100) / IC2Value;

    /* Frequency computation */
    Frequency = SystemCoreClock / IC2Value;
  }
  else
  {
    DutyCycle = 0;
    Frequency = 0;
  }

}




int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured,
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f10x_xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f10x.c file
     */

SystemInit();
  /* System Clocks Configuration */
  RCC_Configuration();

  /* NVIC configuration */
  NVIC_Configuration();

  /* Configure the GPIO ports */
  GPIO_Configuration();

  /* TIM3 configuration: PWM Input mode ------------------------
     The external signal is connected to TIM3 CH2 pin (PA.01),
     The Rising edge is used as active edge,
     The TIM3 CCR2 is used to compute the frequency value
     The TIM3 CCR1 is used to compute the duty cycle value
  ------------------------------------------------------------ */

  TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;
  TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
  TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
  TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
  TIM_ICInitStructure.TIM_ICFilter = 0x0;

  TIM_PWMIConfig(TIM3, &TIM_ICInitStructure);

  /* Select the TIM3 Input Trigger: TI2FP2 */
  TIM_SelectInputTrigger(TIM3, TIM_TS_TI2FP2);

  /* Select the slave Mode: Reset Mode */
  TIM_SelectSlaveMode(TIM3, TIM_SlaveMode_Reset);

  /* Enable the Master/Slave Mode */
  TIM_SelectMasterSlaveMode(TIM3, TIM_MasterSlaveMode_Enable);

  /* TIM enable counter */
  TIM_Cmd(TIM3, ENABLE);

  /* Enable the CC2 Interrupt Request */
  TIM_ITConfig(TIM3, TIM_IT_CC2, ENABLE);


  while (1){
  int z;
    GPIO_SetBits(GPIOC,GPIO_Pin_8);
for (z = 0; z < 0x0000015; ++z) {

}
    GPIO_ResetBits(GPIOC,GPIO_Pin_8);
for (z = 0; z < 0x00000015; ++z) {

}
  }
}

/**
  * @brief  Configures the different system clocks.
  * @param  None
  * @retval None
  */
void RCC_Configuration(void)
{
  /* TIM3 clock enable */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);

  /* GPIOA clock enable */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
}

/**
  * @brief  Configure the GPIO Pins.
  * @param  None
  * @retval None
  */
void GPIO_Configuration(void)
{


  /* TIM3 channel 2 pin (PA.07) configuration */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

  GPIO_Init(GPIOA, &GPIO_InitStructure);


  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

  GPIO_Init(GPIOC, &GPIO_InitStructure);
}

/**
  * @brief  Configure the nested vectored interrupt controller.
  * @param  None
  * @retval None
  */
void NVIC_Configuration(void)
{
  NVIC_InitTypeDef NVIC_InitStructure;

  /* Enable the TIM3 global Interrupt */
  NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
}

#ifdef  USE_FULL_ASSERT

/**
  * @brief  Reports the name of the source file and the source line number
  *         where the assert_param error has occurred.
  * @param  file: pointer to the source file name
  * @param  line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t* file, uint32_t line)
{
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

  while (1)
  {}
}

#endif

/**
  * @}
  */

/**
  * @}
  */

/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/


kodlar bunlar, GPIOC.8 den sinyl çıkışı yaptım onu GPIOA.7 ye bağladım. Debug ettiğimde anlamsız degerler alıyorum.
Başlık: Ynt: input capture
Gönderen: muhittin_kaplan - 16 Eylül 2013, 21:23:51
Denemediğim Yöntem Kalmadı. Olmuyor Debug Anında CCR1 ve CCR2 (yada
TIM_GetCapture2(TIM2)
TIM_GetCapture1(TIM2)

den dogru dürüst bilgi alamıyorum. Acaba Debug yapmamdan kaynaklanıyor olabilir mi ? USartla PC yemi Göndersem.
Başlık: Ynt: input capture
Gönderen: Klein - 17 Eylül 2013, 12:48:58
PWM modül kullanarak sinyal çıkışı sağlamayı bir dener misin?
CCP1 ve CCP2  yakalandığında ayrı ayrı kesme üretiyorlarsa ( datasheet'e bakmaya üşendim)
Pending bitini hemen sıfırlama.
kesmenin hangi kaynaktan geldiğine bak.  Kesme kaynağına göre hangi işlemi yapman gerekiyorsa onu yap. Ondan sonra pending bitini sıfırla.
Başlık: Ynt: input capture
Gönderen: muhittin_kaplan - 17 Eylül 2013, 13:34:40
hocam onuda denedim,
başka bir timer la PWM ürettim, capture yapmaya çalıştım yine aynı anlamsız değerler aldım.
Başlık: Ynt: input capture
Gönderen: Klein - 17 Eylül 2013, 13:55:46
Şimdilik Debug modu suçlu gibi duruyor. Bir de veriyi seri porttan basmayı dene. Eğer yine olmazsa, fırsat bulunca ben de deneyeyim.
Başlık: Ynt: input capture
Gönderen: muhittin_kaplan - 17 Eylül 2013, 14:12:33
akşam usarttan basacağım değerleri. bakalım ne olacak.
(debug modda timer lar duruyor mu breakpoint koyunca ?)
Başlık: Ynt: input capture
Gönderen: Klein - 17 Eylül 2013, 14:34:03
Sebebini anlayamadığım bir sorun olmadığı sürece Debug moda pek girmiyorum. Bu yüzden timer davranışları konusunda fikrim yok.
Başlık: Ynt: input capture
Gönderen: mistek - 17 Eylül 2013, 14:49:07
Alıntı yapılan: muhittin_kaplan - 17 Eylül 2013, 14:12:33
akşam usarttan basacağım değerleri. bakalım ne olacak.
(debug modda timer lar duruyor mu breakpoint koyunca ?)

Hocam debug modda Run yapınca Timerlar çalışıyor kesme gelince breakpoint noktasına geliyor. Eğer adım adım işletirseniz timerlar duruyor.
Başlık: Ynt: input capture
Gönderen: muhittin_kaplan - 17 Eylül 2013, 14:59:22
Adım Adım Çalıştığında timer da değerine göre artış oluyor yani.
Başlık: Ynt: input capture
Gönderen: muhittin_kaplan - 17 Eylül 2013, 23:53:52
GPIOC 8  ile toogle yapıyorum. Bu çıkışı kullanıp GPIOA 1 e giriyorum.

ve sadece düşen kenarda void TIM2_IRQHandler(void) fonksiyonuna giriyor.


#include "stm32f10x.h"

TIM_ICInitTypeDef  TIM_ICInitStructure;

/* Private function prototypes -----------------------------------------------*/
void RCC_Configuration(void);
void GPIO_Configuration(void);
void SetupNVIC(void);
void SetupPWM_Input(void);
/* Private functions ---------------------------------------------------------*/


int IC2Value = 0;
int IC1Value = 0;
int DutyCycle = 0;
int Frequency = 0;




void TIM2_IRQHandler(void)
{

  TIM_ClearITPendingBit(TIM2, TIM_IT_CC2);


  IC2Value = TIM_GetCapture2(TIM2); //CCR2

  if (IC2Value != 0)
  {
    /* Duty cycle computation */
  IC1Value=TIM_GetCapture1(TIM2);
    DutyCycle = (IC1Value * 100) / IC2Value;

    /* Frequency computation */
    Frequency = SystemCoreClock / IC2Value;
  }
  else
  {
    DutyCycle = 0;
    Frequency = 0;
  }
}

void SetupPWM_Input(void)
{
  /* TIM2 configuration: PWM Input mode ------------------------
     The external signal is connected to TIM2 CH2 pin (PA.01),
     The Rising edge is used as active edge,
     The TIM2 CCR2 is used to compute the frequency value
     The TIM2 CCR1 is used to compute the duty cycle value
  ------------------------------------------------------------ */

//he TIMxCLK frequency is set to 3.6 MHz, the Prescaler is 20 so the TIM2 counter
//clock is 3.6 MHz.  3600M/65535=55Hz The minmum value can be measured is 55Hz,the max is
   TIM_PrescalerConfig(TIM2, 9, TIM_PSCReloadMode_Immediate);   //TIM2CLK/£¨20£©=3.6MHz


  TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;
  TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising ;
  TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
  TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
  TIM_ICInitStructure.TIM_ICFilter = 0x03;

  TIM_PWMIConfig(TIM2, &TIM_ICInitStructure);

  TIM_PrescalerConfig(TIM2, 19, TIM_PSCReloadMode_Immediate);   //TIM2CLK/£¨20£©=3.6MHz

  /* Select the TIM2 Input Trigger: TI2FP2 */
  TIM_SelectInputTrigger(TIM2, TIM_TS_TI2FP2);

  /* Select the slave Mode: Reset Mode */
  TIM_SelectSlaveMode(TIM2, TIM_SlaveMode_Reset);

  /* Enable the Master/Slave Mode */
  TIM_SelectMasterSlaveMode(TIM2, TIM_MasterSlaveMode_Enable);



  /* Enable the CC2 Interrupt Request */
  TIM_ITConfig(TIM2, TIM_IT_CC2, ENABLE);

    /* TIM enable counter */
   TIM_Cmd(TIM2, ENABLE);
}


int main(void)
{

  SystemInit();
  RCC_Configuration();
  SetupPWM_Input();
  SetupNVIC();
  GPIO_Configuration();


  while (1){
  int z;
  GPIO_SetBits(GPIOC,GPIO_Pin_8);

  GPIO_ResetBits(GPIOC,GPIO_Pin_8);
  }
}


void RCC_Configuration(void)
{
  /* TIM3 clock enable */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);

  /* GPIOA clock enable */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
}


void GPIO_Configuration(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

  GPIO_Init(GPIOA, &GPIO_InitStructure);

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

    GPIO_Init(GPIOC, &GPIO_InitStructure);



}


void SetupNVIC(void)
{
  NVIC_InitTypeDef NVIC_InitStructure;

#ifdef  VECT_TAB_RAM
  /* Set the Vector Table base location at 0x20000000 */
  NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
#else  /* VECT_TAB_FLASH  */
  /* Set the Vector Table base location at 0x08000000 */
  NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
#endif

  /* Enable the TIM2 global Interrupt */
  NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);


}


mesaj birleştirme:: 18 Eylül 2013, 00:26:53

buda kendi örneği, yine PC8 de toggle yaptım sadece yükselen kenarda giriyor. Bir Deneyip Sonucu Bana Bildiren olursa sevineceğim.

#include "stm32f10x.h"

/** @addtogroup STM32F10x_StdPeriph_Examples
  * @{
  */

/** @addtogroup TIM_PWM_Input
  * @{
  */

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
TIM_ICInitTypeDef  TIM_ICInitStructure;

/* Private function prototypes -----------------------------------------------*/
void RCC_Configuration(void);
void GPIO_Configuration(void);
void NVIC_Configuration(void);

/* Private functions ---------------------------------------------------------*/

__IO uint16_t IC2Value = 0;
__IO uint16_t DutyCycle = 0;
__IO uint32_t Frequency = 0;


void TIM3_IRQHandler(void)
{
  /* Clear TIM3 Capture compare interrupt pending bit */
  TIM_ClearITPendingBit(TIM3, TIM_IT_CC2);

  /* Get the Input Capture value */
  IC2Value = TIM_GetCapture2(TIM3);

  if (IC2Value != 0)
  {
    /* Duty cycle computation */
    DutyCycle = (TIM_GetCapture1(TIM3) * 100) / IC2Value;

    /* Frequency computation */
    Frequency = SystemCoreClock / IC2Value;
  }
  else
  {
    DutyCycle = 0;
    Frequency = 0;
  }
}





int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured,
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f10x_xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f10x.c file
     */
SystemInit();
  /* System Clocks Configuration */
  RCC_Configuration();

  /* NVIC configuration */
  NVIC_Configuration();

  /* Configure the GPIO ports */
  GPIO_Configuration();

  /* TIM3 configuration: PWM Input mode ------------------------
     The external signal is connected to TIM3 CH2 pin (PA.01),
     The Rising edge is used as active edge,
     The TIM3 CCR2 is used to compute the frequency value
     The TIM3 CCR1 is used to compute the duty cycle value
  ------------------------------------------------------------ */

  TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;
  TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
  TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
  TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
  TIM_ICInitStructure.TIM_ICFilter = 0x0;

  TIM_PWMIConfig(TIM3, &TIM_ICInitStructure);

  /* Select the TIM3 Input Trigger: TI2FP2 */
  TIM_SelectInputTrigger(TIM3, TIM_TS_TI2FP2);

  /* Select the slave Mode: Reset Mode */
  TIM_SelectSlaveMode(TIM3, TIM_SlaveMode_Reset);

  /* Enable the Master/Slave Mode */
  TIM_SelectMasterSlaveMode(TIM3, TIM_MasterSlaveMode_Enable);

  /* TIM enable counter */
  TIM_Cmd(TIM3, ENABLE);

  /* Enable the CC2 Interrupt Request */
  TIM_ITConfig(TIM3, TIM_IT_CC2, ENABLE);

  while (1){
  GPIO_ResetBits(GPIOC,GPIO_Pin_8);
  GPIO_SetBits(GPIOC,GPIO_Pin_8);
  }
}

/**
  * @brief  Configures the different system clocks.
  * @param  None
  * @retval None
  */
void RCC_Configuration(void)
{
  /* TIM3 clock enable */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);

  /* GPIOA clock enable */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);

}

/**
  * @brief  Configure the GPIO Pins.
  * @param  None
  * @retval None
  */
void GPIO_Configuration(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;

  /* TIM3 channel 2 pin (PA.07) configuration */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

  GPIO_Init(GPIOA, &GPIO_InitStructure);

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

    GPIO_Init(GPIOC, &GPIO_InitStructure);
}

/**
  * @brief  Configure the nested vectored interrupt controller.
  * @param  None
  * @retval None
  */
void NVIC_Configuration(void)
{
  NVIC_InitTypeDef NVIC_InitStructure;

  /* Enable the TIM3 global Interrupt */
  NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
}

#ifdef  USE_FULL_ASSERT

/**
  * @brief  Reports the name of the source file and the source line number
  *         where the assert_param error has occurred.
  * @param  file: pointer to the source file name
  * @param  line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t* file, uint32_t line)
{
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

  while (1)
  {}
}

#endif

/**
  * @}
  */

/**
  * @}
  */

/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
Başlık: Ynt: input capture
Gönderen: muhittin_kaplan - 18 Eylül 2013, 00:58:06
Acaba hala hata mı  yapıyorum dedim. ve int rutinin içerisine PC 9 u togge yapacak bir satır ekledim. yani her int girdiğinde PC 9 durum değiştirecekti. PC 8 dende toggle eden basit iki satr yazdım. aşağıdaki şeklde kanal 1 PC8, kanal 2 PC 9 yani int rutini içerisinde durum değiştiren pin.

(http://img7.imageshack.us/img7/7607/py7m.png)

mesaj birleştirme:: 18 Eylül 2013, 00:59:06

Hep Yükselen Kenarda Durum değiştiriyor.
Peki Bu Adamlar Nasıl Ölçüm Yapmış PWM in Duty i ile Frekansını ?

(Hala Acaba Ben mi hata Yapıyorum Bir Yerde Atladığım bir yermi var diyorum.)

mesaj birleştirme:: 18 Eylül 2013, 01:09:03

şu fonksiyon ilginç

void TIM_PWMIConfig(TIM_TypeDef* TIMx, TIM_ICInitTypeDef* TIM_ICInitStruct)
{
  uint16_t icoppositepolarity = TIM_ICPolarity_Rising;
  uint16_t icoppositeselection = TIM_ICSelection_DirectTI;
  /* Check the parameters */
  assert_param(IS_TIM_LIST6_PERIPH(TIMx));
  /* Select the Opposite Input Polarity */
  if (TIM_ICInitStruct->TIM_ICPolarity == TIM_ICPolarity_Rising)
  {
    icoppositepolarity = TIM_ICPolarity_Falling;
  }
  else
  {
    icoppositepolarity = TIM_ICPolarity_Rising;
  }
  /* Select the Opposite Input */
  if (TIM_ICInitStruct->TIM_ICSelection == TIM_ICSelection_DirectTI)
  {
    icoppositeselection = TIM_ICSelection_IndirectTI;
  }
  else
  {
    icoppositeselection = TIM_ICSelection_DirectTI;
  }
  if (TIM_ICInitStruct->TIM_Channel == TIM_Channel_1)
  {
    /* TI1 Configuration */
    TI1_Config(TIMx, TIM_ICInitStruct->TIM_ICPolarity, TIM_ICInitStruct->TIM_ICSelection,
               TIM_ICInitStruct->TIM_ICFilter);
    /* Set the Input Capture Prescaler value */
    TIM_SetIC1Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler);
    /* TI2 Configuration */
    TI2_Config(TIMx, icoppositepolarity, icoppositeselection, TIM_ICInitStruct->TIM_ICFilter);
    /* Set the Input Capture Prescaler value */
    TIM_SetIC2Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler);
  }
  else
  {
    /* TI2 Configuration */
    TI2_Config(TIMx, TIM_ICInitStruct->TIM_ICPolarity, TIM_ICInitStruct->TIM_ICSelection,
               TIM_ICInitStruct->TIM_ICFilter);
    /* Set the Input Capture Prescaler value */
    TIM_SetIC2Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler);
    /* TI1 Configuration */
    TI1_Config(TIMx, icoppositepolarity, icoppositeselection, TIM_ICInitStruct->TIM_ICFilter);
    /* Set the Input Capture Prescaler value */
    TIM_SetIC1Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler);
  }
}

parametrelerin opositini alıyor ve TI2_Config e gönderiyor.
Başlık: Ynt: input capture
Gönderen: muhittin_kaplan - 18 Eylül 2013, 09:42:34
herhangi bir sinyalin 1 de kalma süresini ölçmek istiyorum, çok mu :'(
bunun için hem1 hem 0 a giden kenarların yakalanması gerekmez mi.

neden sadece
TIM_ITConfig(TIM2, TIM_IT_CC2, ENABLE);
yapmışta
TIM_ITConfig(TIM2, TIM_IT_CC1, ENABLE);
i eklememiş.
(biri yükselen diğeri düşen kenar için)
Başlık: Ynt: input capture
Gönderen: JKramer - 18 Eylül 2013, 10:37:51
Belirlediğiniz kenarda capture olduğunda, ilgili register sayıcı değerini donanımsal olarak alıyor; kesmede yazılımsal yapılan bir şey yok. Biz, giriş sinyalinin bir periyodu tamamlandığında register'larda yakalanan capture değerlerini kullanıp frekans ve duty değerini hesaplamak için kesmeye gidiyoruz.
Başlık: Ynt: input capture
Gönderen: muhittin_kaplan - 18 Eylül 2013, 10:44:24
anlamadım.
Başlık: Ynt: input capture
Gönderen: JKramer - 18 Eylül 2013, 10:46:37
Düşen kenarda kesmeye girmesinin bir anlamı yok, daha periyot tamamlanmadı.
Başlık: Ynt: input capture
Gönderen: muhittin_kaplan - 18 Eylül 2013, 10:49:13
ama duty tamamlandı. Duty yi nereden anlıyorsunuz ?
Başlık: Ynt: input capture
Gönderen: JKramer - 18 Eylül 2013, 11:08:01
Düşen kenarda register, sayıcıdan o anki değeri alıyor çünkü CCR1'e bağlı IC1 düşen kenar tetiklemeli. Birkaç mesaj yukarıda "parametrelerin opositini alıyor ve TI2_Config e gönderiyor." demişsiniz ama aslında T1'e gönderiyor çünkü InitStructure'da ayarları yaparken şöyle yazmışsınız: "TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;"
Başlık: Ynt: input capture
Gönderen: yldzelektronik - 18 Eylül 2013, 12:32:59
Belki ihtiyaç vardır.Microchipin app notu.Güzel döküman;

http://s3.dosya.tc/server10/IkUyHY/41214a.pdf.html (http://s3.dosya.tc/server10/IkUyHY/41214a.pdf.html)
Başlık: Ynt: input capture
Gönderen: muhittin_kaplan - 18 Eylül 2013, 13:17:46
Hocam Ürün STM
Başlık: Ynt: input capture
Gönderen: yldzelektronik - 18 Eylül 2013, 13:20:57
Alıntı yapılan: muhittin_kaplan - 18 Eylül 2013, 13:17:46
Hocam Ürün STM

Abi farkındayım da duty ölçümünde frekans ölçümünde metodda yardımı olur diye düşündüm.
Başlık: Ynt: input capture
Gönderen: muhittin_kaplan - 18 Eylül 2013, 13:21:44
@yldzelektronik
Sağol Hocam.

@jkramer
Hocam Konuyu , eğer siizn için problem olmayacaksa örnekle açıklayabilirmisiniz
Başlık: Ynt: input capture
Gönderen: JKramer - 18 Eylül 2013, 15:00:23
[IMG]http://i.imgur.com/7RkRjeQ.png[/img]

Bu resimde TI1, sinyali bağladığınız pin'dir. IC1'den sonrası CCR1 register'ına gidiyor.

Dikkat ederseniz IC1 yazan bölüm, yapacağımız seçime göre TI1FP1'e, TI2FP1'e ya da TRC'ye bağlanabiliyor. (IC1 CCR1'e bağlı) Yani CCR1 register'ının sayaçtan hangi girişle (TI1FP1, TI2FP1, TRC)  hangi olayla (düşen kenar, yükselen kenar) mevcut değeri alacağını (capture edeceğini) seçebiliyoruz. Aynı şey IC2'nin bağlı olduğu CCR2 register'ı için de geçerli.

[IMG]http://i.imgur.com/dGIzbftl.png[/img]

Yukarıdaki resimde yazanları sırayla inceleyelim. Dediği gibi örnek olarak TI1'e PWM uygulansın. Bu durumda CCR1'den periyotu, CCR2'de duty'i alalım.

Sinyali TI1'e uyguladığımız için periyot ve duty değerini alacağımız CCR1 ve CCR2'yi TI1'e bağlamamız lazım.

İlk resime bakarsak; CCR1, IC1'e bağlı. IC1'i TI1FP1'e bağlamak için CCMR1'deki CC1S'e  01 yazmamız gerekiyor (eğer sinyal TI2'den gelseydi, register'a 10 yazarak IC1'i TI2FP1'e bağlamamız gerekecekti). Resimde sola doğru gitmeye devam edelim, sırada polarite seçimi var. Timing diagram'da görüldüğü gibi bununla duty'nin polariteleri ters olmak zorunda. Bu yüzden eğer bunu yükselen kenar tetiklemeli seçersek diğerini düşen kenar tetiklemeli seçmek zorundayız. Diagram'da olduğu gibi yükselen kenar seçtikten sonra bununla işimiz bitti.

Duty'e geçelim. CCR2, IC2'ye bağlı. Bu arkadaşı TI1FP2'e bağlamak için CCMR1'deki CC2S'e 10 yazmamız gerekiyor. Polaritesi de düşen kenar olmalı. TI1FP1 ve TI1FP2 konusunu daha iyi anlayabilmek için STM8 ref. manual'dan aldığım resime bakabilirsiniz:

[IMG]http://i.imgur.com/CLvKXXfl.png[/img]

Sanırım yukarıdaki resim, TI1FP2'nin IC2'ye nasıl bağlandığı konusunda açıklayıcı olmuştur.

Tüm bu bağlantılarla birlikte CCER register'ından capture'ları enable ettikten sonra; sinyalin yükselen kenarı gelmişse CCR1 register'ı sayacın o andaki değerini alacak, düşen kenarı gelmişse CCR2 register'ı sayacın o andaki değerini alacaktır. Yani bu "capture" işlemlerinin, CC1 ya da CC2 kesmesinin açık-kapalı olmasıyla bir ilgisi yok. Zaten bir olay olduğunda (burada düşen kenar-yükselen kenar, USART'da rx kesmesi, vb.) ilgili kesme kapalı dahi olsa bayrağı set ediliyor, öyle değil mi? Burada periyot değerinin saklandığı register CCR1 olduğundan sadece buna bağlı CC1 kesmesini açıyoruz ki periyot ve duty değerlerinin hazır olduğunu bilelim.
Başlık: Ynt: input capture
Gönderen: muhittin_kaplan - 19 Eylül 2013, 01:18:25
Yok benim Tüm Kodları Yeniden Anlayarak Yazmam Gerekiyor.
(kütüphane ile çalışıncada böyle oluyor. neyi nereye bağladın arkadaş.)
Başlık: Ynt: input capture
Gönderen: muhittin_kaplan - 19 Eylül 2013, 21:47:25

Aşağıda denediğim proje var. biryerde hata yapıyorum. belki küçük bir yer, miyop olmamdan dolayı göremiyorumdur.
denemeyi PC8 i PA7 bağlayarak yaptım.

PC8 Toggle Sinyal
PA7 Capture input

pc8 i while döngüsünün içerisinde devamlı toggle yapıyorum.

projeyi deneyip çalışıp çalışmadığını yazarsanız, hatanın nerede olduğunuda mümkünse beni bu ızdıraptan kurtarırsınız.

http://www.dosya.tc/server16/dzEBbt/Hc_Sr_04_Stm32F1xx.rar.html (http://www.dosya.tc/server16/dzEBbt/Hc_Sr_04_Stm32F1xx.rar.html)

altı üstü HC-SR4 ulrasonic sensör dü

Başlık: Ynt: input capture
Gönderen: muhittin_kaplan - 19 Eylül 2013, 22:51:13
Sadece Capture Yapsam Dahi ()çok farklı değerler alıyorum.
Çalışan bir örnek varmı elinizde ?
Başlık: Ynt: input capture
Gönderen: mistek - 20 Eylül 2013, 00:26:38
Hocam sabah örneği deneyeceğim sonucu yazarım.

Birde while içerisinde pin toggle işlemi aralarına biraz gecikme koyarmısınız ? Bit set oluyor birkaç nanosaniye sonra reset oluyor, kenar dedektörü iniş çıkış durumunu fark edemiyordur belki. (Konunun bütününü okumadım "belki" diyerek yazdım.)

-------
Konuya tepeden indiğim için bir sonuca varamadım hocam. Datasheeti adım adım okumak lazım.
Başlık: Ynt: input capture
Gönderen: muhittin_kaplan - 20 Eylül 2013, 21:16:31
sadece capture örneğini yapıyorum mistek. yani bana sadece freq bilgisi verebiliyor.
ondaki değerleri bile usart tan gönderdiğimde

466

466

1003

1003

466

466

1002

1002

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1003

1003

466

466

1002

1002

466

466

1003

1003

466

466

1002

1002

466

466

1002

1002

466

466

1003

1003

466

466

1002



gibi değer ler alıyorum.

mesaj birleştirme:: 20 Eylül 2013, 21:21:19

Orjinal örnek üzerinde yaptığım değişiklik.
USART
GPIOC 8 i pin out olarak kullandım. ve bu çıkışı GPIOA 7 ye yani capture girişine bağladım.
Orjinal örnekte xxxxx_it.h ve c dosyaları kullanmıştı ben TIM3_IRQHandler fonksiyonunu main.c ye aldım. o dosyaları kullanmadım.

/**
  ******************************************************************************
  * @file    TIM/InputCapture/main.c
  * @author  MCD Application Team
  * @version V3.5.0
  * @date    08-April-2011
  * @brief   Main program body
  ******************************************************************************
  * @attention
  *
  * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  *
  * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  ******************************************************************************
  */

/* Includes ------------------------------------------------------------------*/
#include "stm32f10x.h"
#include "stm32f10x_gpio.h"
#include "stm32f10x_flash.h"
#include "stm32f10x_rcc.h"
#include "stm32f10x_tim.h"
#include "stm32f10x_usart.h"
#include "misc.h"
#include <stdio.h>
/** @addtogroup STM32F10x_StdPeriph_Examples
  * @{
  */
__IO uint16_t IC3ReadValue1 = 0, IC3ReadValue2 = 0;
__IO uint16_t CaptureNumber = 0;
__IO uint32_t Capture = 0;
__IO uint32_t TIM3Freq = 0;



/** @addtogroup TIM_Input_Capture
  * @{
  */

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
TIM_ICInitTypeDef  TIM_ICInitStructure;

/* Private function prototypes -----------------------------------------------*/
void RCC_Configuration(void);
void GPIO_Configuration(void);
void NVIC_Configuration(void);

void TIM3_IRQHandler(void)
{

  if(TIM_GetITStatus(TIM3, TIM_IT_CC2) == SET)
  {
    /* Clear TIM3 Capture compare interrupt pending bit */
    TIM_ClearITPendingBit(TIM3, TIM_IT_CC2);
    if(CaptureNumber == 0)
    {
      /* Get the Input Capture value */
      IC3ReadValue1 = TIM_GetCapture2(TIM3);
      CaptureNumber = 1;
    }
    else if(CaptureNumber == 1)
    {
      /* Get the Input Capture value */
      IC3ReadValue2 = TIM_GetCapture2(TIM3);

      /* Capture computation */
      if (IC3ReadValue2 > IC3ReadValue1)
      {
        Capture = (IC3ReadValue2 - IC3ReadValue1);
      }
      else
      {
        Capture = ((0xFFFF - IC3ReadValue1) + IC3ReadValue2);
      }
      /* Frequency computation */
      TIM3Freq = (uint32_t) SystemCoreClock / Capture;
      CaptureNumber = 0;
    }
  }
}

void SetupUSART()
{
      GPIO_InitTypeDef  GPIO_InitStructure;
      USART_InitTypeDef USART_InitStructure;

      /* Enable GPIOA clock                                                   */
      RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);

      /* Configure USART1 Rx (PA10) as input floating                         */
      GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_10;
      GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_IN_FLOATING;
      GPIO_Init(GPIOA, &GPIO_InitStructure);

      /* Configure USART1 Tx (PA9) as alternate function push-pull            */
      GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_9;
      GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
      GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF_PP;
      GPIO_Init(GPIOA, &GPIO_InitStructure);

      USART_InitStructure.USART_BaudRate            = 9600;
      USART_InitStructure.USART_WordLength          = USART_WordLength_8b;
      USART_InitStructure.USART_StopBits            = USART_StopBits_1;
      USART_InitStructure.USART_Parity              = USART_Parity_No ;
      USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
      USART_InitStructure.USART_Mode                = USART_Mode_Rx | USART_Mode_Tx;
      USART_Init(USART1, &USART_InitStructure);
      USART_Cmd(USART1, ENABLE);
}


void USART_puts(USART_TypeDef* USARTx, volatile char *s){

    while(*s){
        // wait until data register is empty
        while( !(USARTx->SR & 0x00000040) );
        USART_SendData(USARTx, *s);
        *s++;
    }
}
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured,
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f10x_xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f10x.c file
     */
SystemInit();
  /* System Clocks Configuration */
  RCC_Configuration();

  /* NVIC configuration */
  NVIC_Configuration();

  /* Configure the GPIO ports */
  GPIO_Configuration();

  SetupUSART();
  /* TIM3 configuration: Input Capture mode ---------------------
     The external signal is connected to TIM3 CH2 pin (PA.07)
     The Rising edge is used as active edge,
     The TIM3 CCR2 is used to compute the frequency value
  ------------------------------------------------------------ */

  TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;
  TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
  TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
  TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
  TIM_ICInitStructure.TIM_ICFilter = 0x0;

  TIM_ICInit(TIM3, &TIM_ICInitStructure);

  /* TIM enable counter */
  TIM_Cmd(TIM3, ENABLE);

  /* Enable the CC2 Interrupt Request */
  TIM_ITConfig(TIM3, TIM_IT_CC2, ENABLE);


  while (1){
  int i;
  GPIO_SetBits(GPIOC,GPIO_Pin_8);
    for (i = 0; i < 1; ++i) {

}

  GPIO_ResetBits(GPIOC,GPIO_Pin_8);
    for (i = 0; i < 1; ++i) {

}

    char Buffer[8];
    sprintf(Buffer,"%ld\r\n",TIM3Freq);
    USART_puts(USART1,Buffer);

  }
}

/**
  * @brief  Configures the different system clocks.
  * @param  None
  * @retval None
  */
void RCC_Configuration(void)
{
  /* TIM3 clock enable */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);

  /* GPIOA and GPIOB clock enable */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_USART1 , ENABLE);
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);


}

/**
  * @brief  Configure the GPIOD Pins.
  * @param  None
  * @retval None
  */
void GPIO_Configuration(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;

  /* TIM3 channel 2 pin (PA.07) configuration */
  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_7;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

  GPIO_Init(GPIOA, &GPIO_InitStructure);

  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_8|GPIO_Pin_9;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

  GPIO_Init(GPIOC, &GPIO_InitStructure);
}

/**
  * @brief  Configure the nested vectored interrupt controller.
  * @param  None
  * @retval None
  */
void NVIC_Configuration(void)
{
  NVIC_InitTypeDef NVIC_InitStructure;

  /* Enable the TIM3 global Interrupt */
  NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
}

#ifdef  USE_FULL_ASSERT

/**
  * @brief  Reports the name of the source file and the source line number
  *         where the assert_param error has occurred.
  * @param  file: pointer to the source file name
  * @param  line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t* file, uint32_t line)
{
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

  while (1)
  {}
}

#endif

/**
  * @}
  */

/**
  * @}
  */

/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
Başlık: Ynt: input capture
Gönderen: mistek - 20 Eylül 2013, 22:33:02
Hocam NXP de yaptığım çalışmayı anlatayım belki fikir verebilir. ST ile çok farklı bir yapıda olabilir emin değilim.

Timer ın Capture registerı var Capture pinine yükselen kenar-düşen kenar geldiğinde O an ki timer değeri Capture Register içerisine yazılıyor.
Dikkat: Eğer her kesme geldiğinde timer sıfırlanmazsa program while içerisinde dönse bile sonraki kesmede aynı değerler gelmeyebilir.

PWM duty cycle okurken.
1) Capture birimi hem yükselen kenarda kesmeoluşturacak hemde düşen kenarda kesme oluşturacak şekilde ayarlanmalı.
2) Yükselen kenar okunur kaydedilir sonra düşen kenar okunur kaydedilir ikisinin farkı duty değerini verir.

Sizdeki örneği çalıştırdım kesme geliyor ancak tek kenar kontrol olduğu için duty değeri burada nasıl çıkacak onu anlayamadım. Yada otomatik olarak donanım düşen kenarda da timer değerini saklıyor olabilir datasheet e bakmak gerek.
Başlık: Ynt: input capture
Gönderen: muhittin_kaplan - 20 Eylül 2013, 22:47:05
Son Verdiğim Örnek, Sadece Freq bilgisi veriyor sanırım. Sadece Capture örneği. PWM input örneğinde ise dediğin gibiymiş. Yani otomatik olarak CCR1 ve CCR2 reg atıyormuş.
(jkramer)
Başlık: Ynt: input capture
Gönderen: muhittin_kaplan - 21 Eylül 2013, 01:26:51
Yok Arkadaş Datasındaki INPUT PWM ı register ile yaptım. Bundada Int giriyor. ama Ne CCR1 Nede CCR2 Artmıyor.
Pes Ettim.
Başlık: Ynt: input capture
Gönderen: muhittin_kaplan - 29 Eylül 2013, 17:10:00
timer ı EXTI ile Başlatıp (yükselen Kenar) Yine EXTI ile durdurabilirmiyim (DÜşen Kenar)
Başlık: Ynt: input capture
Gönderen: muhittin_kaplan - 30 Eylül 2013, 10:33:37
24mhz lik stm32f100rbt6 nın min ölçebileceği freq nedir, 72mhz için 1100hz denmiş
Başlık: Ynt: input capture
Gönderen: Klein - 30 Eylül 2013, 12:38:28
Ön bölücü 16 bit. 72000000 / 65535 =  1098
Başlık: Ynt: input capture
Gönderen: muhittin_kaplan - 30 Eylül 2013, 13:14:55
24000000/65535=366 hz mi yani
Başlık: Ynt: input capture
Gönderen: Klein - 30 Eylül 2013, 13:48:42
Ölçüm yöntemine bağlı. 
Eğer Bir timer kurup  timer taşana kadar geçen sürede kaçdarbe geldiğini sayacaksan, evet ölçebileceğin en düşük frekans bu olacaktır.

Eğer iki kenar arasında geçen süreyi bulup ona göre frekans hesaplayacaksan, çok daha düşük frekansları ölçebilirsin.
Başlık: Ynt: input capture
Gönderen: muhittin_kaplan - 30 Eylül 2013, 13:57:14
Sormamdaki amaç
acaba freq çok mu düşük deger sapıtık çıkıyor. Freq ve duty ölçmek için bir peryodun bitmesi gerek. peryod bitmeden sayıcı overflow olursa değerim yanlış çıkar diye düşünüyorum.
Başlık: Ynt: input capture
Gönderen: Klein - 30 Eylül 2013, 14:22:16
Öçeceğin  periyot nedir?
Başlık: Ynt: input capture
Gönderen: muhittin_kaplan - 30 Eylül 2013, 14:46:15
Hocam Problemi Çözmeye Çalışıyorum. Bir türlü INPUT PWM uygulaması yapamadım. gerçi 30HZ ile 1KHZ  ve hatta 100khz de de denedim.
Başlık: Ynt: input capture
Gönderen: muhittin_kaplan - 01 Ekim 2013, 20:30:25
Şüpheleniyordum, Kendisine ürettiriyordum pwm i, stm32f4disco ile üretince ölçü abi. garip ama debugda bile ölçüyor.
şimdi düşük freq ile deneyeceğim.

mesaj birleştirme:: 01 Ekim 2013, 20:37:15

200hz i denedim. ama ölçtüğüm deger devamlı 1180hz oldu. 24Mhz de
Başlık: Ynt: input capture
Gönderen: muhittin_kaplan - 01 Ekim 2013, 23:12:17
HC-SR04 sensörü ile o freq ulaşılamıyor dolayısıyla input pwm i kullanamayacağım.

önceki sorumu tekrar edeyim,
timer, exti ile tetiklenip durdurulabilir mi ?
Başlık: Ynt: input capture
Gönderen: Klein - 02 Ekim 2013, 17:30:47
Exti ile açıp kapatmaktan kasıt, kesme içinde kod işletmeden, doğrudn pin durumu ile açıp kapatmak sanırım. eğer öyle ise malesef öyle bir ağlantı görmedm datasheetlerde. 
Senin sorununa şöyle bir çözüm önerebilirim.
Timer darbe kaynağı olarak harici bir kaynak veya başka bir timer çıkışını seçersin. Böylece çok daha düşük frekanslara inebilirsin.
Başlık: Ynt: input capture
Gönderen: muhittin_kaplan - 02 Ekim 2013, 20:28:15
Hocam Şöyle EXTI yi yükselen yada düşen kenar yapabiliyoruz EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
buradan yola çıkarak
Yükselen Kenarda Saymaya Başlayan Timer Düşen Kenarda Durursa Ben Duty i almış olurum.


mesaj birleştirme:: 02 Ekim 2013, 20:34:26

şurada ne yapmaya çalıştığını anlamadım.
https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Discovery/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/STM32Discovery/incrementation%20of%20a%20timer%20%20problem&FolderCTID=0x01200200770978C69A1141439FE559EB459D75800084C20D8867EAD444A5987D47BE638E0F&currentviews=296
Başlık: Ynt: input capture
Gönderen: Klein - 03 Ekim 2013, 12:58:46
EXTI yükselen veya düşen kenar olarak ayarlanabiliyor. Ama EXTI ile doğrudan Timer tetikleyeceğin bir bağlantı ben görmedim. Exti ile kesmeye girip kendin aç kapat yapman gerek.
Diğer önerimi düşün bence.

Verdiğin örnek, TIMx_ETR pininden harici darbe ygulayarak, zamanlayıcıyı tetikleme üzerine.
Başlık: Ynt: input capture
Gönderen: muhittin_kaplan - 03 Ekim 2013, 18:12:50
hocam pire için (ultrasonic mesafe sensörü) yorgan yakmak istemiyorum. iki adet timer ı bu iş için heba etmek istemiyorum.
exti ile timer ı (gerekirse kod yazarak) başlatıp durduracağım, EXTI nin yükselen yada düşen kenar olduğunu anlayan bit var mı ? EXTI_IRQ da, kütüphanede böyle bir fonksiyon varmı ?
Başlık: Ynt: input capture
Gönderen: muhittin_kaplan - 03 Ekim 2013, 19:43:57
Şu Şekil Bir Kod Yazsam Yükselen ve düşen kenarı yakalayabilir miyim acaba ? okuyacağım Puls süresi min 150us. 


void EXTI0_IRQHandler(void)
{

    if (EXTI_GetITStatus(EXTI_Line0) != RESET)
    {

    if (GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_0)){
    GPIO_SetBits(GPIOC,GPIO_Pin_8);
    GPIO_ResetBits(GPIOC,GPIO_Pin_9);
    }
    else {
    GPIO_SetBits(GPIOC,GPIO_Pin_9);
    GPIO_ResetBits(GPIOC,GPIO_Pin_8);
    }
        EXTI_ClearITPendingBit(EXTI_Line0);
    }
}
Başlık: Ynt: input capture
Gönderen: muhittin_kaplan - 03 Ekim 2013, 21:19:17
benim yapmak istediğime yakın bir örnek sanırım.

http://wenku.baidu.com/view/f1b4e72758fb770bf78a55f8.html (http://wenku.baidu.com/view/f1b4e72758fb770bf78a55f8.html)
Başlık: Ynt: input capture
Gönderen: Klein - 04 Ekim 2013, 15:53:04
Bu projede Timer'ler çok mu kıymetli? Eğer bu iş için 1 tane ekstra timer kullanırsan , başka işler için timer eksiğin mi kalıyor?

mesaj birleştirme:: 04 Ekim 2013, 15:55:22

Ayrıca, emin olmamakla birlikte , diğer Timer'lara giriş kaynağı olarak kullanacağın bu Timer aynı zamanda kesme de üretebilir. Yani başka işler için de kullanabilirsin aynı zamanda.
Başlık: Ynt: input capture
Gönderen: muhittin_kaplan - 04 Ekim 2013, 17:02:31
Projenin tam gereksinimini bilmiyorum. mümkün olan en az donanımla yapayım isteği var. 
eski Usul Döngü zamanını hesaplayarak ile yapsam mı :)
bana göndereceği sinyal min 150us, max 25ms.
buda 25ms boyunca cpu yu kitleyeceğim anlamına geliyor.
(gelinlik kızlara döndüm, ne kadar kararsızım)
Başlık: Ynt: input capture
Gönderen: Klein - 04 Ekim 2013, 17:54:45
Bence yan yollara sapma.
Sonradan çıkacak ihtiyacı o zaman düşünürsün.  Belki o sorunu çözmek bundan kolay olacak.
Başlık: Ynt: input capture
Gönderen: muhittin_kaplan - 04 Ekim 2013, 18:29:08
onepulse un mantığı nedir hocam timer da.

mesaj birleştirme:: 04 Ekim 2013, 18:37:03

şöyle bir örnek var.
ama her seferinde tmer ı tekrar mı kurmak gerekiyor. basit bir PULS komutu yokmu kütüphanede.
void tim3ch3onePulse()
{

/*Please set RCC before to 24mhz (or calculate new prescalers for your
* desired values)
* */
TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
TIM_OCInitTypeDef  TIM_OCInitStructure;

//set clock to TIM3
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);

//enable port B and alternate function
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB |RCC_APB2Periph_AFIO,ENABLE);

GPIO_InitTypeDef GPIO_InitStructure;

//init port B pin 0 = TIM3 channel 3 to alternate function push-pull

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_0;
GPIO_Init(GPIOB, &GPIO_InitStructure);

//timer basestructure 24mhz/(0+1)/(0+1) ~ 2,72mS (655353/24000000)s for full period
TIM_TimeBaseStructure.TIM_Prescaler = 0 ;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseStructure.TIM_Period = 65535 ;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);


/* TIM3 PWM2 Mode configuration: Channel1 */
//for one pulse mode set PWM2, output enable, pulse (1/(t_wanted=TIM_period-TIM_Pulse)), set polarity high
   TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;
   TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
   TIM_OCInitStructure.TIM_Pulse = 48000;
   TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;

   TIM_OC3Init(TIM3, &TIM_OCInitStructure);

   TIM_OC3PreloadConfig(TIM3, TIM_OCPreload_Enable);

   /* OPM Bit -> Only one pulse */
   TIM3->CR1 |= (1 << 3);
   /* TIM3 enable counter */
   TIM_Cmd(TIM3, ENABLE);

Başlık: Ynt: input capture
Gönderen: Klein - 04 Ekim 2013, 19:12:13
Timer'i yeniden kurmaktan kasıt tüm ayarları tekrar yapmak ise; hayır. Tüm ayarları yeniden yapmana gerek yok. Bir kez ayarlarsın. Timer'i başlatırsın, taşma olunca durur. Sen yeniden başlatırsın.

mesaj birleştirme:: 04 Ekim 2013, 19:22:34

Genel zamanlama için Tick Timer kullanmıyor musun? Muhtemelen kullanıyorsun.
Tick kesmesi içinde bir pini toggle yap. Bu pini de Input Capture için kullanacağın zamanlayıcının CLK girişine bağla. Hem ekstra timer harcamazsın, hem de oldukça düşük frekanslara inersin.
Başlık: Ynt: input capture
Gönderen: muhittin_kaplan - 04 Ekim 2013, 19:23:08
Çokmu soruyorum.
TIMx->CNT o anki sayıcı degerini veriyor. ben bunu nasıl 0 larım .

Başlık: Ynt: input capture
Gönderen: Klein - 04 Ekim 2013, 19:24:44
TIMx->CNT = 0;

Not: Yukarıdaki mesajımı tekrar gözden geçir.
Başlık: Ynt: input capture
Gönderen: muhittin_kaplan - 04 Ekim 2013, 19:25:44
Alıntı yapılan: Klein - 04 Ekim 2013, 19:12:13
Genel zamanlama için Tick Timer kullanmıyor musun? Muhtemelen kullanıyorsun.
Tick kesmesi içinde bir pini toggle yap. Bu pini de Input Capture için kullanacağın zamanlayıcının CLK girişine bağla. Hem ekstra timer harcamazsın, hem de oldukça düşük frekanslara inersin.
gitti bir pin daha. hocam stm ile ultrasonik sensörle Uzaklık Ölçeceğim. Garip Ama deniz derya aşıp, Derede Boğuluyorum.
(Aynştandan bu yana Zaman Mekan Kavramını yitirdim zaten.)

Okudum Hocam, ekleme Mesajları aynı andamı yazmışız
Başlık: Ynt: input capture
Gönderen: Klein - 04 Ekim 2013, 19:51:53
İlk mesajına tekrar baktım.  Prescaler değerine ne verdiğini göremedim.
Senin 200Hz yakalamada bir sorunun olmaması gerek.
Muhtemelen prescaler değerin çok düşük.

Örn:
Yükselen kenarda CNT sıfırlandı ve saymaya başladı.   24MHZ için bölücün 24 olsun.  budurumda geçen her mikrosaniyede CNT değerin 1 artacak.  Düşen kenarda Pulse değerini aldın. Tekrar yükselen kenarda da period değerini aldın.  Frekansın 200Hz = 5mS olduğu için ,  elinde periyot değeri olarak 5000 sayısı olması gerekir.
Başlık: Ynt: input capture
Gönderen: muhittin_kaplan - 04 Ekim 2013, 20:11:47
Bu Konu Neden Bu Kadar uzadı Anlamışda değilim de, yani input pwm ile yapabilmem gerek diye düşünüyordum.

mesaj birleştirme:: 04 Ekim 2013, 20:14:33

bu ST nin input capture örneği. Çalışıyor ama ölçemiyorum.

/* TIM3 configuration: PWM Input mode ------------------------
     The external signal is connected to TIM3 CH2 pin (PA.01),
     The Rising edge is used as active edge,
     The TIM3 CCR2 is used to compute the frequency value
     The TIM3 CCR1 is used to compute the duty cycle value
  ------------------------------------------------------------ */

  TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;
  TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
  TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
  TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
  TIM_ICInitStructure.TIM_ICFilter = 0x0;

  TIM_PWMIConfig(TIM3, &TIM_ICInitStructure);

  /* Select the TIM3 Input Trigger: TI2FP2 */
  TIM_SelectInputTrigger(TIM3, TIM_TS_TI2FP2);

  /* Select the slave Mode: Reset Mode */
  TIM_SelectSlaveMode(TIM3, TIM_SlaveMode_Reset);

  /* Enable the Master/Slave Mode */
  TIM_SelectMasterSlaveMode(TIM3, TIM_MasterSlaveMode_Enable);

  /* TIM enable counter */
  TIM_Cmd(TIM3, ENABLE);

  /* Enable the CC2 Interrupt Request */
  TIM_ITConfig(TIM3, TIM_IT_CC2, ENABLE);

  while (1);
}
Başlık: Ynt: input capture
Gönderen: muhittin_kaplan - 05 Ekim 2013, 00:44:47
aha anambabam usulu hc-sr4
#include "stm32f10x.h"
#include "stm32f10x_rcc.h"
#include "stm32f10x_gpio.h"

int main(void)
{
SystemInit();
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOC, ENABLE);

GPIO_InitTypeDef GPIO_InitStructure;

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_Init(GPIOC, &GPIO_InitStructure);


GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_Init(GPIOC, &GPIO_InitStructure);

int i,z;
float Measure;
  while (1){
//Sorgulama sinyali için 100us lik bir duty gerekiyor.
  GPIO_SetBits(GPIOC,GPIO_Pin_8);
  for (i = 0; i < 0x000000F0; ++i) {

}
  GPIO_ResetBits(GPIOC,GPIO_Pin_8);
 
//Sorgulama Sinyali sonrası yaklaşık 461us bekleniyor. burada sensör echo çıkışı 1 oluyor
                for (i = 0; i < 0x00000468; ++i) {

}
//sensör çıkışı 0 olana kadar i arttırılıyor
  i=0;
  z=1;
  while(z){
  i++;
z=GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_7);
  }
  Measure=(i*24)/58; //24000000hz de uzaklık hesaplanıyor.

//tekrar sorgulama ile araya boşluk koyuluyor. ana program için gereksiz olabilir başka işler yapılır.
  GPIO_ResetBits(GPIOC,GPIO_Pin_8);
    for (i = 0; i < 0x00000FFF; ++i) {

  }

  }
}
Başlık: Ynt: input capture
Gönderen: Klein - 05 Ekim 2013, 13:48:30
ST'nin örneğinde  TımeBase ayarları yok. Muhtemelen örneğin başka bir yerindedir. Önce TimeBse ayarlarını yap.
Başlık: Ynt: input capture
Gönderen: SpeedyX - 06 Ekim 2013, 15:50:40
Merhaba,
stm32f103 de PC9, PB1, PB10 ve PB11 e bağlı butonlardan birine basıldığında bir fonksiyonu çağırmak istiyorum.
EXT_INT ile optimize bir şekilde yapılabilir mi?

Diğer bir sorum da;
Pin e girilen PWM in period ve duty sini bulmak için ne önerirsiniz? Örneğin RC alıcı çıkışındaki PWM sinyalini ölçmek gibi.
Başlık: Ynt: input capture
Gönderen: Klein - 06 Ekim 2013, 16:18:23
Biraz önce Pulse-Period ölçümüörneği yayınladım.
Bu konunun esas meselesi 200Hz olduğu için bu frekansta denedim. sorun yok.