我用迷你f1做了个频率计,要求是能测任何波形,
0.1-3v,
能测1-1Mhz,
但是实际只能测到165-1Mhz,如何才能改进精度测到1-165hz?
程序:
#include "delay.h"
#include "sys.h"
#include "usart.h"
#include "timer.h"
#include "lcd.h"
extern u32 TIM2CH1_CAPTURE_VAL;//êäèë2¶»ñÖμ
extern u32 a,b;
extern u32 OverValve;
extern u16 period;
extern u16 duty;
extern u8 CollectFlag ;
int main(void)
{
uart_init(9600);
delay_init();
LCD_Init();
TIM5_PWMINPUT_INIT(0xffff,72-1); //pwmêäèë3õê¼»ˉòÔ1MμÄÆμÂê2¶×½
TIM3_Int_Init(9999,7199);//10KhzμļÆêyÆμÂ꣬¼Æêyμ½5000Îa500ms
TIM2_Cap_Init();
NVIC_Configuration(); //éèÖÃNVICÖD¶Ï·Ö×é2:2λÇàÕ¼óÅÏ輶£¬2λÏìó|óÅÏ輶
POINT_COLOR=BLUE;//éèÖÃ×ÖìåÎaà¶é«
LCD_ShowString(10,60,200,24,24,"Frequency Unit ");
// LCD_ShowString(35,90,200,24,24," to practice");
POINT_COLOR=RED;
while(1)
{
delay_ms(10);
// if(!CollectFlag)
// {
//// LCD_ShowString(10,180,200,24,24,"Duty cycle:");
//// LCD_ShowxNum(140,180,(period+1)*100/(duty+1),5,24,0);//ÏÔê¾Õ¼¿Õ±è
//
//// LCD_ShowString(10,240,200,24,24,"Period:");
//// LCD_ShowxNum(140,240,(duty)+1,5,24,0);//ÏÔê¾ÖüÆú
// CollectFlag = 1;
// }
if(a<1000)
{
LCD_ShowxNum(10,150,a,10,24,0);
LCD_ShowString(130,150,200,24,24," HZ");
}
else if(a>1000)
{
LCD_ShowxNum(10,150,a,10,24,0);//
LCD_ShowString(130,150,200,24,24," HZ");
}
}
}
你的程序没有贴中断处理的内容,所以不知道楼主是用什么方式实现的
一周热门 更多>