极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 18274|回复: 4

arduino 如何测定输入信号频率?

[复制链接]
发表于 2015-1-16 19:06:01 | 显示全部楼层 |阅读模式
是这样的,我需要测定一个转轴的实时转速,买了如下图所示的转速仪,600脉冲/转
我想通过实时测定信号频率,确定转速
请教如何通过arduino 测定输入信号频率?

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复

使用道具 举报

发表于 2015-1-16 22:11:13 | 显示全部楼层
这是我测风扇转速的,你可以参考一下

//code by Crenn from http://thebestcasescenario.com
//project by Charles Gantt from http://themakersworkbench.com


/*To disable interrupts:
cli();                // disable global interrupts

and to enable them:  
sei();                // enable interrupts
*/


                                   //Varibles used for calculations
int NbTopsFan;
int Calc;

                                  //The pin location of the sensor
int hallsensor = 2;

                        
typedef struct{                  //Defines the structure for multiple fans and their dividers
  char fantype;
  unsigned int fandiv;
}fanspec;

//Definitions of the fans
fanspec fanspace[3]={{0,1},{1,2},{2,8}};

char fan = 1;   //This is the varible used to select the fan and it's divider, set 1 for unipole hall effect sensor
               //and 2 for bipole hall effect sensor


void rpm ()      //This is the function that the interupt calls
{
NbTopsFan++;
}

              //This is the setup function where the serial port is initialised,
             //and the interrupt is attached
void setup()
{
pinMode(hallsensor, INPUT);
Serial.begin(9600);
attachInterrupt(0, rpm, RISING);
}
void loop ()
{
   NbTopsFan = 0;        //Set NbTops to 0 ready for calculations
   sei();                //Enables interrupts
   delay (1000);        //Wait 1 second
   cli();                //Disable interrupts
   Calc = ((NbTopsFan * 60)/fanspace[fan].fandiv); //Times NbTopsFan (which is apprioxiamately the fequency the fan is spinning at) by 60 seconds before dividing by the fan's divider
   Serial.print (Calc, DEC); //Prints the number calculated above
   Serial.print (" rpm\r\n"); //Prints " rpm" and a new line
}
回复 支持 反对

使用道具 举报

发表于 2015-1-17 17:19:19 | 显示全部楼层
用中断计时
回复 支持 反对

使用道具 举报

发表于 2015-1-17 19:43:10 | 显示全部楼层
这是我用来测cpu风扇转速的程序,很好用,你这个应该也能适用

//code by Crenn from http://thebestcasescenario.com
//project by Charles Gantt from http://themakersworkbench.com


/*To disable interrupts:
cli();                // disable global interrupts

and to enable them:  
sei();                // enable interrupts
*/


                                   //Varibles used for calculations
int NbTopsFan;
int Calc;

                                  //The pin location of the sensor
int hallsensor = 2;

                        
typedef struct{                  //Defines the structure for multiple fans and their dividers
  char fantype;
  unsigned int fandiv;
}fanspec;

//Definitions of the fans
fanspec fanspace[3]={{0,1},{1,2},{2,8}};

char fan = 1;   //This is the varible used to select the fan and it's divider, set 1 for unipole hall effect sensor
               //and 2 for bipole hall effect sensor


void rpm ()      //This is the function that the interupt calls
{
NbTopsFan++;
}

              //This is the setup function where the serial port is initialised,
             //and the interrupt is attached
void setup()
{
pinMode(hallsensor, INPUT);
Serial.begin(9600);
attachInterrupt(0, rpm, RISING);
}
void loop ()
{
   NbTopsFan = 0;        //Set NbTops to 0 ready for calculations
   sei();                //Enables interrupts
   delay (1000);        //Wait 1 second
   cli();                //Disable interrupts
   Calc = ((NbTopsFan * 60)/fanspace[fan].fandiv); //Times NbTopsFan (which is apprioxiamately the fequency the fan is spinning at) by 60 seconds before dividing by the fan's divider
   Serial.print (Calc, DEC); //Prints the number calculated above
   Serial.print (" rpm\r\n"); //Prints " rpm" and a new line
}
回复 支持 反对

使用道具 举报

发表于 2015-1-17 20:31:34 | 显示全部楼层
用中断计数,我用stm32最高测到1.37M
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|联系我们|极客工坊

GMT+8, 2026-6-10 05:07 , Processed in 0.060439 second(s), 21 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表