- From: Salvador Eduardo Tropea <salvador_at_inti.gov.ar>
- Date: Wed, 04 Feb 2004 15:31:05 -0300
Hi All! I attached a test program that I used to test my patch that adds support for the 8254 found in PCI DAS08 boards. I´m sending it so the mailing list archive gets a copy and people looking for an example can try it. I added some comments explaining the external connections needed to run the test and what should you get. Regards, SET -- Salvador Eduardo Tropea (SET). (Electronics Engineer) Visit my home page: http://welcome.to/SetSoft or http://www.geocities.com/SiliconValley/Vista/6552/ Alternative e-mail: set_at_computer.org set_at_ieee.org Address: Curapaligue 2124, Caseros, 3 de Febrero Buenos Aires, (1678), ARGENTINA Phone: +(5411) 4759 0013
/*
* Test example to test the 8254 support for the PCI DAS08 board.
* Coded by Salvador Eduardo Tropea.
* Based on "Tutorial example #1" that's part of Comedilib:
*
* Copyright (c) 1999,2000 David A. Schleef <ds_at_schleef.org>
*
* This file may be freely modified, distributed, and combined with
* other software, as long as proper attribution is given in the
* source code.
*
* Notes: You have to connect any of the digital outputs (the program
* drives all at the same time ;-) to the channel 0 clock. That's pin
* 2 (CTR1 CLK) for my board.
* You also have to provide a logic level 1 in the gate of this
* channel (pin 21 CTR1 GATE) in order to enable the channel.
*
* Compile with: gcc -o 8254test 8254test.c -lcomedi
*
* How to use:
* After doing the above mentioned connection run this program passing
* one argument in the command line. It will program channel 0 in Mode
* 0 and set the initial count to 6.
* Then run the program again without an argument. It will decrement
* the counter and show 0x30 as status.
* Run it again and again until you reach 0, in this run the status
* will become 0xB0. It indicates the output for this channel is 1 and
* that's what should happend in mode 0.
*
*/
#include <stdio.h> /* for printf() */
#include <comedilib.h>
int subdev = 5; /* change this to your input subdevice */
int chan = 0; /* change this to your channel */
int range = 0; /* more on this later */
int aref = AREF_GROUND; /* more on this later */
int main(int argc,char *argv[])
{
comedi_t *it;
int chan=0;
lsampl_t data[5];
comedi_insn insn;
it=comedi_open("/dev/comedi0");
comedi_data_read(it,subdev,chan,range,aref,data);
/* If the counter is 0 or we want to force it: */
if (!data[0] || argc>1)
{/* Set channel 0 as mode 0 and binary counter */
memset(&insn,0,sizeof(insn));
insn.insn = INSN_CONFIG;
insn.n = 2;
insn.data = data;
insn.subdev = subdev;
insn.chanspec = CR_PACK(chan,0,0);
data[0]=INSN_CONFIG_8254_SET_MODE;
data[1]=I8254_MODE0 | I8254_BINARY;
comedi_do_insn(it,&insn);
/* Set the channel 0 counter to 6 */
comedi_data_write(it,subdev,chan,range,aref,0x6);
}
/* Generate a pulse in the digital outputs */
comedi_data_write(it,3,0,range,aref,0);
comedi_data_write(it,3,0,range,aref,0xFF);
comedi_data_write(it,3,0,range,aref,0);
/* Read the channel 0 of the counter */
comedi_data_read(it,subdev,chan,range,aref,data);
printf("Counter %X\n",data[0]);
/* Read the status for channel 0 counter */
memset(&insn,0,sizeof(insn));
insn.insn = INSN_CONFIG;
insn.n = 2;
insn.data = data;
insn.subdev = subdev;
insn.chanspec = CR_PACK(chan,0,0);
data[0]=INSN_CONFIG_8254_READ_STATUS;
comedi_do_insn(it,&insn);
printf("Status %X\n",data[1]);
return 0;
}
Received on 2004-02-04Z18:31:05