我是一名大学生,需要学习有关在BeagleBone Black中进行ADC捕获的知识。
一切顺利。我可以从ADC采样数据,甚至可以在每个采样值中打印时间戳。然后,我使用示波器检查了我获得的结果的采样周期,并使用“ BeagleBoneBlack-GPIO ”库检查了来自GPIO P8_10的波形。最后,我意识到采样周期根本不稳定。 / p>
我以为我应该在BeagleBone Black中使用Interrupt计时器。但是我自己的根本领还很低。
无论如何。如何通过c ++通过GPIO设置中断计时器,因为我需要使用中断计时器来控制ADC来实现稳定的采样周期(例如3ms)。
下面的数据是我正在使用的版本,代码以及现在的结果
-BeagleBone Black -Debian GNU/LInux 8.11 (jessie) -Linux 5.0.3-bone5 -ARMv7 Processor rev2 (v7l)
#include <stdio.h>
#include <sys/time.h>
#include <time.h>
#include <math.h>
#include<iostream>
#include<fstream>
#include<string>
#include<sstream>
#include<unistd.h>
#include "GPIO/GPIOManager.h"
#include "GPIO/GPIOConst.h"
using namespace std;
#define LIN0_PATH "/sys/bus/iio/devices/iio:device0/in_voltage"
int readAnalog(int number){
stringstream ss;
ss << LIN0_PATH << number << "_raw";
fstream fs;
fs.open(ss.str().c_str(), fstream::in);
fs >> number;
fs.close();
return number;
}
int main(int argc, char* argv[ ]){
int i=0;
GPIO::GPIOManager* gp = GPIO::GPIOManager::getInstance();
int pin1 = GPIO::GPIOConst::getInstance()->getGpioByKey("P8_10");
gp->setDirection(pin1, GPIO::OUTPUT);
char buffer[26];
int millisec;
struct tm* tm_info;
struct timeval tv;
gettimeofday(&tv, NULL);
millisec = lrint(tv.tv_usec/1000.0); // Round to nearest millisec
if (millisec>=1000) {
millisec -=1000;
tv.tv_sec++;
} tm_info = localtime(&tv.tv_sec);
strftime(buffer, 26, "%d/%m/%Y %H:%M:%S", tm_info);
cout<<"print date and time"<<buffer<<":"<<millisec << endl;
for (int j=0;j<100;j++){
gp->setValue(pin1, GPIO::HIGH);
float value[j] = readAnalog(0)*(1.8/4096) ;
gp->setValue(pin1, GPIO::LOW);
usleep(300);
}
for (int j=0;j<100;j++){
cout << fixed;
cout.precision(3);
cout <<i<<";"<<value<< endl;
i++; }
return 0; }
这些是运行我的文件的命令
g++ GPIO/GPIOConst.cpp GPIO/GPIOManager.cpp try.cpp
然后
./a.out
这就是结果
print date and time10/04/2019 17:02:27:460 0;1.697 1;1.697 2;1.695 3;1.693 4;1.694 5;1.693 6;1.693 7;1.692 8;1.691 9;1.692 10;1.693 11;1.692 12;1.694 13;1.694 14;1.694 15;1.692 16;1.695 17;1.692 18;1.693 19;1.694 20;1.693 21;1.691 22;1.692 23;1.693 24;1.691 25;1.693 26;1.693 27;1.693 28;1.694 29;1.691 30;1.694 31;1.693 32;1.695 33;1.691 34;1.694 35;1.693 36;1.693 37;1.691 38;1.693 39;1.691 40;1.692 41;1.694 42;1.692 43;1.692 44;1.693 45;1.692 46;1.694 47;1.693 48;1.693 49;1.692 50;1.692 51;1.692 52;1.691 53;1.690 54;1.691 55;1.692 56;1.693 57;1.692 58;1.692 59;1.692 60;1.694 61;1.694 62;1.694 63;1.694 64;1.693 65;1.692 66;1.693 67;1.692 68;1.693 69;1.693 70;1.692 71;1.692 72;1.693 73;1.694 74;1.693 75;1.694 76;1.693 77;1.692 78;1.694 79;1.692 80;1.692 81;1.692 82;1.692 83;1.692 84;1.694 85;1.694 86;1.693 87;1.693 88;1.694 89;1.693 90;1.693 91;1.692 92;1.694 93;1.691 94;1.694 95;1.693 96;1.691 97;1.692 98;1.693 99;1.694
[这是我从示波器得到的] [1]
如果有人愿意给我一些建议,那将是非常不错的。而且,如果有关于你们的事情。请随时问我。
最好的问候
花生花生酱