Commit de9cf8e01a92cebf53fd9405e6f184081d65075e

Authored by bachi
1 parent 5ddf572fd3
Exists in master

ad9915.c & ad9915.h : suppression de la fonction checksize

Showing 2 changed files with 0 additions and 5 deletions Inline Diff

/* 1 1 /*
dds initialisation et SPI 2 2 dds initialisation et SPI
*/ 3 3 */
4 4
#include <stdint.h> 5 5 #include <stdint.h>
#include <unistd.h> 6 6 #include <unistd.h>
#include <stdio.h> 7 7 #include <stdio.h>
#include <stdlib.h> 8 8 #include <stdlib.h>
#include <getopt.h> 9 9 #include <getopt.h>
#include <fcntl.h> 10 10 #include <fcntl.h>
#include <sys/ioctl.h> 11 11 #include <sys/ioctl.h>
#include <linux/types.h> 12 12 #include <linux/types.h>
#include <linux/spi/spidev.h> 13 13 #include <linux/spi/spidev.h>
/* memory management */ 14 14 /* memory management */
#include <sys/mman.h> 15 15 #include <sys/mman.h>
#include "spi.h" 16 16 #include "spi.h"
#include <string.h> 17 17 #include <string.h>
#include <math.h> 18 18 #include <math.h>
#include <time.h> 19 19 #include <time.h>
20 20
21 21
static const char CFRAddress[] = {0x00,0x01,0x02,0x03}; 22 22 static const char CFRAddress[] = {0x00,0x01,0x02,0x03};
23 23
static const char CFR1Start[] ={0x00, 0x01, 0x00, 0x0a}; 24 24 static const char CFR1Start[] ={0x00, 0x01, 0x00, 0x0a};
//static const char CFR1Start[] ={0x00, 0x01, 0x01, 0x08}; //with osk enable 25 25 //static const char CFR1Start[] ={0x00, 0x01, 0x01, 0x08}; //with osk enable
static const char CFR2Start[] ={0x00, 0x80, 0x09, 0x00}; //0x80 enable prof mode 26 26 static const char CFR2Start[] ={0x00, 0x80, 0x09, 0x00}; //0x80 enable prof mode
static const char CFR3Start[] = {0x00, 0x00, 0x19, 0x1C}; 27 27 static const char CFR3Start[] = {0x00, 0x00, 0x19, 0x1C};
static const char CFR4Start[] = {0x00, 0x05, 0x21, 0x20}; 28 28 static const char CFR4Start[] = {0x00, 0x05, 0x21, 0x20};
//static const char CFR4Start[] = {0x20, 0x21, 0x05, 0x00}; 29 29 //static const char CFR4Start[] = {0x20, 0x21, 0x05, 0x00};
30 30
31 31
static const char USR0Address = 0x1B; 32 32 static const char USR0Address = 0x1B;
static const char FTW0Address = 0x0b; //profile 0 ftw 33 33 static const char FTW0Address = 0x0b; //profile 0 ftw
static const char PA0Address = 0x0c; //profile 0 34 34 static const char PA0Address = 0x0c; //profile 0
35 35
static const char DACCalEnable[] = {0x01, 0x05, 0x21, 0x20}; //Command to enable the DAC Cal, should be 0x01XXXXXX, where X is the last 6 digits of CFR4Start 36 36 static const char DACCalEnable[] = {0x01, 0x05, 0x21, 0x20}; //Command to enable the DAC Cal, should be 0x01XXXXXX, where X is the last 6 digits of CFR4Start
37 37
38 38
void sendReset(int f_dds); 39 39 void sendReset(int f_dds);
void sendIOUpdate (int f_dds); //Send the update to set the control registers 40 40 void sendIOUpdate (int f_dds); //Send the update to set the control registers
void writeRegister (int fd, unsigned char addr, unsigned char d3, unsigned char d2, unsigned char d1, unsigned char d0); 41 41 void writeRegister (int fd, unsigned char addr, unsigned char d3, unsigned char d2, unsigned char d1, unsigned char d0);
void readRegister (int fd, unsigned char addr, uint32_t *readword); 42 42 void readRegister (int fd, unsigned char addr, uint32_t *readword);
void readRegister_ini (int fd,unsigned char addr); 43 43 void readRegister_ini (int fd,unsigned char addr);
void initializeDDS (int fd, int f_dds); 44 44 void initializeDDS (int fd, int f_dds);
void calibrateDAC(int fd, int f_dds); 45 45 void calibrateDAC(int fd, int f_dds);
void basicSetup(int fd, int f_dds, uint16_t ampWord, uint16_t phaseWord); 46 46 void basicSetup(int fd, int f_dds, uint16_t ampWord, uint16_t phaseWord);
void modulusSetup(int fd, int f_dds); 47 47 void modulusSetup(int fd, int f_dds);
void setFreqMM(int fd, int f_dds, unsigned int ftw, unsigned int A, unsigned int B); 48 48 void setFreqMM(int fd, int f_dds, unsigned int ftw, unsigned int A, unsigned int B);
void setAmpPhaseWord(int fd, int f_dds,unsigned int phaseAmpWord); 49 49 void setAmpPhaseWord(int fd, int f_dds,unsigned int phaseAmpWord);
void checkSize(void); 50
int openAndSetDdsFreq( char * device, char * gpio_update, double f_clk, double f_out, uint16_t ampWord, uint16_t phaseWord); 51 50 int openAndSetDdsFreq( char * device, char * gpio_update, double f_clk, double f_out, uint16_t ampWord, uint16_t phaseWord);
int receiveParameterFromPythonServer(char * device, double f_clk, double f_out); 52 51 int receiveParameterFromPythonServer(char * device, double f_clk, double f_out);
int setDdsFreqFull ( int fd, int f_dds, double f_clk, double f_out, uint16_t ampWord, uint16_t phaseWord); 53 52 int setDdsFreqFull ( int fd, int f_dds, double f_clk, double f_out, uint16_t ampWord, uint16_t phaseWord);
54 53
//------------ DRCTL 55 54 //------------ DRCTL
56 55
void sendCtrlUp(int fp); 57 56 void sendCtrlUp(int fp);
void SendCtrlDown(int fp); 58 57 void SendCtrlDown(int fp);
void SendHold(int fp); 59 58 void SendHold(int fp);
void SendUnhold(int fp); 60 59 void SendUnhold(int fp);
int testRampFreq(int fd, int f_dds, int fp); 61 60 int testRampFreq(int fd, int f_dds, int fp);
62 61
//-------Profile register mode 63 62 //-------Profile register mode
64 63
/* 1 1 /*
SPI : initialisation du dds et communication SPI 2 2 SPI : initialisation du dds et communication SPI
*/ 3 3 */
#include"ad9915.h" 4 4 #include"ad9915.h"
#include "spi.h" 5 5 #include "spi.h"
#include "ddsFreq.h" 6 6 #include "ddsFreq.h"
7 7
#define debug 8 8 #define debug
//fonction reset 9 9 //fonction reset
void sendReset(int f_dds) 10 10 void sendReset(int f_dds)
{ 11 11 {
write(f_dds,"2",1); 12 12 write(f_dds,"2",1);
} 13 13 }
14 14
//fonction ioupdate 15 15 //fonction ioupdate
void sendIOUpdate(int f_dds) 16 16 void sendIOUpdate(int f_dds)
{ 17 17 {
write(f_dds,"1",1); 18 18 write(f_dds,"1",1);
} 19 19 }
20 20
//fonction write register 21 21 //fonction write register
void writeRegister (int fd, unsigned char addr, unsigned char d3, unsigned char d2, unsigned char d1, unsigned char d0) 22 22 void writeRegister (int fd, unsigned char addr, unsigned char d3, unsigned char d2, unsigned char d1, unsigned char d0)
{ 23 23 {
unsigned char tx[5]={0}; 24 24 unsigned char tx[5]={0};
tx[0]=addr; 25 25 tx[0]=addr;
tx[1]=d3; 26 26 tx[1]=d3;
tx[2]=d2; 27 27 tx[2]=d2;
tx[3]=d1; 28 28 tx[3]=d1;
tx[4]=d0; 29 29 tx[4]=d0;
//spi_put_multiple envoie le vecteur dans cet ordre 30 30 //spi_put_multiple envoie le vecteur dans cet ordre
//[tx0]-[tx1]-[tx2] -> adresse->bit poids Fort->bit poids faible 31 31 //[tx0]-[tx1]-[tx2] -> adresse->bit poids Fort->bit poids faible
spi_put_multiple(fd,tx,5,NULL,0); 32 32 spi_put_multiple(fd,tx,5,NULL,0);
} 33 33 }
34 34
//fonction read register 35 35 //fonction read register
36 36
void readRegister (int fd,unsigned char addr, uint32_t *readword) 37 37 void readRegister (int fd,unsigned char addr, uint32_t *readword)
{ 38 38 {
unsigned char tx[1] = {0}; 39 39 unsigned char tx[1] = {0};
unsigned char rx[4] = {0}; 40 40 unsigned char rx[4] = {0};
addr = addr|0x80;//instruction byte for the read : 1000 0000 | byte_adress 41 41 addr = addr|0x80;//instruction byte for the read : 1000 0000 | byte_adress
tx[0]=addr; 42 42 tx[0]=addr;
spi_put_multiple(fd,tx,1,rx,4); 43 43 spi_put_multiple(fd,tx,1,rx,4);
//printf("TX:%x RX:%x %x %x %x\n",tx[0],rx[0],rx[1],rx[2],rx[3]); 44 44 //printf("TX:%x RX:%x %x %x %x\n",tx[0],rx[0],rx[1],rx[2],rx[3]);
*readword = 0x00000000; 45 45 *readword = 0x00000000;
*readword = *readword|(rx[0]<<24); 46 46 *readword = *readword|(rx[0]<<24);
*readword = *readword|(rx[1]<<16); 47 47 *readword = *readword|(rx[1]<<16);
*readword = *readword|(rx[2]<<8); 48 48 *readword = *readword|(rx[2]<<8);
*readword = *readword|rx[3]; 49 49 *readword = *readword|rx[3];
} 50 50 }
51 51
//fonction read register 52 52 //fonction read register
void readRegisterIni (int fd, unsigned char addr) 53 53 void readRegisterIni (int fd, unsigned char addr)
{ 54 54 {
unsigned char tx[1] = {0}; 55 55 unsigned char tx[1] = {0};
unsigned char rx[4] = {0}; 56 56 unsigned char rx[4] = {0};
addr = addr|0x80; 57 57 addr = addr|0x80;
tx[0]=addr; 58 58 tx[0]=addr;
spi_put_multiple(fd,tx,1,rx,4); 59 59 spi_put_multiple(fd,tx,1,rx,4);
printf("TX:%x RX:%x %x %x %x\n",tx[0],rx[0],rx[1],rx[2],rx[3]); 60 60 printf("TX:%x RX:%x %x %x %x\n",tx[0],rx[0],rx[1],rx[2],rx[3]);
// sendIOUpdate (f_dds); //Send the update to set the control registers 61 61 // sendIOUpdate (f_dds); //Send the update to set the control registers
} 62 62 }
63 63
//initialisation du dds 64 64 //initialisation du dds
void initializeDDS (int fd, int f_dds) 65 65 void initializeDDS (int fd, int f_dds)
{ 66 66 {
sendReset(f_dds); 67 67 sendReset(f_dds);
writeRegister(fd,CFRAddress[0],CFR1Start[0], CFR1Start[1], CFR1Start[2], CFR1Start[3]); 68 68 writeRegister(fd,CFRAddress[0],CFR1Start[0], CFR1Start[1], CFR1Start[2], CFR1Start[3]);
sendIOUpdate (f_dds); //Send the update to set the control registers 69 69 sendIOUpdate (f_dds); //Send the update to set the control registers
writeRegister(fd,CFRAddress[1], CFR2Start[0], CFR2Start[1], CFR2Start[2], CFR2Start[3]); 70 70 writeRegister(fd,CFRAddress[1], CFR2Start[0], CFR2Start[1], CFR2Start[2], CFR2Start[3]);
sendIOUpdate (f_dds); 71 71 sendIOUpdate (f_dds);
writeRegister(fd,CFRAddress[2], CFR3Start[0], CFR3Start[1], CFR3Start[2], CFR3Start[3]); 72 72 writeRegister(fd,CFRAddress[2], CFR3Start[0], CFR3Start[1], CFR3Start[2], CFR3Start[3]);
sendIOUpdate (f_dds); 73 73 sendIOUpdate (f_dds);
writeRegister(fd,CFRAddress[3], CFR4Start[0], CFR4Start[1], CFR4Start[2], CFR4Start[3]); 74 74 writeRegister(fd,CFRAddress[3], CFR4Start[0], CFR4Start[1], CFR4Start[2], CFR4Start[3]);
sendIOUpdate (f_dds); 75 75 sendIOUpdate (f_dds);
writeRegister(fd,USR0Address, 0xA2, 0x00, 0x08, 0x00); 76 76 writeRegister(fd,USR0Address, 0xA2, 0x00, 0x08, 0x00);
sendIOUpdate (f_dds); 77 77 sendIOUpdate (f_dds);
} 78 78 }
79 79
//calibration du dac 80 80 //calibration du dac
void calibrateDAC (int fd, int f_dds) 81 81 void calibrateDAC (int fd, int f_dds)
{ 82 82 {
writeRegister(fd,CFRAddress[3], DACCalEnable[0], DACCalEnable[1], DACCalEnable[2], DACCalEnable[3]); 83 83 writeRegister(fd,CFRAddress[3], DACCalEnable[0], DACCalEnable[1], DACCalEnable[2], DACCalEnable[3]);
sendIOUpdate (f_dds); 84 84 sendIOUpdate (f_dds);
writeRegister(fd,CFRAddress[3], CFR4Start[0], CFR4Start[1], CFR4Start[2], CFR4Start[3]); 85 85 writeRegister(fd,CFRAddress[3], CFR4Start[0], CFR4Start[1], CFR4Start[2], CFR4Start[3]);
sendIOUpdate (f_dds); 86 86 sendIOUpdate (f_dds);
} 87 87 }
88 88
void modulusSetup(int fd, int f_dds) 89 89 void modulusSetup(int fd, int f_dds)
{ 90 90 {
writeRegister(fd,0x00,0x00, 0x01, 0x01, 0x0a); //OSK enable //0x08 91 91 writeRegister(fd,0x00,0x00, 0x01, 0x01, 0x0a); //OSK enable //0x08
sendIOUpdate (f_dds); 92 92 sendIOUpdate (f_dds);
writeRegister(fd,0x01,0x00, 0x89, 0x09, 0x00); //enable program modulus and digital ramp 93 93 writeRegister(fd,0x01,0x00, 0x89, 0x09, 0x00); //enable program modulus and digital ramp
sendIOUpdate (f_dds); 94 94 sendIOUpdate (f_dds);
} 95 95 }
96 96
void basicSetup(int fd, int f_dds,uint16_t ampWord, uint16_t phaseWord) 97 97 void basicSetup(int fd, int f_dds,uint16_t ampWord, uint16_t phaseWord)
{ 98 98 {
writeRegister(fd,0x00,0x00, 0x01, 0x01, 0x08); //OSK enable 99 99 writeRegister(fd,0x00,0x00, 0x01, 0x01, 0x08); //OSK enable
sendIOUpdate (f_dds); 100 100 sendIOUpdate (f_dds);
writeRegister(fd,0x01,0x00, 0x89, 0x09, 0x00); //enable program modulus and digital ramp 101 101 writeRegister(fd,0x01,0x00, 0x89, 0x09, 0x00); //enable program modulus and digital ramp
sendIOUpdate (f_dds); 102 102 sendIOUpdate (f_dds);
writeRegister(fd,0x04,0x19, 0x99, 0x99, 0x99); //ftw 103 103 writeRegister(fd,0x04,0x19, 0x99, 0x99, 0x99); //ftw
sendIOUpdate (f_dds); 104 104 sendIOUpdate (f_dds);
writeRegister(fd,0x05,0xC0, 0x00, 0x00, 0x00); //A 105 105 writeRegister(fd,0x05,0xC0, 0x00, 0x00, 0x00); //A
sendIOUpdate (f_dds); 106 106 sendIOUpdate (f_dds);
writeRegister(fd,0x06,0x00, 0x00, 0x00, 0x05); //B 107 107 writeRegister(fd,0x06,0x00, 0x00, 0x00, 0x05); //B
sendIOUpdate (f_dds); 108 108 sendIOUpdate (f_dds);
writeRegister(fd,0x0c, (uint8_t)((ampWord>>8) & 0x0F), (uint8_t)(ampWord & 0xFF), (uint8_t)((phaseWord>>8) & 0xFF), (uint8_t)(phaseWord & 0xFF)); // amp (12b) ph(16) 109 109 writeRegister(fd,0x0c, (uint8_t)((ampWord>>8) & 0x0F), (uint8_t)(ampWord & 0xFF), (uint8_t)((phaseWord>>8) & 0xFF), (uint8_t)(phaseWord & 0xFF)); // amp (12b) ph(16)
sendIOUpdate (f_dds); 110 110 sendIOUpdate (f_dds);
} 111 111 }
112 112
void setFreqMM(int fd, int f_dds, unsigned int ftw, unsigned int A, unsigned int B) 113 113 void setFreqMM(int fd, int f_dds, unsigned int ftw, unsigned int A, unsigned int B)
{ 114 114 {
writeRegister(fd,0x04,ftw>>24&0xFF, ftw>>16&0xFF, ftw>>8&0xFF, ftw&0xFF); //ftw 115 115 writeRegister(fd,0x04,ftw>>24&0xFF, ftw>>16&0xFF, ftw>>8&0xFF, ftw&0xFF); //ftw
sendIOUpdate(f_dds); 116 116 sendIOUpdate(f_dds);
writeRegister(fd,0x05,A>>24&0xFF,A>>16&0xFF, A>>8&0xFF, A&0xFF); //A 117 117 writeRegister(fd,0x05,A>>24&0xFF,A>>16&0xFF, A>>8&0xFF, A&0xFF); //A
sendIOUpdate(f_dds); 118 118 sendIOUpdate(f_dds);
writeRegister(fd,0x06,B>>24&0xFF,B>>16&0xFF, B>>8&0xFF, B&0xFF); //B 119 119 writeRegister(fd,0x06,B>>24&0xFF,B>>16&0xFF, B>>8&0xFF, B&0xFF); //B
sendIOUpdate(f_dds); 120 120 sendIOUpdate(f_dds);
} 121 121 }
122 122
void setAmpPhaseWord(int fd, int f_dds,unsigned int phaseAmpWord) 123 123 void setAmpPhaseWord(int fd, int f_dds,unsigned int phaseAmpWord)
{ 124 124 {
writeRegister(fd,0x0c, phaseAmpWord>>24&0xFF, phaseAmpWord>>16&0xFF,phaseAmpWord>>8&0xFF,phaseAmpWord&0xFF); // amp (12b) ph(16) 125 125 writeRegister(fd,0x0c, phaseAmpWord>>24&0xFF, phaseAmpWord>>16&0xFF,phaseAmpWord>>8&0xFF,phaseAmpWord&0xFF); // amp (12b) ph(16)
sendIOUpdate(f_dds); 126 126 sendIOUpdate(f_dds);
} 127 127 }
128 128
void checkSize(void) 129
{ 130
printf("int : %d\n",sizeof(unsigned int)); 131
} 132
133 129
int openAndSetDdsFreq( char * device, char * gpio_update, double f_clk, double f_out, uint16_t ampWord, uint16_t phaseWord) 134 130 int openAndSetDdsFreq( char * device, char * gpio_update, double f_clk, double f_out, uint16_t ampWord, uint16_t phaseWord)
{ 135 131 {
#ifdef debug 136 132 #ifdef debug
printf("device=%s\tgpio_update=%s\tf_clk=%e\tf_out=%e\tampWord=%d\tphaseWord=%d\n\n",device,gpio_update,f_clk,f_out,ampWord,phaseWord); 137 133 printf("device=%s\tgpio_update=%s\tf_clk=%e\tf_out=%e\tampWord=%d\tphaseWord=%d\n\n",device,gpio_update,f_clk,f_out,ampWord,phaseWord);
#else 138 134 #else
printf("device=%s\tgpio_update=%s\tf_clk=%e\tf_out=%e\tampWord=%d\tphaseWord=%d\n\n",device,gpio_update,f_clk,f_out,ampWord,phaseWord); 139 135 printf("device=%s\tgpio_update=%s\tf_clk=%e\tf_out=%e\tampWord=%d\tphaseWord=%d\n\n",device,gpio_update,f_clk,f_out,ampWord,phaseWord);
int fd=configureSpi(device); //ex #define FILENAME2 "/dev/spidev0.0" 140 136 int fd=configureSpi(device); //ex #define FILENAME2 "/dev/spidev0.0"
printf("fd(funct)=%d\n",fd); 141 137 printf("fd(funct)=%d\n",fd);
setMode(fd,SPI_MODE_0); 142 138 setMode(fd,SPI_MODE_0);
if (fd <= 0){ 143 139 if (fd <= 0){
printf("ERREUR : ouverture périphérique SPI %s\n",device); 144 140 printf("ERREUR : ouverture périphérique SPI %s\n",device);
return EXIT_FAILURE; 145 141 return EXIT_FAILURE;
} 146 142 }
int f_dds=open(gpio_update,O_RDWR); //ex #define UPDATE2 "/sys/dds/gpio24/updateOn" 147 143 int f_dds=open(gpio_update,O_RDWR); //ex #define UPDATE2 "/sys/dds/gpio24/updateOn"
printf("f_dds(funct)=%d\n",f_dds); 148 144 printf("f_dds(funct)=%d\n",f_dds);
if (f_dds <= 0){ 149 145 if (f_dds <= 0){
printf("ERREUR : ouverture ");printf(gpio_update);printf("\n"); 150 146 printf("ERREUR : ouverture ");printf(gpio_update);printf("\n");
printf("Chargez le module ddsIOupdateX\n"); 151 147 printf("Chargez le module ddsIOupdateX\n");
return EXIT_FAILURE; 152 148 return EXIT_FAILURE;
} 153 149 }
setddsFreq(fd,f_dds,f_out,f_clk); 154 150 setddsFreq(fd,f_dds,f_out,f_clk);
//debug 155 151 //debug
phaseWord = 0x0000; 156 152 phaseWord = 0x0000;
ampWord=0x0FFF; 157 153 ampWord=0x0FFF;
uint32_t phaseAmpWord = phaseWord | ampWord<<16; 158 154 uint32_t phaseAmpWord = phaseWord | ampWord<<16;
setAmpPhaseWord(fd, f_dds, phaseAmpWord); 159 155 setAmpPhaseWord(fd, f_dds, phaseAmpWord);
#endif 160 156 #endif
return EXIT_SUCCESS; 161 157 return EXIT_SUCCESS;
} 162 158 }
163 159
int setDdsFreqFull ( int fd, int f_dds, double f_clk, double f_out, uint16_t ampWord, uint16_t phaseWord) 164 160 int setDdsFreqFull ( int fd, int f_dds, double f_clk, double f_out, uint16_t ampWord, uint16_t phaseWord)
{ 165 161 {
setddsFreq(fd,f_dds,f_out,f_clk); 166 162 setddsFreq(fd,f_dds,f_out,f_clk);
#ifdef debug 167 163 #ifdef debug
phaseWord = 0x0000; 168 164 phaseWord = 0x0000;
ampWord=0x0FFF; 169 165 ampWord=0x0FFF;
#endif 170 166 #endif
uint32_t phaseAmpWord = phaseWord | ampWord<<16; 171 167 uint32_t phaseAmpWord = phaseWord | ampWord<<16;
setAmpPhaseWord(fd, f_dds, phaseAmpWord); 172 168 setAmpPhaseWord(fd, f_dds, phaseAmpWord);
173 169
return EXIT_SUCCESS; 174 170 return EXIT_SUCCESS;
} 175 171 }
176 172
void sendCtrlUp(int fp) 177 173 void sendCtrlUp(int fp)
{ 178 174 {
//pente positive 179 175 //pente positive
write(fp,"0",1); 180 176 write(fp,"0",1);
} 181 177 }
182 178
void sendCtrlDown(int fp) 183 179 void sendCtrlDown(int fp)
{ 184 180 {
//pente negative 185 181 //pente negative
write(fp,"2",1); 186 182 write(fp,"2",1);
} 187 183 }
188 184
void sendHold(int fp) 189 185 void sendHold(int fp)
{ 190 186 {
//rampe bloquee 191 187 //rampe bloquee
write(fp,"1",1); 192 188 write(fp,"1",1);
} 193 189 }
194 190
void sendUnhold(int fp) 195 191 void sendUnhold(int fp)
{ 196 192 {
//rampe debloquee 197 193 //rampe debloquee
write(fp,"3",1); //reset 198 194 write(fp,"3",1); //reset
} 199 195 }
200 196
201 197
int testRampFreq(int fd, int f_dds, int fp) 202 198 int testRampFreq(int fd, int f_dds, int fp)
{ 203 199 {
204 200
205 201
//3-Rampe de pente positive + debloquage 206 202 //3-Rampe de pente positive + debloquage
sendCtrlDown(fp);//rampe up 207 203 sendCtrlDown(fp);//rampe up
sendUnhold(fp); 208 204 sendUnhold(fp);
209 205
sendReset(f_dds); 210 206 sendReset(f_dds);
//Initialize_DDS (fd, f_dds); 211 207 //Initialize_DDS (fd, f_dds);
212 208
//0- paramètre de bases 213 209 //0- paramètre de bases
writeRegister(fd,0x00,0x00,0x01,0x01,0x0a);//OSKenable+Read&write 214 210 writeRegister(fd,0x00,0x00,0x01,0x01,0x0a);//OSKenable+Read&write
sendIOUpdate(f_dds); 215 211 sendIOUpdate(f_dds);
readRegisterIni(fd,0x00); 216 212 readRegisterIni(fd,0x00);
217 213
writeRegister(fd,0x01,0x00, 0x00, 0x09, 0x00); // enable amp ramp 218 214 writeRegister(fd,0x01,0x00, 0x00, 0x09, 0x00); // enable amp ramp
sendIOUpdate(f_dds); 219 215 sendIOUpdate(f_dds);
readRegisterIni(fd,0x00); 220 216 readRegisterIni(fd,0x00);
221 217
222 218
writeRegister(fd,0x0b,0x02,0xd0,0xe5,0x60);//mot de frequence 223 219 writeRegister(fd,0x0b,0x02,0xd0,0xe5,0x60);//mot de frequence
sendIOUpdate(f_dds); 224 220 sendIOUpdate(f_dds);
writeRegister(fd,0x0c,0x0F,0xFF,0x00,0x00); //mot de amp et de phase : amp max, phase nulle 225 221 writeRegister(fd,0x0c,0x0F,0xFF,0x00,0x00); //mot de amp et de phase : amp max, phase nulle
sendIOUpdate(f_dds); 226 222 sendIOUpdate(f_dds);
227 223
printf("Les mots de frequences, d'amplitudes et de phases sont envoyes\n"); 228 224 printf("Les mots de frequences, d'amplitudes et de phases sont envoyes\n");
printf("Lecture registre de frequence: 0x0b\n"); 229 225 printf("Lecture registre de frequence: 0x0b\n");
readRegisterIni(fd,0x0b); 230 226 readRegisterIni(fd,0x0b);
printf("Lecture registre de amp et phase: 0x0c\n"); 231 227 printf("Lecture registre de amp et phase: 0x0c\n");
readRegisterIni(fd,0x0c); 232 228 readRegisterIni(fd,0x0c);
233 229
calibrateDAC (fd,f_dds); 234 230 calibrateDAC (fd,f_dds);
printf("\n\n ----------------------- \n\n"); 235 231 printf("\n\n ----------------------- \n\n");
236 232
237 233
return EXIT_SUCCESS; 238 234 return EXIT_SUCCESS;
} 239 235 }
240 236
//---------------rajout 8/1 241 237 //---------------rajout 8/1
242 238
int putAmpWord(int fd, int f_dds, double amplitude) 243 239 int putAmpWord(int fd, int f_dds, double amplitude)
{ 244 240 {
uint16_t PhaseWord = 0x0000; 245 241 uint16_t PhaseWord = 0x0000;
uint16_t AmpWord = 0x0000; 246 242 uint16_t AmpWord = 0x0000;
uint32_t ReadPhaseAmpWord=0x00000000; 247 243 uint32_t ReadPhaseAmpWord=0x00000000;
248 244
AmpWord = rint(amplitude*(pow(2.0,12.0)-1)/100); 249 245 AmpWord = rint(amplitude*(pow(2.0,12.0)-1)/100);
250 246
readRegister(fd,0x0c,&ReadPhaseAmpWord); 251 247 readRegister(fd,0x0c,&ReadPhaseAmpWord);
252 248
PhaseWord = ReadPhaseAmpWord&0xFFFF; 253 249 PhaseWord = ReadPhaseAmpWord&0xFFFF;
254 250
writeRegister(fd,0x0c,AmpWord>>8&0xFF,AmpWord&0xFF,PhaseWord>>8&0xFF,PhaseWord&0xFF); 255 251 writeRegister(fd,0x0c,AmpWord>>8&0xFF,AmpWord&0xFF,PhaseWord>>8&0xFF,PhaseWord&0xFF);
sendIOUpdate(f_dds); 256 252 sendIOUpdate(f_dds);
257 253
return 0; 258 254 return 0;
} 259 255 }
260 256
261 257
int putPhaseWord(int fd, int f_dds, double phase) 262 258 int putPhaseWord(int fd, int f_dds, double phase)
{ 263 259 {
//uint16_t PhaseWord = 0x0000; 264 260 //uint16_t PhaseWord = 0x0000;
//uint16_t AmpWord = 0x0000; 265 261 //uint16_t AmpWord = 0x0000;
uint32_t ReadPhaseAmpWord=0x00000000; 266 262 uint32_t ReadPhaseAmpWord=0x00000000;
267 263
uint16_t PhaseWord = rint(phase*(pow(2.0,16.0)-1)/360); 268 264 uint16_t PhaseWord = rint(phase*(pow(2.0,16.0)-1)/360);
269 265
readRegister(fd,0x0c,&ReadPhaseAmpWord); 270 266 readRegister(fd,0x0c,&ReadPhaseAmpWord);
271 267
uint16_t AmpWord = ReadPhaseAmpWord>>16&0xFFFF; 272 268 uint16_t AmpWord = ReadPhaseAmpWord>>16&0xFFFF;
273 269
writeRegister(fd,0x0c,AmpWord>>8&0xFF,AmpWord&0xFF,PhaseWord>>8&0xFF,PhaseWord&0xFF); 274 270 writeRegister(fd,0x0c,AmpWord>>8&0xFF,AmpWord&0xFF,PhaseWord>>8&0xFF,PhaseWord&0xFF);
sendIOUpdate(f_dds); 275 271 sendIOUpdate(f_dds);
276 272
return 0; 277 273 return 0;
} 278 274 }
279 275
int putFrequencyWord(int fd, int f_dds, double fclk,double fout)//Attention uniquement valable pour fclk = 1 GHz 280 276 int putFrequencyWord(int fd, int f_dds, double fclk,double fout)//Attention uniquement valable pour fclk = 1 GHz
{ 281 277 {
282 278
//uint32_t FTWR = 0x00000000; 283 279 //uint32_t FTWR = 0x00000000;
uint32_t FTWR = rint((fout/fclk)*pow(2.0,32.0)); 284 280 uint32_t FTWR = rint((fout/fclk)*pow(2.0,32.0));
writeRegister(fd,0x0b,FTWR>>24&0xFF,FTWR>>16&0xFF,FTWR>>8&0xFF,FTWR&0xFF);//mot de frequence 285 281 writeRegister(fd,0x0b,FTWR>>24&0xFF,FTWR>>16&0xFF,FTWR>>8&0xFF,FTWR&0xFF);//mot de frequence
sendIOUpdate(f_dds); 286 282 sendIOUpdate(f_dds);
287 283
return 0; 288 284 return 0;
} 289 285 }
290 286
291 287
int putFrequencyAmpPhaseWord(int fd, int f_dds, double fout, double fclk,double amp, double phase)//n'existe pas dans le mode profile enable 292 288 int putFrequencyAmpPhaseWord(int fd, int f_dds, double fout, double fclk,double amp, double phase)//n'existe pas dans le mode profile enable
{ 293 289 {
294 290
//uint32_t FTWR = 0x00000000; 295 291 //uint32_t FTWR = 0x00000000;
296 292
uint32_t FTWR = rint((fout/fclk)*pow(2.0,32.0)); 297 293 uint32_t FTWR = rint((fout/fclk)*pow(2.0,32.0));
298 294
writeRegister(fd,0x0b,FTWR>>24&0xFF,FTWR>>16&0xFF,FTWR>>8&0xFF,FTWR&0xFF);//mot de frequence 299 295 writeRegister(fd,0x0b,FTWR>>24&0xFF,FTWR>>16&0xFF,FTWR>>8&0xFF,FTWR&0xFF);//mot de frequence
300 296
sendIOUpdate(f_dds); 301 297 sendIOUpdate(f_dds);
302 298
putPhaseWord(fd,f_dds,phase); 303 299 putPhaseWord(fd,f_dds,phase);
putAmpWord(fd,f_dds,amp); 304 300 putAmpWord(fd,f_dds,amp);
305 301
return 0; 306 302 return 0;
} 307 303 }
308 304
309 305
int initialisationProfileMode (int fd,int f_dds) 310 306 int initialisationProfileMode (int fd,int f_dds)
{ 311 307 {
312 308
sendReset(f_dds); //les registres sont maintenant par defaut 313 309 sendReset(f_dds); //les registres sont maintenant par defaut
writeRegister(fd,0x00,0x00,0x01,0x01,0x0a); //OSK+SDIO input only//ok 314 310 writeRegister(fd,0x00,0x00,0x01,0x01,0x0a); //OSK+SDIO input only//ok
sendIOUpdate(f_dds); 315 311 sendIOUpdate(f_dds);
writeRegister(fd,0x01,0x00,0x80,0x09,0x00); // profile mode enable very important 316 312 writeRegister(fd,0x01,0x00,0x80,0x09,0x00); // profile mode enable very important
sendIOUpdate(f_dds); 317 313 sendIOUpdate(f_dds);
writeRegister(fd,0x02,0x00,0x00,0x19,0x1c); // default 318 314 writeRegister(fd,0x02,0x00,0x00,0x19,0x1c); // default
sendIOUpdate(f_dds); 319 315 sendIOUpdate(f_dds);
writeRegister(fd,0x03,0x01,0x05,0x21,0x20); // calibration 1/2 :enable 320 316 writeRegister(fd,0x03,0x01,0x05,0x21,0x20); // calibration 1/2 :enable
sendIOUpdate(f_dds); 321 317 sendIOUpdate(f_dds);
writeRegister(fd,0x03,0x00,0x05,0x21,0x20); // calibration 2/2 :desenable 322 318 writeRegister(fd,0x03,0x00,0x05,0x21,0x20); // calibration 2/2 :desenable
sendIOUpdate(f_dds); 323 319 sendIOUpdate(f_dds);
324 320
return 0; 325 321 return 0;
} 326 322 }
327 323
328 324
329 325
//------------------- FIN RAJOUT 8/1 330 326 //------------------- FIN RAJOUT 8/1
331 327
332 328
//-------------------------FONCTIONS RAMPES HARDWARE 333 329 //-------------------------FONCTIONS RAMPES HARDWARE
334 330
//1-rampe de frequence 335 331 //1-rampe de frequence
336 332
//rampe simple de fréquence 337 333 //rampe simple de fréquence
int frequencySweep (int fd, int f_dds,double fclk,double dfUp, double dfDown, double FreqMax,double FreqMin, double DeltaTimeUp, double DeltaTimeDown) 338 334 int frequencySweep (int fd, int f_dds,double fclk,double dfUp, double dfDown, double FreqMax,double FreqMin, double DeltaTimeUp, double DeltaTimeDown)
{ 339 335 {
//calcul de N => N=DeltaF/df = DeltaT/dt 340 336 //calcul de N => N=DeltaF/df = DeltaT/dt
341 337
//1-fmax > fmin 342 338 //1-fmax > fmin
double DeltaFreq = FreqMax-FreqMin; 343 339 double DeltaFreq = FreqMax-FreqMin;
if(FreqMax<FreqMin) 344 340 if(FreqMax<FreqMin)
{ 345 341 {
printf("FreqMax should be > FreqMin\n"); 346 342 printf("FreqMax should be > FreqMin\n");
printf("Can't Start the ramp\n"); 347 343 printf("Can't Start the ramp\n");
return -1; 348 344 return -1;
} 349 345 }
350 346
//2- Calcul du nombre de points de la rampe 351 347 //2- Calcul du nombre de points de la rampe
int NumberPointsUp = DeltaFreq/dfUp; 352 348 int NumberPointsUp = DeltaFreq/dfUp;
int NumberPointsDown = DeltaFreq/dfDown; 353 349 int NumberPointsDown = DeltaFreq/dfDown;
354 350
//3- En déduire la valeur de dtUp et dtDown 355 351 //3- En déduire la valeur de dtUp et dtDown
double dtUp = DeltaTimeUp/NumberPointsUp; 356 352 double dtUp = DeltaTimeUp/NumberPointsUp;
double dtDown = DeltaTimeDown/NumberPointsDown; 357 353 double dtDown = DeltaTimeDown/NumberPointsDown;
358 354
double dtmin = 24/fclk; 359 355 double dtmin = 24/fclk;
double dtmax = dtmin*(pow(2.0,16.0)-1); 360 356 double dtmax = dtmin*(pow(2.0,16.0)-1);
361 357
//Check Up 362 358 //Check Up
if(dtUp<dtmin) 363 359 if(dtUp<dtmin)
{ 364 360 {
printf("During of ramp UP should be > %f s\n",dtmin*NumberPointsUp); 365 361 printf("During of ramp UP should be > %f s\n",dtmin*NumberPointsUp);
printf("Can't start the ramp\n"); 366 362 printf("Can't start the ramp\n");
return -1; 367 363 return -1;
} 368 364 }
369 365
if(dtUp>dtmax) 370 366 if(dtUp>dtmax)
{ 371 367 {
printf("During of ramp UP should be < %f\n",dtmax*NumberPointsUp); 372 368 printf("During of ramp UP should be < %f\n",dtmax*NumberPointsUp);
printf("Can't start the ramp\n"); 373 369 printf("Can't start the ramp\n");
return -1; 374 370 return -1;
} 375 371 }
376 372
//Check Down 377 373 //Check Down
if(dtDown<dtmin) 378 374 if(dtDown<dtmin)
{ 379 375 {
printf("During of ramp DOWN should be > %f s\n",dtmin*NumberPointsDown); 380 376 printf("During of ramp DOWN should be > %f s\n",dtmin*NumberPointsDown);
printf("Can't start the ramp\n"); 381 377 printf("Can't start the ramp\n");
return -1; 382 378 return -1;
} 383 379 }
384 380
if(dtDown>dtmax) 385 381 if(dtDown>dtmax)
{ 386 382 {
printf("During of ramp DOWN should be < %f\n",dtmax*NumberPointsDown); 387 383 printf("During of ramp DOWN should be < %f\n",dtmax*NumberPointsDown);
printf("Can't start the ramp\n"); 388 384 printf("Can't start the ramp\n");
return -1; 389 385 return -1;
} 390 386 }
391 387
392 388
//4 - Put word in register 393 389 //4 - Put word in register
394 390
395 391
//4.1 Limit register 396 392 //4.1 Limit register
uint32_t FTWRmin = rint((FreqMin/fclk)*pow(2.0,32.0)); 397 393 uint32_t FTWRmin = rint((FreqMin/fclk)*pow(2.0,32.0));
writeRegister(fd,0x04,FTWRmin>>24&0xFF,FTWRmin>>16&0xFF,FTWRmin>>8&0xFF,FTWRmin&0xFF);//mot de frequence 398 394 writeRegister(fd,0x04,FTWRmin>>24&0xFF,FTWRmin>>16&0xFF,FTWRmin>>8&0xFF,FTWRmin&0xFF);//mot de frequence
sendIOUpdate(f_dds); 399 395 sendIOUpdate(f_dds);
400 396
uint32_t FTWRmax = rint((FreqMax/fclk)*pow(2.0,32.0)); 401 397 uint32_t FTWRmax = rint((FreqMax/fclk)*pow(2.0,32.0));
writeRegister(fd,0x05,FTWRmax>>24&0xFF,FTWRmax>>16&0xFF,FTWRmax>>8&0xFF,FTWRmax&0xFF);//mot de frequence 402 398 writeRegister(fd,0x05,FTWRmax>>24&0xFF,FTWRmax>>16&0xFF,FTWRmax>>8&0xFF,FTWRmax&0xFF);//mot de frequence
sendIOUpdate(f_dds); 403 399 sendIOUpdate(f_dds);
404 400
405 401
//4.2 dfUP et dfDown 406 402 //4.2 dfUP et dfDown
double df_up = DeltaFreq/NumberPointsUp; 407 403 double df_up = DeltaFreq/NumberPointsUp;
double df_down = DeltaFreq/NumberPointsDown; 408 404 double df_down = DeltaFreq/NumberPointsDown;
409 405
uint32_t Word_df_up = rint(df_up*pow(2.0,32.0)/fclk); 410 406 uint32_t Word_df_up = rint(df_up*pow(2.0,32.0)/fclk);
uint32_t Word_df_down = rint(df_down*pow(2.0,32.0)/fclk); 411 407 uint32_t Word_df_down = rint(df_down*pow(2.0,32.0)/fclk);
412 408
writeRegister(fd,0x06,Word_df_up>>24&0xFF,Word_df_up>>16&0xFF,Word_df_up>>8&0xFF,Word_df_up&0xFF); //df_up 413 409 writeRegister(fd,0x06,Word_df_up>>24&0xFF,Word_df_up>>16&0xFF,Word_df_up>>8&0xFF,Word_df_up&0xFF); //df_up
sendIOUpdate(f_dds); 414 410 sendIOUpdate(f_dds);
writeRegister(fd,0x07,Word_df_down>>24&0xFF,Word_df_down>>16&0xFF,Word_df_down>>8&0xFF,Word_df_down&0xFF);//df_down 415 411 writeRegister(fd,0x07,Word_df_down>>24&0xFF,Word_df_down>>16&0xFF,Word_df_down>>8&0xFF,Word_df_down&0xFF);//df_down
sendIOUpdate(f_dds); 416 412 sendIOUpdate(f_dds);
417 413
418 414
//4.3 dtUp et dtDown 419 415 //4.3 dtUp et dtDown
420 416
uint16_t Word_dt_up = 0x0000; 421 417 uint16_t Word_dt_up = 0x0000;
uint16_t Word_dt_down = 0x0000; 422 418 uint16_t Word_dt_down = 0x0000;
423 419
Word_dt_up = rint(dtUp*fclk/24); 424 420 Word_dt_up = rint(dtUp*fclk/24);
Word_dt_down = rint(dtDown*fclk/24); 425 421 Word_dt_down = rint(dtDown*fclk/24);
426 422
writeRegister(fd,0x08,Word_dt_down>>8&0xFF,Word_dt_down&0xFF,Word_dt_up>>8&0xFF,Word_dt_up&0xFF); // il y a 2 dt 427 423 writeRegister(fd,0x08,Word_dt_down>>8&0xFF,Word_dt_down&0xFF,Word_dt_up>>8&0xFF,Word_dt_up&0xFF); // il y a 2 dt
sendIOUpdate(f_dds); 428 424 sendIOUpdate(f_dds);
429 425
//5 Start of the ramp 430 426 //5 Start of the ramp
431 427
writeRegister(fd,0x01,0x00,0x08,0x09,0x00); //rampe simple 432 428 writeRegister(fd,0x01,0x00,0x08,0x09,0x00); //rampe simple
sendIOUpdate(f_dds); 433 429 sendIOUpdate(f_dds);
return 0; 434 430 return 0;
435 431
436 432
437 433
return EXIT_SUCCESS; 438 434 return EXIT_SUCCESS;
439 435
} 440 436 }
441 437
442 438
//rampe continue de fréquence 443 439 //rampe continue de fréquence
int continueFrequencySweep (int fd, int f_dds,double fclk,double dfUp, double dfDown, double FreqMax,double FreqMin, double DeltaTimeUp, double DeltaTimeDown) 444 440 int continueFrequencySweep (int fd, int f_dds,double fclk,double dfUp, double dfDown, double FreqMax,double FreqMin, double DeltaTimeUp, double DeltaTimeDown)
{ 445 441 {
//calcul de N => N=DeltaF/df = DeltaT/dt 446 442 //calcul de N => N=DeltaF/df = DeltaT/dt
447 443
//1-fmax > fmin 448 444 //1-fmax > fmin
double DeltaFreq = FreqMax-FreqMin; 449 445 double DeltaFreq = FreqMax-FreqMin;
if(FreqMax<FreqMin) 450 446 if(FreqMax<FreqMin)
{ 451 447 {
printf("FreqMax should be > FreqMin\n"); 452 448 printf("FreqMax should be > FreqMin\n");
printf("Can't Start the ramp\n"); 453 449 printf("Can't Start the ramp\n");
return -1; 454 450 return -1;
} 455 451 }
456 452
//2- Calcul du nombre de points de la rampe 457 453 //2- Calcul du nombre de points de la rampe
int NumberPointsUp = DeltaFreq/dfUp; 458 454 int NumberPointsUp = DeltaFreq/dfUp;
int NumberPointsDown = DeltaFreq/dfDown; 459 455 int NumberPointsDown = DeltaFreq/dfDown;
460 456
//3- En déduire la valeur de dtUp et dtDown 461 457 //3- En déduire la valeur de dtUp et dtDown
double dtUp = DeltaTimeUp/NumberPointsUp; 462 458 double dtUp = DeltaTimeUp/NumberPointsUp;
double dtDown = DeltaTimeDown/NumberPointsDown; 463 459 double dtDown = DeltaTimeDown/NumberPointsDown;
464 460
double dtmin = 24/fclk; 465 461 double dtmin = 24/fclk;
double dtmax = dtmin*(pow(2.0,16.0)-1); 466 462 double dtmax = dtmin*(pow(2.0,16.0)-1);
467 463
//Check Up 468 464 //Check Up
if(dtUp<dtmin) 469 465 if(dtUp<dtmin)
{ 470 466 {
printf("During of ramp UP should be > %f s\n",dtmin*NumberPointsUp); 471 467 printf("During of ramp UP should be > %f s\n",dtmin*NumberPointsUp);
printf("Can't start the ramp\n"); 472 468 printf("Can't start the ramp\n");
return -1; 473 469 return -1;
} 474 470 }
475 471
if(dtUp>dtmax) 476 472 if(dtUp>dtmax)
{ 477 473 {
printf("During of ramp UP should be < %f\n",dtmax*NumberPointsUp); 478 474 printf("During of ramp UP should be < %f\n",dtmax*NumberPointsUp);
printf("Can't start the ramp\n"); 479 475 printf("Can't start the ramp\n");
return -1; 480 476 return -1;
} 481 477 }
482 478
//Check Down 483 479 //Check Down
if(dtDown<dtmin) 484 480 if(dtDown<dtmin)
{ 485 481 {
printf("During of ramp DOWN should be > %f s\n",dtmin*NumberPointsDown); 486 482 printf("During of ramp DOWN should be > %f s\n",dtmin*NumberPointsDown);
printf("Can't start the ramp\n"); 487 483 printf("Can't start the ramp\n");
return -1; 488 484 return -1;
} 489 485 }
490 486
if(dtDown>dtmax) 491 487 if(dtDown>dtmax)
{ 492 488 {
printf("During of ramp DOWN should be < %f\n",dtmax*NumberPointsDown); 493 489 printf("During of ramp DOWN should be < %f\n",dtmax*NumberPointsDown);
printf("Can't start the ramp\n"); 494 490 printf("Can't start the ramp\n");
return -1; 495 491 return -1;
} 496 492 }
497 493
498 494
//4 - Put word in register 499 495 //4 - Put word in register
500 496
501 497
//4.1 Limit register 502 498 //4.1 Limit register
uint32_t FTWRmin = rint((FreqMin/fclk)*pow(2.0,32.0)); 503 499 uint32_t FTWRmin = rint((FreqMin/fclk)*pow(2.0,32.0));
writeRegister(fd,0x04,FTWRmin>>24&0xFF,FTWRmin>>16&0xFF,FTWRmin>>8&0xFF,FTWRmin&0xFF);//mot de frequence 504 500 writeRegister(fd,0x04,FTWRmin>>24&0xFF,FTWRmin>>16&0xFF,FTWRmin>>8&0xFF,FTWRmin&0xFF);//mot de frequence
sendIOUpdate(f_dds); 505 501 sendIOUpdate(f_dds);
506 502
uint32_t FTWRmax = rint((FreqMax/fclk)*pow(2.0,32.0)); 507 503 uint32_t FTWRmax = rint((FreqMax/fclk)*pow(2.0,32.0));
writeRegister(fd,0x05,FTWRmax>>24&0xFF,FTWRmax>>16&0xFF,FTWRmax>>8&0xFF,FTWRmax&0xFF);//mot de frequence 508 504 writeRegister(fd,0x05,FTWRmax>>24&0xFF,FTWRmax>>16&0xFF,FTWRmax>>8&0xFF,FTWRmax&0xFF);//mot de frequence
sendIOUpdate(f_dds); 509 505 sendIOUpdate(f_dds);
510 506
511 507
//4.2 dfUP et dfDown 512 508 //4.2 dfUP et dfDown
double df_up = DeltaFreq/NumberPointsUp; 513 509 double df_up = DeltaFreq/NumberPointsUp;
double df_down = DeltaFreq/NumberPointsDown; 514 510 double df_down = DeltaFreq/NumberPointsDown;
515 511
uint32_t Word_df_up = rint(df_up*pow(2.0,32.0)/fclk); 516 512 uint32_t Word_df_up = rint(df_up*pow(2.0,32.0)/fclk);
uint32_t Word_df_down = rint(df_down*pow(2.0,32.0)/fclk); 517 513 uint32_t Word_df_down = rint(df_down*pow(2.0,32.0)/fclk);
518 514
writeRegister(fd,0x06,Word_df_up>>24&0xFF,Word_df_up>>16&0xFF,Word_df_up>>8&0xFF,Word_df_up&0xFF); //df_up 519 515 writeRegister(fd,0x06,Word_df_up>>24&0xFF,Word_df_up>>16&0xFF,Word_df_up>>8&0xFF,Word_df_up&0xFF); //df_up
sendIOUpdate(f_dds); 520 516 sendIOUpdate(f_dds);
writeRegister(fd,0x07,Word_df_down>>24&0xFF,Word_df_down>>16&0xFF,Word_df_down>>8&0xFF,Word_df_down&0xFF);//df_down 521 517 writeRegister(fd,0x07,Word_df_down>>24&0xFF,Word_df_down>>16&0xFF,Word_df_down>>8&0xFF,Word_df_down&0xFF);//df_down
sendIOUpdate(f_dds); 522 518 sendIOUpdate(f_dds);
523 519
524 520
//4.3 dtUp et dtDown 525 521 //4.3 dtUp et dtDown
526 522
uint16_t Word_dt_up = 0x0000; 527 523 uint16_t Word_dt_up = 0x0000;
uint16_t Word_dt_down = 0x0000; 528 524 uint16_t Word_dt_down = 0x0000;
529 525
Word_dt_up = rint(dtUp*fclk/24); 530 526 Word_dt_up = rint(dtUp*fclk/24);
Word_dt_down = rint(dtDown*fclk/24); 531 527 Word_dt_down = rint(dtDown*fclk/24);
532 528
writeRegister(fd,0x08,Word_dt_down>>8&0xFF,Word_dt_down&0xFF,Word_dt_up>>8&0xFF,Word_dt_up&0xFF); // il y a 2 dt 533 529 writeRegister(fd,0x08,Word_dt_down>>8&0xFF,Word_dt_down&0xFF,Word_dt_up>>8&0xFF,Word_dt_up&0xFF); // il y a 2 dt
sendIOUpdate(f_dds); 534 530 sendIOUpdate(f_dds);
535 531
//5 Start of the ramp 536 532 //5 Start of the ramp
537 533
writeRegister(fd,0x01,0x00,0x8e,0x29,0x00); //rampe triangulaire 538 534 writeRegister(fd,0x01,0x00,0x8e,0x29,0x00); //rampe triangulaire
sendIOUpdate(f_dds); 539 535 sendIOUpdate(f_dds);
return 0; 540 536 return 0;
541 537
542 538
543 539
return EXIT_SUCCESS; 544 540 return EXIT_SUCCESS;
545 541
} 546 542 }
547 543
//2-rampe d'amplitude 548 544 //2-rampe d'amplitude
549 545
int amplitudeSweep (int fd, int f_dds,double fclk,double dAUp, double dADown, double AMax,double AMin, double DeltaTimeUp, double DeltaTimeDown) 550 546 int amplitudeSweep (int fd, int f_dds,double fclk,double dAUp, double dADown, double AMax,double AMin, double DeltaTimeUp, double DeltaTimeDown)
{ 551 547 {
552 548
553 549
//calcul de N => N=DeltaF/df = DeltaT/dt 554 550 //calcul de N => N=DeltaF/df = DeltaT/dt
555 551
//1-Amax > Amin 556 552 //1-Amax > Amin
double DeltaAmp = AMax-AMin; 557 553 double DeltaAmp = AMax-AMin;
if(AMax<AMin) 558 554 if(AMax<AMin)
{ 559 555 {
printf("AMax should be > AMin\n"); 560 556 printf("AMax should be > AMin\n");
printf("Can't Start the ramp\n"); 561 557 printf("Can't Start the ramp\n");
return -1; 562 558 return -1;
} 563 559 }
564 560
565 561
//2- Calcul du nombre de points de la rampe 566 562 //2- Calcul du nombre de points de la rampe
int NumberPointsUp = DeltaAmp/dAUp; 567 563 int NumberPointsUp = DeltaAmp/dAUp;
int NumberPointsDown = DeltaAmp/dADown; 568 564 int NumberPointsDown = DeltaAmp/dADown;
569 565
//3- En déduire la valeur de dtUp et dtDown 570 566 //3- En déduire la valeur de dtUp et dtDown
double dtUp = DeltaTimeUp/NumberPointsUp; 571 567 double dtUp = DeltaTimeUp/NumberPointsUp;
double dtDown = DeltaTimeDown/NumberPointsDown; 572 568 double dtDown = DeltaTimeDown/NumberPointsDown;
573 569
double dtmin = 24/fclk; 574 570 double dtmin = 24/fclk;
double dtmax = dtmin*(pow(2.0,16.0)-1); 575 571 double dtmax = dtmin*(pow(2.0,16.0)-1);
576 572
//Check Up 577 573 //Check Up
if(dtUp<dtmin) 578 574 if(dtUp<dtmin)
{ 579 575 {
printf("During of ramp UP should be > %f s\n",dtmin*NumberPointsUp); 580 576 printf("During of ramp UP should be > %f s\n",dtmin*NumberPointsUp);
printf("Can't start the ramp\n"); 581 577 printf("Can't start the ramp\n");
return -1; 582 578 return -1;
} 583 579 }
584 580
if(dtUp>dtmax) 585 581 if(dtUp>dtmax)
{ 586 582 {
printf("During of ramp UP should be < %f\n",dtmax*NumberPointsUp); 587 583 printf("During of ramp UP should be < %f\n",dtmax*NumberPointsUp);
printf("Can't start the ramp\n"); 588 584 printf("Can't start the ramp\n");
return -1; 589 585 return -1;
} 590 586 }
591 587
//Check Down 592 588 //Check Down
if(dtDown<dtmin) 593 589 if(dtDown<dtmin)
{ 594 590 {
printf("During of ramp DOWN should be > %f s\n",dtmin*NumberPointsDown); 595 591 printf("During of ramp DOWN should be > %f s\n",dtmin*NumberPointsDown);
printf("Can't start the ramp\n"); 596 592 printf("Can't start the ramp\n");
return -1; 597 593 return -1;
} 598 594 }
599 595
if(dtDown>dtmax) 600 596 if(dtDown>dtmax)
{ 601 597 {
printf("During of ramp DOWN should be < %f\n",dtmax*NumberPointsDown); 602 598 printf("During of ramp DOWN should be < %f\n",dtmax*NumberPointsDown);
printf("Can't start the ramp\n"); 603 599 printf("Can't start the ramp\n");
return -1; 604 600 return -1;
} 605 601 }
606 602
607 603
608 604
//check if DeltaAmp is enouth 609 605 //check if DeltaAmp is enouth
double enouthUP=0.5*NumberPointsUp*100/4095; 610 606 double enouthUP=0.5*NumberPointsUp*100/4095;
double enouthDOWN=0.5*NumberPointsDown*100/4095; 611 607 double enouthDOWN=0.5*NumberPointsDown*100/4095;
612 608
int borneUP = rint(enouthUP); 613 609 int borneUP = rint(enouthUP);
int borneDown = rint(enouthDOWN); 614 610 int borneDown = rint(enouthDOWN);
615 611
if(DeltaAmp<=enouthUP) 616 612 if(DeltaAmp<=enouthUP)
{ 617 613 {
printf("The amplitude difference should be > %d\n, decrease Number Points for positive slope",borneUP); 618 614 printf("The amplitude difference should be > %d\n, decrease Number Points for positive slope",borneUP);
} 619 615 }
620 616
if(DeltaAmp<=enouthDOWN) 621 617 if(DeltaAmp<=enouthDOWN)
{ 622 618 {
printf("The amplitude difference should be > %d\n, decrease Number Points for negative slope",borneDown); 623 619 printf("The amplitude difference should be > %d\n, decrease Number Points for negative slope",borneDown);
} 624 620 }
625 621
626 622
//4 - Put word in register 627 623 //4 - Put word in register
628 624
629 625
//4.1 Limit register 630 626 //4.1 Limit register
uint32_t WordAmin = rint(AMin*4095/100); 631 627 uint32_t WordAmin = rint(AMin*4095/100);
uint32_t WordAmax= rint(AMax*4095/100); 632 628 uint32_t WordAmax= rint(AMax*4095/100);
633 629
writeRegister(fd,0x04,WordAmin>>24&0xFF,WordAmin>>16&0xFF,WordAmin>>8&0xFF,WordAmin&0xFF); //min => lim-(Amp ) = 0x800 = Amax/2 634 630 writeRegister(fd,0x04,WordAmin>>24&0xFF,WordAmin>>16&0xFF,WordAmin>>8&0xFF,WordAmin&0xFF); //min => lim-(Amp ) = 0x800 = Amax/2
sendIOUpdate(f_dds); 635 631 sendIOUpdate(f_dds);
writeRegister(fd,0x05,WordAmax>>24&0xFF,WordAmax>>16&0xFF,WordAmax>>8&0xFF,WordAmax&0xFF);//max => lim+(Amp) = 0xFFF= Amax0 636 632 writeRegister(fd,0x05,WordAmax>>24&0xFF,WordAmax>>16&0xFF,WordAmax>>8&0xFF,WordAmax&0xFF);//max => lim+(Amp) = 0xFFF= Amax0
sendIOUpdate(f_dds); 637 633 sendIOUpdate(f_dds);
638 634
639 635
//4.2 dAUP et dADown 640 636 //4.2 dAUP et dADown
641 637
uint32_t Word_dA_up = rint(dAUp*4095/100); 642 638 uint32_t Word_dA_up = rint(dAUp*4095/100);
uint32_t Word_dA_down = rint(dADown*4095/100); 643 639 uint32_t Word_dA_down = rint(dADown*4095/100);
644 640
writeRegister(fd,0x06,Word_dA_up>>24&0xFF,Word_dA_up>>16&0xFF,Word_dA_up>>8&0xFF,Word_dA_up&0xFF); //dA_up 645 641 writeRegister(fd,0x06,Word_dA_up>>24&0xFF,Word_dA_up>>16&0xFF,Word_dA_up>>8&0xFF,Word_dA_up&0xFF); //dA_up
sendIOUpdate(f_dds); 646 642 sendIOUpdate(f_dds);
writeRegister(fd,0x07,Word_dA_down>>24&0xFF,Word_dA_down>>16&0xFF,Word_dA_down>>8&0xFF,Word_dA_down&0xFF);//dA_down 647 643 writeRegister(fd,0x07,Word_dA_down>>24&0xFF,Word_dA_down>>16&0xFF,Word_dA_down>>8&0xFF,Word_dA_down&0xFF);//dA_down
sendIOUpdate(f_dds); 648 644 sendIOUpdate(f_dds);
649 645
650 646
//4.3 dtUp et dtDown 651 647 //4.3 dtUp et dtDown
652 648
uint16_t Word_dt_up = rint(dtUp*fclk/24); 653 649 uint16_t Word_dt_up = rint(dtUp*fclk/24);
uint16_t Word_dt_down = rint(dtDown*fclk/24); 654 650 uint16_t Word_dt_down = rint(dtDown*fclk/24);
655 651
writeRegister(fd,0x08,Word_dt_down>>8&0xFF,Word_dt_down&0xFF,Word_dt_up>>8&0xFF,Word_dt_up&0xFF); // il y a 2 dt 656 652 writeRegister(fd,0x08,Word_dt_down>>8&0xFF,Word_dt_down&0xFF,Word_dt_up>>8&0xFF,Word_dt_up&0xFF); // il y a 2 dt
sendIOUpdate(f_dds); 657 653 sendIOUpdate(f_dds);
658 654
//5 Start of the ramp 659 655 //5 Start of the ramp
660 656
writeRegister(fd,0x01,0x00,0x28,0x09,0x00); //rampe simple montante 661 657 writeRegister(fd,0x01,0x00,0x28,0x09,0x00); //rampe simple montante
//writeRegister(fd,0x01,0x00,0xAE,0x29,0x00); //rampe continue 662 658 //writeRegister(fd,0x01,0x00,0xAE,0x29,0x00); //rampe continue
sendIOUpdate(f_dds); 663 659 sendIOUpdate(f_dds);
664 660
return EXIT_SUCCESS; 665 661 return EXIT_SUCCESS;
} 666 662 }
667 663
int continueAmplitudeSweep (int fd, int f_dds,double fclk,double dAUp, double dADown, double AMax,double AMin, double DeltaTimeUp, double DeltaTimeDown) 668 664 int continueAmplitudeSweep (int fd, int f_dds,double fclk,double dAUp, double dADown, double AMax,double AMin, double DeltaTimeUp, double DeltaTimeDown)
{ 669 665 {
670 666
671 667
//calcul de N => N=DeltaF/df = DeltaT/dt 672 668 //calcul de N => N=DeltaF/df = DeltaT/dt
673 669
//1-Amax > Amin 674 670 //1-Amax > Amin
double DeltaAmp = AMax-AMin; 675 671 double DeltaAmp = AMax-AMin;
if(AMax<AMin) 676 672 if(AMax<AMin)
{ 677 673 {
printf("AMax should be > AMin\n"); 678 674 printf("AMax should be > AMin\n");
printf("Can't Start the ramp\n"); 679 675 printf("Can't Start the ramp\n");
return -1; 680 676 return -1;
} 681 677 }
682 678
683 679
//2- Calcul du nombre de points de la rampe 684 680 //2- Calcul du nombre de points de la rampe
int NumberPointsUp = DeltaAmp/dAUp; 685 681 int NumberPointsUp = DeltaAmp/dAUp;
int NumberPointsDown = DeltaAmp/dADown; 686 682 int NumberPointsDown = DeltaAmp/dADown;
687 683
//3- En déduire la valeur de dtUp et dtDown 688 684 //3- En déduire la valeur de dtUp et dtDown
double dtUp = DeltaTimeUp/NumberPointsUp; 689 685 double dtUp = DeltaTimeUp/NumberPointsUp;
double dtDown = DeltaTimeDown/NumberPointsDown; 690 686 double dtDown = DeltaTimeDown/NumberPointsDown;
691 687
double dtmin = 24/fclk; 692 688 double dtmin = 24/fclk;
double dtmax = dtmin*(pow(2.0,16.0)-1); 693 689 double dtmax = dtmin*(pow(2.0,16.0)-1);
694 690
//Check Up 695 691 //Check Up
if(dtUp<dtmin) 696 692 if(dtUp<dtmin)
{ 697 693 {
printf("During of ramp UP should be > %f s\n",dtmin*NumberPointsUp); 698 694 printf("During of ramp UP should be > %f s\n",dtmin*NumberPointsUp);
printf("Can't start the ramp\n"); 699 695 printf("Can't start the ramp\n");
return -1; 700 696 return -1;
} 701 697 }
702 698
if(dtUp>dtmax) 703 699 if(dtUp>dtmax)
{ 704 700 {
printf("During of ramp UP should be < %f\n",dtmax*NumberPointsUp); 705 701 printf("During of ramp UP should be < %f\n",dtmax*NumberPointsUp);
printf("Can't start the ramp\n"); 706 702 printf("Can't start the ramp\n");
return -1; 707 703 return -1;
} 708 704 }
709 705
//Check Down 710 706 //Check Down
if(dtDown<dtmin) 711 707 if(dtDown<dtmin)
{ 712 708 {
printf("During of ramp DOWN should be > %f s\n",dtmin*NumberPointsDown); 713 709 printf("During of ramp DOWN should be > %f s\n",dtmin*NumberPointsDown);
printf("Can't start the ramp\n"); 714 710 printf("Can't start the ramp\n");
return -1; 715 711 return -1;
} 716 712 }
717 713
if(dtDown>dtmax) 718 714 if(dtDown>dtmax)
{ 719 715 {
printf("During of ramp DOWN should be < %f\n",dtmax*NumberPointsDown); 720 716 printf("During of ramp DOWN should be < %f\n",dtmax*NumberPointsDown);
printf("Can't start the ramp\n"); 721 717 printf("Can't start the ramp\n");
return -1; 722 718 return -1;
} 723 719 }
724 720
725 721
726 722
//check if DeltaAmp is enouth 727 723 //check if DeltaAmp is enouth
double enouthUP=0.5*NumberPointsUp*100/4095; 728 724 double enouthUP=0.5*NumberPointsUp*100/4095;
double enouthDOWN=0.5*NumberPointsDown*100/4095; 729 725 double enouthDOWN=0.5*NumberPointsDown*100/4095;
730 726
int borneUP = rint(enouthUP); 731 727 int borneUP = rint(enouthUP);
int borneDown = rint(enouthDOWN); 732 728 int borneDown = rint(enouthDOWN);
733 729
if(DeltaAmp<=enouthUP) 734 730 if(DeltaAmp<=enouthUP)
{ 735 731 {
printf("The amplitude difference should be > %d\n, decrease Number Points for positive slope",borneUP); 736 732 printf("The amplitude difference should be > %d\n, decrease Number Points for positive slope",borneUP);
//return -1; 737 733 //return -1;
} 738 734 }
739 735
if(DeltaAmp<=enouthDOWN) 740 736 if(DeltaAmp<=enouthDOWN)
{ 741 737 {
printf("The amplitude difference should be > %d\n, decrease Number Points for negative slope",borneDown); 742 738 printf("The amplitude difference should be > %d\n, decrease Number Points for negative slope",borneDown);
//return -1; 743 739 //return -1;
} 744 740 }
745 741
746 742
//4 - Put word in register 747 743 //4 - Put word in register