-
Notifications
You must be signed in to change notification settings - Fork 0
/
newdebug.cpp
476 lines (379 loc) · 13.3 KB
/
newdebug.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
#include "newdebug.h"
#include "ui_newdebug.h"
NewDebug::NewDebug(QWidget *parent) :
QDialog(parent),
ui(new Ui::NewDebug)
{
ui->setupUi(this);
// this->setFixedSize(1024, 768);
this->setWindowFlags(Qt::FramelessWindowHint);
//this->setWindowState(Qt::WindowFullScreen);
//this->setWindowFlag(Qt::WindowStaysOnTopHint);
this->setAttribute(Qt::WA_DeleteOnClose, true); //so that it will be deleted when closed
localFPGAaddr = globalVars::global_FPGA_ADDR;
timer_autoManualClick = new QTimer(this);
connect(timer_autoManualClick, SIGNAL(timeout()), this, SLOT(on_timer_autoManualClicked()));
timer_autoManualClick->setInterval(100);
//timer_autoManualClick->start();
timer_configRegister = new QTimer(this);
connect(timer_configRegister, SIGNAL(timeout()), this, SLOT(on_timer_configRegister_Elapsed()));
timer_configRegister->setInterval(100);
*(localFPGAaddr + 0x06) = 0x00;
}
void NewDebug::on_pb_Close_clicked()
{
emit tx_generate_ThisGUI(gui_FIRST_WIN);
emit tx_ClosingWindow_DebugWin();
}
NewDebug::~NewDebug()
{
delete ui;
}
int adcNumber = 0;
void NewDebug::on_pb_Reset_clicked()
{
}
void NewDebug::on_pb_StartConversion_clicked()
{
*(localFPGAaddr + 0x02) = 0x01;
*(localFPGAaddr + 0x06) = 0x00;
*(localFPGAaddr + 0x03) = 0x08;
*(localFPGAaddr + 0x08) = 0x00; // Pulse
*(localFPGAaddr + 0x08) = 0x01;
*(localFPGAaddr + 0x08) = 0x00;
//qDebug()<<"\t\t WriteRegister Method: Addr: "<<address<<" val: "<<val<<" mosi:"<<sendValue<<"\n";
}
uint32_t NewDebug::on_pb_ReadConversion_clicked()
{
int finalIndx = ui->sp_ADC->value() + adcNumber;
int PulseIndx = finalIndx/ 8;
/*
uint16_t lsb = *(localFPGAaddr+((PulseIndx*5)+48));
uint16_t msb = *(localFPGAaddr+((PulseIndx*5)+49));
uint8_t first = 0x00;
uint8_t middle = 0x00;
uint8_t last = 0x00;
first = (msb & 0xFF);
middle = (lsb & 0xFF00) >> 8;
last = (lsb & 0xFF);
*/
uint32_t endResult = 0x00000000;
// endResult = (first<<16);
// endResult = endResult |(middle<<8);
// endResult = endResult |(last);
uint8_t lsb = 0x00;
uint8_t msb = 0x00;
endResult = *(localFPGAaddr+(PulseIndx+48));
lsb = (endResult & 0xFF0000)>>16;
msb = endResult & 0xFF;
endResult = endResult & 0xFF00;
endResult = endResult | (lsb & 0xFF);
endResult = endResult | (msb<<16);
//qDebug()<<" FullPCB:: current ADC:"<<finalIndx<<" read-Addr:"<<PulseIndx+48<<" endResult (hex):"<<QString::number(endResult, 16);
*(localFPGAaddr + 0x02) = 0x03;
*(localFPGAaddr + 0x06) = 0x00;
*(localFPGAaddr + 0x03) = 0xFF;
*(localFPGAaddr + (PulseIndx+8)) = 0x00; // Pulse //qDebug()<<"\t\t WriteRegister Method: Addr: "<<address<<" val: "<<val<<" mosi:"<<sendValue<<"\n";
*(localFPGAaddr + (PulseIndx+8)) = 0x01;
*(localFPGAaddr + (PulseIndx+8)) = 0x00;
return endResult;
}
void NewDebug::on_pb_ADC_Number_clicked()
{
*(localFPGAaddr + 0x01) = ui->sp_ADC->value();
}
void NewDebug::on_pb_readRegister_clicked()
{
uint8_t val = 0x00;
uint8_t rReg = 0x20;
QString addrTxt = ui->txt_readRegister->toPlainText();
bool okVar = false;
uint8_t addrInt = addrTxt.toUInt(&okVar, 10);
val = (rReg| (addrInt<<2));
*(localFPGAaddr + 0x03) = val;
*(localFPGAaddr + 0x02) = 0x02;
int indxx = ui->sp_ADC->value();
int actualIDX = indxx / 8;
*(localFPGAaddr + actualIDX+8) = 0x00; // pulse
*(localFPGAaddr + actualIDX+8) = 0x01;
*(localFPGAaddr + actualIDX+8) = 0x00;
//usleep(100000);
//uint16_t lsb = *(localFPGAaddr+((actualIDX*5)+48));
//uint16_t msb = *(localFPGAaddr+((actualIDX*5)+49));
uint32_t reply = *(localFPGAaddr+(actualIDX+48));; //(msb<<16 & 0xffff0000) + (lsb & 0xffff);
//qDebug()<<" readRegister:: lsb:"<<lsb<<" MSB:"<<msb<<" both:"<<reply<<" Pulse:"<<actualIDX+8;
qDebug()<<" readRegister::"<<reply<<" Pulse:"<<actualIDX+8<<" read-Addr:"<<indxx+48;
ui->lbl_readRegister->setText(QString::number(reply, 16));
}
void NewDebug::on_pb_setClock_clicked()
{
QString valTxt = ui->txt_setClock->toPlainText();
bool okVar = false;
uint32_t valInt = valTxt.toUInt(&okVar, 10);
okVar = false;
//qDebug()<<"Write:: adc: "<<adcIndx<<" addr(int):"<<addInt<<" Val:"<<valTxt.toUInt(&okVar, 10);
//valInt *= 1000;
valInt /= 0.02;
*(localFPGAaddr+ 0x00) = valInt;
//ui->lbl_SetClock->setText(QString::number(*(localFPGAaddr+00), 16));
}
void NewDebug::on_pb_samplingRate_clicked()
{
QString valTxt = ui->txt_setSamplingRate->toPlainText();
bool okVar = false;
uint32_t valInt = valTxt.toUInt(&okVar, 10);
okVar = false;
//qDebug()<<"Write:: adc: "<<adcIndx<<" addr(int):"<<addInt<<" Val:"<<valTxt.toUInt(&okVar, 10);
//valInt *= 1000;
valInt /= 0.02;
*(localFPGAaddr + 14) = valInt;
//ui->lbl_setSamplingRate->setText(QString::number(*(localFPGAaddr+14), 16));
}
void NewDebug::on_pb_writeRegister_1_clicked()
{
QString valTxt = ui->txt_writeRegister_1->toPlainText();
bool okVar = false;
uint8_t valInt = valTxt.toUInt(&okVar, 10);
writeRegister(0x00, valInt);
//usleep(5000000);
//ui->lbl_writeRegister_1->setText(QString::number(readRegister(0x00), 16));
}
void NewDebug::on_pb_writeRegister_2_clicked()
{
QString valTxt = ui->txt_writeRegister_2->toPlainText();
bool okVar = false;
uint8_t valInt = valTxt.toUInt(&okVar, 10);
writeRegister(0x01, valInt);
//usleep(5000000);
//ui->lbl_writeRegister_2->setText(QString::number(readRegister(0x01), 16));
}
void NewDebug::on_pb_writeRegister_3_clicked()
{
QString valTxt = ui->txt_writeRegister_3->toPlainText();
bool okVar = false;
uint8_t valInt = valTxt.toUInt(&okVar, 10);
writeRegister(0x02, valInt);
//usleep(5000000);
//ui->lbl_writeRegister_3->setText(QString::number(readRegister(0x02), 16));
}
void NewDebug::on_pb_writeRegister_4_clicked()
{
QString valTxt = ui->txt_writeRegister_4->toPlainText();
bool okVar = false;
uint8_t valInt = valTxt.toUInt(&okVar, 10);
writeRegister(0x03, valInt);
//usleep(5000000);
//ui->lbl_writeRegister_4->setText(QString::number(readRegister(0x03), 16));
}
void NewDebug::on_pb_Timer_clicked()
{
if(timer_autoManualClick->isActive())
{
timer_autoManualClick->stop();
ui->pb_Timer->setStyleSheet("background-color: red;");
}
else
{
timer_autoManualClick->start();
ui->pb_Timer->setStyleSheet("background-color: lime;");
}
}
void NewDebug::on_timer_autoManualClicked()
{
if(autoMode_isEnable)
{ // automatic
showValueofPCB_Channels(0, getCalculatedFromRawValue(*(localFPGAaddr+0x00)));
showValueofPCB_Channels(1, getCalculatedFromRawValue(*(localFPGAaddr+0x01)));
showValueofPCB_Channels(2, getCalculatedFromRawValue(*(localFPGAaddr+0x02)));
showValueofPCB_Channels(3, getCalculatedFromRawValue(*(localFPGAaddr+0x03)));
showValueofPCB_Channels(4, getCalculatedFromRawValue(*(localFPGAaddr+0x04)));
showValueofPCB_Channels(5, getCalculatedFromRawValue(*(localFPGAaddr+0x05)));
showValueofPCB_Channels(6, getCalculatedFromRawValue(*(localFPGAaddr+0x06)));
showValueofPCB_Channels(7, getCalculatedFromRawValue(*(localFPGAaddr+0x07)));
}
else
{
if(adcNumber == 8) adcNumber = 0;
else adcNumber++;
//adcNumber = ui->sp_ADC->value();adcNumber
*(localFPGAaddr + 0x01) = (ui->sp_ADC->value() + adcNumber);
uint32_t rawValue = on_pb_ReadConversion_clicked();
usleep(10000);
rawValue = on_pb_ReadConversion_clicked();
float internalRef = 2.048;
double coeficient = pow(2, 24);
float calculatedValue = (rawValue/coeficient) * internalRef;
showValueofPCB_Channels(adcNumber, calculatedValue);
}
//on_pb_Write_New_clicked();
//on_pb_Read_New_clicked();
//readData();
//on_pb_writeRegister_1_clicked();
//on_pb_ReadConversion_clicked();
//on_pb_readRegister_clicked();
}
float NewDebug::getCalculatedFromRawValue(uint32_t raw)
{
//int32_t simpleInt = (raw & 0x7FFFFF);
//simpleInt = simpleInt + ((raw & 0x800000)<<8); // >> 23;
float internalRef = 2.048;
float coeficient = pow(2, 24);
float calculatedValue = (raw/coeficient) * internalRef;
return calculatedValue;
}
void NewDebug::on_timer_configRegister_Elapsed()
{
}
int NewDebug::writeRegister(uint8_t addr, uint8_t val)
{
uint8_t wReg = 0x40;
uint8_t address = 0x00;
address = (wReg|(addr<<2));
uint32_t sendValue = 0x00;
sendValue = ((val<<8) & 0xff00) + (address & 0xff);
*(localFPGAaddr + 0x02) = 0x02;
*(localFPGAaddr + 0x06) = 0x00;
*(localFPGAaddr + 0x03) = sendValue;
int indxx = ui->sp_ADC->value();
int actualIDX = indxx / 8;
actualIDX += 8;
*(localFPGAaddr + actualIDX) = 0x00; // Pulse
*(localFPGAaddr + actualIDX) = 0x01;
*(localFPGAaddr + actualIDX) = 0x00;
qDebug()<<"\t\t WriteRegister Method: Addr: "<<address<<" val: "<<val<<" mosi:"<<sendValue<<" Pulse Indx:"<<actualIDX<<"\n";
return 1;
}
uint32_t NewDebug::readRegister(uint8_t addr)
{
uint8_t val = 0x00;
uint8_t rReg = 0x20;
val = (rReg| (addr<<2));
*(localFPGAaddr + 0x03) = val;
*(localFPGAaddr + 0x02) = 0x02;
int indxx = ui->sp_ADC->value();
int actualIDX = indxx / 8;
*(localFPGAaddr + actualIDX+8) = 0x00; // pulse
*(localFPGAaddr + actualIDX+8) = 0x01;
*(localFPGAaddr + actualIDX+8) = 0x00;
//usleep(100000);
//uint16_t lsb = *(localFPGAaddr+((actualIDX*5)+48));
//uint16_t msb = *(localFPGAaddr+((actualIDX*5)+49));
uint32_t reply = *(localFPGAaddr+(actualIDX+48)); //(msb<<16 & 0xffff0000) + (lsb & 0xffff);
//qDebug()<<" readRegister:: lsb:"<<lsb<<" MSB:"<<msb<<" both:"<<reply<<" Pulse:"<<actualIDX+8;
qDebug()<<" readRegister:: "<<reply<<" Pulse:"<<actualIDX+8;
return reply;
}
void NewDebug::readData()
{
*(localFPGAaddr + 0x02) = 0x03;
*(localFPGAaddr + 0x06) = 0x00;
*(localFPGAaddr + 0x03) = 0xFF;
*(localFPGAaddr + 0x08) = 0x00; // Pulse
*(localFPGAaddr + 0x08) = 0x01;
*(localFPGAaddr + 0x08) = 0x00;
//qDebug()<<"\t\t WriteRegister Method: Addr: "<<address<<" val: "<<val<<" mosi:"<<sendValue<<"\n";
uint16_t lsb = *(localFPGAaddr + 48);
uint16_t msb = *(localFPGAaddr + 49);
uint32_t dd = (((msb&0xFF)<<16)&0xFFFF0000)+ (lsb&0xFF);
qDebug()<<" readData() method:: value (hex):"<<QString::number(dd, 16);
}
void NewDebug::on_pb_readRegister_2_clicked()
{
uint16_t lsb = *(localFPGAaddr+48);
uint16_t msb = *(localFPGAaddr+49);
msb = (msb & 0xFF);
uint32_t reply = (msb<<16 & 0xffff0000) + (lsb & 0xffff);
qDebug()<<" readRegister 2:: lsb:"<<lsb<<" MSB:"<<msb<<" both:"<<reply;
ui->lbl_readRegister->setText(QString::number(reply, 16));
}
void NewDebug::on_pb_read_ALLChannels_clicked()
{
if(timer_autoManualClick->isActive())
{
timer_autoManualClick->stop();
ui->pb_read_ALLChannels->setStyleSheet("background-color:red;");
}
else
{
timer_autoManualClick->start(50);
ui->pb_read_ALLChannels->setStyleSheet("background-color:lime;");
}
}
void NewDebug::showValueofPCB_Channels(int idx, float val)
{
switch (idx) {
case 0: {
ui->lbl_Channel_1->setText(QString::number(val, 'f', 2));
break;
}
case 1: {
ui->lbl_Channel_2->setText(QString::number(val, 'f', 2));
break;
}
case 2: {
ui->lbl_Channel_3->setText(QString::number(val, 'f', 2));
break;
}
case 3: {
ui->lbl_Channel_4->setText(QString::number(val, 'f', 2));
break;
}
case 4: {
ui->lbl_Channel_5->setText(QString::number(val, 'f', 2));
break;
}
case 5: {
ui->lbl_Channel_6->setText(QString::number(val, 'f', 2));
break;
}
case 6: {
ui->lbl_Channel_7->setText(QString::number(val, 'f', 2));
break;
}
case 7: {
ui->lbl_Channel_8->setText(QString::number(val, 'f', 2));
break;
}
}
}
void NewDebug::on_pb_ConfigAll_clicked()
{
int delay = 10000;
for(int i=0; i<8; i++)
{
*(localFPGAaddr+0x01) = (ui->sp_ADC->value())+ i;
usleep(delay);
on_pb_writeRegister_1_clicked();
usleep(delay);
on_pb_writeRegister_2_clicked();
usleep(delay);
on_pb_writeRegister_3_clicked();
usleep(delay);
on_pb_writeRegister_4_clicked();
usleep(delay);
on_pb_StartConversion_clicked();
usleep(delay);
qDebug()<<"\t" <<i <<" Channel Configured ";
}
qDebug()<<" all Channels Configured ";
}
void NewDebug::on_pb_read_Automatic_clicked()
{
//if(timer_autoManualClick->isActive()) {
if(autoMode_isEnable) {
//timer_autoManualClick->stop();
ui->pb_read_Automatic->setStyleSheet("background-color:red;");
*(localFPGAaddr+0x06) = 0x00;
*(localFPGAaddr+0x07) = 0x00;
autoMode_isEnable = false;
}
else {
*(localFPGAaddr+0x06) = 0x01;
*(localFPGAaddr+0x07) = 0x00;
*(localFPGAaddr+0x07) = 0x01;
*(localFPGAaddr+0x07) = 0x00;
autoMode_isEnable = true;
//timer_autoManualClick->start();
ui->pb_read_Automatic->setStyleSheet("background-color:lime;");
}
}