- From: Nick Iorio <niorio_at_jmar.com>
- Date: Mon, 21 Feb 2005 14:59:33 -0800
I'm finally able to get back to this task. Below is my attempt to do an
insn for the external trigger and clock. I know I'm supposed to set
command's scan_begin_src to TRIG_OTHER, which I know how to do in the
cmd program but don't know how to do with insn. Do I use a INSN_CONFIG
instruction? If so, how?
When I run this code I get the error:
/dev/comedi0: invalid argument
most of my insn.c:
int main(int argc, char *argv[])
{
int ret,i;
comedi_insn insn[4];
comedi_insnlist il;
struct timeval t1,t2;
lsampl_t data[MAX_SAMPLES];
n_scan = 10; /* override default n_scan value to something more suitable */
parse_options(argc,argv);
if( n_scan > MAX_SAMPLES ){
fprintf( stderr, "Requested too many samples, reducing to %i\n", MAX_SAMPLES );
n_scan = MAX_SAMPLES;
}
device=comedi_open(filename);
if(!device){
comedi_perror(filename);
exit(0);
}
if(verbose){
printf("measuring device=%s subdevice=%d channel=%d range=%d analog reference=%d\n",
filename,subdevice,channel,range,aref);
}
/* Set up a the "instruction list", which is just a pointer
* to the array of instructions and the number of instructions.
*/
il.n_insns=4;
il.insns=insn;
/* Instruction 0: perform a gettimeofday() */
insn[0].insn=INSN_GTOD;
insn[0].n=2;
insn[0].data=(void *)&t1;
/* Instruction 1: perform a timer config */
insn[1].insn=INSN_CONFIG;
insn[1].n=2;
data[0]=INSN_CONFIG_TIMER_1;
data[1]=COMEDI_EV_SCAN_BEGIN;
data[2]=0;
data[3]=0x04;
data[4]=2;
insn[1].data=data;
/* Instruction 2: do 10 analog input reads */
insn[2].insn=INSN_READ;
insn[2].n=n_scan;
insn[2].data=data;
insn[2].subdev=subdevice;
insn[2].chanspec=CR_PACK(channel,range,aref);
/* Instruction 3: perform a gettimeofday() */
insn[3].insn=INSN_GTOD;
insn[3].n=2;
insn[3].data=(void *)&t2;
ret=comedi_do_insnlist(device,&il);
if(ret<0){
comedi_perror(filename);
exit(0);
}
printf("initial time: %ld.%06ld\n",t1.tv_sec,t1.tv_usec);
for(i=0;i<n_scan;i++){
printf("%d\n",data[i]);
}
printf("final time: %ld.%06ld\n",t2.tv_sec,t2.tv_usec);
printf("difference (us): %ld\n",(t2.tv_sec-t1.tv_sec)*1000000+
(t2.tv_usec-t1.tv_usec));
return 0;
}
thanks - nick
}
Frank Mori Hess wrote:
>-----BEGIN PGP SIGNED MESSAGE-----
>Hash: SHA1
>
>On Monday 20 December 2004 11:49 am, Nick Iorio wrote:
>
>
>>I've posted this question at comedi.org and not received a response. My
>>boss keeps bugging me to get this external clock code working but I
>>don't know how to do it.
>>I found a reference to this INSN_CONFIG_TIMER_1 since I sent this email
>>which helps some but still leaves a lot of questions. Now, I guess the
>>data structures should look like:
>>
>>data[0]=INSN_CONFIG_TIMER_1;
>>data[1]=COMEDI_EV_SCAN_BEGIN; correct?
>>
>>
>
>Yes. And you want to set your command's scan_begin_src to TRIG_OTHER.
>
>
>
>>data[2]= ??? trigger negative edge (digital, not analog trigger)
>>
>>
>
>That would be "channel_number | CR_INVERT | CR_EDGE". The driver doesn't
>care though. I assume I ignored that parameter in the driver because the
>hardware doesn't let you configure that. I really should have added some
>verification that the hardware behaves the way you are requesting it to
>though.
>
>
>
>>data[3]=0x04;
>>data[4]=??? divisor for 10Mhz clock
>>
>>
>
>If you set the divisor to N, then the board will trigger on every Nth clock
>signal it receives from your external clock. The hardware's minimum
>divisor is 2.
>
>
>
>>As you can see I'm still guessing on some of this. If there's any
>>documentation that would help me please point me to it.
>>
>>
>>
>
>there isn't any, aside from what you already found, and the driver source
>code.
>
>- --
>Frank
>
>-----BEGIN PGP SIGNATURE-----
>Version: GnuPG v1.2.4 (GNU/Linux)
>
>iD8DBQFBx3nH5vihyNWuA4URAlj8AKDQPVHElK5pN3afNm76fNvQhdm+dACgjS5Y
>ER7YVL4l/ZYTktKK36CMzrI=
>=xNc4
>-----END PGP SIGNATURE-----
>
>_______________________________________________
>comedi mailing list
>comedi_at_comedi.org
>https://cvs.comedi.org/cgi-bin/mailman/listinfo/comedi
>
>
Received on 2005-02-21Z22:59:33