📄 dac.c
字号:
/***************************************************************************
FILE NAME: DAC.C
FILE DESCRIPTION: DAC (Digtal to Analog conversion)
Sample program that demonstrates how to use the analog output.
This program demonstrates how to use the digital to analog converters on
the A/D board. The program simply scans the output of the DAC from the
low end of its range to the high end of its range in millivolt steps.
When the scan reaches the high end of the DAC's range it starts over at
the low end of the range.
One A/D channel is displayed in the middle of the screen while this
program is running. If you wire the D/A channel to this A/D channel
you can monitor the output of the DAC directly on your computer.
Alternatively, you can monitor the output of the DAC with an oscilloscope.
PROJECT NAME: DAC (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 AD_CHAN 0 // Channel to read D/A data back.
#define GAIN 0 // Gain (for A/D).
#define ADRANGE 0 // -5 to +5 volts.
#define SE_DIFF 0 // Single-ended.
#define AD_SLOPE (65536.0/20.0) // Number Bits divided by AD Range.
#define DAC_SLOPE (65536.0/20.0) // Number Bits divided by DAC Range.
#define DAC_OFFSET 0 // Offset of the output line signal.
/***************************************************************************
SetProgramScreen()
The SetProgramScreen function initializes the screen.
****************************************************************************/
void SetProgramScreen(void)
{
clrscr();
// Print header and footer.
gotoxy( 1, 1); cprintf(TitleString6430());
gotoxy(43, 1); cprintf("Digital to Analog Conversions");
gotoxy( 1,25); cprintf("Press any key to exit. . .");
// Define data window and print labels for the samples.
window(1, 3, 80, 23);
gotoxy(20, 6); cprintf("D/A output Channel 1 : ");
gotoxy(20, 8); cprintf("A/D input Channel %d : ", AD_CHAN + 1);
gotoxy(20, 10); cprintf("Difference: ");
} //SetProgramScreen
int main(void)
{
int mV; // mV counter.
int DAData; // Data for analog output.
float ADData; // Variable to store acquired data.
int Data;
SetProgramScreen();
SetBaseAddress(BASE_ADDRESS);
InitBoard6430(); // Board initializing.
SetConversionSelect6430(0); // Set conversion select to software.
SetChannelGain6430(AD_CHAN, GAIN, SE_DIFF); // Initilaize Single A/D conversion.
ClearADFIFO6430(); // Clear A/D fifo.
mV = -5000; // Start DAC scan at -5000 mvolts.
while ( !kbhit() ) { // Run untill any key is pressed.
DAData = ((mV / 1000.0) * DAC_SLOPE) + DAC_OFFSET;
// Counting output data.
LoadDAC6430(DAData); // Sending analog output data.
StartConversion6430(); // Perform a Single A/D conversion.
while ( IsADFIFOEmpty6430() ); // Wait until data is ready to read.
Data = ReadADData6430(); // Read acquired data.
ADData = Data /AD_SLOPE; // Convert AD data to Volts.
gotoxy(43, 6); cprintf("%6.3f V", (float)mV/1000.0);
// Display output Data.
gotoxy(43, 8); cprintf("%6.3f V", ADData);
// Display input Data.
gotoxy(43,10); cprintf("%6.3f V", (float)mV/1000.0 - ADData);
// Display the difference.
mV += 10; // Increment data.
if (mV > 5000) // If greater than 5,000 mvolts
mV = -5000; // Start over at -5,000 mvolts.
} //while
getch(); // Read the pressed character.
LoadDAC6430(0); // Sending analog output data.
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 + -