Analog I/O Where to Start? Diamond-MM-32-AT

Hi all,
I’ve just purchased a new analog I/O card (PC/104) Diamond-MM-32-AT. I have
QNX running smoothly, but need to roll my own routines to communicate with
the board. I have read tons of documentation, but now I’m so confused I
don’t know where to start. Basically I want:

-to read/write analog values at regular intervals
-as fast as possible.

Should I be tying to write an ISR or a Resource manager, or can I do this
with a quick set of routines using low level functions like in16(), out16()
and OR’ing bitmasks? If anyone can offer a game plan or even some sample
code I would be extremely appreciative!

I also bought Bob Krten’s book…Getting Started with QNX Neutrino, but have
no idea what code sections I should use…
Thanks for any help you can offer,
-Charles

p.s. I’m a mechanical engineer, but I’m the only semi-software guy around
here, so now I’m bit twiddling, please excuse my ignorance.

dude <asdf@aos.com> wrote:

Hi all,
I’ve just purchased a new analog I/O card (PC/104) Diamond-MM-32-AT. I have
QNX running smoothly, but need to roll my own routines to communicate with
the board. I have read tons of documentation, but now I’m so confused I
don’t know where to start. Basically I want:

-to read/write analog values at regular intervals
-as fast as possible.

Should I be tying to write an ISR or a Resource manager, or can I do this
with a quick set of routines using low level functions like in16(), out16()
and OR’ing bitmasks? If anyone can offer a game plan or even some sample
code I would be extremely appreciative!

I also bought Bob Krten’s book…Getting Started with QNX Neutrino, but have
no idea what code sections I should use…
Thanks for any help you can offer,
-Charles

Hi,

read the whole thing :slight_smile: but the part that will be most relevant to you
is the “Interrupts” section, if you want to handle interrupts (i.e., you
need to get some kind of asynchronous events from the card), and then read
the “resource managers” section. I also have a video training course :slight_smile:

Alternatively, you can just do in/out instructions to talk to the card(s)
if you don’t want/need to do any “decoupling” between the users of the card
and the driver for the card…

Cheers,
-RK


Robert Krten, PARSE Software Devices +1 613 599 8316.
Realtime Systems Architecture, Books, Video-based and Instructor-led
Training and Consulting at www.parse.com.
Email my initials at parse dot com.

Robert Krten <nospam89@parse.com> wrote:
: read the whole thing :slight_smile:

That would be “Read The Full Manual?” :slight_smile:


Steve Reid stever@qnx.com
TechPubs (Technical Publications)
QNX Software Systems

I would really enjoy just using in16() and out16() but there are other
functions like inportb() and outportb() and inp(), outp() which ones should
I use? Does anyone have any code snippets that would be a good place to
start?
The book covers advanced methods of abstraction and wonderful ideas, but i
really want something fast and lean…
-Charles



“Steve Reid” <stever@qnx.com> wrote in message
news:a6nlqj$2u3$1@nntp.qnx.com

Robert Krten <> nospam89@parse.com> > wrote:
: read the whole thing > :slight_smile:

That would be “Read The Full Manual?” > :slight_smile:


Steve Reid > stever@qnx.com
TechPubs (Technical Publications)
QNX Software Systems

Charles <caw2@po.cwru.edu> wrote:

I would really enjoy just using in16() and out16() but there are other
functions like inportb() and outportb() and inp(), outp() which ones should
I use? Does anyone have any code snippets that would be a good place to
start?
The book covers advanced methods of abstraction and wonderful ideas, but i
really want something fast and lean…

They’re all pretty much the same – just depends on if you want to read
8 bits or 16 bits or 32 bits… Sorry, I don’t have any code snippets for
I/O…

Cheers,
-RK

“Steve Reid” <> stever@qnx.com> > wrote in message
news:a6nlqj$2u3$> 1@nntp.qnx.com> …
Robert Krten <> nospam89@parse.com> > wrote:
: read the whole thing > :slight_smile:

That would be “Read The Full Manual?” > :slight_smile:

Yup :slight_smile:


Steve Reid > stever@qnx.com
TechPubs (Technical Publications)
QNX Software Systems


Robert Krten, PARSE Software Devices +1 613 599 8316.
Realtime Systems Architecture, Books, Video-based and Instructor-led
Training and Consulting at www.parse.com.
Email my initials at parse dot com.

Thanks for everyone’s help!

Diamond Systems is currently working on support for QNX so I’ve been told.


“dude” <asdf@aos.com> wrote in message news:a6m6gm$8o0$1@inn.qnx.com

Hi all,
I’ve just purchased a new analog I/O card (PC/104) Diamond-MM-32-AT. I
have
QNX running smoothly, but need to roll my own routines to communicate with
the board. I have read tons of documentation, but now I’m so confused I
don’t know where to start. Basically I want:

-to read/write analog values at regular intervals
-as fast as possible.

Should I be tying to write an ISR or a Resource manager, or can I do this
with a quick set of routines using low level functions like in16(),
out16()
and OR’ing bitmasks? If anyone can offer a game plan or even some sample
code I would be extremely appreciative!

I also bought Bob Krten’s book…Getting Started with QNX Neutrino, but
have
no idea what code sections I should use…
Thanks for any help you can offer,
-Charles

p.s. I’m a mechanical engineer, but I’m the only semi-software guy around
h66 1 so now I’m bit twiddling, please excuse my ignorance.

Charles…

If you are working with RTP (Neutrino base), then in Neutrino you would
do something like what follows. If you are working in QNX 4.25, then you
do the second part…

Hope it helps.

Regards…

Miguel.

P.S. these are for a Dyamond Sys. a/d board.

//////////////// neutrino based system
//////////////////////////////////
template
void ICLad::init( void )
{
int errvalue;

//… attach the hardware adrress…
errno = EOK;
//… get the memory location for device io
ThreadCtl( _NTO_TCTL_IO, 0);
portAD = mmap_device_io( 2, ICL_AD_BASE );
portAD_LSB = mmap_device_io( 1, ICL_AD_PORT_LSB );
portAD_MSB = mmap_device_io( 1, ICL_AD_PORT_MSB );
portAD_CHREG = mmap_device_io( 1, ICL_AD_PORT_CHREG );
portAD_DIO = mmap_device_io( 1, ICL_AD_PORT_DIO );
portAD_SR = mmap_device_io( 1, ICL_AD_PORT_SR );
portAD_CR = mmap_device_io( 1, ICL_AD_PORT_CR );
portAD_TCR = mmap_device_io( 1, ICL_AD_PORT_TCR );
portAD_RBR = mmap_device_io( 1, ICL_AD_PORT_RBR );
portAD_CT0 = mmap_device_io( 1, ICL_AD_PORT_CT0 );
portAD_CT1 = mmap_device_io( 1, ICL_AD_PORT_CT1 );
portAD_CT2 = mmap_device_io( 1, ICL_AD_PORT_CT2 );
portAD_CTRX = mmap_device_io( 1, ICL_AD_PORT_CTRX );
//…
errvalue = errno;
printf( “The error generated was %d\n”, errvalue );
printf( “That means: %s\n”, strerror( errvalue ) );
//…

//…init the state machine
CurrentState = ICL_STATE_MPC_INIT;

//…counter 1 is driven by internal clock, and this counter in
//…turns drives counter 2 which drives the AD interrupt
//…both counters use mode 2, which corresponds to a rate generator.

//…initizlize the counter for internal AD trigger
//… both are binary counters…
out8( portAD_CTRX, 0x74 ); //… 0111 0100 => k1, write lsb frst. then
msb, mode 2, bin
out8( portAD_CTRX, 0xB4 ); //… 1011 0100 => k2, write lsb frst, then
msb, mode 2, bin

//… we want to sample each AD channer at 80 Hz.
out8( portAD_CT1, 0x1A ); //… 0001 1010 => 0x1A 0x61A |
out8( portAD_CT1, 0x06 ); //… 0000 0110 => 0x06 = 1562 | 0x61A*1 =
0X61A = 1562;
out8( portAD_CT2, 0x01 ); //… 0000 0001 => 0x01 = 1 | 1 MHz /
1562 = 640.2 Hz
out8( portAD_CT2, 0 ); //… 0000 0000 => 0x00 = 0 _| 640.2
Hz/8 = 80.02 Hz per AD channel

//…init the counter/timer control register
//…no gate for external A/D clocking, internal input source to
//…timer counter, counters 1 and 2 run freely
out8( portAD_TCR, 0x02 );

//…init the first and final A/D channel to servic: start at
//…channel 0 and end at channel 7 (differential, bipolar)
out8( portAD_CHREG, 0x70 );

//…clear interrupt
out8( portAD_SR, 0);


//…init the A/D Control Register (CR)
//…enable interrupts, interrupt level 7, disable DMA operation,
//…Enable hardware trigger, internal trigger source.
out8( portAD_CR, 0xF3 );
}
////////////////////////////////////////////////////////////////////////


/////////////////// QNX 4.25 based system ////////////////////////////
template
void ICLad::init( void )
{
//…this is how we compile this file…
//… CC -o ad -T1 ad.C

//…init the state machine
CurrentState = ICL_STATE_MPC_INIT;

//…counter 1 is driven by internal clock, and this counter in
//…turns drives counter 2 which drives the AD interrupt
//…both counters use mode 2, which corresponds to a rate generator.

//…initizlize the counter for internal AD trigger
//… both are binary counters…
outp( ICL_AD_PORT_CTRX, 0x74 ); //… 0111 0100 => k1, write lsb frst.
then msb, mode 2, bin
outp( ICL_AD_PORT_CTRX, 0xB4 ); //… 1011 0100 => k2, write lsb frst,
then msb, mode 2, bin

//… we want to sample each AD channer at 80 Hz. _
outp( ICL_AD_PORT_CT1, 0x1A ); //… 0001 1010 => 0x1A 0x61A |
outp( ICL_AD_PORT_CT1, 0x06 ); //… 0000 0110 => 0x06 = 1562 |
0x61A*1 = 0X61A = 1562;
outp( ICL_AD_PORT_CT2, 0x01 ); //… 0000 0001 => 0x01 = 1 | 1 MHz
/ 1562 = 640.2 Hz
outp( ICL_AD_PORT_CT2, 0 ); //… 0000 0000 => 0x00 = 0 _|
640.2 Hz/8 = 80.02 Hz per AD channel

//…init the counter/timer control register
//…no gate for external A/D clocking, internal input source to
//…timer counter, counters 1 and 2 run freely
outp( ICL_AD_PORT_TCR, 0x02 );

//…init the first and final A/D channel to servic: start at
//…channel 0 and end at channel 7 (differential, bipolar)
outp( ICL_AD_PORT_CHREG, 0x70 );

//…clear interrupt
outp(ICL_AD_PORT_SR, 0);


//…init the A/D Control Register (CR)
//…enable interrupts, interrupt level 7, disable DMA operation,
//…Enable hardware trigger, internal trigger source.
outp( ICL_AD_PORT_CR, 0xF3 );
//printf("\n ICL_AD_PORT_CR = %x",inp(ICL_AD_PORT_CR) );

}
////////////////////////////////////////////////////////////////////////

my opinions are mine, only mine, solely mine, and they are not related
in any possible way to the institution(s) in which I study and work.

Miguel Simon
Research Engineer
School of Aerospace and Mechanical Engineering
University of Oklahoma
http://www.amerobotics.ou.edu/
http://www.saic.com