实验要求:AD采集100HZ的信号,监测到最低点时输出脉冲信号。
驱动修改:将LED的驱动中GPB5改为GPB1,用于脉冲输出。
程序:#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <linux/fs.h>
#include <errno.h>
#include <string.h>
int main(void)
{
int fd = open("/dev/adc", 0);
int fd1 = open("/dev/leds", 0);
int a = 0;
int aa = 0;
int aaa= 0;
int iii;
if (fd < 0)
{
perror("open ADC device:");
return 1;
}
for(;;)
{
char buffer[30];
int len = read(fd, buffer, sizeof buffer -1);
if (len > 0)
{
buffer[len] = '\0';
int value = -1;
sscanf(buffer, "%d", &value);
printf("ADC Value: %d\n", value);
a=aa;
aa=aaa;
aaa=value;
if ((a>=aa) && (aa<=aaa))
{
printf("make a break : a=%d,aa=%d,aaa=%d\n",a,aa,aaa);
usleep(50);
ioctl(fd1, 1,0);
ioctl(fd1, 1,1);
usleep(50);
ioctl(fd1, 0,0);
ioctl(fd1, 0,1);
}
}
else
{
perror("read ADC device:");
return 1;
}
}
close(fd1);
close(fd);
}
实验结果:1、AD采集每个周期只能采集10个点左右,即1000HZ。
2、脉冲输出信号的脉宽最小只能为5ms,设置为微秒级时无效。
问题:怎么能让AD采集频率提高,脉冲宽度变小啊?到底是usleep的原因?还是驱动程序的原因?还是内核的转换频率设置问题啊?请各位指教。

[ 此帖被张翼881107在2011-08-17 14:55重新编辑 ]