Main Page | Modules | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

ad6620.c

Go to the documentation of this file.
00001 /*! \file ad6620.c \brief Analog Devices AD6620 Digital Receiver Driver. */
00002 //*****************************************************************************
00003 //
00004 // File Name    : 'ad6620.c'
00005 // Title        : Analog Devices AD6620 Digital Receiver Driver
00006 // Author       : Pascal Stang - Copyright (C) 2004
00007 // Created      : 2004.07.08
00008 // Revised      : 2004.07.12
00009 // Version      : 0.1
00010 // Target MCU   : ARM processors
00011 // Editor Tabs  : 4
00012 //
00013 // NOTE: This code is currently below version 1.0, and therefore is considered
00014 // to be lacking in some functionality or documentation, or may not be fully
00015 // tested.  Nonetheless, you can expect most functions to work.
00016 //
00017 // This code is distributed under the GNU Public License
00018 //      which can be found at http://www.gnu.org/licenses/gpl.txt
00019 //
00020 //*****************************************************************************
00021 
00022 #include "lpc2000.h"
00023 
00024 #include "global.h"
00025 #include "timer.h"
00026 #include "membus.h"
00027 #include "rprintf.h"
00028 #include "ad6620.h"
00029 
00030 // global variables
00031 
00032 void ad6620Write(unsigned int addr, unsigned char data)
00033 {
00034     ((volatile u16*)AD6620_REG_BASE)[addr] = data;
00035 }
00036 
00037 unsigned char ad6620Read(unsigned int addr)
00038 {
00039     return ((volatile u16*)AD6620_REG_BASE)[addr];
00040 }
00041 
00042 void ad6620Init(void)
00043 {
00044     //membusInit();
00045 
00046     // reset device
00047     //IOSET = AD9854_RESET;
00048     //IODIR |= AD9854_RESET;
00049     //delay(10000);
00050     //IOCLR = AD9854_RESET;
00051 
00052     // initialize registers
00053 
00054     // initialize receiver - set soft reset
00055     ad6620WriteReg(AD6620_REG_MODE_CTRL, 0x01);
00056     // initialize RCF filter coeffs
00057     ad6620WriteReg(AD6620_REG_RCF_COEFF, 0x20000);
00058     // set NCO
00059     ad6620WriteReg(AD6620_REG_NCO_CTRL, 0);
00060     ad6620WriteReg(AD6620_REG_NCO_SYNC, 0);
00061     ad6620WriteReg(AD6620_REG_NCO_FREQ, 0);
00062     ad6620WriteReg(AD6620_REG_NCO_PHASE, 0);
00063     // set CIC2 filter
00064     ad6620WriteReg(AD6620_REG_CIC2_SCALE, 6);
00065     ad6620WriteReg(AD6620_REG_CIC2_DECIM, 16-1);
00066 //  ad6620WriteReg(AD6620_REG_CIC2_SCALE, 2);
00067 //  ad6620WriteReg(AD6620_REG_CIC2_DECIM, 4-1);
00068     // set CIC5 filter
00069     ad6620WriteReg(AD6620_REG_CIC5_SCALE, 20);
00070     ad6620WriteReg(AD6620_REG_CIC5_DECIM, 32-1);
00071 //  ad6620WriteReg(AD6620_REG_CIC5_SCALE, 12);
00072 //  ad6620WriteReg(AD6620_REG_CIC5_DECIM, 10-1);
00073     // set RCF filter
00074     ad6620WriteReg(AD6620_REG_RCF_CTRL, 1);
00075     ad6620WriteReg(AD6620_REG_RCF_DECIM, 32-1);
00076     ad6620WriteReg(AD6620_REG_RCFADDR_OFS, 0);
00077     ad6620WriteReg(AD6620_REG_RCF_TAPS, 0);
00078 //  ad6620WriteReg(AD6620_REG_RCF_TAPS, 32-1);
00079     // set reserved register to zero
00080     ad6620WriteReg(AD6620_REG_RESERVED, 0x00);
00081     // initialize receiver - set operation mode
00082     ad6620WriteReg(AD6620_REG_MODE_CTRL, 0x08);
00083 
00084 }
00085 
00086 void ad6620WriteReg(u16 reg, u32 data)
00087 {
00088     // write address
00089     ad6620Write(AD6620_REG_AMR, reg>>8);
00090     ad6620Write(AD6620_REG_LAR, reg);
00091     // write value
00092     ad6620Write(AD6620_REG_DR3, data>>24);
00093     ad6620Write(AD6620_REG_DR2, data>>16);
00094     ad6620Write(AD6620_REG_DR1, data>>8);
00095     ad6620Write(AD6620_REG_DR0, data);
00096 }
00097 
00098 
00099 u32 ad6620ReadReg(u16 reg)
00100 {
00101     u32 data;
00102     // write address
00103     ad6620Write(AD6620_REG_AMR, reg>>8);
00104     ad6620Write(AD6620_REG_LAR, reg);
00105     // read value
00106     data  = (ad6620Read(AD6620_REG_DR0) & 0x000000FF);
00107     data |= (ad6620Read(AD6620_REG_DR1) & 0x000000FF)<<8;
00108     data |= (ad6620Read(AD6620_REG_DR2) & 0x000000FF)<<16;
00109     data |= (ad6620Read(AD6620_REG_DR3) & 0x000000FF)<<24;
00110     return data;
00111 }
00112 
00113 void ad6620SetNCOMode(u08 mode)
00114 {
00115     ad6620WriteReg(AD6620_REG_NCO_CTRL, mode);
00116 }
00117 
00118 void ad6620SetNCOFreq(u32 freqHz)
00119 {
00120     u32 nco_freq;
00121     nco_freq = ((u64)freqHz<<32)/(AD6620_REFCLK_FREQ);
00122     ad6620WriteReg(AD6620_REG_NCO_FREQ, nco_freq);
00123 }
00124 
00125 void ad6620SetNCOPhase(u16 phase)
00126 {
00127     ad6620WriteReg(AD6620_REG_NCO_PHASE, phase);
00128 }
00129 
00130 void ad6620LoadRCFilter(int start, int taps, s32* coeffs)
00131 {
00132     int i;
00133     // load RCF filter taps into receiver
00134     for(i=0;i<taps;i++)
00135     {
00136         ad6620WriteReg(AD6620_REG_RCF_COEFF+start+i, coeffs[i]>>12);
00137     }
00138 }
00139 
00140 
00141 void ad6620ShowRegisters(void)
00142 {
00143     // read and print all registers
00144 
00145     rprintfStr("Mode Control      :       0x");
00146     rprintfu08(ad6620ReadReg(AD6620_REG_MODE_CTRL));
00147     rprintfCRLF();
00148 
00149     rprintfStr("NCO Control       :       0x");
00150     rprintfu08(ad6620ReadReg(AD6620_REG_NCO_CTRL));
00151     rprintfCRLF();
00152 
00153     rprintfStr("NCO SYNC Control  : 0x");
00154     rprintfu32(ad6620ReadReg(AD6620_REG_NCO_SYNC));
00155     rprintfCRLF();
00156 
00157     rprintfStr("NCO Frequency     : 0x");
00158     rprintfu32(ad6620ReadReg(AD6620_REG_NCO_FREQ));
00159     rprintfCRLF();
00160 
00161     rprintfStr("NCO Phase Offset  :     0x");
00162     rprintfu16(ad6620ReadReg(AD6620_REG_NCO_PHASE));
00163     rprintfCRLF();
00164 
00165     rprintfStr("INPUT/CIC2 Scale  :       0x");
00166     rprintfu08(ad6620ReadReg(AD6620_REG_CIC2_SCALE));
00167     rprintfCRLF();
00168 
00169     rprintfStr("CIC2 Decimation   :       0x");
00170     rprintfu08(ad6620ReadReg(AD6620_REG_CIC2_DECIM));
00171     rprintfCRLF();
00172 
00173     rprintfStr("CIC5 Scale        :       0x");
00174     rprintfu08(ad6620ReadReg(AD6620_REG_CIC5_SCALE));
00175     rprintfCRLF();
00176 
00177     rprintfStr("CIC5 Decimation   :       0x");
00178     rprintfu08(ad6620ReadReg(AD6620_REG_CIC5_DECIM));
00179     rprintfCRLF();
00180 
00181     rprintfStr("OUTPUT/RCF Control:       0x");
00182     rprintfu08(ad6620ReadReg(AD6620_REG_RCF_CTRL));
00183     rprintfCRLF();
00184 
00185     rprintfStr("RCF Decimation    :       0x");
00186     rprintfu08(ad6620ReadReg(AD6620_REG_RCF_DECIM));
00187     rprintfCRLF();
00188 
00189     rprintfStr("RCF Address Offset:       0x");
00190     rprintfu08(ad6620ReadReg(AD6620_REG_RCFADDR_OFS));
00191     rprintfCRLF();
00192 
00193     rprintfStr("RCF Taps          :       0x");
00194     rprintfu08(ad6620ReadReg(AD6620_REG_RCF_TAPS));
00195     rprintfCRLF();
00196 }
00197     

Generated on Mon Nov 6 23:36:58 2006 for Procyon ARMlib by  doxygen 1.4.2