資源簡介
使用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
評論
共有 條評論