DDS AD9854, library to configure a AD9854 Serial Interface (SPI)

Dependents:   JRO_DDSv2 JRO_DDSv2_rev2019

Committer:
miguelcordero191
Date:
Wed Sep 04 22:26:24 2019 +0000
Revision:
1:d81fca2297fb
Parent:
0:156a9e15919e
04/09/2019

Who changed what in which revision?

UserRevisionLine numberNew contents of line
miguelcordero191 0:156a9e15919e 1 #include "AD9854.h"
miguelcordero191 0:156a9e15919e 2
miguelcordero191 0:156a9e15919e 3 static char controlRegister[4];
miguelcordero191 0:156a9e15919e 4 static char read_spi_data[6];
miguelcordero191 1:d81fca2297fb 5 static char message[0x32];
miguelcordero191 0:156a9e15919e 6
miguelcordero191 1:d81fca2297fb 7 static char *MODULATION[6] = {"Single Tone ", "FSK ", "Ramped FSK ", "Chirp ", "BPSK ", "Not Allowed "};
miguelcordero191 0:156a9e15919e 8
miguelcordero191 0:156a9e15919e 9 DDS::DDS(SPI *spi_dev, DigitalOut *mreset, DigitalOut *outramp, DigitalOut *spmode, DigitalOut *cs, DigitalOut *ioreset, DigitalInOut *updclk){
miguelcordero191 0:156a9e15919e 10
miguelcordero191 0:156a9e15919e 11 spi_device = spi_dev;
miguelcordero191 0:156a9e15919e 12
miguelcordero191 0:156a9e15919e 13 dds_mreset = mreset;
miguelcordero191 0:156a9e15919e 14 dds_outramp = outramp;
miguelcordero191 0:156a9e15919e 15 dds_sp_mode = spmode;
miguelcordero191 0:156a9e15919e 16 dds_cs = cs;
miguelcordero191 0:156a9e15919e 17 dds_io_reset = ioreset;
miguelcordero191 0:156a9e15919e 18 dds_updclk = updclk;
miguelcordero191 0:156a9e15919e 19
miguelcordero191 0:156a9e15919e 20 dds_updclk->input();
miguelcordero191 0:156a9e15919e 21 *dds_sp_mode = 0;
miguelcordero191 0:156a9e15919e 22 *dds_cs = 1;
miguelcordero191 0:156a9e15919e 23 *dds_outramp = 0;
miguelcordero191 0:156a9e15919e 24
miguelcordero191 0:156a9e15919e 25 cmd_answer = NULL;
miguelcordero191 0:156a9e15919e 26 cmd_answer_len = 0;
miguelcordero191 0:156a9e15919e 27
miguelcordero191 0:156a9e15919e 28 spi_device->format(SPI_BITS, SPI_MODE);
miguelcordero191 0:156a9e15919e 29 spi_device->frequency(SPI_FREQ);
miguelcordero191 0:156a9e15919e 30
miguelcordero191 0:156a9e15919e 31 this->isConfig = false;
miguelcordero191 0:156a9e15919e 32
miguelcordero191 0:156a9e15919e 33 }
miguelcordero191 0:156a9e15919e 34
miguelcordero191 0:156a9e15919e 35 int DDS::__writeData(char addr, char ndata, const char* data){
miguelcordero191 0:156a9e15919e 36
miguelcordero191 0:156a9e15919e 37 // I/O reset
miguelcordero191 0:156a9e15919e 38 *dds_updclk = 0;
miguelcordero191 0:156a9e15919e 39 *dds_io_reset = 1;
miguelcordero191 0:156a9e15919e 40 wait_us(10);
miguelcordero191 0:156a9e15919e 41 *dds_io_reset = 0;
miguelcordero191 0:156a9e15919e 42 wait_us(10);
miguelcordero191 0:156a9e15919e 43
miguelcordero191 0:156a9e15919e 44 *dds_cs = 0;
miguelcordero191 0:156a9e15919e 45
miguelcordero191 0:156a9e15919e 46 //Sending serial address
miguelcordero191 0:156a9e15919e 47 //printf("\r\nWriting Addr = %d", addr);
miguelcordero191 0:156a9e15919e 48 spi_device->write(addr & 0x0F);
miguelcordero191 0:156a9e15919e 49
miguelcordero191 0:156a9e15919e 50 for(char i = 0; i < ndata; i++)
miguelcordero191 0:156a9e15919e 51 {
miguelcordero191 0:156a9e15919e 52 wait_us(150);
miguelcordero191 0:156a9e15919e 53 spi_device->write(data[i]);
miguelcordero191 0:156a9e15919e 54 }
miguelcordero191 0:156a9e15919e 55
miguelcordero191 0:156a9e15919e 56 *dds_cs = 1;
miguelcordero191 0:156a9e15919e 57 /*
miguelcordero191 0:156a9e15919e 58 for(char i = 0; i < ndata; i++)
miguelcordero191 0:156a9e15919e 59 {
miguelcordero191 0:156a9e15919e 60 printf("\tData[%d] = 0x%x", i, data[i]);
miguelcordero191 0:156a9e15919e 61 }
miguelcordero191 0:156a9e15919e 62 */
miguelcordero191 0:156a9e15919e 63
miguelcordero191 0:156a9e15919e 64
miguelcordero191 0:156a9e15919e 65 wait_us(10);
miguelcordero191 0:156a9e15919e 66 *dds_updclk = 1;
miguelcordero191 0:156a9e15919e 67 wait_us(10);
miguelcordero191 0:156a9e15919e 68 *dds_updclk = 0;
miguelcordero191 0:156a9e15919e 69 wait_us(10);
miguelcordero191 0:156a9e15919e 70
miguelcordero191 0:156a9e15919e 71 return 1;
miguelcordero191 0:156a9e15919e 72 }
miguelcordero191 0:156a9e15919e 73
miguelcordero191 0:156a9e15919e 74
miguelcordero191 0:156a9e15919e 75 char* DDS::__readData(char addr, char ndata){
miguelcordero191 0:156a9e15919e 76
miguelcordero191 0:156a9e15919e 77 // I/O reset
miguelcordero191 0:156a9e15919e 78 *dds_io_reset = 1;
miguelcordero191 0:156a9e15919e 79 wait_us(10);
miguelcordero191 0:156a9e15919e 80 *dds_io_reset = 0;
miguelcordero191 0:156a9e15919e 81 wait_us(10);
miguelcordero191 0:156a9e15919e 82
miguelcordero191 0:156a9e15919e 83 *dds_cs = 0;
miguelcordero191 0:156a9e15919e 84
miguelcordero191 0:156a9e15919e 85 //Sending serial address
miguelcordero191 0:156a9e15919e 86 //printf("\r\nReading Addr = %d", addr);
miguelcordero191 0:156a9e15919e 87 spi_device->write((addr & 0x0F) | 0x80);
miguelcordero191 0:156a9e15919e 88
miguelcordero191 0:156a9e15919e 89 for(char i = 0; i < ndata; i++)
miguelcordero191 0:156a9e15919e 90 {
miguelcordero191 0:156a9e15919e 91 wait_us(150);
miguelcordero191 0:156a9e15919e 92 read_spi_data[i] = spi_device->write(0x00);
miguelcordero191 0:156a9e15919e 93 }
miguelcordero191 0:156a9e15919e 94
miguelcordero191 0:156a9e15919e 95 *dds_cs = 1;
miguelcordero191 0:156a9e15919e 96 /*
miguelcordero191 0:156a9e15919e 97 for(char i = 0; i < ndata; i++)
miguelcordero191 0:156a9e15919e 98 {
miguelcordero191 0:156a9e15919e 99 printf("\r\nData[%d] = 0x%x", i, read_spi_data[i]);
miguelcordero191 0:156a9e15919e 100 }
miguelcordero191 0:156a9e15919e 101 */
miguelcordero191 0:156a9e15919e 102
miguelcordero191 0:156a9e15919e 103 wait_us(10);
miguelcordero191 0:156a9e15919e 104
miguelcordero191 0:156a9e15919e 105 return read_spi_data;
miguelcordero191 0:156a9e15919e 106 }
miguelcordero191 0:156a9e15919e 107
miguelcordero191 1:d81fca2297fb 108 int DDS::__writeDataAndVerify(char addr, char ndata, char* wr_spi_data, SerialDriver *screen){
miguelcordero191 0:156a9e15919e 109
miguelcordero191 0:156a9e15919e 110 int success;
miguelcordero191 0:156a9e15919e 111 char* rd_spi_data;
miguelcordero191 0:156a9e15919e 112
miguelcordero191 1:d81fca2297fb 113 //Avoid some values in Control Register
miguelcordero191 1:d81fca2297fb 114
miguelcordero191 1:d81fca2297fb 115 if (addr==0x07){
miguelcordero191 1:d81fca2297fb 116 wr_spi_data[2] = wr_spi_data[2] & 0xFE; //cr_ioupdclk always as an input = 0
miguelcordero191 1:d81fca2297fb 117 wr_spi_data[3] = wr_spi_data[3] & 0xFD; //LSB first = 0, MSB first enabled
miguelcordero191 1:d81fca2297fb 118 wr_spi_data[3] = wr_spi_data[3] | 0x01; //cr_sdo enable = 1
miguelcordero191 1:d81fca2297fb 119
miguelcordero191 1:d81fca2297fb 120 cr_qdac_pwdn = (wr_spi_data[0] & 0x04) >> 2;
miguelcordero191 1:d81fca2297fb 121
miguelcordero191 1:d81fca2297fb 122 cr_multiplier = (wr_spi_data[1] & 0x1F) >> 0;
miguelcordero191 1:d81fca2297fb 123 cr_pll_bypass = (wr_spi_data[1] & 0x20) >> 5;
miguelcordero191 1:d81fca2297fb 124 cr_pll_range = (wr_spi_data[1] & 0x40) >> 6;
miguelcordero191 1:d81fca2297fb 125
miguelcordero191 1:d81fca2297fb 126 cr_ioupdclk = (wr_spi_data[2] & 0x01) >> 0;
miguelcordero191 1:d81fca2297fb 127 cr_mode = (wr_spi_data[2] & 0x07) >> 1;
miguelcordero191 1:d81fca2297fb 128
miguelcordero191 1:d81fca2297fb 129 cr_sdo = (wr_spi_data[3] & 0x01) >> 0;
miguelcordero191 1:d81fca2297fb 130 cr_msb_lsb = (wr_spi_data[3] & 0x02) >> 1;
miguelcordero191 1:d81fca2297fb 131 cr_osk_int = (wr_spi_data[3] & 0x10) >> 4;
miguelcordero191 1:d81fca2297fb 132 cr_osk_en = (wr_spi_data[3] & 0x20) >> 5;
miguelcordero191 1:d81fca2297fb 133 cr_inv_sinc = (wr_spi_data[3] & 0x40) >> 6;
miguelcordero191 1:d81fca2297fb 134
miguelcordero191 1:d81fca2297fb 135 }
miguelcordero191 1:d81fca2297fb 136
miguelcordero191 1:d81fca2297fb 137
miguelcordero191 0:156a9e15919e 138 this->__writeData(addr, ndata, wr_spi_data);
miguelcordero191 0:156a9e15919e 139 rd_spi_data = this->__readData(addr, ndata);
miguelcordero191 0:156a9e15919e 140
miguelcordero191 0:156a9e15919e 141 success = 1;
miguelcordero191 0:156a9e15919e 142
miguelcordero191 0:156a9e15919e 143 for(char i = 0; i < ndata; i++)
miguelcordero191 0:156a9e15919e 144 {
miguelcordero191 0:156a9e15919e 145 if (screen != NULL){
miguelcordero191 0:156a9e15919e 146 screen->putc(wr_spi_data[i]);
miguelcordero191 0:156a9e15919e 147 screen->putc(0x3D);
miguelcordero191 0:156a9e15919e 148 screen->putc(rd_spi_data[i]);
miguelcordero191 0:156a9e15919e 149 }
miguelcordero191 0:156a9e15919e 150
miguelcordero191 0:156a9e15919e 151 if (wr_spi_data[i] != rd_spi_data[i])
miguelcordero191 0:156a9e15919e 152 {
miguelcordero191 0:156a9e15919e 153 success = 0;
miguelcordero191 0:156a9e15919e 154 break;
miguelcordero191 0:156a9e15919e 155 }
miguelcordero191 0:156a9e15919e 156
miguelcordero191 0:156a9e15919e 157 }
miguelcordero191 0:156a9e15919e 158
miguelcordero191 0:156a9e15919e 159 //Update Control Register
miguelcordero191 0:156a9e15919e 160 if ((success == 1) && (addr==0x07)){
miguelcordero191 0:156a9e15919e 161 cr_multiplier = rd_spi_data[1] & 0x1F;
miguelcordero191 0:156a9e15919e 162 cr_mode = (rd_spi_data[2] & 0x0E) >> 1;
miguelcordero191 0:156a9e15919e 163 }
miguelcordero191 0:156a9e15919e 164 //printf("\r\nSuccessful writting = %d\r\n", success);
miguelcordero191 0:156a9e15919e 165
miguelcordero191 0:156a9e15919e 166 return success;
miguelcordero191 0:156a9e15919e 167 }
miguelcordero191 0:156a9e15919e 168
miguelcordero191 0:156a9e15919e 169 char* DDS::__getControlRegister(){
miguelcordero191 1:d81fca2297fb 170 /*
miguelcordero191 0:156a9e15919e 171 if (cr_multiplier >= 4){
miguelcordero191 1:d81fca2297fb 172 cr_pll_bypass = 0;
miguelcordero191 0:156a9e15919e 173 }
miguelcordero191 0:156a9e15919e 174
miguelcordero191 1:d81fca2297fb 175 if (this->clock >= 200.0){
miguelcordero191 1:d81fca2297fb 176 cr_pll_range = 1;
miguelcordero191 0:156a9e15919e 177 }
miguelcordero191 1:d81fca2297fb 178 */
miguelcordero191 1:d81fca2297fb 179
miguelcordero191 0:156a9e15919e 180 controlRegister[0] = 0x10 + cr_qdac_pwdn*4;
miguelcordero191 1:d81fca2297fb 181 controlRegister[1] = cr_pll_range*64 + cr_pll_bypass*32 + (cr_multiplier & 0x1F);
miguelcordero191 0:156a9e15919e 182 controlRegister[2] = (cr_mode & 0x07)*2 + cr_ioupdclk;
miguelcordero191 0:156a9e15919e 183 controlRegister[3] = cr_inv_sinc*64 + cr_osk_en*32 + cr_osk_int*16 + cr_msb_lsb*2 + cr_sdo;
miguelcordero191 0:156a9e15919e 184
miguelcordero191 0:156a9e15919e 185 return controlRegister;
miguelcordero191 0:156a9e15919e 186
miguelcordero191 0:156a9e15919e 187 }
miguelcordero191 0:156a9e15919e 188
miguelcordero191 0:156a9e15919e 189 int DDS::__writeControlRegister(){
miguelcordero191 0:156a9e15919e 190
miguelcordero191 0:156a9e15919e 191 bool success;
miguelcordero191 0:156a9e15919e 192 char* wr_spi_data;
miguelcordero191 0:156a9e15919e 193 char* rd_spi_data;
miguelcordero191 0:156a9e15919e 194 char addr = 0x07, ndata = 4;
miguelcordero191 0:156a9e15919e 195
miguelcordero191 0:156a9e15919e 196 wr_spi_data = this->__getControlRegister();
miguelcordero191 0:156a9e15919e 197
miguelcordero191 0:156a9e15919e 198 success = this->__writeData(addr, ndata, wr_spi_data);
miguelcordero191 0:156a9e15919e 199
miguelcordero191 0:156a9e15919e 200 ////printf("\r\nChanging UPD_CLK as an OUTPUT ...");
miguelcordero191 0:156a9e15919e 201 dds_updclk->output();
miguelcordero191 0:156a9e15919e 202
miguelcordero191 0:156a9e15919e 203 wait_us(100);
miguelcordero191 0:156a9e15919e 204 *dds_updclk = 1;
miguelcordero191 0:156a9e15919e 205 wait_us(10);
miguelcordero191 0:156a9e15919e 206 *dds_updclk = 0;
miguelcordero191 0:156a9e15919e 207 wait_us(10);
miguelcordero191 0:156a9e15919e 208
miguelcordero191 0:156a9e15919e 209 rd_spi_data = this->__readData(addr, ndata);
miguelcordero191 0:156a9e15919e 210
miguelcordero191 0:156a9e15919e 211 success = true;
miguelcordero191 0:156a9e15919e 212
miguelcordero191 0:156a9e15919e 213 for(char i = 0; i < ndata; i++)
miguelcordero191 0:156a9e15919e 214 {
miguelcordero191 0:156a9e15919e 215 if (wr_spi_data[i] != rd_spi_data[i])
miguelcordero191 0:156a9e15919e 216 {
miguelcordero191 0:156a9e15919e 217 success = false;
miguelcordero191 0:156a9e15919e 218 break;
miguelcordero191 0:156a9e15919e 219 }
miguelcordero191 0:156a9e15919e 220 }
miguelcordero191 0:156a9e15919e 221
miguelcordero191 0:156a9e15919e 222 return success;
miguelcordero191 0:156a9e15919e 223 }
miguelcordero191 0:156a9e15919e 224
miguelcordero191 0:156a9e15919e 225
miguelcordero191 0:156a9e15919e 226 int DDS::reset(){
miguelcordero191 0:156a9e15919e 227
miguelcordero191 0:156a9e15919e 228 // Master reset
miguelcordero191 0:156a9e15919e 229 //Set as a input, temporary
miguelcordero191 0:156a9e15919e 230 //printf("\r\nChange updclk direction as an INPUT ...\r\n");
miguelcordero191 0:156a9e15919e 231 dds_updclk->input();
miguelcordero191 0:156a9e15919e 232 dds_updclk->mode(PullDown);
miguelcordero191 0:156a9e15919e 233
miguelcordero191 0:156a9e15919e 234 //printf("\r\nReseting DDS ...\r\n");
miguelcordero191 0:156a9e15919e 235 *dds_mreset = 1;
miguelcordero191 0:156a9e15919e 236 wait_ms(1);
miguelcordero191 0:156a9e15919e 237 *dds_mreset = 0;
miguelcordero191 0:156a9e15919e 238 wait_ms(1);
miguelcordero191 0:156a9e15919e 239
miguelcordero191 0:156a9e15919e 240 this->rf_enabled = false;
miguelcordero191 1:d81fca2297fb 241 this->programmed = false;
miguelcordero191 0:156a9e15919e 242
miguelcordero191 0:156a9e15919e 243 return 0;
miguelcordero191 0:156a9e15919e 244 }
miguelcordero191 0:156a9e15919e 245
miguelcordero191 0:156a9e15919e 246 int DDS::scanIOUpdate(){
miguelcordero191 0:156a9e15919e 247
miguelcordero191 0:156a9e15919e 248 unsigned int cont = 0;
miguelcordero191 0:156a9e15919e 249
miguelcordero191 0:156a9e15919e 250 this->reset();
miguelcordero191 0:156a9e15919e 251
miguelcordero191 0:156a9e15919e 252 //printf("\r\nWaiting a upd_clk ...\r\n");
miguelcordero191 0:156a9e15919e 253 while(true){
miguelcordero191 0:156a9e15919e 254 if (*dds_updclk == 1)
miguelcordero191 0:156a9e15919e 255 break;
miguelcordero191 0:156a9e15919e 256
miguelcordero191 0:156a9e15919e 257 cont += 1;
miguelcordero191 0:156a9e15919e 258 if (cont > 10000)
miguelcordero191 0:156a9e15919e 259 break;
miguelcordero191 0:156a9e15919e 260
miguelcordero191 0:156a9e15919e 261 wait_us(1);
miguelcordero191 0:156a9e15919e 262 }
miguelcordero191 0:156a9e15919e 263
miguelcordero191 0:156a9e15919e 264 if (cont > 10000){
miguelcordero191 0:156a9e15919e 265 //printf("\r\nA upd_clk was not found\r\n");
miguelcordero191 0:156a9e15919e 266 return 0;
miguelcordero191 0:156a9e15919e 267 }
miguelcordero191 0:156a9e15919e 268
miguelcordero191 0:156a9e15919e 269 //printf("\r\nA upd_clk was found ...\r\n");
miguelcordero191 0:156a9e15919e 270
miguelcordero191 0:156a9e15919e 271 return 1;
miguelcordero191 0:156a9e15919e 272 }
miguelcordero191 0:156a9e15919e 273
miguelcordero191 0:156a9e15919e 274 int DDS::find(){
miguelcordero191 0:156a9e15919e 275 /*
miguelcordero191 0:156a9e15919e 276 char phase[];
miguelcordero191 0:156a9e15919e 277
miguelcordero191 0:156a9e15919e 278 phase[0] = 0x0A;
miguelcordero191 0:156a9e15919e 279 phase[1] = 0x55;
miguelcordero191 0:156a9e15919e 280
miguelcordero191 0:156a9e15919e 281 this->__writeDataAndVerify(0x00, 5, phase);
miguelcordero191 0:156a9e15919e 282 */
miguelcordero191 0:156a9e15919e 283 this->__readData(0x05, 4);
miguelcordero191 0:156a9e15919e 284 this->__readData(0x0A, 1);
miguelcordero191 0:156a9e15919e 285 return 1;
miguelcordero191 0:156a9e15919e 286
miguelcordero191 0:156a9e15919e 287 }
miguelcordero191 0:156a9e15919e 288
miguelcordero191 0:156a9e15919e 289
miguelcordero191 0:156a9e15919e 290 int DDS::init(){
miguelcordero191 0:156a9e15919e 291
miguelcordero191 0:156a9e15919e 292 //printf("\r\nSetting default parameters in CR ...\r\n");
miguelcordero191 0:156a9e15919e 293
miguelcordero191 0:156a9e15919e 294 //Serial mode enabled
miguelcordero191 1:d81fca2297fb 295 this->clock = 200.0; // Work clock in MHz
miguelcordero191 0:156a9e15919e 296 this->cr_multiplier = 4; // Multiplier 4- 20
miguelcordero191 0:156a9e15919e 297 this->cr_mode = 0; // Single, FSK, Ramped FSK, Chirp, BPSK
miguelcordero191 0:156a9e15919e 298 this->cr_qdac_pwdn = 0; // QDAC power down enabled: 0 -> disable
miguelcordero191 0:156a9e15919e 299 this->cr_ioupdclk = 0; // IO Update clock direction: 0 -> input, 1 -> output
miguelcordero191 0:156a9e15919e 300 this->cr_inv_sinc = 0; // Sinc inverser filter enable: 0 -> enable
miguelcordero191 1:d81fca2297fb 301 this->cr_osk_en = 0; // Enable Amplitude multiplier: 0 -> disabled
miguelcordero191 0:156a9e15919e 302 this->cr_osk_int = 0; // register/counter output shaped control: 0 -> register, 1 -> counter
miguelcordero191 0:156a9e15919e 303 this->cr_msb_lsb = 0; // msb/lsb bit first: 0 -> MSB, 1 -> LSB
miguelcordero191 0:156a9e15919e 304 this->cr_sdo = 1; // SDO pin active: 0 -> inactive
miguelcordero191 0:156a9e15919e 305
miguelcordero191 1:d81fca2297fb 306 this->cr_pll_range = 1; // Clock >= 200Mhz
miguelcordero191 1:d81fca2297fb 307 this->cr_pll_bypass = 0;
miguelcordero191 1:d81fca2297fb 308
miguelcordero191 1:d81fca2297fb 309 this->cr_osk_en_bkp = this->cr_osk_en;
miguelcordero191 1:d81fca2297fb 310 this->cr_osk_int_bkp = this->cr_osk_int;
miguelcordero191 1:d81fca2297fb 311
miguelcordero191 0:156a9e15919e 312 //printf("\r\nSetting in serial mode ...\r\n");
miguelcordero191 0:156a9e15919e 313 *dds_sp_mode = 0;
miguelcordero191 0:156a9e15919e 314 *dds_cs = 1;
miguelcordero191 0:156a9e15919e 315
miguelcordero191 0:156a9e15919e 316 this->reset();
miguelcordero191 0:156a9e15919e 317
miguelcordero191 0:156a9e15919e 318 //printf("\r\nWritting CR ...\r\n");
miguelcordero191 0:156a9e15919e 319
miguelcordero191 0:156a9e15919e 320 if (not this->__writeControlRegister()){
miguelcordero191 0:156a9e15919e 321 //printf("\r\nUnsuccessful DDS initialization");
miguelcordero191 0:156a9e15919e 322 this->isConfig = false;
miguelcordero191 0:156a9e15919e 323 return false;
miguelcordero191 0:156a9e15919e 324 }
miguelcordero191 0:156a9e15919e 325
miguelcordero191 0:156a9e15919e 326 //printf("\r\nSuccessfull DDS initialization");
miguelcordero191 0:156a9e15919e 327
miguelcordero191 0:156a9e15919e 328 this->isConfig = true;
miguelcordero191 0:156a9e15919e 329
miguelcordero191 0:156a9e15919e 330 return true;
miguelcordero191 0:156a9e15919e 331 }
miguelcordero191 0:156a9e15919e 332
miguelcordero191 0:156a9e15919e 333 char* DDS::rdMode(){
miguelcordero191 0:156a9e15919e 334
miguelcordero191 0:156a9e15919e 335 char* rd_data;
miguelcordero191 0:156a9e15919e 336 char mode;
miguelcordero191 0:156a9e15919e 337
miguelcordero191 0:156a9e15919e 338 rd_data = this->__readData(0x07, 4);
miguelcordero191 0:156a9e15919e 339 mode = (rd_data[2] & 0x0E) >> 1;
miguelcordero191 0:156a9e15919e 340
miguelcordero191 0:156a9e15919e 341 this->cr_mode = mode;
miguelcordero191 0:156a9e15919e 342
miguelcordero191 0:156a9e15919e 343 rd_data[0] = mode;
miguelcordero191 0:156a9e15919e 344
miguelcordero191 0:156a9e15919e 345 return rd_data;
miguelcordero191 0:156a9e15919e 346 }
miguelcordero191 0:156a9e15919e 347
miguelcordero191 0:156a9e15919e 348 char* DDS::rdMultiplier(){
miguelcordero191 0:156a9e15919e 349
miguelcordero191 0:156a9e15919e 350 char* rd_data;
miguelcordero191 0:156a9e15919e 351 char mult;
miguelcordero191 0:156a9e15919e 352
miguelcordero191 0:156a9e15919e 353 rd_data = this->__readData(0x07, 4);
miguelcordero191 0:156a9e15919e 354 mult = (rd_data[1] & 0x1F);
miguelcordero191 0:156a9e15919e 355 this->cr_multiplier = mult;
miguelcordero191 0:156a9e15919e 356
miguelcordero191 0:156a9e15919e 357 //Reaconditioning data to return
miguelcordero191 0:156a9e15919e 358 rd_data[0] = mult;
miguelcordero191 1:d81fca2297fb 359 rd_data[1] = ((int)(this->clock) >> 8) & 0xff;
miguelcordero191 1:d81fca2297fb 360 rd_data[2] = (int)(this->clock) & 0xff;
miguelcordero191 0:156a9e15919e 361
miguelcordero191 0:156a9e15919e 362 return rd_data;
miguelcordero191 0:156a9e15919e 363 }
miguelcordero191 0:156a9e15919e 364 char* DDS::rdPhase1(){
miguelcordero191 0:156a9e15919e 365
miguelcordero191 0:156a9e15919e 366 char* rd_data;
miguelcordero191 0:156a9e15919e 367
miguelcordero191 0:156a9e15919e 368 rd_data = this->__readData(0x00, 2);
miguelcordero191 0:156a9e15919e 369
miguelcordero191 0:156a9e15919e 370 return rd_data;
miguelcordero191 0:156a9e15919e 371
miguelcordero191 0:156a9e15919e 372 }
miguelcordero191 0:156a9e15919e 373 char* DDS::rdPhase2(){
miguelcordero191 0:156a9e15919e 374
miguelcordero191 0:156a9e15919e 375 char* rd_data;
miguelcordero191 0:156a9e15919e 376
miguelcordero191 0:156a9e15919e 377 rd_data = this->__readData(0x01, 2);
miguelcordero191 0:156a9e15919e 378
miguelcordero191 0:156a9e15919e 379 return rd_data;
miguelcordero191 0:156a9e15919e 380 }
miguelcordero191 0:156a9e15919e 381 char* DDS::rdFrequency1(){
miguelcordero191 0:156a9e15919e 382
miguelcordero191 0:156a9e15919e 383 char* rd_data;
miguelcordero191 0:156a9e15919e 384
miguelcordero191 0:156a9e15919e 385 rd_data = this->__readData(0x02, 6);
miguelcordero191 0:156a9e15919e 386
miguelcordero191 0:156a9e15919e 387 for (int i=0; i<6; i++)
miguelcordero191 0:156a9e15919e 388 frequency1[i] = rd_data[i];
miguelcordero191 0:156a9e15919e 389
miguelcordero191 0:156a9e15919e 390 return rd_data;
miguelcordero191 0:156a9e15919e 391
miguelcordero191 0:156a9e15919e 392 }
miguelcordero191 0:156a9e15919e 393 char* DDS::rdFrequency2(){
miguelcordero191 0:156a9e15919e 394
miguelcordero191 0:156a9e15919e 395 char* rd_data;
miguelcordero191 0:156a9e15919e 396
miguelcordero191 0:156a9e15919e 397 rd_data = this->__readData(0x03, 6);
miguelcordero191 0:156a9e15919e 398
miguelcordero191 0:156a9e15919e 399 for (int i=0; i<6; i++)
miguelcordero191 0:156a9e15919e 400 frequency2[i] = rd_data[i];
miguelcordero191 0:156a9e15919e 401
miguelcordero191 0:156a9e15919e 402 return rd_data;
miguelcordero191 0:156a9e15919e 403 }
miguelcordero191 0:156a9e15919e 404 char* DDS::rdAmplitudeI(){
miguelcordero191 0:156a9e15919e 405
miguelcordero191 0:156a9e15919e 406 char* rd_data;
miguelcordero191 0:156a9e15919e 407
miguelcordero191 0:156a9e15919e 408 rd_data = this->__readData(0x08, 2);
miguelcordero191 0:156a9e15919e 409
miguelcordero191 0:156a9e15919e 410 return rd_data;
miguelcordero191 0:156a9e15919e 411 }
miguelcordero191 0:156a9e15919e 412 char* DDS::rdAmplitudeQ(){
miguelcordero191 0:156a9e15919e 413
miguelcordero191 0:156a9e15919e 414 char* rd_data;
miguelcordero191 0:156a9e15919e 415
miguelcordero191 0:156a9e15919e 416 rd_data = this->__readData(0x09, 2);
miguelcordero191 0:156a9e15919e 417
miguelcordero191 0:156a9e15919e 418 return rd_data;
miguelcordero191 0:156a9e15919e 419 }
miguelcordero191 0:156a9e15919e 420
miguelcordero191 0:156a9e15919e 421 int DDS::isRFEnabled(){
miguelcordero191 0:156a9e15919e 422
miguelcordero191 0:156a9e15919e 423 if (this->rf_enabled)
miguelcordero191 0:156a9e15919e 424 return 1;
miguelcordero191 0:156a9e15919e 425
miguelcordero191 0:156a9e15919e 426 return 0;
miguelcordero191 0:156a9e15919e 427 }
miguelcordero191 1:d81fca2297fb 428
miguelcordero191 1:d81fca2297fb 429 int DDS::isAmplitudeEnabled(){
miguelcordero191 1:d81fca2297fb 430
miguelcordero191 1:d81fca2297fb 431 if (this->cr_osk_en)
miguelcordero191 1:d81fca2297fb 432 return 1;
miguelcordero191 1:d81fca2297fb 433
miguelcordero191 1:d81fca2297fb 434 return 0;
miguelcordero191 1:d81fca2297fb 435 }
miguelcordero191 1:d81fca2297fb 436
miguelcordero191 1:d81fca2297fb 437 char* DDS::rdDeltaFrequency(){
miguelcordero191 1:d81fca2297fb 438 char* rd_data;
miguelcordero191 1:d81fca2297fb 439
miguelcordero191 1:d81fca2297fb 440 rd_data = this->__readData(0x04, 6);
miguelcordero191 1:d81fca2297fb 441
miguelcordero191 1:d81fca2297fb 442 return rd_data;
miguelcordero191 1:d81fca2297fb 443
miguelcordero191 1:d81fca2297fb 444 }
miguelcordero191 1:d81fca2297fb 445
miguelcordero191 1:d81fca2297fb 446 char* DDS::rdUpdateClock(){
miguelcordero191 1:d81fca2297fb 447 char* rd_data;
miguelcordero191 1:d81fca2297fb 448
miguelcordero191 1:d81fca2297fb 449 rd_data = this->__readData(0x05, 4);
miguelcordero191 1:d81fca2297fb 450
miguelcordero191 1:d81fca2297fb 451 return rd_data;
miguelcordero191 1:d81fca2297fb 452
miguelcordero191 1:d81fca2297fb 453 }
miguelcordero191 1:d81fca2297fb 454
miguelcordero191 1:d81fca2297fb 455 char* DDS::rdRampRateClock(){
miguelcordero191 1:d81fca2297fb 456 char* rd_data;
miguelcordero191 1:d81fca2297fb 457
miguelcordero191 1:d81fca2297fb 458 rd_data = this->__readData(0x06, 3);
miguelcordero191 1:d81fca2297fb 459
miguelcordero191 1:d81fca2297fb 460 return rd_data;
miguelcordero191 1:d81fca2297fb 461
miguelcordero191 1:d81fca2297fb 462 }
miguelcordero191 1:d81fca2297fb 463
miguelcordero191 1:d81fca2297fb 464 char* DDS::rdAmplitudeRampRate(){
miguelcordero191 1:d81fca2297fb 465 char* rd_data;
miguelcordero191 1:d81fca2297fb 466
miguelcordero191 1:d81fca2297fb 467 rd_data = this->__readData(0x0A, 1);
miguelcordero191 1:d81fca2297fb 468
miguelcordero191 1:d81fca2297fb 469 return rd_data;
miguelcordero191 1:d81fca2297fb 470
miguelcordero191 1:d81fca2297fb 471 }
miguelcordero191 0:156a9e15919e 472
miguelcordero191 0:156a9e15919e 473 int DDS::wrMode(char mode){
miguelcordero191 0:156a9e15919e 474
miguelcordero191 0:156a9e15919e 475 this->cr_mode = mode & 0x07;
miguelcordero191 0:156a9e15919e 476
miguelcordero191 0:156a9e15919e 477 return this->__writeControlRegister();
miguelcordero191 0:156a9e15919e 478 }
miguelcordero191 1:d81fca2297fb 479
miguelcordero191 0:156a9e15919e 480 int DDS::wrMultiplier(char multiplier, float clock){
miguelcordero191 0:156a9e15919e 481
miguelcordero191 0:156a9e15919e 482 this->cr_multiplier = multiplier & 0x1F;
miguelcordero191 0:156a9e15919e 483 this->clock = clock;
miguelcordero191 0:156a9e15919e 484
miguelcordero191 0:156a9e15919e 485 //printf("\r\n mult = %d, clock = %f", multiplier, clock);
miguelcordero191 0:156a9e15919e 486 //printf("\r\n cr_mult = %d", cr_multiplier);
miguelcordero191 0:156a9e15919e 487
miguelcordero191 0:156a9e15919e 488 return this->__writeControlRegister();
miguelcordero191 0:156a9e15919e 489 }
miguelcordero191 0:156a9e15919e 490
miguelcordero191 0:156a9e15919e 491 int DDS::wrPhase1(char* phase, SerialDriver *screen){
miguelcordero191 0:156a9e15919e 492
miguelcordero191 0:156a9e15919e 493 return this->__writeDataAndVerify(0x00, 2, phase, screen);
miguelcordero191 0:156a9e15919e 494
miguelcordero191 0:156a9e15919e 495 }
miguelcordero191 0:156a9e15919e 496
miguelcordero191 0:156a9e15919e 497 int DDS::wrPhase2(char* phase, SerialDriver *screen){
miguelcordero191 0:156a9e15919e 498
miguelcordero191 0:156a9e15919e 499 return this->__writeDataAndVerify(0x01, 2, phase, screen);
miguelcordero191 0:156a9e15919e 500
miguelcordero191 0:156a9e15919e 501 }
miguelcordero191 0:156a9e15919e 502
miguelcordero191 0:156a9e15919e 503 int DDS::wrFrequency1(char* freq, SerialDriver *screen){
miguelcordero191 0:156a9e15919e 504 int sts;
miguelcordero191 0:156a9e15919e 505
miguelcordero191 0:156a9e15919e 506 sts = this->__writeDataAndVerify(0x02, 6, freq, screen);
miguelcordero191 0:156a9e15919e 507
miguelcordero191 0:156a9e15919e 508 if (sts){
miguelcordero191 0:156a9e15919e 509 for (int i=0; i<6; i++)
miguelcordero191 0:156a9e15919e 510 frequency1[i] = freq[i];
miguelcordero191 1:d81fca2297fb 511
miguelcordero191 1:d81fca2297fb 512 this->programmed = true;
miguelcordero191 0:156a9e15919e 513 }
miguelcordero191 1:d81fca2297fb 514
miguelcordero191 0:156a9e15919e 515 return sts;
miguelcordero191 0:156a9e15919e 516
miguelcordero191 0:156a9e15919e 517 }
miguelcordero191 0:156a9e15919e 518 int DDS::wrFrequency2(char* freq, SerialDriver *screen){
miguelcordero191 0:156a9e15919e 519 int sts;
miguelcordero191 0:156a9e15919e 520
miguelcordero191 0:156a9e15919e 521 sts = this->__writeDataAndVerify(0x03, 6, freq, screen);
miguelcordero191 0:156a9e15919e 522
miguelcordero191 0:156a9e15919e 523 if (sts){
miguelcordero191 0:156a9e15919e 524 for (int i=0; i<6; i++)
miguelcordero191 0:156a9e15919e 525 frequency2[i] = freq[i];
miguelcordero191 0:156a9e15919e 526 }
miguelcordero191 0:156a9e15919e 527 return sts;
miguelcordero191 0:156a9e15919e 528 }
miguelcordero191 0:156a9e15919e 529
miguelcordero191 0:156a9e15919e 530 int DDS::wrAmplitudeI(char* amplitude, SerialDriver *screen){
miguelcordero191 0:156a9e15919e 531
miguelcordero191 0:156a9e15919e 532 amplitudeI[0] = amplitude[0];
miguelcordero191 0:156a9e15919e 533 amplitudeI[1] = amplitude[1];
miguelcordero191 0:156a9e15919e 534
miguelcordero191 0:156a9e15919e 535 this->rf_enabled = true;
miguelcordero191 0:156a9e15919e 536
miguelcordero191 0:156a9e15919e 537 return this->__writeDataAndVerify(0x08, 2, amplitude, screen);
miguelcordero191 0:156a9e15919e 538
miguelcordero191 0:156a9e15919e 539 }
miguelcordero191 0:156a9e15919e 540
miguelcordero191 0:156a9e15919e 541 int DDS::wrAmplitudeQ(char* amplitude, SerialDriver *screen){
miguelcordero191 0:156a9e15919e 542
miguelcordero191 0:156a9e15919e 543 amplitudeQ[0] = amplitude[0];
miguelcordero191 0:156a9e15919e 544 amplitudeQ[1] = amplitude[1];
miguelcordero191 0:156a9e15919e 545
miguelcordero191 0:156a9e15919e 546 this->rf_enabled = true;
miguelcordero191 0:156a9e15919e 547
miguelcordero191 0:156a9e15919e 548 return this->__writeDataAndVerify(0x09, 2, amplitude, screen);
miguelcordero191 0:156a9e15919e 549
miguelcordero191 0:156a9e15919e 550 }
miguelcordero191 0:156a9e15919e 551
miguelcordero191 1:d81fca2297fb 552 int DDS::wrDeltaFrequency(char* delta_freq, SerialDriver *screen){
miguelcordero191 1:d81fca2297fb 553 int sts;
miguelcordero191 1:d81fca2297fb 554
miguelcordero191 1:d81fca2297fb 555 sts = this->__writeDataAndVerify(0x04, 6, delta_freq, screen);
miguelcordero191 1:d81fca2297fb 556
miguelcordero191 1:d81fca2297fb 557 if (sts){
miguelcordero191 1:d81fca2297fb 558 for (int i=0; i<6; i++)
miguelcordero191 1:d81fca2297fb 559 delta_frequency[i] = delta_freq[i];
miguelcordero191 1:d81fca2297fb 560 }
miguelcordero191 1:d81fca2297fb 561
miguelcordero191 1:d81fca2297fb 562 return sts;
miguelcordero191 1:d81fca2297fb 563
miguelcordero191 1:d81fca2297fb 564 }
miguelcordero191 1:d81fca2297fb 565
miguelcordero191 1:d81fca2297fb 566 int DDS::wrUpdateClock(char* upd_clock, SerialDriver *screen){
miguelcordero191 1:d81fca2297fb 567 int sts;
miguelcordero191 1:d81fca2297fb 568
miguelcordero191 1:d81fca2297fb 569 sts = this->__writeDataAndVerify(0x05, 4, upd_clock, screen);
miguelcordero191 1:d81fca2297fb 570
miguelcordero191 1:d81fca2297fb 571 if (sts){
miguelcordero191 1:d81fca2297fb 572 for (int i=0; i<4; i++)
miguelcordero191 1:d81fca2297fb 573 update_clock[i] = upd_clock[i];
miguelcordero191 1:d81fca2297fb 574 }
miguelcordero191 1:d81fca2297fb 575
miguelcordero191 1:d81fca2297fb 576 return sts;
miguelcordero191 1:d81fca2297fb 577
miguelcordero191 1:d81fca2297fb 578 }
miguelcordero191 1:d81fca2297fb 579
miguelcordero191 1:d81fca2297fb 580 int DDS::wrRampRateClock(char* rr_clock, SerialDriver *screen){
miguelcordero191 1:d81fca2297fb 581 int sts;
miguelcordero191 1:d81fca2297fb 582
miguelcordero191 1:d81fca2297fb 583 sts = this->__writeDataAndVerify(0x06, 3, rr_clock, screen);
miguelcordero191 1:d81fca2297fb 584
miguelcordero191 1:d81fca2297fb 585 if (sts){
miguelcordero191 1:d81fca2297fb 586 for (int i=0; i<3; i++)
miguelcordero191 1:d81fca2297fb 587 ramp_rate_clock[i] = rr_clock[i];
miguelcordero191 1:d81fca2297fb 588 }
miguelcordero191 1:d81fca2297fb 589
miguelcordero191 1:d81fca2297fb 590 return sts;
miguelcordero191 1:d81fca2297fb 591
miguelcordero191 1:d81fca2297fb 592 }
miguelcordero191 1:d81fca2297fb 593
miguelcordero191 1:d81fca2297fb 594 int DDS::wrAmplitudeRampRate(char* ampl_rate, SerialDriver *screen){
miguelcordero191 1:d81fca2297fb 595 int sts;
miguelcordero191 1:d81fca2297fb 596
miguelcordero191 1:d81fca2297fb 597 sts = this->__writeDataAndVerify(0x0A, 1, ampl_rate, screen);
miguelcordero191 1:d81fca2297fb 598
miguelcordero191 1:d81fca2297fb 599 if (sts){
miguelcordero191 1:d81fca2297fb 600 for (int i=0; i<1; i++)
miguelcordero191 1:d81fca2297fb 601 amplitude_ramp_rate[i] = ampl_rate[i];
miguelcordero191 1:d81fca2297fb 602 }
miguelcordero191 1:d81fca2297fb 603
miguelcordero191 1:d81fca2297fb 604 return sts;
miguelcordero191 1:d81fca2297fb 605
miguelcordero191 1:d81fca2297fb 606 }
miguelcordero191 1:d81fca2297fb 607
miguelcordero191 1:d81fca2297fb 608 int DDS::enableAmplitude(){
miguelcordero191 1:d81fca2297fb 609
miguelcordero191 1:d81fca2297fb 610 this->cr_osk_en = 1;
miguelcordero191 1:d81fca2297fb 611
miguelcordero191 1:d81fca2297fb 612 return this->__writeControlRegister();
miguelcordero191 1:d81fca2297fb 613 }
miguelcordero191 1:d81fca2297fb 614
miguelcordero191 1:d81fca2297fb 615 int DDS::disableAmplitude(){
miguelcordero191 1:d81fca2297fb 616
miguelcordero191 1:d81fca2297fb 617 this->cr_osk_en = 0;
miguelcordero191 1:d81fca2297fb 618
miguelcordero191 1:d81fca2297fb 619 return this->__writeControlRegister();
miguelcordero191 1:d81fca2297fb 620 }
miguelcordero191 1:d81fca2297fb 621
miguelcordero191 0:156a9e15919e 622 int DDS::enableRF(){
miguelcordero191 0:156a9e15919e 623
miguelcordero191 1:d81fca2297fb 624 this->cr_osk_en = this->cr_osk_en_bkp;
miguelcordero191 1:d81fca2297fb 625 this->cr_osk_int = this->cr_osk_int_bkp;
miguelcordero191 1:d81fca2297fb 626
miguelcordero191 1:d81fca2297fb 627 this->__writeControlRegister();
miguelcordero191 1:d81fca2297fb 628
miguelcordero191 1:d81fca2297fb 629 this->__writeDataAndVerify(0x08, 2, this->amplitudeI);
miguelcordero191 1:d81fca2297fb 630
miguelcordero191 0:156a9e15919e 631 this->rf_enabled = true;
miguelcordero191 0:156a9e15919e 632
miguelcordero191 0:156a9e15919e 633 return this->__writeDataAndVerify(0x09, 2, this->amplitudeQ);
miguelcordero191 0:156a9e15919e 634
miguelcordero191 0:156a9e15919e 635 }
miguelcordero191 0:156a9e15919e 636
miguelcordero191 0:156a9e15919e 637 int DDS::disableRF(){
miguelcordero191 0:156a9e15919e 638
miguelcordero191 1:d81fca2297fb 639 this->cr_osk_en_bkp = this->cr_osk_en;
miguelcordero191 1:d81fca2297fb 640 this->cr_osk_int_bkp = this->cr_osk_int;
miguelcordero191 1:d81fca2297fb 641
miguelcordero191 1:d81fca2297fb 642 this->cr_osk_en = 1;
miguelcordero191 1:d81fca2297fb 643 this->cr_osk_int = 0;
miguelcordero191 1:d81fca2297fb 644
miguelcordero191 1:d81fca2297fb 645 this->__writeControlRegister();
miguelcordero191 1:d81fca2297fb 646
miguelcordero191 1:d81fca2297fb 647 this->__writeDataAndVerify(0x08, 2, "\x00\x00");
miguelcordero191 1:d81fca2297fb 648
miguelcordero191 0:156a9e15919e 649 this->rf_enabled = false;
miguelcordero191 0:156a9e15919e 650
miguelcordero191 0:156a9e15919e 651 return this->__writeDataAndVerify(0x09, 2, "\x00\x00");
miguelcordero191 0:156a9e15919e 652
miguelcordero191 0:156a9e15919e 653 }
miguelcordero191 1:d81fca2297fb 654
miguelcordero191 0:156a9e15919e 655 int DDS::defaultSettings(SerialDriver *screen){
miguelcordero191 0:156a9e15919e 656
miguelcordero191 0:156a9e15919e 657 if (!(screen == NULL)){
miguelcordero191 0:156a9e15919e 658 screen->putc(0x37);
miguelcordero191 0:156a9e15919e 659 screen->putc(0x30);
miguelcordero191 0:156a9e15919e 660 }
miguelcordero191 0:156a9e15919e 661
miguelcordero191 0:156a9e15919e 662 this->wrMultiplier(1, 0.0);
miguelcordero191 0:156a9e15919e 663 this->wrAmplitudeI("\x0F\xC0", screen); //0xFC0 produces best SFDR than 0xFFF
miguelcordero191 0:156a9e15919e 664 this->wrAmplitudeQ("\x0F\xC0"); //0xFC0 produces best SFDR than 0xFFF
miguelcordero191 0:156a9e15919e 665 this->wrFrequency1("\x00\x00\x00\x00\x00\x00"); // 49.92 <> 0x3f 0xe5 0xc9 0x1d 0x14 0xe3 <> 49.92/clock*(2**48) \x3f\xe5\xc9\x1d\x14\xe3
miguelcordero191 0:156a9e15919e 666 this->wrFrequency2("\x00\x00\x00\x00\x00\x00");
miguelcordero191 0:156a9e15919e 667 this->wrPhase1("\x00\x00"); //0 grados
miguelcordero191 0:156a9e15919e 668 this->wrPhase2("\x20\x00"); //180 grados <> 0x20 0x00 <> 180/360*(2**14)
miguelcordero191 1:d81fca2297fb 669 this->disableAmplitude();
miguelcordero191 0:156a9e15919e 670 this->disableRF();
miguelcordero191 0:156a9e15919e 671
miguelcordero191 0:156a9e15919e 672 if (!(screen == NULL)){
miguelcordero191 0:156a9e15919e 673 screen->putc(0x37);
miguelcordero191 0:156a9e15919e 674 screen->putc(0x31);
miguelcordero191 0:156a9e15919e 675 }
miguelcordero191 1:d81fca2297fb 676 this->programmed = false;
miguelcordero191 1:d81fca2297fb 677 return this->wrMode(0); //BPSK mode
miguelcordero191 0:156a9e15919e 678
miguelcordero191 0:156a9e15919e 679 }
miguelcordero191 0:156a9e15919e 680
miguelcordero191 0:156a9e15919e 681 char* DDS::setCommand(unsigned short cmd, char* payload, unsigned long payload_len){
miguelcordero191 0:156a9e15919e 682
miguelcordero191 1:d81fca2297fb 683 bool success = false;
miguelcordero191 0:156a9e15919e 684
miguelcordero191 1:d81fca2297fb 685 strcpy(message, MSG_CMD_OK);
miguelcordero191 1:d81fca2297fb 686
miguelcordero191 1:d81fca2297fb 687 this->cmd_answer = message;
miguelcordero191 1:d81fca2297fb 688 this->cmd_answer_len = strlen(message);
miguelcordero191 0:156a9e15919e 689
miguelcordero191 0:156a9e15919e 690 //printf("cmd = %d, payload_len = %d", cmd, payload_len);
miguelcordero191 0:156a9e15919e 691
miguelcordero191 0:156a9e15919e 692 //printf("\r\nPayload = ");
miguelcordero191 0:156a9e15919e 693 //for(unsigned long i=0; i< payload_len; i++)
miguelcordero191 0:156a9e15919e 694 //printf("0x%x ", payload[i]);
miguelcordero191 0:156a9e15919e 695
miguelcordero191 0:156a9e15919e 696 //Si el DDS no esta inicializado siempre retornar NI_MSG
miguelcordero191 0:156a9e15919e 697 if (not this->isConfig){
miguelcordero191 1:d81fca2297fb 698
miguelcordero191 1:d81fca2297fb 699 strcpy(message, MSG_STATUS_FAIL);
miguelcordero191 1:d81fca2297fb 700
miguelcordero191 1:d81fca2297fb 701 this->cmd_answer = message;
miguelcordero191 1:d81fca2297fb 702 this->cmd_answer_len = strlen(message);
miguelcordero191 0:156a9e15919e 703
miguelcordero191 0:156a9e15919e 704 return this->cmd_answer;
miguelcordero191 0:156a9e15919e 705 }
miguelcordero191 0:156a9e15919e 706
miguelcordero191 0:156a9e15919e 707 switch ( cmd )
miguelcordero191 0:156a9e15919e 708 {
miguelcordero191 0:156a9e15919e 709 case DDS_CMD_RESET:
miguelcordero191 0:156a9e15919e 710 success = this->init();
miguelcordero191 1:d81fca2297fb 711 success = this->defaultSettings();
miguelcordero191 1:d81fca2297fb 712 break;
miguelcordero191 1:d81fca2297fb 713
miguelcordero191 1:d81fca2297fb 714 case DDS_CMD_STATUS:
miguelcordero191 1:d81fca2297fb 715
miguelcordero191 1:d81fca2297fb 716 if (this->programmed == false)
miguelcordero191 1:d81fca2297fb 717 strcpy(message, MSG_STATUS_ON);
miguelcordero191 1:d81fca2297fb 718
miguelcordero191 1:d81fca2297fb 719 if ((this->programmed == true) && (this->rf_enabled == false))
miguelcordero191 1:d81fca2297fb 720 strcpy(message, MSG_STATUS_RF_DIS);
miguelcordero191 1:d81fca2297fb 721
miguelcordero191 1:d81fca2297fb 722 if ((this->programmed == true) && (this->rf_enabled == true))
miguelcordero191 1:d81fca2297fb 723 strcpy(message, MSG_STATUS_RF_ENA);
miguelcordero191 1:d81fca2297fb 724
miguelcordero191 1:d81fca2297fb 725 this->cmd_answer = message;
miguelcordero191 1:d81fca2297fb 726 this->cmd_answer_len = strlen(message);
miguelcordero191 0:156a9e15919e 727 break;
miguelcordero191 0:156a9e15919e 728
miguelcordero191 0:156a9e15919e 729 case DDS_CMD_ENABLE_RF:
miguelcordero191 0:156a9e15919e 730 if (payload_len == 1){
miguelcordero191 0:156a9e15919e 731 if (payload[0] == 0)
miguelcordero191 0:156a9e15919e 732 success = this->disableRF();
miguelcordero191 0:156a9e15919e 733 else
miguelcordero191 0:156a9e15919e 734 success = this->enableRF();
miguelcordero191 0:156a9e15919e 735 }
miguelcordero191 0:156a9e15919e 736 break;
miguelcordero191 1:d81fca2297fb 737
miguelcordero191 1:d81fca2297fb 738 case DDS_CMD_ENABLE_AMP:
miguelcordero191 1:d81fca2297fb 739 if (payload_len == 1){
miguelcordero191 1:d81fca2297fb 740 if (payload[0] == 0)
miguelcordero191 1:d81fca2297fb 741 success = this->disableAmplitude();
miguelcordero191 1:d81fca2297fb 742 else
miguelcordero191 1:d81fca2297fb 743 success = this->enableAmplitude();
miguelcordero191 1:d81fca2297fb 744 }
miguelcordero191 1:d81fca2297fb 745 break;
miguelcordero191 1:d81fca2297fb 746
miguelcordero191 0:156a9e15919e 747 case DDS_CMD_MULTIPLIER:
miguelcordero191 0:156a9e15919e 748 if (payload_len == 1){
miguelcordero191 0:156a9e15919e 749 success = this->wrMultiplier(payload[0]);
miguelcordero191 0:156a9e15919e 750 }
miguelcordero191 0:156a9e15919e 751 if (payload_len == 3){
miguelcordero191 0:156a9e15919e 752 unsigned short clock = payload[1]*256 + payload[2];
miguelcordero191 0:156a9e15919e 753 success = this->wrMultiplier(payload[0], (float)clock);
miguelcordero191 0:156a9e15919e 754 }
miguelcordero191 0:156a9e15919e 755 break;
miguelcordero191 0:156a9e15919e 756
miguelcordero191 0:156a9e15919e 757 case DDS_CMD_MODE:
miguelcordero191 0:156a9e15919e 758 if (payload_len == 1){
miguelcordero191 0:156a9e15919e 759 success = this->wrMode(payload[0]);
miguelcordero191 0:156a9e15919e 760 }
miguelcordero191 0:156a9e15919e 761 break;
miguelcordero191 0:156a9e15919e 762
miguelcordero191 0:156a9e15919e 763 case DDS_CMD_FREQUENCYA:
miguelcordero191 0:156a9e15919e 764 if (payload_len == 6){
miguelcordero191 0:156a9e15919e 765 success = this->wrFrequency1(payload);
miguelcordero191 0:156a9e15919e 766 }
miguelcordero191 0:156a9e15919e 767 break;
miguelcordero191 0:156a9e15919e 768
miguelcordero191 0:156a9e15919e 769 case DDS_CMD_FREQUENCYB:
miguelcordero191 0:156a9e15919e 770 if (payload_len == 6){
miguelcordero191 0:156a9e15919e 771 success = this->wrFrequency2(payload);
miguelcordero191 0:156a9e15919e 772 }
miguelcordero191 0:156a9e15919e 773 break;
miguelcordero191 0:156a9e15919e 774
miguelcordero191 0:156a9e15919e 775 case DDS_CMD_PHASEA:
miguelcordero191 0:156a9e15919e 776 if (payload_len == 2){
miguelcordero191 0:156a9e15919e 777 success = this->wrPhase1(payload);
miguelcordero191 0:156a9e15919e 778 }
miguelcordero191 0:156a9e15919e 779 break;
miguelcordero191 0:156a9e15919e 780
miguelcordero191 0:156a9e15919e 781 case DDS_CMD_PHASEB:
miguelcordero191 0:156a9e15919e 782 if (payload_len == 2){
miguelcordero191 0:156a9e15919e 783 success = this->wrPhase2(payload);
miguelcordero191 0:156a9e15919e 784 }
miguelcordero191 0:156a9e15919e 785 break;
miguelcordero191 0:156a9e15919e 786
miguelcordero191 0:156a9e15919e 787 case DDS_CMD_AMPLITUDE1:
miguelcordero191 0:156a9e15919e 788 if (payload_len == 2){
miguelcordero191 0:156a9e15919e 789 success = this->wrAmplitudeI(payload);
miguelcordero191 0:156a9e15919e 790 }
miguelcordero191 0:156a9e15919e 791 break;
miguelcordero191 0:156a9e15919e 792
miguelcordero191 0:156a9e15919e 793 case DDS_CMD_AMPLITUDE2:
miguelcordero191 0:156a9e15919e 794 if (payload_len == 2){
miguelcordero191 0:156a9e15919e 795 success = this->wrAmplitudeQ(payload);
miguelcordero191 0:156a9e15919e 796 }
miguelcordero191 0:156a9e15919e 797 break;
miguelcordero191 1:d81fca2297fb 798
miguelcordero191 1:d81fca2297fb 799 case DDS_CMD_AMP_RAMP_RATE:
miguelcordero191 1:d81fca2297fb 800 if (payload_len == 1){
miguelcordero191 1:d81fca2297fb 801 success = this->wrAmplitudeRampRate(payload);
miguelcordero191 1:d81fca2297fb 802 }
miguelcordero191 1:d81fca2297fb 803 break;
miguelcordero191 1:d81fca2297fb 804
miguelcordero191 1:d81fca2297fb 805 case DDS_CMD_DELTA_FREQ:
miguelcordero191 1:d81fca2297fb 806 if (payload_len == 1){
miguelcordero191 1:d81fca2297fb 807 success = this->wrDeltaFrequency(payload);
miguelcordero191 1:d81fca2297fb 808 }
miguelcordero191 1:d81fca2297fb 809 break;
miguelcordero191 1:d81fca2297fb 810
miguelcordero191 1:d81fca2297fb 811 case DDS_CMD_UPD_CLOCK:
miguelcordero191 1:d81fca2297fb 812 if (payload_len == 1){
miguelcordero191 1:d81fca2297fb 813 success = this->wrUpdateClock(payload);
miguelcordero191 1:d81fca2297fb 814 }
miguelcordero191 1:d81fca2297fb 815 break;
miguelcordero191 1:d81fca2297fb 816
miguelcordero191 1:d81fca2297fb 817 case DDS_CMD_RAMP_RATE_CLOCK:
miguelcordero191 1:d81fca2297fb 818 if (payload_len == 1){
miguelcordero191 1:d81fca2297fb 819 success = this->wrRampRateClock(payload);
miguelcordero191 1:d81fca2297fb 820 }
miguelcordero191 1:d81fca2297fb 821 break;
miguelcordero191 1:d81fca2297fb 822
miguelcordero191 0:156a9e15919e 823 case DDS_CMD_READ | DDS_CMD_ENABLE_RF:
miguelcordero191 0:156a9e15919e 824 if (this->isRFEnabled() == 1)
miguelcordero191 1:d81fca2297fb 825 strcpy(message, MSG_ENABLED);
miguelcordero191 0:156a9e15919e 826 else
miguelcordero191 1:d81fca2297fb 827 strcpy(message, MSG_DISABLED);
miguelcordero191 0:156a9e15919e 828
miguelcordero191 1:d81fca2297fb 829 this->cmd_answer_len = strlen(message);
miguelcordero191 0:156a9e15919e 830
miguelcordero191 0:156a9e15919e 831 break;
miguelcordero191 0:156a9e15919e 832
miguelcordero191 1:d81fca2297fb 833 case DDS_CMD_READ | DDS_CMD_ENABLE_AMP:
miguelcordero191 1:d81fca2297fb 834 if (this->cr_osk_en == 1)
miguelcordero191 1:d81fca2297fb 835 strcpy(message, MSG_ENABLED);
miguelcordero191 1:d81fca2297fb 836 else
miguelcordero191 1:d81fca2297fb 837 strcpy(message, MSG_DISABLED);
miguelcordero191 1:d81fca2297fb 838
miguelcordero191 1:d81fca2297fb 839 this->cmd_answer_len = strlen(message);
miguelcordero191 1:d81fca2297fb 840
miguelcordero191 1:d81fca2297fb 841 break;
miguelcordero191 1:d81fca2297fb 842
miguelcordero191 0:156a9e15919e 843 case DDS_CMD_READ | DDS_CMD_MULTIPLIER:
miguelcordero191 1:d81fca2297fb 844 this->cmd_answer = this->rdMultiplier();
miguelcordero191 1:d81fca2297fb 845 this->cmd_answer_len = 1;
miguelcordero191 0:156a9e15919e 846 break;
miguelcordero191 0:156a9e15919e 847
miguelcordero191 0:156a9e15919e 848 case DDS_CMD_READ | DDS_CMD_MODE:
miguelcordero191 1:d81fca2297fb 849 this->cmd_answer = this->rdMode();
miguelcordero191 1:d81fca2297fb 850 this->cmd_answer_len = 1;
miguelcordero191 0:156a9e15919e 851 break;
miguelcordero191 0:156a9e15919e 852
miguelcordero191 0:156a9e15919e 853 case DDS_CMD_READ | DDS_CMD_FREQUENCYA:
miguelcordero191 1:d81fca2297fb 854 this->cmd_answer = this->rdFrequency1();
miguelcordero191 1:d81fca2297fb 855 this->cmd_answer_len = 6;
miguelcordero191 0:156a9e15919e 856 break;
miguelcordero191 0:156a9e15919e 857
miguelcordero191 0:156a9e15919e 858 case DDS_CMD_READ | DDS_CMD_FREQUENCYB:
miguelcordero191 1:d81fca2297fb 859 this->cmd_answer = this->rdFrequency2();
miguelcordero191 1:d81fca2297fb 860 this->cmd_answer_len = 6;
miguelcordero191 0:156a9e15919e 861 break;
miguelcordero191 0:156a9e15919e 862
miguelcordero191 0:156a9e15919e 863 case DDS_CMD_READ | DDS_CMD_PHASEA:
miguelcordero191 1:d81fca2297fb 864 this->cmd_answer = this->rdPhase1();
miguelcordero191 1:d81fca2297fb 865 this->cmd_answer_len = 2;
miguelcordero191 0:156a9e15919e 866 break;
miguelcordero191 0:156a9e15919e 867
miguelcordero191 0:156a9e15919e 868 case DDS_CMD_READ | DDS_CMD_PHASEB:
miguelcordero191 1:d81fca2297fb 869 this->cmd_answer = this->rdPhase2();
miguelcordero191 1:d81fca2297fb 870 this->cmd_answer_len = 2;
miguelcordero191 0:156a9e15919e 871 break;
miguelcordero191 0:156a9e15919e 872
miguelcordero191 0:156a9e15919e 873 case DDS_CMD_READ | DDS_CMD_AMPLITUDE1:
miguelcordero191 1:d81fca2297fb 874 this->cmd_answer = this->rdAmplitudeI();
miguelcordero191 1:d81fca2297fb 875 this->cmd_answer_len = 2;
miguelcordero191 0:156a9e15919e 876 break;
miguelcordero191 0:156a9e15919e 877
miguelcordero191 0:156a9e15919e 878 case DDS_CMD_READ | DDS_CMD_AMPLITUDE2:
miguelcordero191 1:d81fca2297fb 879 this->cmd_answer = this->rdAmplitudeQ();
miguelcordero191 1:d81fca2297fb 880 this->cmd_answer_len = 2;
miguelcordero191 1:d81fca2297fb 881 break;
miguelcordero191 1:d81fca2297fb 882
miguelcordero191 1:d81fca2297fb 883 case DDS_CMD_READ | DDS_CMD_AMP_RAMP_RATE:
miguelcordero191 1:d81fca2297fb 884 this->cmd_answer = this->rdAmplitudeRampRate();
miguelcordero191 1:d81fca2297fb 885 this->cmd_answer_len = 1;
miguelcordero191 1:d81fca2297fb 886 break;
miguelcordero191 1:d81fca2297fb 887
miguelcordero191 1:d81fca2297fb 888 case DDS_CMD_READ | DDS_CMD_DELTA_FREQ:
miguelcordero191 1:d81fca2297fb 889 this->cmd_answer = this->rdDeltaFrequency();
miguelcordero191 1:d81fca2297fb 890 this->cmd_answer_len = 6;
miguelcordero191 1:d81fca2297fb 891 break;
miguelcordero191 1:d81fca2297fb 892
miguelcordero191 1:d81fca2297fb 893 case DDS_CMD_READ | DDS_CMD_UPD_CLOCK:
miguelcordero191 1:d81fca2297fb 894 this->cmd_answer = this->rdUpdateClock();
miguelcordero191 1:d81fca2297fb 895 this->cmd_answer_len = 4;
miguelcordero191 1:d81fca2297fb 896 break;
miguelcordero191 1:d81fca2297fb 897
miguelcordero191 1:d81fca2297fb 898 case DDS_CMD_READ | DDS_CMD_RAMP_RATE_CLOCK:
miguelcordero191 1:d81fca2297fb 899 this->cmd_answer = this->rdRampRateClock();
miguelcordero191 1:d81fca2297fb 900 this->cmd_answer_len = 3;
miguelcordero191 1:d81fca2297fb 901 break;
miguelcordero191 1:d81fca2297fb 902
miguelcordero191 1:d81fca2297fb 903 case DDS_CMD_WRITE:
miguelcordero191 1:d81fca2297fb 904 if (payload_len == 0x28){
miguelcordero191 1:d81fca2297fb 905 success = this->writeAllDevice(payload);
miguelcordero191 1:d81fca2297fb 906 }
miguelcordero191 1:d81fca2297fb 907 break;
miguelcordero191 1:d81fca2297fb 908
miguelcordero191 1:d81fca2297fb 909 case DDS_CMD_READ:
miguelcordero191 1:d81fca2297fb 910 this->cmd_answer = this->readAllDevice();
miguelcordero191 1:d81fca2297fb 911 this->cmd_answer_len = 0x28;
miguelcordero191 0:156a9e15919e 912 break;
miguelcordero191 0:156a9e15919e 913
miguelcordero191 0:156a9e15919e 914 default:
miguelcordero191 0:156a9e15919e 915 success = false;
miguelcordero191 1:d81fca2297fb 916 strcpy(message, MSG_CMD_KO);
miguelcordero191 1:d81fca2297fb 917 this->cmd_answer = message;
miguelcordero191 1:d81fca2297fb 918 this->cmd_answer_len = strlen(message);
miguelcordero191 0:156a9e15919e 919
miguelcordero191 0:156a9e15919e 920 }
miguelcordero191 0:156a9e15919e 921
miguelcordero191 0:156a9e15919e 922 if (success){
miguelcordero191 1:d81fca2297fb 923 strcpy(message, MSG_CMD_OK);
miguelcordero191 1:d81fca2297fb 924 this->cmd_answer = message;
miguelcordero191 1:d81fca2297fb 925 this->cmd_answer_len = strlen(message);
miguelcordero191 0:156a9e15919e 926 }
miguelcordero191 0:156a9e15919e 927
miguelcordero191 1:d81fca2297fb 928 return this->cmd_answer;
miguelcordero191 0:156a9e15919e 929 }
miguelcordero191 0:156a9e15919e 930
miguelcordero191 0:156a9e15919e 931 char* DDS::getCmdAnswer(){
miguelcordero191 0:156a9e15919e 932
miguelcordero191 0:156a9e15919e 933 return this->cmd_answer;
miguelcordero191 0:156a9e15919e 934
miguelcordero191 0:156a9e15919e 935 }
miguelcordero191 0:156a9e15919e 936
miguelcordero191 0:156a9e15919e 937 unsigned long DDS::getCmdAnswerLen(){
miguelcordero191 0:156a9e15919e 938
miguelcordero191 0:156a9e15919e 939 return this->cmd_answer_len;
miguelcordero191 0:156a9e15919e 940
miguelcordero191 0:156a9e15919e 941 }
miguelcordero191 0:156a9e15919e 942
miguelcordero191 0:156a9e15919e 943 bool DDS::wasInitialized(){
miguelcordero191 0:156a9e15919e 944
miguelcordero191 0:156a9e15919e 945 return this->isConfig;
miguelcordero191 0:156a9e15919e 946 }
miguelcordero191 0:156a9e15919e 947
miguelcordero191 0:156a9e15919e 948 char DDS::getMultiplier(){
miguelcordero191 0:156a9e15919e 949 return this->cr_multiplier;
miguelcordero191 0:156a9e15919e 950 }
miguelcordero191 0:156a9e15919e 951
miguelcordero191 0:156a9e15919e 952 double DDS::getFreqFactor1(){
miguelcordero191 0:156a9e15919e 953 factor_freq1 = ((double)frequency1[0])/256.0 + ((double)frequency1[1])/65536.0 + ((double)frequency1[2])/16777216.0 + ((double)frequency1[3])/4294967296.0;
miguelcordero191 0:156a9e15919e 954 factor_freq1 *= ((double)this->cr_multiplier);
miguelcordero191 0:156a9e15919e 955
miguelcordero191 0:156a9e15919e 956 return factor_freq1;
miguelcordero191 0:156a9e15919e 957 }
miguelcordero191 0:156a9e15919e 958
miguelcordero191 0:156a9e15919e 959 double DDS::getFreqFactor2(){
miguelcordero191 0:156a9e15919e 960 factor_freq2 = ((double)frequency2[0])/256.0 + ((double)frequency2[1])/65536.0 + ((double)frequency2[2])/16777216.0 + ((double)frequency2[3])/4294967296.0;
miguelcordero191 0:156a9e15919e 961 factor_freq2 *= ((double)this->cr_multiplier);
miguelcordero191 0:156a9e15919e 962
miguelcordero191 0:156a9e15919e 963 return factor_freq2;
miguelcordero191 0:156a9e15919e 964 }
miguelcordero191 0:156a9e15919e 965
miguelcordero191 0:156a9e15919e 966 char DDS::getMode(){
miguelcordero191 0:156a9e15919e 967 return this->cr_mode;
miguelcordero191 0:156a9e15919e 968 }
miguelcordero191 0:156a9e15919e 969
miguelcordero191 0:156a9e15919e 970 char* DDS::getModeStr(){
miguelcordero191 0:156a9e15919e 971
miguelcordero191 0:156a9e15919e 972 if (this->cr_mode > 4)
miguelcordero191 0:156a9e15919e 973 return MODULATION[5];
miguelcordero191 0:156a9e15919e 974
miguelcordero191 0:156a9e15919e 975 return MODULATION[this->cr_mode];
miguelcordero191 1:d81fca2297fb 976 }
miguelcordero191 1:d81fca2297fb 977
miguelcordero191 1:d81fca2297fb 978
miguelcordero191 1:d81fca2297fb 979 int DDS::writeAllDevice(char* payload, SerialDriver *screen){
miguelcordero191 1:d81fca2297fb 980
miguelcordero191 1:d81fca2297fb 981 int sts;
miguelcordero191 1:d81fca2297fb 982 char* phase1, *phase2;
miguelcordero191 1:d81fca2297fb 983 char* freq1, *freq2;
miguelcordero191 1:d81fca2297fb 984 char* delta_freq, *upd_rate_clk, *ramp_rate_clk;
miguelcordero191 1:d81fca2297fb 985 char* control_reg;
miguelcordero191 1:d81fca2297fb 986 char* amplitudeI, *amplitudeQ, *ampl_ramp_rate;
miguelcordero191 1:d81fca2297fb 987 char* qdac;
miguelcordero191 1:d81fca2297fb 988
miguelcordero191 1:d81fca2297fb 989 //parm = payload[ParallelAddress]
miguelcordero191 1:d81fca2297fb 990 phase1 = &payload[0x00];
miguelcordero191 1:d81fca2297fb 991 phase2 = &payload[0x02];
miguelcordero191 1:d81fca2297fb 992 freq1 = &payload[0x04];
miguelcordero191 1:d81fca2297fb 993 freq2 = &payload[0x0A];
miguelcordero191 1:d81fca2297fb 994 delta_freq = &payload[0x10];
miguelcordero191 1:d81fca2297fb 995 upd_rate_clk = &payload[0x16];
miguelcordero191 1:d81fca2297fb 996 ramp_rate_clk = &payload[0x1A];
miguelcordero191 1:d81fca2297fb 997 control_reg = &payload[0x1D];
miguelcordero191 1:d81fca2297fb 998 amplitudeI = &payload[0x21];
miguelcordero191 1:d81fca2297fb 999 amplitudeQ = &payload[0x23];
miguelcordero191 1:d81fca2297fb 1000 ampl_ramp_rate = &payload[0x25];
miguelcordero191 1:d81fca2297fb 1001 qdac = &payload[0x26];
miguelcordero191 1:d81fca2297fb 1002
miguelcordero191 1:d81fca2297fb 1003 control_reg[2] = control_reg[2] & 0xFE; //cr_ioupdclk always as an input = 0 when serial operation is used
miguelcordero191 1:d81fca2297fb 1004 control_reg[3] = control_reg[3] & 0xFD; //LSB first = 0, MSB first enabled
miguelcordero191 1:d81fca2297fb 1005 control_reg[3] = control_reg[3] | 0x01; //cr_sdo enable = 1
miguelcordero191 1:d81fca2297fb 1006
miguelcordero191 1:d81fca2297fb 1007 cr_osk_int_bkp = (control_reg[3] & 0x10) >> 4;
miguelcordero191 1:d81fca2297fb 1008 cr_osk_en_bkp = (control_reg[3] & 0x20) >> 5;
miguelcordero191 1:d81fca2297fb 1009
miguelcordero191 1:d81fca2297fb 1010 //this->__writeDataAndVerify(SerialAddress, NumberOfBytes, Bytes);
miguelcordero191 1:d81fca2297fb 1011 //this->__writeDataAndVerify(0x04, 6, delta_freq);
miguelcordero191 1:d81fca2297fb 1012 //this->__writeDataAndVerify(0x05, 4, upd_rate_clk);
miguelcordero191 1:d81fca2297fb 1013 //this->__writeDataAndVerify(0x06, 3, ramp_rate_clk);
miguelcordero191 1:d81fca2297fb 1014 this->__writeDataAndVerify(0x07, 4, control_reg);
miguelcordero191 1:d81fca2297fb 1015
miguelcordero191 1:d81fca2297fb 1016 //this->__writeDataAndVerify(0x0A, 1, ampl_ramp_rate);
miguelcordero191 1:d81fca2297fb 1017 this->__writeDataAndVerify(0x0B, 2, qdac, screen);
miguelcordero191 1:d81fca2297fb 1018
miguelcordero191 1:d81fca2297fb 1019 this->wrPhase1(phase1);
miguelcordero191 1:d81fca2297fb 1020 this->wrPhase2(phase2);
miguelcordero191 1:d81fca2297fb 1021 this->wrFrequency1(freq1);
miguelcordero191 1:d81fca2297fb 1022 this->wrFrequency2(freq2);
miguelcordero191 1:d81fca2297fb 1023 this->wrDeltaFrequency(delta_freq);
miguelcordero191 1:d81fca2297fb 1024 this->wrUpdateClock(upd_rate_clk);
miguelcordero191 1:d81fca2297fb 1025 this->wrRampRateClock(ramp_rate_clk);
miguelcordero191 1:d81fca2297fb 1026
miguelcordero191 1:d81fca2297fb 1027 this->wrAmplitudeI(amplitudeI);
miguelcordero191 1:d81fca2297fb 1028 this->wrAmplitudeQ(amplitudeQ);
miguelcordero191 1:d81fca2297fb 1029
miguelcordero191 1:d81fca2297fb 1030 this->wrAmplitudeRampRate(ampl_ramp_rate);
miguelcordero191 1:d81fca2297fb 1031
miguelcordero191 1:d81fca2297fb 1032 //Enabling RF
miguelcordero191 1:d81fca2297fb 1033 sts = this->enableRF();
miguelcordero191 1:d81fca2297fb 1034
miguelcordero191 1:d81fca2297fb 1035 return sts;
miguelcordero191 1:d81fca2297fb 1036
miguelcordero191 1:d81fca2297fb 1037 }
miguelcordero191 1:d81fca2297fb 1038
miguelcordero191 1:d81fca2297fb 1039
miguelcordero191 1:d81fca2297fb 1040 char* DDS::readAllDevice(){
miguelcordero191 1:d81fca2297fb 1041
miguelcordero191 1:d81fca2297fb 1042 char* rd_data;
miguelcordero191 1:d81fca2297fb 1043 int i=0, k=0;
miguelcordero191 1:d81fca2297fb 1044
miguelcordero191 1:d81fca2297fb 1045 rd_data = this->rdPhase1();
miguelcordero191 1:d81fca2297fb 1046
miguelcordero191 1:d81fca2297fb 1047 for (i=0; i<2; i++)
miguelcordero191 1:d81fca2297fb 1048 message[k+i] = rd_data[i];
miguelcordero191 1:d81fca2297fb 1049 k += i;
miguelcordero191 1:d81fca2297fb 1050
miguelcordero191 1:d81fca2297fb 1051 rd_data = this->rdPhase2();
miguelcordero191 1:d81fca2297fb 1052
miguelcordero191 1:d81fca2297fb 1053 for (i=0; i<2; i++)
miguelcordero191 1:d81fca2297fb 1054 message[k+i] = rd_data[i];
miguelcordero191 1:d81fca2297fb 1055 k += i;
miguelcordero191 1:d81fca2297fb 1056
miguelcordero191 1:d81fca2297fb 1057 rd_data = this->rdFrequency1();
miguelcordero191 1:d81fca2297fb 1058
miguelcordero191 1:d81fca2297fb 1059 for (i=0; i<6; i++)
miguelcordero191 1:d81fca2297fb 1060 message[k+i] = rd_data[i];
miguelcordero191 1:d81fca2297fb 1061 k += i;
miguelcordero191 1:d81fca2297fb 1062
miguelcordero191 1:d81fca2297fb 1063 rd_data = this->rdFrequency2();
miguelcordero191 1:d81fca2297fb 1064
miguelcordero191 1:d81fca2297fb 1065 for (i=0; i<6; i++)
miguelcordero191 1:d81fca2297fb 1066 message[k+i] = rd_data[i];
miguelcordero191 1:d81fca2297fb 1067 k += i;
miguelcordero191 1:d81fca2297fb 1068
miguelcordero191 1:d81fca2297fb 1069 rd_data = this->rdDeltaFrequency();
miguelcordero191 1:d81fca2297fb 1070
miguelcordero191 1:d81fca2297fb 1071 for (i=0; i<6; i++)
miguelcordero191 1:d81fca2297fb 1072 message[k+i] = rd_data[i];
miguelcordero191 1:d81fca2297fb 1073 k += i;
miguelcordero191 1:d81fca2297fb 1074
miguelcordero191 1:d81fca2297fb 1075 rd_data = this->rdUpdateClock();
miguelcordero191 1:d81fca2297fb 1076
miguelcordero191 1:d81fca2297fb 1077 for (i=0; i<4; i++)
miguelcordero191 1:d81fca2297fb 1078 message[k+i] = rd_data[i];
miguelcordero191 1:d81fca2297fb 1079 k += i;
miguelcordero191 1:d81fca2297fb 1080
miguelcordero191 1:d81fca2297fb 1081 rd_data = this->rdRampRateClock();
miguelcordero191 1:d81fca2297fb 1082
miguelcordero191 1:d81fca2297fb 1083 for (i=0; i<3; i++)
miguelcordero191 1:d81fca2297fb 1084 message[k+i] = rd_data[i];
miguelcordero191 1:d81fca2297fb 1085 k += i;
miguelcordero191 1:d81fca2297fb 1086
miguelcordero191 1:d81fca2297fb 1087 rd_data = this->__readData(0x07, 4);
miguelcordero191 1:d81fca2297fb 1088
miguelcordero191 1:d81fca2297fb 1089 for (i=0; i<4; i++)
miguelcordero191 1:d81fca2297fb 1090 message[k+i] = rd_data[i];
miguelcordero191 1:d81fca2297fb 1091 k += i;
miguelcordero191 1:d81fca2297fb 1092
miguelcordero191 1:d81fca2297fb 1093 rd_data = this->rdAmplitudeI();
miguelcordero191 1:d81fca2297fb 1094
miguelcordero191 1:d81fca2297fb 1095 for (i=0; i<2; i++)
miguelcordero191 1:d81fca2297fb 1096 message[k+i] = rd_data[i];
miguelcordero191 1:d81fca2297fb 1097 k += i;
miguelcordero191 1:d81fca2297fb 1098
miguelcordero191 1:d81fca2297fb 1099 rd_data = this->rdAmplitudeQ();
miguelcordero191 1:d81fca2297fb 1100
miguelcordero191 1:d81fca2297fb 1101
miguelcordero191 1:d81fca2297fb 1102 for (i=0; i<2; i++)
miguelcordero191 1:d81fca2297fb 1103 message[k+i] = rd_data[i];
miguelcordero191 1:d81fca2297fb 1104 k += i;
miguelcordero191 1:d81fca2297fb 1105
miguelcordero191 1:d81fca2297fb 1106 rd_data = this->rdAmplitudeRampRate();
miguelcordero191 1:d81fca2297fb 1107
miguelcordero191 1:d81fca2297fb 1108 for (i=0; i<1; i++)
miguelcordero191 1:d81fca2297fb 1109 message[k+i] = rd_data[i];
miguelcordero191 1:d81fca2297fb 1110 k += i;
miguelcordero191 1:d81fca2297fb 1111
miguelcordero191 1:d81fca2297fb 1112 rd_data = this->__readData(0x0B, 2);
miguelcordero191 1:d81fca2297fb 1113
miguelcordero191 1:d81fca2297fb 1114 for (i=0; i<2; i++)
miguelcordero191 1:d81fca2297fb 1115 message[k+i] = rd_data[i];
miguelcordero191 1:d81fca2297fb 1116 k += i;
miguelcordero191 1:d81fca2297fb 1117
miguelcordero191 1:d81fca2297fb 1118 return message;
miguelcordero191 1:d81fca2297fb 1119
miguelcordero191 1:d81fca2297fb 1120 }