dm6430-multi-burst.c

来自「rt 6430 采集卡 linux下驱动源代码」· C语言 代码 · 共 172 行

C
172
字号
/*	FILE NAME: dm6430-multi-burst.c	FILE DESCRIPTION: Burst scan on multiple channels sample program		Sample program that demonstrates how to perform an analog to		digital conversion on multiple channels using the channel gain		table.  Burst mode means that all the channels in the table		are sampled once for each trigger.  The time between channels		is set by the burst clock.  If the burst clock is set to the		highest rate, this mode simulates simultaneous sampling.		This program uses the Burst Clock, Pacer clock and the channel		gain table to acquire data on several channels.  The burst		clock starts the conversions.  The pacer clock triggers the		burst clock.		While the measurement is running, the acquired A/D data is		displayed on the screen, one line with every sample.	PROJECT NAME: Linux DM6430 Driver, Library, and Example Programs	PROJECT VERSION: (Defined in README.TXT)	Copyright 2004 RTD Embedded Technologies, Inc.  All Rights Reserved.*/#include <errno.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <sys/poll.h>#include <unistd.h>#include <dm6430lib.h>#define FIRST_CHAN3	DM6430HR_AIN1	// First channel to scan#define NUM_OF_CHAN3	8		// Number of channels to scan#define RATE3		1		// Sample rate in [Hz]#define BURST_RATE3	100000		// Burst rate in [Hz]#define ADSLOPE3	(65536.0/20.0)	// Number Bits divided by AD Rangechar *program_name_p;static voidusage(void) {    fprintf(	stderr,	"\n"        "Usage: %s MINOR_NUMBER"        "\n",	program_name_p    );    exit(EXIT_FAILURE);}static voidverify_success(int status, const char *message_p) {    if (status == -1) {	perror(message_p);	exit(EXIT_FAILURE);    }}static intisstdindata(int timeout) {    struct pollfd	in = {0, POLLIN | POLLERR | POLLPRI, 0};    int			num_fds;    while (((num_fds = poll(&in, 1, timeout)) == -1) && (errno == EINTR))	;    return ((num_fds == 1) && (in.revents & (POLLIN | POLLPRI)));}intmain(int argument_count, char **arguments_p_p) {    ADTableRow		ADTable[NUM_OF_CHAN3];    double		dummy;    int			channel;    int			descriptor;    int			status;    unsigned int	minor_number;    program_name_p = arguments_p_p[0];    if (argument_count != 2) {	fprintf(stderr, "Invalid number of options given.\n");	usage();    }    if (sscanf(arguments_p_p[1], "%u", &minor_number) == 0) {	fprintf(stderr, "Invalid device minor number.\n");	usage();    }    descriptor = OpenBoard6430(minor_number);    verify_success(descriptor, "OpenBoard6430() FAILED");    status = InitBoard6430(descriptor);    verify_success(status, "InitBoard6430() FAILED");    for (channel = 0; channel < NUM_OF_CHAN3; channel++) {	ADTable[channel].Channel = (FIRST_CHAN3 + channel);	ADTable[channel].Gain = DM6430HR_GAINx1;	ADTable[channel].Se_Diff = DM6430HR_SE_SE;	ADTable[channel].Pause = 0;	ADTable[channel].Skip = 0;    }    status = SetPacerClock6430(descriptor, RATE3, &dummy);    verify_success(status, "SetPacerClock6430() FAILED");    status = SetBurstClock6430(descriptor, BURST_RATE3, &dummy);    verify_success(status, "SetBurstClock6430() FAILED");    status = SetBurstTrigger6430(descriptor, DM6430HR_BURST_TRIG_PACER);    verify_success(status, "SetBurstTrigger6430() FAILED");    status = SetStartTrigger6430(descriptor, DM6430HR_START_TRIG_SOFTWARE);    verify_success(status, "SetStartTrigger6430() FAILED");    status = SetStopTrigger6430(descriptor, DM6430HR_STOP_TRIG_SOFTWARE);    verify_success(status, "SetStopTrigger6430() FAILED");    status = SetConversionSelect6430(descriptor, DM6430HR_CONV_BURST_CLOCK);    verify_success(status, "SetConversionSelect6430() FAILED");    status = LoadADTable6430(descriptor, NUM_OF_CHAN3, ADTable);    verify_success(status, "LoadADTable6430() FAILED");    status = EnableTables6430(descriptor, 1, 0);    verify_success(status, "EnableTables6430() FAILED");    status = ClearADFIFO6430(descriptor);    verify_success(status, "ClearADFIFO6430() FAILED");    fprintf(stdout, "AIN1 - AIN8 range = bipolar 10V\nPress Enter for stop\n");    status = StartConversion6430(descriptor);    verify_success(status, "StartConversion6430() FAILED");    while (!isstdindata(200)) {	for (channel = 0; channel < NUM_OF_CHAN3; channel++) {	    int		empty_flag;	    int16_t	data;	    do {		status = IsADFIFOEmpty6430(descriptor, &empty_flag);		verify_success(status, "IsADFIFOEmpty6430() FAILED");	    } while (empty_flag);	    status = ReadADData6430(descriptor, &data);	    verify_success(status, "ReadADData6430() FAILED");	    fprintf(		stdout, "CH%d: %+04.1lf mV\n", (channel + 1), data / ADSLOPE3	    );	}	fprintf(stdout, "\n");    }    exit(EXIT_SUCCESS);}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?