• 大小: 4KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-15
  • 语言: 其他
  • 标签: STM32F103  频率计  

资源简介

使用STM32内部的定时器的捕获模式采集输入的PWM波的频率,测量范围在大约1K~100K,精度到整数位

资源截图

代码片段和文件信息

#include “stm32f10x.h“  //包含的头文件,此头文件会包含库中的一些头文件

void RCC_Configuration(void);
void NVIC_Configuration(void);
void GPIO_Configuration(void);
void Time_Configuration(void);

ErrorStatus HSEStartUpStatus;

/********************************************************************************
* 名    称: int main(void)
* 功    能:主函数
* 入口参数:无
* 出口参数:无
* 说    明:
*******************************************************************************/
int main(void)
{
SystemInit();
GPIO_Configuration();
RCC_Configuration();
NVIC_Configuration(); 

Time_Configuration();   

while(1)
{   

}
}

void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA ENABLE);

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);
}

/********************************************************************************
* 名    称: void Time_Configuration()
* 功    能:定时器配置函数
* 入口参数:无
* 出口参数:无
* 说    明:
*******************************************************************************/
void Time_Configuration()
{
TIM_ICInitTypeDef  TIM_ICInitStructure;

TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;
  TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Falling;
  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_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);
}

/*******************************************************************************
* Function Name  : RCC_Configuration
* Description    : Configures the different system clocks.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void RCC_Configuration(void)
{
  /* TIM2 clock enable */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3 ENABLE);
}
/*******************************************************************************
* Function Name  : NVIC_Configuration
* Description    : Configure the nested vectored interrupt controller.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void NVIC_Configuration(void)
{
  NVIC_InitTypeDef NVIC_InitStructure;

  /* Enable the T

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       3356  2013-07-17 11:38  User\main.c

     文件      23218  2013-07-17 11:38  User\stm32f10x_it.c

     文件       2086  2011-04-04 19:03  User\stm32f10x_it.h

     目录          0  2013-07-17 11:38  User

----------- ---------  ---------- -----  ----

                28660                    4


评论

共有 条评论