⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 random.c

📁 rt采集卡dos下dm6430驱动源代码
💻 C
字号:
/***************************************************************************

	FILE NAME: RANDOM.C

	FILE DESCRIPTION: RANDOM (Scanning Random Channels)

	 Sample program that demonstrates how to perform an analog to digital
	 conversion on multiple channels using the channel gain table. The
	 channels can be loaded into the table in any order. Burst mode is used
	 to sample all the channels in the table each time the board receives a
	 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.

	 Sample program that uses the Burst Clock, Pacer clock and the channel
	 gain table to acquire data on several channels in random order. The
	 burst clock will start the conversions and the burst clock will be
	 triggered by the pacer clock.

	 While the measurement is running the acquired data on the A/D channels
	 is displayed on the screen, one line with every sample.

	PROJECT NAME: RANDOM (Part of DM6430 DOS Driver)

	DRIVER VERSION: 1.1

	COMPILER: Borland C++ 3.1

	TARGET: Real-Mode DOS

	Copyright 2003 RTD Embedded Technologies

***************************************************************************/

#include <conio.h>
#include <dos.h>

#include "drvr6430.h"
#include "dio5812.h"

/***************************************************************************
  Defines

  Change these constants to alter the program parameters.
****************************************************************************/

#define BASE_ADDRESS     768       		// Base address of DM6430.

#define NUM_OF_ROWS      8             // Number of rows in channel gain table.
#define RATE             1.0 	         // Sample rate in [Hz].
#define BURST_RATE       100000.0      // Burst rate in [Hz].
#define ADSLOPE   		(65536.0/20.0) // Number Bits divided by AD Range.

/***************************************************************************
  SetProgramScreen()

  The SetProgramScreen() function initializes the screen.
****************************************************************************/

void SetProgramScreen(void)
{
  int i;

  clrscr();

  // Print header and footer.
  gotoxy( 1, 1); cprintf(TitleString6430());
  gotoxy(50, 1); cprintf("Random Channel Burst");
  gotoxy( 1,25); cprintf("Press any key to exit. . .");

  // Define data window and print the header of the samples.
  window(1, 3, 80, 23);
  gotoxy(7, 3);
  for (i = 0; i < NUM_OF_ROWS; i++)
	 cprintf("Row  %d  ", i);
} //SetProgramScreen


int main(void)
{
  float Data;                    // Store acquired data.
  unsigned int i;                // Row index or sample index.
  unsigned int BurstCounter;     // Column index or channel index.
  int ADData;                    // Store A/D data.

  ADTableRow ADTable[NUM_OF_ROWS];

  SetProgramScreen();

  SetBaseAddress(BASE_ADDRESS);
  InitBoard6430();               // Board initializing.


  ADTable[0].Channel=0; ADTable[0].Gain=0; ADTable[0].Se_Diff=0; ADTable[0].Pause=0; ADTable[0].Skip=0;		// channel 1
  ADTable[1].Channel=2; ADTable[1].Gain=0; ADTable[1].Se_Diff=0; ADTable[1].Pause=0; ADTable[1].Skip=0;		// channel 3
  ADTable[2].Channel=4; ADTable[2].Gain=0; ADTable[2].Se_Diff=0; ADTable[2].Pause=0; ADTable[2].Skip=0;		// channel 5
  ADTable[3].Channel=6; ADTable[3].Gain=0; ADTable[3].Se_Diff=0; ADTable[3].Pause=0; ADTable[3].Skip=0;		// channel 7
  ADTable[4].Channel=1; ADTable[4].Gain=0; ADTable[4].Se_Diff=0; ADTable[4].Pause=0; ADTable[4].Skip=0;		// channel 2
  ADTable[5].Channel=3; ADTable[5].Gain=0; ADTable[5].Se_Diff=0; ADTable[5].Pause=0; ADTable[5].Skip=0;		// channel 4
  ADTable[6].Channel=5; ADTable[6].Gain=0; ADTable[6].Se_Diff=0; ADTable[6].Pause=0; ADTable[6].Skip=0;		// channel 6
  ADTable[7].Channel=7; ADTable[7].Gain=0; ADTable[7].Se_Diff=0; ADTable[7].Pause=0; ADTable[7].Skip=0;		// channel 8



  SetPacerClock6430(RATE);             // Initialize pacer clock.
  SetBurstClock6430(BURST_RATE);       // Initialize burst clock.
  SetBurstTrigger6430(1);              // Set Burst Trigger = Pacer Clock.
  SetStartTrigger6430(0);              // Set Start Trigger = Software.
  SetStopTrigger6430(0);               // Set Stop Trigger = Software.
  SetConversionSelect6430(2);          // Set Conversion select to Burst Clock.
  LoadADTable6430( NUM_OF_ROWS,ADTable); // Load A/D Table.
  EnableTables6430(1,0);               // Enable A/D Table.
  ClearADFIFO6430();                   //Clear FIFO.



  i = 0;
  StartConversion6430();               // Start conversion.

  while ( !kbhit() ) {                 // Run until any key pressed.
	 gotoxy(7, 5 + i);
	 for (BurstCounter=0; BurstCounter<NUM_OF_ROWS; BurstCounter++) {
		while ( IsADFIFOEmpty6430() & !kbhit());// Wait until data is ready to read.
		ADData = ReadADData6430();              // Get data and convert it to voltages.
		Data = ADData /ADSLOPE;
		cprintf("%6.3f  ", Data);        // Display 'Data'.
	 } //for
	 if (++i == 10) i = 0;
  } //while
  getch();

  window(1,1,80,25);                   // Reset original screen coordinates,
  clrscr();                            // and clears the screen.
  return 0;
} //main

⌨️ 快捷键说明

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