📄 quadcontmultichannelbank.cpp
字号:
/* $Name: H11296_1_1 $ */
/*************************************************
*
* Module:
* Ics564PciDemo
*
* Filename:
* QuadratureMultiChannel.cpp ($Id: QuadratureMultiChannel.cpp,v 1.9 2003/06/11 19:00:13 srozin Exp $)
*
* Description:
* ICS564 Loop demo through PCI data path. DAC in Quadrature Upconverter mode
*
* Copyright:
* Copyright 2002 Interactive Circuits and Systems Ltd.
*
* Revision Log:
* $Log: QuadratureMultiChannel.cpp,v $
* Revision 1.9 2003/06/11 19:00:13 srozin
* Corrected constants
*
* Revision 1.8 2003/03/28 16:37:01 srozin
* Corrected printing
*
* Revision 1.7 2003/03/24 20:42:23 srozin
* Corrected frequency printing
*
* Revision 1.6 2003/03/24 16:35:08 srozin
* Removed warning
*
* Revision 1.5 2003/03/24 16:20:54 srozin
* Corrected Continuous Demo
*
* Revision 1.4 2003/03/17 20:06:36 srozin
* Negative frequency in demo
*
* Revision 1.3 2003/02/21 15:46:04 srozin
* Added single tone demo
*
* Revision 1.2 2002/11/15 19:07:12 srozin
* Made samples working
*
* Revision 1.1 2002/11/14 21:31:46 srozin
* Added Quadrature MOde
*
*
* Author:
* J.T.
*
***********************************************/
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <math.h>
#include "ICS564Api.h"
HANDLE hDevice = INVALID_HANDLE_VALUE;
int *buf = NULL;
unsigned long bytesToWrite = 0;
void
main (int argc, char *argv[])
{
ICS564_USER_CONTROL userControl;
ICS564_FIFO_CONTROL fifoControl;
ICS564_CONTROL brdControl;
ICS564_DAC_INSTRUCTION dacInstr;
ICS564_LOAD transferRegs;
ICS564_DAC_CONFIG dacConfig;
ICS564_DAC_RESET miscDACConfig;
double inputRate;
double angle;
double mhertzPerBin;
int binNumber;
int value;
double centerFrequency;
long tuningWord;
int numChan;
int interpolation;
unsigned long numSamples;
double basebandFrequency;
double dacClkRate;
int timeout = 5;
unsigned long i;
int chan;
unsigned long temp;
int upperData, lowerData;
ULONGLONG trigger;
ULONGLONG bufferLength;
DWORD actualLength;
/* maximum number of samples that can be written to any one channel is (fifo depth - fifo almost full offset) */
/* 262144 = dept of fifo, 16384 = fifo almost full offset flag programmed with MAKE_FIFO_16K_SAMPLES macro */
numSamples = 131072;
numChan = 4; /* Number of output channels */
basebandFrequency= 5.0; /* Output frequency 1-24MHz. This is the baseband freq */
centerFrequency = 70.0; /* Center frequency in MHz. Negative frequencies flip spectrum */
dacClkRate = 50.0*4.0; /* in MHz, 50MHz int.clk, 4x pll multiplier */
interpolation = 4; /* This is the total interpolation. Must be divisible by 4. Range: 4 to 252 */
/*
In the quadrature mode:
Range for centreFrequency:
abs(centreFrequency)<= FS/2*(1-1/interpolation)
& abs(centreFrequency) >=FS/2*(1/interpolation).
This ensures that there is no aliasing.
The bandwidth (incl guardband) is +/-Fs/2*(1/interpolation)
The flattop bandwidth is typically 80% of the total bandwidth
Range of the basebandFrequency (or the baseband frequency):
abs(basebandFrequency)<= 0.4*FS/2*(1/interpolation).
This ensures that the generated signal falls within the pass band
The baseband data must be complex to obtain the full bandwidth of the board.
*/
hDevice = CreateFile ("\\\\.\\ICS564-1",
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, 0, (HANDLE) NULL);
if (INVALID_HANDLE_VALUE == hDevice) {
printf ("Error: Cannot open a handle for ICS564!!!\n");
exit (1);
}
bytesToWrite = numSamples*2; /* number of bytes to be written to 564 fifo */
buf = (int*) malloc (bytesToWrite);
if(NULL == buf) {
printf("Error: Not enough memory for %d bytes\n", bytesToWrite);
goto MainError;
}
memset(buf, 0, bytesToWrite);
/* ics564BoardReset */
if(ICS564_ERROR == ics564BoardReset(hDevice)){
printf("Error: ics564BoardReset failed.\n");
goto MainError;
}
memset(&miscDACConfig,0,sizeof(ICS564_DAC_RESET));
// reset dacs -
miscDACConfig.dac1_rst = 1;miscDACConfig.dac2_rst = 1;
miscDACConfig.dac3_rst = 1;miscDACConfig.dac4_rst = 1;
if(ICS564_ERROR == ics564DACResetSet(hDevice, &miscDACConfig)){
printf("Error: ics564DACResetSet failed.\n");
goto MainError;
}
//clear dac reset bits
miscDACConfig.dac1_rst = 0;miscDACConfig.dac2_rst = 0;
miscDACConfig.dac3_rst = 0;miscDACConfig.dac4_rst = 0;
if(ICS564_ERROR == ics564DACResetSet(hDevice, &miscDACConfig)){
printf("Error: ics564DACResetSet failed.\n");
goto MainError;
}
/* configure all active channels */
for(chan = 0; chan < numChan; chan++) {
memset(&dacInstr,0,sizeof(ICS564_DAC_INSTRUCTION));
/* dac selected bits initialized once */
dacInstr.dac_sel = chan;
dacInstr.data_byte = 0xA4; /* pll at 4x , sdio input only */
dacInstr.address = 0;
if(ICS564_ERROR == ics564DACInstructionSet(hDevice, &dacInstr)){
printf("Error: ics564DACInstructionSet failed.\n");
goto MainError;
}
Sleep(1); /* wait for DAC serial register transfer to finish */
/* set single tone mode */
/* this allows frequency updates using FUD/PDCLK dual pin */
dacInstr.data_byte = 0x01;
dacInstr.address = 1;
if(ICS564_ERROR == ics564DACInstructionSet(hDevice, &dacInstr)){
printf("Error: ics564DACInstructionSet failed.\n");
goto MainError;
}
Sleep(1); /* wait for DAC serial register transfer to finish */
/* CIC interpolation and bypass */
if(interpolation < 5)
dacInstr.data_byte = ((interpolation/4)<<2)|0x1; /* inv cic filter off */
else
dacInstr.data_byte = ((interpolation/4)<<2)|0x0; /* inv cic filter on */
dacInstr.address = 6;
if(ICS564_ERROR == ics564DACInstructionSet(hDevice, &dacInstr)){
printf("Error: ics564DACInstructionSet failed.\n");
goto MainError;
}
Sleep(1); /* wait for DAC serial register transfer to finish */
/* scale output */
dacInstr.data_byte = 181; /* 128 = bypass scaler, 181 compensates for 3dB tunning.loss, 255 maximum value */
dacInstr.address = 7;
if(ICS564_ERROR == ics564DACInstructionSet(hDevice, &dacInstr)){
printf("Error: ics564DACInstructionSet failed.\n");
goto MainError;
}
Sleep(1); /* wait for DAC serial register transfer to finish */
/* Get center frequency increased by 1MHz for each channel */
/* Ensure that the centre frequency for all the channels meet the limits noted earlier */
tuningWord = (long)floor((((double)((centerFrequency + chan)/dacClkRate))*0x100000000));
printf("Upconverter center frequency = %lf MHz on channel %d\n",
(centerFrequency + chan), chan+1);
/* set upc center frequency */
dacInstr.data_byte = ((tuningWord)&0x000000FF);
dacInstr.address = 2;
if(ICS564_ERROR == ics564DACInstructionSet(hDevice, &dacInstr)){
printf("Error: ics564DACInstructionSet failed.\n");
goto MainError;
}
Sleep(1); /* wait for DAC serial register transfer to finish */
dacInstr.data_byte = ((tuningWord>>8)&0x000000FF);
dacInstr.address = 3;
if(ICS564_ERROR == ics564DACInstructionSet(hDevice, &dacInstr)){
printf("Error: ics564DACInstructionSet failed.\n");
goto MainError;
}
Sleep(1); /* wait for DAC serial register transfer to finish */
dacInstr.data_byte = ((tuningWord>>16)&0x000000FF);
dacInstr.address = 4;
if(ICS564_ERROR == ics564DACInstructionSet(hDevice, &dacInstr)){
printf("Error: ics564DACInstructionSet failed.\n");
goto MainError;
}
Sleep(1); /* wait for DAC serial register transfer to finish */
dacInstr.data_byte = ((tuningWord>>24)&0x000000FF);
dacInstr.address = 5;
if(ICS564_ERROR == ics564DACInstructionSet(hDevice, &dacInstr)){
printf("Error: ics564DACInstructionSet failed.\n");
goto MainError;
}
Sleep(1); /* wait for DAC serial register transfer to finish */
/* setup for center freq. update in dac */
/* set ST and FUD bits in dac config reg., these have to be cleared before set again */
/* ST has to be set before FUD and kept set during FUD */
/* ST keeps FUD 3-stated when FUD is PDCLK (dual pin on dac) */
memset(&dacConfig,0,sizeof(ICS564_DAC_CONFIG));
/* drive FUD */
if(0 == chan) dacConfig.dac1_st = ICS564_ENABLE;
if(1 == chan) dacConfig.dac2_st = ICS564_ENABLE;
if(2 == chan) dacConfig.dac3_st = ICS564_ENABLE;
if(3 == chan) dacConfig.dac4_st = ICS564_ENABLE;
if(ICS564_ERROR == ics564DACConfigSet(hDevice, &dacConfig)){
printf("Error: ics564DACConfigSet failed.\n");
goto MainError;
}
/* update center freq. in dac */
if(0 == chan) dacConfig.dac1_fud = ICS564_ENABLE;
if(1 == chan) dacConfig.dac2_fud = ICS564_ENABLE;
if(2 == chan) dacConfig.dac3_fud = ICS564_ENABLE;
if(3 == chan) dacConfig.dac4_fud = ICS564_ENABLE;
if(ICS564_ERROR == ics564DACConfigSet(hDevice, &dacConfig)){
printf("Error: ics564DACConfigSet failed.\n");
goto MainError;
}
/* 3-state FUD */
if(0 == chan) dacConfig.dac1_st = ICS564_DISABLE;
if(1 == chan) dacConfig.dac2_st = ICS564_DISABLE;
if(2 == chan) dacConfig.dac3_st = ICS564_DISABLE;
if(3 == chan) dacConfig.dac4_st = ICS564_DISABLE;
if(ICS564_ERROR == ics564DACConfigSet(hDevice, &dacConfig)){
printf("Error: ics564DACConfigSet failed.\n");
goto MainError;
}
/* clear FUD */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -