Mercurial > hg > fxanalyse
changeset 108:54e7b129ecc2
Minimal cleanup of AD9912 DDS driver
author | Daniele Nicolodi <daniele.nicolodi@obspm.fr> |
---|---|
date | Fri, 28 Jun 2013 14:45:12 +0200 |
parents | 6fd67aa13d10 |
children | 2a9f8a811d87 |
files | DDS4xAD9912.c DDS4xAD9912.h |
diffstat | 2 files changed, 56 insertions(+), 85 deletions(-) [+] |
line wrap: on
line diff
--- a/DDS4xAD9912.c Fri Jun 28 14:33:26 2013 +0200 +++ b/DDS4xAD9912.c Fri Jun 28 14:45:12 2013 +0200 @@ -45,38 +45,43 @@ //============================================================================== -static int DDS4xAD9912_SendCmd(int DDSNum, char * Buffer) // essentially a private function - { - int res_1,res_2; +static int DDS4xAD9912_SendCmd(int DDSNum, char * Buffer) +{ + int port; + int rv; - switch(DDSNum) - { + switch (DDSNum) { case 1: - res_1=ConnectToTCPServer (&hConv, Port1, Adress, OnTCPEvent, 0, 0); - if(res_1 <0) MessagePopup("DDS4xAD9912_1 Serveur", "Connection to server failed !"); + port = Port1; break; case 2: - res_1=ConnectToTCPServer (&hConv, Port2, Adress, OnTCPEvent, 0, 0); - if(res_1 <0) MessagePopup("DDS4xAD9912_2 Serveur", "Connection to server failed !"); + port = Port2; break; - - case 3: - res_1=ConnectToTCPServer (&hConv, Port3, Adress, OnTCPEvent, 0, 0); - if(res_1 <0) MessagePopup("DDS4xAD9912_3 Serveur", "Connection to server failed !"); + case 3: + port = Port3; + break; + case 4: + port = Port4; break; - - case 4: - res_1=ConnectToTCPServer (&hConv, Port4, Adress, OnTCPEvent, 0, 0); - if(res_1 <0) MessagePopup("DDS4xAD9912_4 Serveur", "Connection to server failed !"); - break; - - } + default: + return -1; + } + + rv = ConnectToTCPServer(&hConv, port, Adress, OnTCPEvent, 0, 0); + if (rv < 0) { + MessagePopup("DDS4xAD9912", "Connection to server failed!"); + return rv; + } - res_2=ClientTCPWrite (hConv, Buffer, strlen(Buffer)+1, 0); - if(res_2 <0) MessagePopup("DDS Serveur", "Write to server failed !"); - DisconnectFromTCPServer (hConv); - return (res_1+res_2) ; + rv = ClientTCPWrite(hConv, Buffer, strlen(Buffer)+1, 0); + if (rv < 0) { + MessagePopup("DDS Serveur", "Write to server failed!"); } + + DisconnectFromTCPServer(hConv); + + return rv; +} //============================================================================== @@ -169,63 +174,29 @@ } - -int DDS4xAD9912_FrequencyRampe ( DDS4xAD9912_Data * Instance, int DDSNum, double Frequin,double Frequout, double Step ) +/* + * ramp DDS frequency from `f1` to `f2` in steps of `fstep` + * with a delay of 0.01 seoconds after each step + */ +int DDS4xAD9912_RampFrequency(DDS4xAD9912_Data *dds, int channel, double f1, double f2, double fstep) { - int i=0,imax=0; - double Frequactu=0; - double delaysecond=0.01; - + const double delay = 0.01; - if ( (Frequout - Frequin)>0) - { - if ((Frequout-Frequin) > Step) - { - imax= (Frequout-Frequin)/Step ; - for (i=0; i<imax;i++) - { - Delay(delaysecond); - Frequactu= Frequin+i*Step; - DDS4xAD9912_SetFrequency(Instance, DDSNum, Frequactu); - - } - } - } - - else - { - if ((Frequin-Frequout) > Step) - { - imax= (Frequin-Frequout)/Step ; - for (i=0; i<imax;i++) - { - Delay(delaysecond); - Frequactu= Frequin-i*Step; - DDS4xAD9912_SetFrequency(Instance, DDSNum, Frequactu); - } - } - - } - - DDS4xAD9912_SetFrequency(Instance, DDSNum, Frequout); - return(0); + /* f2 > f1 */ + while ((f2 - f1) > fstep) { + f1 += fstep; + DDS4xAD9912_SetFrequency(dds, channel, f1); + Delay(delay); + } + /* f2 < f1 */ + while ((f1 - f2) > fstep) { + f1 -= fstep; + DDS4xAD9912_SetFrequency(dds, channel, f1); + Delay(delay); + } + + /* final adjustment */ + DDS4xAD9912_SetFrequency(dds, channel, f2); + return 0; } - -/*Word=WORD(Frequactu,Clk); - b5=(unsigned char)(Word/E48); - b4=(unsigned char)((Word - E48*b5)/E32); - b3=(unsigned char)((Word - E48*b5 -E32*b4)/E24); - b2=(unsigned char)((Word - E48*b5 -E32*b4 -E24*b3)/E16); - b1=(unsigned char)((Word - E48*b5 -E32*b4 -E24*b3 -E16*b2)/E8); - b0=(unsigned char)((Word - E48*b5 -E32*b4 -E24*b3 -E16*b2 -E8*b1)/1.0); - reste = (Word - E48*b5 -E32*b4 -E24*b3 -E16*b2 -E8*b1-1.0*b0) ; - sprintf(Request,"set;%i;%i;%i;%i;%i;%i;%i;%i",0,10,b5,b4,b3,b2,b1,b0); - res_0 = DDS4xAD9912_SendCmd(DDSNum, Request) ; - if (DDSNum==1) Instance->Frequency1 = Frequactu - reste*Clk/E48 ; - if (DDSNum==2) Instance->Frequency2 = Frequactu - reste*Clk/E48 ; - if (DDSNum==3) Instance->Frequency3 = Frequactu - reste*Clk/E48 ; - if (DDSNum==4) Instance->Frequency4 = Frequactu - reste*Clk/E48 ; - sprintf(Request,"set;%i;%i",0,18); - res_0 = DDS4xAD9912_SendCmd(DDSNum, Request) ; */ -
--- a/DDS4xAD9912.h Fri Jun 28 14:33:26 2013 +0200 +++ b/DDS4xAD9912.h Fri Jun 28 14:45:12 2013 +0200 @@ -9,7 +9,7 @@ //============================================================================== #ifndef __DDS4XAD9912_H__ -#define __DDS42XAD9912_H__ +#define __DDS4XAD9912_H__ #ifdef __cplusplus extern "C" { @@ -63,14 +63,14 @@ static int DDS4xAD9912_SendCmd(int DDSNum,char *Buffer) ; // essentially a private function, hence the static scope... -int DDS4xAD9912_SetFrequency(DDS4xAD9912_Data * Instance, int DDSNum, double Freq) ; -int DDS4xAD9912_Reset(DDS4xAD9912_Data * Instance) ; -int DDS4xAD9912_FrequencyRampe ( DDS4xAD9912_Data * Instance,int DDSNum, double Frequin,double Frequout, double Step ) ; +int DDS4xAD9912_SetFrequency(DDS4xAD9912_Data * Instance, int DDSNum, double Freq); +int DDS4xAD9912_Reset(DDS4xAD9912_Data * Instance); +int DDS4xAD9912_RampFrequency(DDS4xAD9912_Data *dds, int channel, double f1, double f2, double fstep); #ifdef __cplusplus } #endif -#endif /* ndef __DDS2XAD9858_H__ */ +#endif