📄 amltscan.c
字号:
/***************************************************************************
FILE NAME: AMLTSCAN.C
FILE DESCRIPTION: AMLTSCAN (Automatic Channel Scanning)
Sample program that demonstrates how to use the pacer clock, sample
counter and channel gain table to scan groups of channels, multiple
times.
This program will show how to use the sample counter and the pacer
clock features of the DM6430 to do MULTI-SCAN sampling. The board
will be set up to sample a set of channels, 3 times every time the
board receives a trigger from the on board 8254.
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: AMLTSCAN (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 FIRST_CHAN 0 // First channel to scan.
#define NUM_OF_CHAN 4 // Number of channels to scan.
#define RATE 1000.0 // Sample rate in [Hz].
#define USER_RATE 1.0 // Measurement trigger period 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.
gotoxy(1,1); cprintf(TitleString6430());
gotoxy(50, 1); cprintf("Automatic Multi Channel Scan");
// Print footer.
gotoxy(1, 25);
cprintf("Press <Esc> 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_CHAN; i++)
cprintf(" CH %d ", FIRST_CHAN + i + 1);
} //SetProgramScreen
int main(void)
{
unsigned int i; // Cycle variable for display.
float Data; // Store acquired data.
int ch; // Store the pressed character.
int ADData; // Store A/D data.
float ActualRate0; // Actual clock rate returned from timer 0.
ADTableRow ADTable[NUM_OF_CHAN];
SetProgramScreen(); // Prepare the screen.
SetBaseAddress(BASE_ADDRESS);
InitBoard6430(); // Board initializing.
for (i=0;i<NUM_OF_CHAN;i++) { // Set Up AD Table.
ADTable[i].Channel=FIRST_CHAN+i; // Set Channel.
ADTable[i].Gain=0; // Set Gain.
ADTable[i].Skip=0; // Set Skip Bit.
ADTable[i].Se_Diff=0; // Set single ended or differential.
ADTable[i].Pause=0; // Set Pause Bit.
}
SetPacerClock6430(RATE*NUM_OF_CHAN); // Initialize pacer clock.
ActualRate0 = SetUserClock6430(0, 8000000.0, 20000.0); // Initialize User Clock0.
SetUserClock6430(1, ActualRate0, USER_RATE); // Initialize User Clock1.
SetTriggerRepeat6430(1); // Enable trigger repeat.
SetStartTrigger6430(3); // Set Start trigger User TC Counter 1.
SetStopTrigger6430(3); // Set Stop Trigger Sample Counter.
SetConversionSelect6430(1); // Set Conversion Pacer Clock.
LoadADSampleCounter6430(NUM_OF_CHAN*3); // Load Sample Counter.
LoadADTable6430(NUM_OF_CHAN,ADTable); // Load ADTable.
EnableTables6430(1,0); // Enable AD table.
ClearADFIFO6430(); // Clear FIFO.
ch = 0; // Initialize program variables.
i = 0;
gotoxy(7, 5); // Position the cursor on the screen.
StartConversion6430(); // Start conversion.
while ( ch != 27 ) { // Run untill any <ESC> is pressed.
if ( kbhit() ) { // Check the keyboard.
ch = getch(); // Get the pressed character.
} //if ( kbhit() )
if ( !IsADFIFOEmpty6430() ) { // Check if conversion ready.
ADData = ReadADData6430(); // Read acquired data.
Data = ADData / ADSLOPE; // Convert data to Volts.
cprintf("%6.3f ", Data); // Display Data.
if ((++i % NUM_OF_CHAN) == 0)
gotoxy(7, 5 + i/NUM_OF_CHAN); // Next line.
if (i == (10 * NUM_OF_CHAN)) {
i = 0; // Next screen.
gotoxy(7, 5);
} //if
} //if A/D ready
} //while
window(1,1,80,25); // Reset original screen coordinates,
clrscr(); // and clear the screen.
return 0;
} //main
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -