阅读:2004回复:13
evoc 711b 采集卡,dos,求中断例程。查询可以,中断不行
/* _dos_getvect and _dos_setvect example */
#include <stdio.h> #include <dos.h>//for interrupt function #include <conio.h>//for i/o function #ifdef __cplusplus #define __CPPARGS ... #else #define __CPPARGS #endif #define TIME_INTR 0x1c #define PCL711BASE 0x220 void interrupt get_out(__CPPARGS); /* interrupt prototype */ void interrupt (*oldfunc)(__CPPARGS); /* interrupt function pointer */ void interrupt pcl_count(__CPPARGS); /* pcl interrupt prototype */ void interrupt (*old6func)(__CPPARGS); /* irq=6 interrupt function pointer */ int looping = 1; int time_counter = 0; int pulse_counter = 0; int low_data = 0; int high_data = 0; int main(void) { puts(\"Programe start!\"); //disable();//close all interrupt //Start timer /* save the old time interrupt */ oldfunc = _dos_getvect(TIME_INTR); /* install time interrupt handler */ _dos_setvect(TIME_INTR,get_out); //Initial 711b outp(PCL711BASE+10,0);//set sample chanel 0 outp(PCL711BASE+9,0);//set gain +-5V outp(PCL711BASE+11,0x63);//set IRQ=6, mode = interrupt/pulse // outp(PCL711BASE+11,0x66); outp(PCL711BASE+1,0x28); outp(PCL711BASE+2,0x0a); // old6func = _dos_getvect(6);//save the old no6 interrupt _dos_setvect(6,pcl_count); outp(PCL711BASE+8,0); //enable();//open all interript /* do loop nothing */ do { if(!(high_data & 0x10)) printf(\"%d,%d,%d\\n\",pulse_counter,low_data,high_data); } while (looping); /* restore to original interrupt routine */ _dos_setvect(TIME_INTR,oldfunc); _dos_setvect(6,old6func); puts(\"Success\"); return 0; } void interrupt get_out(__CPPARGS) { //disable(); //printf(\"current pulse counter = %d\",pulse_counter); time_counter++; if(time_counter>100) looping = 0; /* change global var to get out of loop */ pulse_counter = 0; //enable(); return; } void interrupt pcl_count(__CPPARGS) { //disable(); high_data = inp(PCL711BASE+5); low_data = inp(PCL711BASE+4); pulse_counter++; outp(PCL711BASE+8,0); //enable(); } |
|
沙发#
发布于:2002-08-12 09:56
有什么错误呢?
printf(\"%d,%d,%d\\n\",pulse_counter,low_data,high_data); 不输出? |
|
板凳#
发布于:2002-08-12 10:24
问题是:
一,程序结束时pulse_counter=0;。 是否要设置8259的参数呢?怎样设置, 二,我试过设置8259的参数,开中断,关中断,发EOI,然后,中断可以进去了,但是采样频率只有200hz。即,程序结束时,pulse_counter=2000。 qq:117234850 |
|
地板#
发布于:2002-08-12 11:49
对你的irq6,要设8259的,开,关,EOI等。
dos的时钟频率不是1/100秒呀。 用if(time_counter>100) looping = 0;来计时算中断频率对吗? |
|
地下室#
发布于:2002-08-12 12:06
谢谢arthurtu
采样频率是由下面的语句定的,是板上的时钟 outp(PCL711BASE+11,0x66); outp(PCL711BASE+1,0x28); outp(PCL711BASE+2,0x0a); if(time_counter>100) looping = 0;是控制总的工作时间 我设为if(time_counter>185) looping = 0;及总的工作时间是10秒,dos的时钟中断每秒18.5次。 |
|
5楼#
发布于:2002-08-12 12:21
采样频率应该是多少呢?
|
|
6楼#
发布于:2002-08-12 15:31
thanks arthurtu
c1=>outp(PCL711BASE+1,0x28); c2=>outp(PCL711BASE+2,0x0a); F=2M/c1*c2=2.5Khz |
|
7楼#
发布于:2002-08-12 16:32
2。5khz,不算高啊。
应该是你的测算不准。 |
|
8楼#
发布于:2002-08-12 17:13
我不是测算的,是在中断服务例程里,加了一个计数,pulse_counter,在程序结束后,显示这个值,就是中断进去的次数。
|
|
9楼#
发布于:2002-08-13 08:31
呵呵,我的意思就是觉得你的代码不太好,结果当然就不太好。
考虑改进一下下? ;) |
|
10楼#
发布于:2002-08-13 09:24
怎样改进?提供点思路。不是每次进中断就计数器+1吗?还有别的方法?
|
|
11楼#
发布于:2002-08-13 11:36
计时的方法改进一下下?
|
|
12楼#
发布于:2002-08-13 11:59
你的意思是:我用的时钟不准吗?我需要额外的加定时器吗?
|
|
13楼#
发布于:2002-08-13 16:44
void interrupt get_out(__CPPARGS) {
//disable(); time_counter++; //if(time_counter>100) looping = 0; /* change global var to get out of loop */ //enable(); return; } //充当计时,像GetTickCount() void interrupt pcl_count(__CPPARGS) { //disable(); high_data = inp(PCL711BASE+5); low_data = inp(PCL711BASE+4); pulse_counter++; if(timer_counter>= (18.2*5)) //5秒或2秒 { //frq是个全局的float,在main里面输出 frq=18.2 * (float)pulse_counter/timer_counter; timer_counter=0; //在main里面初始化为0 } outp(PCL711BASE+8,0); //enable(); } 不知道精度能有多少,18.2可能会有较大的误差。 |
|