狗趴(GodPub),开源硬件学习与实践

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
查看: 7163|回复: 3
打印 上一主题 下一主题

【二叔科技】二叔测频率的测试

[复制链接]

13

主题

33

帖子

155

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
155
跳转到指定楼层
楼主
发表于 2014-11-25 15:25:12 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
要测频率先得有一个频率源吧,不太准凑合用,用blink改造一下,大概20Hz的样子吧
  1. /*
  2.   Blink
  3.   Turns on an LED on for one second, then off for one second, repeatedly.

  4.   This example code is in the public domain.
  5. */

  6. // Pin 13 has an LED connected on most Arduino boards.
  7. // give it a name:
  8. int led = 13;

  9. // the setup routine runs once when you press reset:
  10. void setup() {               
  11.   // initialize the digital pin as an output.
  12.   pinMode(led, OUTPUT);     
  13. }

  14. // the loop routine runs over and over again forever:
  15. void loop() {
  16.   digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  17.   delay(25);               // wait for a second
  18.   digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  19.   delay(25);               // wait for a second
  20. }
复制代码


分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏

13

主题

33

帖子

155

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
155
沙发
 楼主| 发表于 2014-11-25 15:56:31 | 只看该作者
参考了一个卖传感器的商家的代码,当年二叔买这个传感器花了40+还有运费,一直扔着没用呢
http://detail.etao.com/18934469888.htm
  1. int pin = 8;
  2. unsigned long duration;
  3. unsigned long starttime;
  4. unsigned long sampletime_ms = 5000;
  5. unsigned long lowpulseoccupancy = 0;
  6. float ratio = 0;

  7. void setup() {
  8.   Serial.begin(9600);
  9.   pinMode(pin,INPUT);
  10.   starttime = millis();
  11. }

  12. void loop() {
  13.   duration = pulseIn(pin, LOW);
  14.   lowpulseoccupancy++;
  15.   if ((millis()-starttime) > sampletime_ms)
  16.   {
  17.     ratio = lowpulseoccupancy*1000/sampletime_ms;
  18.     Serial.print(ratio);
  19.     Serial.println("Hz");
  20.     lowpulseoccupancy = 0;
  21.     starttime = millis();
  22.   }
  23. }
复制代码



13

主题

33

帖子

155

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
155
板凳
 楼主| 发表于 2014-11-25 15:58:22 | 只看该作者
测试结果20Hz蛮准确的


改到250Hz(不一定准),测得结果249Hz,这个结果可以接受啦

13

主题

33

帖子

155

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
155
地板
 楼主| 发表于 2014-11-25 16:04:11 | 只看该作者
更专业的频率测试,不过二叔没看懂,来自饥渴工坊
http://www.geek-workshop.com/thread-3085-1-1.html
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|狗趴(GodPub) Arduino&Raspberry Pi开源硬件学习与实践[QQ群:20085629]  

GMT+8, 2024-5-7 11:22 , Processed in 0.027715 second(s), 32 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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