For what it's worth, I attach here following a snippet of the C++ code I
use to drive the I0CG's AD9951 DDS in the SDR-X receiver. Feel free to
use it as an example for your project.

In the code below, the assumptions are that the DDS is connected to the
parallel port in this way :

DDS DATA    D0 (pin 2)
DDS CLOCK   D1 (pin 3)
DDS I/O UPD D2 (pin 4)
DDS RESET   D3 (pin 5)

the pin numbers above are those of the 25-pin Centronics parallel port
connector. The SM object referred to in the code is a kernel driver that
allows to do direct port I/O under Windows XP. The LED object is just
that, a Led in the GUI. You can ignore that.

73  Alberto  I2PHD
-------------------------------------------------------


//----------------------------------------------------------------------\
-----
#define DDS_CLK_HIGH    {x=SM->ReadByte(base);  x |= 0x02;
SM->WriteByte(base, x); Sleep(0);}
#define DDS_CLK_LOW     {x=SM->ReadByte(base);  x &= 0xfd;
SM->WriteByte(base, x); Sleep(0);}
#define DDS_DATA_HIGH   {x=SM->ReadByte(base);  x |= 0x01;
SM->WriteByte(base, x); Sleep(0);}
#define DDS_DATA_LOW    {x=SM->ReadByte(base);  x &= 0xfe;
SM->WriteByte(base, x); Sleep(0);}
#define DDS_UPDATE_HIGH {x=SM->ReadByte(base);  x |= 0x04;
SM->WriteByte(base, x); Sleep(0);}
#define DDS_UPDATE_LOW  {x=SM->ReadByte(base);  x &= 0xfb;
SM->WriteByte(base, x); Sleep(0);}
#define DDS_RESET_HIGH  {x=SM->ReadByte(base);  x |= 0x08;
SM->WriteByte(base, x); Sleep(1);}
#define DDS_RESET_LOW   {x=SM->ReadByte(base);  x &= 0xf7;
SM->WriteByte(base, x); Sleep(1);}

static  long two2_32;          // actually, this is a class member. I
have placed it here for simplicity
static  long double DDSclock;  // actually, this is a class member. I
have placed it here for simplicity
//----------------------------------------------------------------------\
-----
void __fastcall TDLLForm::Initialize(void)
{
     char name[256];

// allocate parallel ports, so to keep Windoze away from it...
     strcpy(name, "LPT1");
     porthandle1 =
        
CreateFile(name,GENERIC_WRITE,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL\
,
                    NULL);

     strcpy(name, "LPT2");
     porthandle2 =
        
CreateFile(name,GENERIC_WRITE,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL\
,
                    NULL);

     two2_32 = 1 << 16;
     two2_32 *= two2_32;
     DDSclock = clockMHz * 1.e6;  // clockMHz can be either 400 or 500

     InitDDS();
}
//----------------------------------------------------------------------\
-----
void __fastcall TDLLForm::InitDDS()
{
     LED->Value = true;
     openLPTport();

     DDS_RESET_HIGH
     DDS_RESET_LOW

     if(clockMHz == 400)   // clockMHz is a class member that can be
either 400 or 500 MHz
     {
       DDSShiftOut(0x01);  // address CFR2
       DDSShiftOut(0);  DDSShiftOut(0);  DDSShiftOut(0x27); // set mult.
fac. to 4
     }                                                      // max pump
current

     DDS_UPDATE_HIGH
     DDS_UPDATE_LOW

     closeLPTport();

     SendFreq(LOfreq);
}
//----------------------------------------------------------------------\
-----
void __fastcall TDLLForm::SendFreq(long freq)
{
     byte b;
     char s[64];
     int    clockMHz, base, x, tword;
     long   double DDSfreq = freq * 4.;;
     int mhz = freq/1000000, khz = (freq - mhz*1000000)/1000, hz = freq -
mhz*1000000 - khz*1000;

     LED->Value = true;
     tword = (int)((DDSfreq / DDSclock) * two2_32 + 0.5);

     openLPTport();

     DDSShiftOut(0x04);              // FTW address
     b = (tword >> 24) & 0x000000ff; // MSB
     DDSShiftOut(b);
     b = (tword >> 16) & 0x000000ff; // MSB - 1
     DDSShiftOut(b);
     b = (tword >> 8)  & 0x000000ff; // MSB - 2
     DDSShiftOut(b);
     b = tword         & 0x000000ff; // MSB - 3  == LSB
     DDSShiftOut(b);

     DDS_UPDATE_HIGH
     DDS_UPDATE_LOW

     closeLPTport();
         sprintf(s, "%3d,%03.3d.%03.3d", mhz, khz, hz);
     LDDSfreq->Caption = s;
     LED->Value = false;
}
//----------------------------------------------------------------------\
-----
void __fastcall TDLLForm::openLPTport(void)
{
     bool bl;

     base = (lpt == one) ? 0x378 : 0x278;

     bl = SM->OpenDriver();
     bl &= SM->IsOpen();

     if(!bl)
     {
       MessageBox(NULL, "Errors opening the kernel driver...", "SDR-X",
MB_OK);
       Application->Terminate();
       return;
     }
}
//----------------------------------------------------------------------\
-----
void __fastcall TDLLForm::closeLPTport(void)
{
     SM->CloseDriver();
}
//----------------------------------------------------------------------\
-----
void __fastcall TDLLForm::DDSShiftOut(byte b)
{
    for(int k=0; k<8; k++)
    {
      if(b & (0x80 >> k))
        DDS_DATA_HIGH
      else
        DDS_DATA_LOW

      DDS_CLK_HIGH
      DDS_CLK_LOW
    }
}
//----------------------------------------------------------------------\
-----





[Non-text portions of this message have been removed]

Reply via email to