Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

[r3533]: branches / Gxsm-2x3-transition-sig / plug-ins / hard / MK3-A810_spmcontrol / dataprocess.c Maximize Restore History

Download this file

dataprocess.c    718 lines (585 with data), 27.6 kB

  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
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
/* SRanger and Gxsm - Gnome X Scanning Microscopy Project
* universal STM/AFM/SARLS/SPALEED/... controlling and
* data analysis software
*
* DSP tools for Linux
*
* Copyright (C) 1999,2000,2001,2002 Percy Zahl
*
* Authors: Percy Zahl <zahl@users.sf.net>
* WWW Home:
* DSP part: http://sranger.sf.net
* Gxsm part: http://gxsm.sf.net
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*/
/* 20040820 CVS fix2 */
/* -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 8 c-style: "K&R" -*- */
/*
*
* dataprocess.c
*
* This is the ISR of the DMA. This ISR is called at each new sample.
*/
#include "g_intrinsics.h"
#include "FB_spm_dataexchange.h"
#include "dataprocess.h"
#include "PAC_pll.h"
/* local used variables for automatic offset compensation */
int IdleTimeTmp;
long tmpsum;
// RMS buffer
#define RMS_N2 8
#define RMS_N (1 << RMS_N2)
int rms_pipi = 0; /* Pipe index */
int rms_I_pipe[RMS_N] =
{
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0
};
DSP_INT32 rms_I2_pipe[RMS_N] =
{
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0
};
// 8x digital sigma-delta over sampling using bit0 of 16 -> gain of 2 bits resoultion (16+2=18)
#define SIGMA_DELTA_LEN 8
int sigma_delta_index = 0;
int max_out_ch = 8; // it's down to 7 when PLL is active -- else PLL output signal is overwritten
DSP_INT32 s_xymult = 0;
// DSP_INT32 zpos_xymult = 0;
DSP_INT32 d_tmp=0;
DSP_INT32 tmp_hrbits = 0;
//#define SIGMA_DELTA_HR_MASK_FAST
#ifdef SIGMA_DELTA_HR_MASK_FAST // Fast HR Matrix -- good idea, but performance/distorsion issues with the A810 due to the high dynamic demands
int sigma_delta_hr_mask[SIGMA_DELTA_LEN * SIGMA_DELTA_LEN] = {
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0, 0, 0,
0, 0, 0, 1, 0, 0, 0, 1,
0, 0, 1, 0, 0, 1, 0, 1,
0, 1, 0, 1, 0, 1, 0, 1,
0, 1, 1, 0, 1, 1, 0, 1,
1, 0, 1, 1, 1, 0, 1, 1,
1, 1, 1, 1, 0, 1, 1, 1
};
#else // Slow HR Matrix -- actually better analog performance
int sigma_delta_hr_mask[SIGMA_DELTA_LEN * SIGMA_DELTA_LEN] = {
0, 0, 0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0, 0, 0,
1, 1, 0, 0, 0, 0, 0, 0,
1, 1, 1, 0, 0, 0, 0, 0,
1, 1, 1, 1, 0, 0, 0, 0,
1, 1, 1, 1, 1, 0, 0, 0,
1, 1, 1, 1, 1, 1, 0, 0,
1, 1, 1, 1, 1, 1, 1, 0
};
#endif
// for(hrb=0; hrb<8; ++hrb) {for(i=0; i<8; ++i) printf ("%d, ", hrb>i?1:0 ); printf("\n");
#define HR_OUT(CH, VALUE32) tmp_hrbits = _SSHL32 (VALUE32, -13) & 7; AIC_OUT(CH) = _SADD16 (_SSHL32 (VALUE32, -16), sigma_delta_hr_mask[(tmp_hrbits<<3) + sigma_delta_index])
#define DC_OUT(CH, VALUE32) AIC_OUT(CH) = _SSHL32 (VALUE32, -16)
int sdt=0;
int sdt_16=0;
DSP_UINT16 QEP_cnt_old[2];
DSP_UINT32 SUM_QEP_cnt_Diff[2];
int gate_cnt = 0;
int gate_cnt_multiplier = 0;
int gate_cnt_1 = 0;
int feedback_hold = 0; /* Probe controlled Feedback-Hold flag */
int pipi = 0; /* Pipe index */
int scnt = 0; /* Slow summing count */
/* IIR tmp */
DSP_INT32 Q30 = 1073741823L;
DSP_INT32 Q15L = 32767L;
DSP_INT32 Q15 = 32767;
DSP_INT32 AbsIn = 0;
/* RANDOM GEN */
DSP_INT32 randomnum = 1L;
/* externals of SPM control */
extern SPM_STATEMACHINE state;
extern SERVO z_servo;
extern SERVO m_servo;
extern FEEDBACK_MIXER feedback_mixer;
extern ANALOG_VALUES analog;
extern MOVE_OFFSET move;
extern AREA_SCAN scan;
extern AUTOAPPROACH autoapp;
extern PROBE probe;
extern CR_OUT_PULSE CR_out_pulse;
extern CR_GENERIC_IO CR_generic_io;
extern SIGNAL_MONITOR sig_mon;
extern int AS_ch2nd_constheight_enabled; /* const H mode flg of areascan process */
extern struct aicregdef aicreg;
extern DSP_INT32 PRB_ACPhaseA32;
DSP_INT32 xy_vec[4];
DSP_INT32 mm_vec[4];
DSP_INT32 result_vec[4];
#define BIAS_ADJUST_STEP (4*(1<<16))
#define Z_ADJUST_STEP (0x200)
/* Auxillary Random Number Generator */
#define RNG_a 16807 /* multiplier */
#define RNG_m 2147483647L /* 2**31 - 1 */
#define RNG_q 127773L /* m div a */
#define RNG_r 2836 /* m mod a */
#define USE_MUL32C
#ifdef USE_MUL32C
// multiplication of 2x 32bit Q31 elements
// The overhead is now 38 cycles and you can use this formula to compute the total number of cycle:
// 38+nx*1.5 cycles. The code size if now 26 instructions instead of 20 for the version I sent to you this morning.
unsigned int mul32(int *restrict x, int *restrict y, int *restrict r, unsigned short nx)
{
int i;
_nassert((int) nx % 2 == 0);
_nassert((int) nx >= 2);
for (i=0; i<nx; i += 2)
{
r[i] =(int)(((long long)(x[i]) * (long long)(y[i])) >> 31);
r[i+1] =(int)(((long long)(x[i+1]) * (long long)(y[i+1])) >> 31);
}
return 0;
}
#if 0
// The overhead of the function (when linked in L1PRAM) is 42 cpu cycles and you have to compute 2 CPU cycles by nx if x, y and r are in L1DRAM.
// So, it is 42+nx*2 cycles.
unsigned int mul32(int *restrict x, int *restrict y, int *restrict r, unsigned short nx){
int i;
for (i=0; i<nx; i++)
r[i] =(int)(((long long)(x[i]) * (long long)(y[i])) >> 31);
return 0;
}
#endif
#else
# include "mul32.h"
#endif
#pragma CODE_SECTION(generate_nextlongrand, ".text:slow")
void generate_nextlongrand (){
DSP_INT32 lo, hi;
lo = _SMPY32 (RNG_a, randomnum & 0xFFFF);
hi = _SMPY32 (RNG_a, (DSP_UINT32)randomnum >> 16);
lo += (hi & 0x7FFF) << 16;
if (lo > RNG_m){
lo &= RNG_m;
++lo;
}
lo += hi >> 15;
if (lo > RNG_m){
lo &= RNG_m;
++lo;
}
randomnum = (DSP_INT32)lo;
}
/* #define AIC_OUT(N) iobuf.mout[N] */
/* smoothly adjust bias - make sure |analog_bias| < 32766-BIAS_ADJUST_STEP !! */
inline void run_bias_adjust (){
if (analog.bias - BIAS_ADJUST_STEP > analog.bias_adjust){
analog.bias_adjust += BIAS_ADJUST_STEP;
}else{
if (analog.bias + BIAS_ADJUST_STEP < analog.bias_adjust)
analog.bias_adjust -= BIAS_ADJUST_STEP;
else
analog.bias_adjust = analog.bias;
}
}
/* smoothly brings Zpos back to zero in case VP left it non zero at finish */
inline void run_Zpos_adjust (){
if (probe.Zpos > Z_ADJUST_STEP)
probe.Zpos -= Z_ADJUST_STEP;
else
if (probe.Zpos < -Z_ADJUST_STEP)
probe.Zpos += Z_ADJUST_STEP;
else
probe.Zpos = 0;
}
/* generic servo controller, run one time step */
/*
* --------------------------------------------------------------------------------
;; compute Proportional-Integral-Feedback signal, SATuration A:
;; delta = ist-soll
;; i_pl_sum += CI*delta
;; z = CP*delta + i_pl_sum
* --------------------------------------------------------------------------------
*/
inline void run_servo_timestep (SERVO *servo){
long long tmp;
servo->i_sum = _SAT32 ((long)servo->i_sum + (long)( ((long long)servo->delta * (long long)servo->ci) >> (15+23)) );
tmp = (long)((long)servo->i_sum + (((long long)servo->delta * (long long) servo->cp) >> (15+23)));
// make both output polarities available
servo->control = _SAT32 (tmp);
servo->neg_control = _SAT32 (-tmp);
servo->watch = 1;
}
/* generic analog out mixer used for most channels */
inline void compute_analog_out (int ch, OUT_MIXER *out){
// sub or smac B operation
if (out->smac_b_fac_q15_p != NULL){
d_tmp = *(out->p);
d_tmp = _SMAC (d_tmp, *(out->sub_b_p),*(out->smac_b_fac_q15_p));
} else {
d_tmp = _SSUB32 (*(out->p), *(out->sub_b_p));
}
// add or smac A operation
if (out->smac_a_fac_q15_p != NULL){
d_tmp = _SMAC (d_tmp, *(out->add_a_p),*(out->smac_a_fac_q15_p));
} else {
d_tmp = _SADD32 (d_tmp, *(out->add_a_p));
}
// HR output
HR_OUT (ch, d_tmp);
}
/* simple out mixer for coarse mode wave output to channel mixing */
inline void compute_analog_wave_out (int ch, OUT_MIXER *out){
AIC_OUT(ch) = _SADD16 (*(out->add_a_p), *(out->p));
}
/* This is ISR is called on each new sample. The "mode"/statevariable
* should be initialized with AIC_OFFSET_COMPENSATION before starting
* the AIC/DMA isr, this assures the correct offset initialization and
* runs the automatic offset compensation on startup.
*/
void dataprocess()
{
/* FEEDBACK */
long long FB_mixer_delta = 0; // 40bit
int i;
/* Update Idle Time */
TSCReadSecond ();
state.IdleTime = MeasuredTime;
TSCReadFirst ();
// ============================================================
// PROCESS MODULE: DSP PROCESSING CLOCK TICKS -- looping
// ============================================================
++state.DSP_time; // 150kHz ticks
// ============================================================
// PROCESS MODULE: PAC (Phase Amplitude Controller)
// and PLL (Phase Locked Loop)
// ============================================================
#ifdef USE_PLL_API
if (state.mode & MD_PLL){
max_out_ch = 7;
DataprocessPLL();
} else {
max_out_ch = 8; // it's down to 7 when PLL is active -- else PLL output signal is overwritten
if (blcklen != -1){
Signal1[blcklen] = pSignal1[0];
Signal2[blcklen] = pSignal2[0];
blcklen--;
}
}
#endif
// ============================================================
// PROCESS MODULE: NOISE GENERATOR (RANDOM NUMBER)
// ============================================================
// update noise source
generate_nextlongrand ();
analog.noise = randomnum;
// ============================================================
// PROCESS MODULE: ANALOG_IN
// ============================================================
// copy AD inputs -- scale to 15.16
for (i=0; i<8; ++i){
analog.in[i] = AIC_IN(i) << 16;
}
// any differentials?
for (i=0; i<4; ++i){
analog.in[i] = _SSUB32 (analog.in[i], *analog.diff_in_p[i]);
}
// =============================================================
// PROCESS MODULE: MIXER INPUT PROCESSING, IIR, adaptive on MIX0
// =============================================================
// map data channels and run real time 4-channel IIR filter
for (i=0; i<4; ++i){ // assign data / Q23 transfromations for ADCs
if (feedback_mixer.FB_IN_is_analog_flg[i]){
FB_mixer_delta = (*(feedback_mixer.input_p[i])) >> 16; // FB_mixer_delta reused as tmp variable -- make 16bit input (original analog in level)
feedback_mixer.q_factor15 = feedback_mixer.iir_ca_q15[i]; // get q
if (i==0){ // special adaptive IIR for MIX0 only
if (feedback_mixer.I_cross > 0){
AbsIn = abs (FB_mixer_delta);
feedback_mixer.q_factor15 = _SSUB32 (Q15L, _SMAC (feedback_mixer.cb_Ic, AbsIn, Q15) / _SADD16 (AbsIn, feedback_mixer.I_cross));
if (feedback_mixer.q_factor15 < feedback_mixer.iir_ca_q15[0])
feedback_mixer.q_factor15 = feedback_mixer.iir_ca_q15[0];
}
}
// compute IIR
feedback_mixer.iir_signal[i] = _SMAC ( _SMPY32 ( _SSUB16 (Q15, feedback_mixer.q_factor15), FB_mixer_delta), feedback_mixer.q_factor15, _SSHL32 (feedback_mixer.iir_signal[i], -16));
feedback_mixer.FB_IN_processed[i] = feedback_mixer.iir_signal[i] >> 8; // Q23.8 for MIXER
} else
feedback_mixer.FB_IN_processed[i] = *(feedback_mixer.input_p[i]); // about Q23.8 range -- assume equiv ~~~ AIC_IN(i) << 8;
if (feedback_mixer.mode[i] & 0x10) // negate feedback source?
feedback_mixer.FB_IN_processed[i] *= -1;
}
// ============================================================
// PROCESS MODULE: RMS -- average and rms computations via FIR
// ============================================================
// Average and RMS computations
d_tmp = *analog.avg_input >> 16; // 32bit (QS15.16 input) -- scale to fit sum
analog.avg_signal = _SADD32 (analog.avg_signal, d_tmp);
analog.avg_signal = _SSUB32 (analog.avg_signal, rms_I_pipe[rms_pipi]);
rms_I_pipe[rms_pipi] = d_tmp;
tmpsum = _SSUB32 (d_tmp, _SSHL32 (analog.avg_signal, -RMS_N2));
// now tricky -- taking chances of mult OVR if RMS is too big, designed for read small noise with offset eliminated.
tmpsum = _SMPY32 (tmpsum, tmpsum);
analog.rms_signal = _SADD32 (analog.rms_signal, tmpsum);
analog.rms_signal = _SSUB32 (analog.rms_signal, rms_I2_pipe[rms_pipi]);
rms_I2_pipe[rms_pipi] = tmpsum;
if (++rms_pipi == RMS_N)
rms_pipi = 0;
// RMS, AVG results normalizsation on host level!
if (sigma_delta_index & 1){
// ============================================================
// PROCESS MODULE: COUNTER
// QEP, GATE TIME CONTROL, COUNTER expansion
// ============================================================
#ifdef USE_ANALOG_16 // if special build for MK2-Analog_16
analog.counter[0] = 0; // Counter/Timer support not yet available via FPGA
analog.counter[1] = 0; // Counter/Timer support not yet available via FPGA
#else // default: MK2-A810
/* Automatic Aligned Gateing by scan or probe process */
// SUM_QEP_cnt_Diff[0]=SUM_QEP_cnt_Diff[0]+(int)(QEP_cnt[0]-QEP_cnt_old[0]);
analog.counter[0]=analog.counter[0] + (unsigned short)(QEP_cnt[0]-QEP_cnt_old[0]);
QEP_cnt_old[0]=QEP_cnt[0];
// SUM_QEP_cnt_Diff[1]=SUM_QEP_cnt_Diff[1]+(int)(QEP_cnt[1]-QEP_cnt_old[1]);
analog.counter[1]=analog.counter[1] + (unsigned short)(QEP_cnt[1]-QEP_cnt_old[1]);
QEP_cnt_old[1]=QEP_cnt[1];
/* always handle Counter_1 -- 16it gatetime only (fast only, < 800ms @ 75 kHz) */
if (++gate_cnt_1 >= CR_generic_io.gatetime_1){
gate_cnt_1 = 0;
CR_generic_io.count_1 = analog.counter[1];
analog.counter[1] = 0;
if (CR_generic_io.count_1 > CR_generic_io.peak_count_1)
CR_generic_io.peak_count_1 = CR_generic_io.count_1;
}
if (!(scan.pflg || probe.pflg) && CR_generic_io.pflg) {
/* stand alone Rate Meter Mode else gating managed via spm_areascan or _probe module */
/* handle Counter_0 -- 32it gatetime (very wide range) */
if (gate_cnt_multiplier >= CR_generic_io.gatetime_h_0){
if (++gate_cnt >= CR_generic_io.gatetime_l_0){
gate_cnt = 0;
gate_cnt_multiplier = 0;
CR_generic_io.count_0 = analog.counter[0];
analog.counter[0] = 0;
if (CR_generic_io.count_0 > CR_generic_io.peak_count_0)
CR_generic_io.peak_count_0 = CR_generic_io.count_0;
}
} else { // this makes up a 32bit counter...
if (++gate_cnt == 0)
++gate_cnt_multiplier;
}
}
#endif
// ============================================================
// PROCESS MODULE: OFFSET MOVE
// ============================================================
/* Offset Move task ? */
if (move.pflg)
run_offset_move ();
// ============================================================
// PROCESS MODULE: AREA SCAN
// ============================================================
/* Area Scan task - normal mode ?
* the feedback task needs to be enabled to see the effect
* --> can set CI/CP to small values to "contineously" disable it!
*/
if (scan.pflg == (AREA_SCAN_RUN | AREA_SCAN_START_NORMAL))
if (!scan.raster_b || !probe.pflg) // pause scan in raster_b is set and probe is going.
run_area_scan ();
// reset FB watch -- see below
z_servo.watch = 0; // for actual watch fb activity
} else {
// ============================================================
// PROCESS MODULE: VECTOR PROBE (VP)
// or if idle VP BIAS and Z-Adjusters to follow controls
// ============================================================
/* Vector Probe task ? (Bias may be changed here) */
feedback_hold = 0;
if (probe.pflg){
run_probe ();
if (probe.vector)
if (probe.vector->options & VP_FEEDBACK_HOLD)
feedback_hold = 1;
} else {
/* (re) Adjust Bias, Zpos ? */
if (analog.bias_adjust != analog.bias)
run_bias_adjust ();
if (probe.Zpos != 0)
run_Zpos_adjust ();
probe.Upos = analog.bias_adjust; // probe.Upos is default master for BIAS at all times, foolowing user control or VP comand
}
}
// ============================================================
// PROCESS MODULE: FULL BW: LockIn task
// ============================================================
if (probe.state >= PROBE_RUN_LOCKIN_PROBE)
run_lockin ();
// ============================================================
// PROCESS MODULE: FAST SCAN
// ============================================================
/* run FAST AREA SCAN (sinusodial) ? */
if (scan.pflg == (AREA_SCAN_RUN | AREA_SCAN_START_FASTSCAN))
run_area_scan_fast ();
// ============================================================
// PROCESS MODULES:
// MIXER DATA TRANSFORMATIONS and DELTA COMPUTATIONS
// DELTA ACCUMULATION
// ============================================================
/* FeedBack (FB) task ? (evaluates several conditions and runs in various modes) */
/** FB_IN_processed[0..3] ==> 4-CHANNEL MIXER MODULE ==> MIXER.delta **/
/** FOLLOWED BY Z-SERVO -- normally main Z feedback **/
if (!feedback_hold && sigma_delta_index & 1){ /* may be freezed by probing process */
/* Let's check out, if the feedback loop is really running. */
feedback_hold = 1;
/* run main Z-servo (feedback) control loop? */
if (state.mode & MD_PID){
if ( !(AS_ch2nd_constheight_enabled && scan.pflg)){ // skip in 2nd const height mode!
feedback_hold = 0;
// Feedback Mixer -- data transform and delta computation, summing
FB_mixer_delta = 0L; // Q23 x 16 (long long) -- can grow to 40+2bits total!
for (i=0; i<4; ++i){
// process MIXER CHANNEL i
switch (feedback_mixer.mode[i]&0x0f){
case 3: // LOG
// log result is Q23 (1 and 2^23-1) from Q23 input:
feedback_mixer.lnx = calc_mix_log (feedback_mixer.FB_IN_processed[i], feedback_mixer.I_offset);
FB_mixer_delta += (long long)(feedback_mixer.lnx - feedback_mixer.setpoint_log[i]) * (long long)feedback_mixer.gain[i];
break;
case 1: // LIN
FB_mixer_delta += (long long)(feedback_mixer.FB_IN_processed[i] - feedback_mixer.setpoint[i]) * (long long)feedback_mixer.gain[i];
break;
case 9: // FUZZY
if (feedback_mixer.FB_IN_processed[i] > feedback_mixer.level[i])
FB_mixer_delta += (long long)(feedback_mixer.FB_IN_processed[i] - feedback_mixer.level[i] - feedback_mixer.setpoint[i]) * (long long)feedback_mixer.gain[i];
break;
case 11: // FUZZY LOG
if (feedback_mixer.FB_IN_processed[i] > feedback_mixer.level[i]){
feedback_mixer.lnx = calc_mix_log (feedback_mixer.FB_IN_processed[i] - feedback_mixer.level[i], 0);
FB_mixer_delta += (long long)(feedback_mixer.lnx - feedback_mixer.setpoint[i]) * (long long)feedback_mixer.gain[i];
}
break;
default: break; // OFF
}
}
feedback_mixer.delta = _SAT32 (FB_mixer_delta>>8); // Q23, SAT
// **SIGNAL** :: default link is *z_servo.input == feedback_mixer.delta
// ============================================================
// PROCESS MODULE: MAIN Z SERVO
// ============================================================
z_servo.delta = _SAT32 ((long)*z_servo.input); // Q23 input and setpoint, SAT difference
run_servo_timestep (&z_servo);
}
}
}
// NOW OUTPUT HR SIGNALS ON XYZ-Offset and XYZ-Scan -- do not touch Bias OUT(6) and Motor OUT(7) here -- handled directly previously.
// note: OUT(0-5) get overridden below by coarse/mover actions if requeste!!!
/* HR sigma-delta data processing (if enabled) -- turn off via adjusting sigma_delta_hr_mask to all 0 */
// do scan coordinate rotation transformation:
if ( !(state.mode & MD_XYSROT))
{
xy_vec[2] = xy_vec[0] = scan.xyz_vec[i_X];
xy_vec[3] = xy_vec[1] = scan.xyz_vec[i_Y];
mul32 (xy_vec, scan.rotm, result_vec, 4);
scan.xy_r_vec[i_X] = _SADD32 (result_vec[0], result_vec[1]);
scan.xy_r_vec[i_Y] = _SADD32 (result_vec[2], result_vec[3]);
} else {
scan.xy_r_vec[i_X] = scan.xyz_vec[i_X];
scan.xy_r_vec[i_Y] = scan.xyz_vec[i_Y];
}
// XY-Offset and XY-Scan output -- calculates Scan XY output and added offset as configured
// default: HR_OUT[3,4] = scan.xy_r_vec + move.xyz_vec
//** done below in one shot loop **
//** compute_analog_out (3, &analog.out[3]);
//** compute_analog_out (4, &analog.out[4]);
// PROCESS MODULE: SLOPE-COMPENSATION
// ==================================================
// Z-Offset -- slope compensation output
//---- slope add X*mx + Y*my
// limit dz add from xy-mult to say 10x scan.fm_dz0x+y, feedback like adjust if "diff" to far off from sudden slope change
// zpos_xymult = move.ZPos + scan.XposR * scan.fm_dz0x + scan.YposR * scan.fm_dz0y ;
// make sure a smooth adjust -- if slope parameters get changed, need to prevent a jump.
mul32 (scan.xy_r_vec, scan.fm_dz0_xy_vec, result_vec, 2);
s_xymult = _SADD32 (result_vec[i_X], result_vec[i_Y]);
d_tmp = _SSUB32 (s_xymult, scan.z_offset_xyslope);
if (d_tmp > scan.z_slope_max) // limit up
scan.z_offset_xyslope = _SADD32 (scan.z_offset_xyslope, scan.z_slope_max);
else if (d_tmp < -scan.z_slope_max) // limit dn
scan.z_offset_xyslope = _SADD32 (scan.z_offset_xyslope, -scan.z_slope_max);
else scan.z_offset_xyslope = s_xymult; // normally this should do it
// PROCESS MODULE: ANALOG OUTPUT MIXER
// ==================================================
// simply process all output channels now in same manner
// ** max_out_ch is 8 for all, must be 7 to not override PAC/PLL output set to CH7 fixed if PLL processing is on.
for (i=0; i<max_out_ch; ++i)
compute_analog_out (i, &analog.out[i]);
//** --- here is what the default means in expanded form: ---
// DEFAULT: Z-Offset output with XY-Scan-slope compensation added *** state.mode & MD_XY_ZSLOPE obsolete
//** compute_analog_out (2, &analog.out[2]);
// DEFAULT: Z SERVO (FEEDBACK) OUT -- calculate Z-Scan output:
// **SIGNAL** :: default link is *analog.out_p[5] == z_servo.neg_control SUB: -probe.Zpos ADD: +NULL
//** compute_analog_out (5, &analog.out[5]);
// DEFAULT: BIAS_ADJUST OUT -- calculate Bias output:
// **SIGNAL** :: default link is *analog.out_p[6] == probe.Upos SUB: -NULL ADD: +NULL
// ** probe and lockin mod/ref is hooking in here!
//** compute_analog_out (6, &analog.out[6]);
// DEFAULT: MOTOR OUT -- calculate Motor output:
// **SIGNAL** :: default link is *analog.out_p[7] == analog.motor SUB: -NULL ADD: +NULL
//** compute_analog_out (7, &analog.out[7]);
// ========== END OUTPUT ANALOG DATA [except coase mover signal overrides later] ==========
sigma_delta_index = (++sigma_delta_index) & 7;
// ========== END HR processing ================
// PROCESS MODULE: COARSE --- WAVE and PULSE out OVERRIDES if active!!
// ======================================================================
/* Run Autoapproch/Movercontrol task ? */
if (autoapp.pflg){
if (autoapp.pflg==2)
autoapp.pflg = 0;
else
run_autoapp ();
if (autoapp.mover_mode & (AAP_MOVER_XYOFFSET | AAP_MOVER_XYSCAN | AAP_MOVER_XXOFFSET | AAP_MOVER_XYMOTOR | AAP_MOVER_ZSCANADD)){
// wave output computation
compute_analog_wave_out (autoapp.wave_out_channel[0], &analog.out[8]);
compute_analog_wave_out (autoapp.wave_out_channel[1], &analog.out[9]);
}
} else
/* Run CoolRunner Out puls(es) task ? */
if (CR_out_pulse.pflg)
run_CR_out_pulse ();
// ============================================================
// PROCESS MODULE: MOTOR SERVO
// ============================================================
m_servo.delta = _SAT32 ((long)m_servo.setpoint - (long)*m_servo.input); // Q23 input and setpoint, SAT difference
run_servo_timestep (&m_servo);
// ============================================================
// PROCESS MODULE: SIGNAL MONITOR data copy processing
// ============================================================
for (i=0; i<NUM_MONITOR_SIGNALS; ++i)
sig_mon.signal[i] = *sig_mon.signal_p[i];
// ************************************************************
// END OF DATA PROCESSING TASKS -- final time keeping
// ************************************************************
/* increment DSP blink statemaschine's counter and time reference */
++state.BLK_count;
/* -- end of all data processing, preformance statistics update now -- */
//-**** asm_read_time ();
/* Update Dataprocess Time */
TSCReadSecond();
state.DataProcessTime = MeasuredTime;
TSCReadFirst();
/* Load Peak Detection */
if (abs(state.DataProcessTime) > abs(state.DataProcessTime_Peak)){
state.DataProcessTime_Peak = state.DataProcessTime;
state.IdleTime_Peak = state.IdleTime;
}
}
/* END */