-
Notifications
You must be signed in to change notification settings - Fork 1
/
adc.tbs
3413 lines (2727 loc) · 88.5 KB
/
adc.tbs
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
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
include "global.tbh"
#define SCL_PIN 0
#define SDA_PIN 1
#define LOAD_PIN 2
#define BUSY_PIN 3
#define RST_PIN 2
#define MCLR_PIN 2
#define INT_PIN 3
'====================================================
' #13
const ADC_CODE_W = &h10
const ADC_CODE_R = &h11
const ADC_CH0 = &h88
const ADC_CH2 = &h98
const ADC_CH4 = &hA8
const ADC_CH6 = &hB8
#define SSI_NUM_13 0
#define SSI_BAUDRATE_13 3
'====================================================
' #14
const DAC_CODE_W = &hC0
#define SSI_NUM_14 0
#define SSI_BAUDRATE_14 1
'====================================================
' #17
const PIC_CHIP_ADDR_R = &h07
const PIC_CHIP_ADDR_W = &h06
const PIC_CMD_R = &h01
const PIC_CMD_W = &h02
const PIC_PORTA = &h000C
const PIC_PORTC = &h000E
const PIC_PIE1 = &h0091
const PIC_OSCCON = &h0099
const PIC_APFCON0 = &h011D
const PIC_APFCON1 = &h011E
const PIC_ANSELA = &h018C
const PIC_ANSELC = &h018E
const PIC_TRISA = &h008C
const PIC_TRISC = &h008E
const PIC_LATA = &h010C
const PIC_LATC = &h010E
const PIC_ADCON0 = &h009D
const PIC_ADCON1 = &h009E
const PIC_ADRESH = &h009C
const PIC_ADRESL = &h009B
const PIC_FVRCON = &h0117
const PIC_CCP1CON = &h0293
const PIC_CCP2CON = &h029A
const PIC_CCP3CON = &h0313
const PIC_CCPR1L = &h0291
const PIC_CCPR2L = &h0298
const PIC_CCPR3L = &h0311
const PIC_CCPTMRS0 = &h029E
const PIC_PR2 = &h001B
const PIC_PR4 = &h0416
const PIC_PR6 = &h041D
const PIC_T2CON = &h001C
const PIC_T4CON = &h0417
const PIC_T6CON = &h041E
const PIC_TXREG = &h019A
const PIC_SPBRGL = &h019B
const PIC_SPBRGH = &h019C
const PIC_RCSTA = &h019D
const PIC_TXSTA = &h019E
const PIC_BAUDCON = &h019F
#define INTERNAL_OSCILLATOR_FREQ_1MHZ_HF 10
#define INTERNAL_OSCILLATOR_FREQ_2MHZ_HF 11
#define INTERNAL_OSCILLATOR_FREQ_4MHZ_HF 12
#define INTERNAL_OSCILLATOR_FREQ_8MHZ_HF 13
#define INTERNAL_OSCILLATOR_FREQ_16MHZ_HF 14
#define INTERNAL_OSCILLATOR_FREQ_32MHZ_HF 15
#ifndef TBT_CLK_SOURCE
#define TBT_CLK_SOURCE INTERNAL_OSCILLATOR_FREQ_1MHZ_HF
#endif
enum pic_pwm_enum
PIC_PWM0,
PIC_PWM1,
PIC_PWM2
end enum
const TBT16_FW ="GRA V00"
#define SSI_NUM_17 2
#define SSI_BAUDRATE_17 105
'====================================================
' #52
const TBT52_FW = "V1.31 2016/12/15"
dim analog_52_bit_error_compensation(2, 4) as real
#define SSI_NUM_52 3
#define SSI_BAUDRATE_52 150
'====================================================
' #22
'TBT_RTD Co-processor Address
const TBT22_RTD_CODE_W = &h1A
const TBT22_RTD_CODE_R = &h1B
'TBT22 Co-processor Command
const TBT22_RTD_CMD_READ = &h1
const TBT22_RTD_CMD_WRITE = &h2
const TBT22_RTD_CMD_FW_VER = &h3
' RTD data, RTD current, and measurement reference voltage.
' RTD coefficient C is required only for temperatures below 0 deg. C.
' The ITS-90 standard is used; other RTDs may have
' coefficients defined by the DIN 43760 or the U.S. Industrial (American) standard.
#define RTD_A_ITS90 3.9080e-3
#define RTD_A_USINDUSTRIAL 3.9692e-3
#define RTD_A_DIN43760 3.9848e-3
#define RTD_B_ITS90 -5.870e-7
#define RTD_B_USINDUSTRIAL -5.8495e-7
#define RTD_B_DIN43760 -5.8019e-7
enum rtd_standart
ITS90 = 0,
USINDUSTRIAL,
DIN43760
end enum
'TBT22 RTD register address
enum tbt22_rtd_reg_write_addr
W_REG_ADDR_CONFIGURATION = &h80,
W_REG_ADDR_HIGH_FAULT_THRESHOLD_MSB = &h83,
W_REG_ADDR_HIGH_FAULT_THRESHOLD_LSB = &h84,
W_REG_ADDR_LOW_FAULT_THRESHOLD_MSB = &h85,
W_REG_ADDR_LOW_FAULT_THRESHOLD_LSB = &h86
end enum
' The Fault Status register latches any detected fault bits.
#define RTD_FAULT_HIGH_THRESHOLD &h80 'RTD High Threshold
#define RTD_FAULT_LOW_THRESHOLD &h40 'RTD Low Threshold
#define RTD_FAULT_REFIN &h20 'REFIN- > 0.85*Vbias
#define RTD_FAULT_REFIN_FORCE &h10 'REFIN- < 0.85*Vbias
#define RTD_FAULT_RTDIN_FORCE &h08 'RTDIN- < 0.85*Vbias
#define RTD_FAULT_VOLTAGE &h04 'Over/Undervoltage
#define RTD_CONFIG_CHECK &h01
enum rtd_conv_mode
tbt22_conversion_with_50_hz_mode = 0,
tbt22_conversion_with_60_hz_mode
end enum
enum rtd_sensor_type
PT100 = 0,
PT200,
PT500,
PT1000
end enum
dim analog_22_normal_0_resistance(NUM_OF_SLOTS) as real
dim analog_22_rtd_sensor_type(NUM_OF_SLOTS) as rtd_sensor_type
dim analog_22_conv_mode(NUM_OF_SLOTS) as rtd_conv_mode
dim analog_22_standart(NUM_OF_SLOTS) as rtd_standart
const TBT22_FW = "V1.02 2017/07/10"
#define SSI_NUM_22 3
#define SSI_BAUDRATE_22 150
'====================================================
' #40x
const TBT40_INIT_SIGNATURE = &h1002
const TBT40_STAMP = "TBT40> "
const TBT40_CR_LF = chr(13) + chr(10)
const TBT40_WRITE_ADDR = &h5E
const TBT40_READ_ADDR = &h5F
enum tbt40_regs
TBT40_VOLATILE_WIPER_0 = &h0, 'write ,read, increment,decrement
TBT40_NON_VOLATILE_WIPER_0 = &h20, 'write ,read, increment,decrement
TBT40_VOLATILE_TCON = &h40,
TBT40_STATUS = &h50
end enum
#define SSI_NUM_40 1
#define SSI_BAUDRATE_40 1
'====================================================
' #53
const TBT53_WRITE_ADDR = &h90
const TBT53_READ_ADDR = &h91
#define SSI_NUM_53 3
#define SSI_BAUDRATE_53 20
'====================================================
' #43
#define TBT43_CMD_CTX chr(&h02)
#define TBT43_CMD_END chr(&h0d)
#define TBT43_ANSWER_OK "A"
#define TBT43_ANSWER_ERROR "ERROR"
#define TBT43_CMD_SET_COMMANDMODE "C"
#define TBT43_CMD_SET_DATAMODE "D"
#define TBT43_CMD_READ_DATA "R"
#define TBT43_CMD_GET_VERSION "V"
#define TBT43_CMD_SET_VOLTAGE "SV"
#define TBT43_CMD_SET_SAMPLERATE "SR"
#define TBT43_CMD_SET_SAMPLEMODE "SM"
#define TBT43_CMD_SET_ENABLECHANNELS "SC"
#define TBT43_CMD_SET_DATAFORMAT "SD"
#define TBT43_CMD_SET_A "SA"
#define TBT43_CMD_SET_B "SB"
#define TBT43_CMD_RESET_TOFACTORY "SF"
#define TBT43_CMD_STORE_SETTINGS "SE"
#define TBT43_CMD_RESTORE_SETTINGS "FE"
#define TBT43_CMD_READ_SETTINGSEEPROM "RE"
#define TBT43_CMD_READ_SETTINGSRAM "RC"
enum TIBBIT43_TYPE
NONE,
EASY_FW,
FULL_FW
end enum
enum TIBBIT43_VOLTAGE
VOLTAGE_M60_P60,
VOLTAGE_M30_P30,
VOLTAGE_M15_P15,
VOLTAGE_0_P60,
VOLTAGE_AUTO,
VOLTAGE_NOT_SUPPORTED
end enum
enum TIBBIT43_SAMPLING_MODE
SAMPLING_SINGLE,
SAMPLING_DIFF
end enum
enum TIBBIT43_DATA_FORMAT
DATA_ASCII,
DATA_BIN,
DATA_HEX
end enum
type TIBBIT43_SETTINGS
SampleRate as integer
Voltage as TIBBIT43_VOLTAGE
SampleMode as TIBBIT43_SAMPLING_MODE
DataFormat as TIBBIT43_DATA_FORMAT
EnableChannels as string
A(4) as byte
B(4) as char
end type
type TIBBIT43_VALUES
value(4) as string(10)
end type
dim tibbit43(4) as TIBBIT43_TYPE
'=================================================================
' CProbes
'=================================================================
' CP#01 #29 Temp
#define SSI_NUM_29 1
#define SSI_BAUDRATE_29 28
const TBT29_MFG_ID = &h54
const TBT29_DEVID = &h400
enum tbt29_resolution
'TBT29_RESOLUSION_MODE_0 = &h00 '0.5C (tCONV = 30 ms typical)
TBT29_RESOLUSION_MODE_1 = &h01 '0.25C (tCONV = 65 ms typical)
'TBT29_RESOLUSION_MODE_2 = &h02 '0.125C (tCONV = 130 ms typical)
'TBT29_RESOLUSION_MODE_3 = &h03 '0.0625C (power-up default, tCONV = 250 ms typical)
end enum
const TBT29_WRITE_ADDR = &h30
const TBT29_READ_ADDR = &h31
enum tbt29_regs
' TBT29_REG_CONF = &h01,
' TBT29_REG_TUP = &h02,
' TBT29_REG_TLO = &h03,
' TBT29_REG_TCRIT = &h04,
TBT29_REG_TA = &h05,
TBT29_REG_MFGID = &h06,
TBT29_REG_IDREV = &h07,
TBT29_REG_RESOL = &h08
end enum
'=================================================================
' CP#02 #30 Temp&Hum
#define SSI_NUM_30 1
#define SSI_BAUDRATE_30 28
const TBT30_WRITE_ADDR = &h4E
const TBT30_READ_ADDR = &h4F
enum tbt30_status
TBT30_STATUS_NORMAL_OPERATION = &h0,
TBT30_STAUTS_STALE_DATA = &h1,
TBT30_STAUTS_IN_COMMAND_MODE = &h2,
TBT30_STAUTS_NOT_USED = &h3
end enum
'=================================================================
' CP#03 #28 Light
#define SSI_NUM_28 1
#define SSI_BAUDRATE_28 28
const TBT28_WRITE_ADDR = &h46 ' address code for write
const TBT28_READ_ADDR = &h47 ' address code for read
const TBT28_CMD_POWER_DOWN = &h00
const TBT28_CMD_POWER_ON = &h01
const TBT28_CMD_AUTO_RESOL_0 = &h10
const TBT28_CMD_HRESOL_0 = &h12
const TBT28_CMD_LRESOL_0 = &h13
'=================================================================
' #35 Pressure
#define SSI_NUM_35 1
#define SSI_BAUDRATE_35 28
const TBT35_WRITE_ADDR = &hC0 ' Manufacturer address code for write
const TBT35_READ_ADDR = &hC1 ' Manufacturer address code for read
const TBT35_CMD_READ_PRESSURE = &h00
const TBT35_CMD_READ_COEFFICIENT = &h04
const TBT35_CMD_START_CONVERSION = &h12
dim a0, b1, b2, c12 as float=0
'====================================================
' GLOBAL VALUES
dim analog_period as byte
dim analog_period_counter as byte
dim analog_ssi_last_use_slot(4) as byte
dim analog_float_values(MAX_ANALOG_LINES) as real
dim analog_values(MAX_ANALOG_LINES) as word
dim analog_last_values(MAX_ANALOG_LINES) as word
dim analog_pwm_pulse(MAX_ANALOG_LINES) as word
dim analog_pwm_period(MAX_ANALOG_LINES) as word
dim analog_pwm_prescaler(MAX_ANALOG_LINES) as pic_prescaler_enum
dim analog_pwm_enable(MAX_ANALOG_LINES) as boolean
dim analog_pic_ccp_rec(MAX_ANALOG_LINES) as byte
dim analog_pwm_change(MAX_ANALOG_LINES) as boolean
declare sub analog_ssi_init()
declare function analog_13_read_channel(slot as byte, channel as byte) as integer
declare sub analog_14_set_channel(slot as byte, channel as byte, value as integer)
declare sub analog_i2c_init(slot as byte)
declare sub analog_i2c_get(slot as byte, ssi_num as byte, ssi_baudrate as byte)
declare sub analog_i2c_start(slot as byte)
declare sub analog_i2c_stop(slot as byte)
declare sub analog_i2c_write(data as byte)
declare function analog_i2c_read(acknak_request as boolean) as byte
declare sub analog_delay_msecond(value as word)
declare sub analog_52_init(slot as byte)
declare sub analog_52_param_read(slot as byte)
declare function analog_52_read_channel(slot as byte, channel as byte, byref int_data as integer) as real
declare sub analog_22_init(slot as byte)
declare function analog_22_read(slot as byte, byref data as real, byref int_data as integer, byref fault_detect as byte, byref fault_status as byte) as ok_ng
declare sub analog_22_rtd_read_all(slot as byte, byref config as byte, byref rtd as word, byref hi_fault as word, byref lo_fault as word, byref fault as byte)
declare function analog_22_rtd_config(slot as byte, mode as rtd_conv_mode, byref status as byte, sensor as rtd_sensor_type) as ok_ng
declare sub analog_22_rtd_reg_write(slot as byte, addr as tbt22_rtd_reg_write_addr, data as byte)
declare sub analog_40_reg_write(slot as byte, addr as tbt40_regs, data as word)
declare function analog_40_reg_read(slot as byte, addr as tbt40_regs)as word
declare sub analog_40_init(slot as byte)
declare sub analog_40_set(slot as byte, value as real)
declare function analog_pic_init(slot as byte) as boolean
declare sub analog_17_set_channel(slot as byte, channel as byte)
declare sub analog_pic_config(slot as byte)
declare sub analog_pic_pwm_config(slot as byte, channel as byte, pulse_width as word, period as word, prescaler as pic_prescaler_enum)
declare sub analog_53_init(slot as byte)
declare function analog_53_read(slot as byte, byref int_data as integer) as real
declare sub analog_agg_send(slot as byte, pin as byte)
declare sub analog_pic_pwm_start(slot as byte, channel as byte)
declare sub analog_pic_pwm_stop(slot as byte, channel as byte)
declare sub analog_29_init(slot as byte)
declare function analog_29_read(slot as byte, byref data as word) as real
declare sub analog_28_init(slot as byte)
declare function analog_28_read(slot as byte) as word
declare sub analog_30_init(slot as byte)
declare function analog_30_read(slot as byte, byref humword as word, byref humidity as float, byref tempword as word, byref temperature as float) as ok_ng
declare sub analog_35_init(slot as byte)
declare function analog_35_read(slot as byte, byref pressureFloat as float)as word
declare sub analog_43_init(slot as byte)
declare function analog_43_read_data(slot as byte, channels as string(7), byref values as TIBBIT43_VALUES) as boolean
'====================================================
sub analog_setup()
dim slot, line as byte
' Read settings parameters
analog_period = val(stg_get("AP", 0))
analog_period_counter = 0
' RTD types
for slot = 0 to NUM_STD_SLOTS - 1
analog_22_rtd_sensor_type(slot) = val(stg_get("RT", slot))
analog_22_conv_mode(slot) = val(stg_get("RM", slot))
analog_22_standart(slot) = val(stg_get("RS", slot))
next slot
for line = 0 to MAX_ANALOG_LINES - 1
analog_float_values(line) = 0
analog_values(line) = 1023
analog_last_values(line) = 65535
analog_pwm_pulse(line) = 0
analog_pwm_period(line) = 0
analog_pwm_prescaler(line) = PIC_PRE_64
analog_pwm_enable(line) = false
analog_pic_ccp_rec(line) = 0
analog_pwm_change(line) = false
next line
for line = 0 to 3
analog_ssi_last_use_slot(line) = 255
next line
analog_ssi_init()
'Analog controls
for slot = 0 to NUM_OF_SLOTS - 1
select case param_st(slot)
case SLOT_IOD_2: ' CProbes maybe
if slot < NUM_I2C_SLOTS then
if io_cprobes(slot) <> IO_CPROBE_DISABLE then
select case io_cprobes(slot) ' CProbe mode
case IO_CPROBE_TEMP:
analog_i2c_init(slot)
analog_29_init(slot)
case IO_CPROBE_TEMPHUM:
analog_i2c_init(slot)
analog_30_init(slot)
case IO_CPROBE_LIGHT:
analog_i2c_init(slot)
analog_28_init(slot)
case IO_CPROBE_PRESSURE:
analog_i2c_init(slot)
analog_35_init(slot)
end select
end if
end if
case SLOT_IA_4: ' #13
analog_i2c_init(slot)
case SLOT_IA_RTD: ' #22
analog_i2c_init(slot)
analog_22_init(slot)
case SLOT_IA_52: ' #52
analog_i2c_init(slot)
analog_52_init(slot)
case SLOT_IA_53: ' #53
analog_i2c_init(slot)
analog_53_init(slot)
case SLOT_OA_4: ' #14
analog_i2c_init(slot)
'set DAC control pin
io.num = io_get_num(slot, LOAD_PIN)
io.enabled = YES
io.lineset(io_get_num(slot, LOAD_PIN), HIGH)
'set RDY-BSY monitor pin
io.num = io_get_num(slot, BUSY_PIN)
io.enabled = NO
for line = 0 to 3
if param_io(slot * 4 + line).io_enabled = YES then
analog_values(slot * 4 + line) = val(stg_get("AV", slot * 4 + line)) ' Set Analog pin initial state
analog_14_set_channel(slot, line, analog_values(slot * 4 + line))
end if
next line
case SLOT_OA_3: ' #16, #17
analog_i2c_init(slot)
if analog_pic_init(slot) = false then
param_st(slot) = SLOT_EMPTY
end if
case SLOT_DP: ' #40x
analog_i2c_init(slot)
analog_40_init(slot)
if param_io(slot * 4).io_enabled = YES then
analog_values(slot * 4) = val(stg_get("AV", slot * 4)) ' Set Analog pin initial state
analog_40_set(slot, analog_values(slot * 4))
end if
case SLOT_IA_4_32:
analog_43_init(slot)
end select
next slot
end sub
sub analog_loop()
dim slot as byte
for slot = 0 to NUM_OF_SLOTS - 1
select case param_st(slot)
case SLOT_IOD_2: ' CProbes maybe
if slot < NUM_I2C_SLOTS then
if io_cprobes(slot) <> IO_CPROBE_DISABLE then
select case io_cprobes(slot) ' CProbe mode
case IO_CPROBE_TEMP:
analog_float_values(slot * 4 + 0) = analog_29_read(slot, analog_values(slot * 4 + 0))
snmp_trap_check_analog(slot * 4 + 1, true)
analog_agg_send(slot, 0)
#if DEV_DEBUG_PRINT
dev_debugprint("#29 slot: " + str(slot) + ", value:" + ftostr(analog_float_values(slot * 4 + 0), FTOSTR_MODE_AUTO, 5))
#endif
case IO_CPROBE_TEMPHUM:
analog_30_read(slot, analog_values(slot * 4 + 1), analog_float_values(slot * 4 + 1), analog_values(slot * 4 + 0), analog_float_values(slot * 4 + 0))
snmp_trap_check_analog(slot * 4 + 0, true)
snmp_trap_check_analog(slot * 4 + 1, true)
analog_agg_send(slot, 0)
analog_agg_send(slot, 1)
#if DEV_DEBUG_PRINT
dev_debugprint("#30 slot: " + str(slot) + ", value temp:" + ftostr(analog_float_values(slot * 4 + 0), FTOSTR_MODE_AUTO, 5))
dev_debugprint("#30 slot: " + str(slot) + ", value hum:" + ftostr(analog_float_values(slot * 4 + 1), FTOSTR_MODE_AUTO, 5))
#endif
case IO_CPROBE_LIGHT:
analog_values(slot * 4 + 0) = analog_28_read(slot)
analog_float_values(slot * 4 + 0) = analog_values(slot * 4 + 0)
snmp_trap_check_analog(slot * 4 + 0, false)
analog_agg_send(slot, 0)
#if DEV_DEBUG_PRINT
dev_debugprint("#28 slot: " + str(slot) + ", value:" + ftostr(analog_float_values(slot * 4 + 0), FTOSTR_MODE_AUTO, 5))
#endif
case IO_CPROBE_PRESSURE:
analog_values(slot * 4 + 0) = analog_35_read(slot, analog_float_values(slot * 4 + 0))
snmp_trap_check_analog(slot * 4 + 0, true)
analog_agg_send(slot, 0)
#if DEV_DEBUG_PRINT
dev_debugprint("#35 slot: " + str(slot) + ", value:" + ftostr(analog_float_values(slot * 4 + 0), FTOSTR_MODE_AUTO, 5))
#endif
end select
end if
end if
case SLOT_IA_4: ' #13
if param_io(slot * 4 + 0).io_enabled = YES then
analog_values(slot * 4 + 0) = analog_13_read_channel(slot, 0)
analog_float_values(slot * 4 + 0) = analog_values(slot * 4 + 0)
snmp_trap_check_analog(slot * 4 + 0, false)
analog_agg_send(slot, 0)
#if DEV_DEBUG_PRINT
dev_debugprint("#13 slot: " + str(slot) + ", value (ch 1):" + ftostr(analog_float_values(slot * 4 + 0), FTOSTR_MODE_AUTO, 5))
#endif
end if
if param_io(slot * 4 + 1).io_enabled = YES then
analog_values(slot * 4 + 1) = analog_13_read_channel(slot, 1)
analog_float_values(slot * 4 + 1) = analog_values(slot * 4 + 1)
snmp_trap_check_analog(slot * 4 + 1, false)
analog_agg_send(slot, 1)
#if DEV_DEBUG_PRINT
dev_debugprint("#13 slot: " + str(slot) + ", value (ch 2):" + ftostr(analog_float_values(slot * 4 + 1), FTOSTR_MODE_AUTO, 5))
#endif
end if
if param_io(slot * 4 + 2).io_enabled = YES then
analog_values(slot * 4 + 2) = analog_13_read_channel(slot, 2)
analog_float_values(slot * 4 + 2) = analog_values(slot * 4 + 2)
snmp_trap_check_analog(slot * 4 + 2, false)
analog_agg_send(slot, 2)
#if DEV_DEBUG_PRINT
dev_debugprint("#13 slot: " + str(slot) + ", value (ch 3):" + ftostr(analog_float_values(slot * 4 + 2), FTOSTR_MODE_AUTO, 5))
#endif
end if
if param_io(slot * 4 + 3).io_enabled = YES then
analog_values(slot * 4 + 3) = analog_13_read_channel(slot, 3)
analog_float_values(slot * 4 + 3) = analog_values(slot * 4 + 3)
snmp_trap_check_analog(slot * 4 + 3, false)
analog_agg_send(slot, 3)
#if DEV_DEBUG_PRINT
dev_debugprint("#13 slot: " + str(slot) + ", value (ch 4):" + ftostr(analog_float_values(slot * 4 + 3), FTOSTR_MODE_AUTO, 5))
#endif
end if
case SLOT_IA_RTD:
dim fault_detect, fault_status as byte
if param_io(slot * 4 + 0).io_enabled = YES then
analog_22_read(slot, analog_float_values(slot * 4 + 0), analog_values(slot * 4 + 0), fault_detect, fault_status)
snmp_trap_check_analog(slot * 4 + 0, true)
analog_agg_send(slot, 0)
#if DEV_DEBUG_PRINT
dev_debugprint("#22 slot: " + str(slot) + ", Temp value :" + ftostr(analog_float_values(slot * 4 + 0), FTOSTR_MODE_AUTO, 5))
#endif
end if
case SLOT_IA_52:
if param_io(slot * 4 + 0).io_enabled = YES then
analog_float_values(slot * 4 + 0) = analog_52_read_channel(slot, 0, analog_values(slot * 4 + 0))
snmp_trap_check_analog(slot * 4 + 0, true)
analog_agg_send(slot, 0)
#if DEV_DEBUG_PRINT
dev_debugprint("#52 slot: " + str(slot) + ", value (ch 1):" + ftostr(analog_float_values(slot * 4 + 0), FTOSTR_MODE_AUTO, 5))
#endif
end if
if param_io(slot * 4 + 1).io_enabled = YES then
analog_float_values(slot * 4 + 1) = analog_52_read_channel(slot, 1, analog_values(slot * 4 + 1))
snmp_trap_check_analog(slot * 4 + 1, true)
analog_agg_send(slot, 1)
#if DEV_DEBUG_PRINT
dev_debugprint("#52 slot: " + str(slot) + ", value (ch 2):" + ftostr(analog_float_values(slot * 4 + 1), FTOSTR_MODE_AUTO, 5))
#endif
end if
if param_io(slot * 4 + 2).io_enabled = YES then
analog_float_values(slot * 4 + 2) = analog_52_read_channel(slot, 2, analog_values(slot * 4 + 2))
snmp_trap_check_analog(slot * 4 + 2, true)
analog_agg_send(slot, 2)
#if DEV_DEBUG_PRINT
dev_debugprint("#52 slot: " + str(slot) + ", value (ch 3):" + ftostr(analog_float_values(slot * 4 + 2), FTOSTR_MODE_AUTO, 5))
#endif
end if
if param_io(slot * 4 + 3).io_enabled = YES then
analog_float_values(slot * 4 + 3) = analog_52_read_channel(slot, 3, analog_values(slot * 4 + 3))
snmp_trap_check_analog(slot * 4 + 3, true)
analog_agg_send(slot, 3)
#if DEV_DEBUG_PRINT
dev_debugprint("#52 slot: " + str(slot) + ", value (ch 4):" + ftostr(analog_float_values(slot * 4 + 3), FTOSTR_MODE_AUTO, 5))
#endif
end if
case SLOT_IA_53:
if param_io(slot * 4 + 0).io_enabled = YES then
analog_float_values(slot * 4 + 0) = analog_53_read(slot, analog_values(slot * 4 + 0))
snmp_trap_check_analog(slot * 4 + 0, true)
analog_agg_send(slot, 0)
#if DEV_DEBUG_PRINT
dev_debugprint("#53 slot: " + str(slot) + ", value:" + ftostr(analog_float_values(slot * 4 + 0), FTOSTR_MODE_AUTO, 5))
#endif
end if
case SLOT_OA_4: ' #14
if param_io(slot * 4 + 0).io_enabled = YES then
if analog_values(slot * 4 + 0) <> analog_last_values(slot * 4 + 0) then
analog_14_set_channel(slot, 0, analog_values(slot * 4 + 0))
analog_last_values(slot * 4 + 0) = analog_values(slot * 4 + 0)
end if
end if
if param_io(slot * 4 + 1).io_enabled = YES then
if analog_values(slot * 4 + 1) <> analog_last_values(slot * 4 + 1) then
analog_14_set_channel(slot, 1, analog_values(slot * 4 + 1))
analog_last_values(slot * 4 + 1) = analog_values(slot * 4 + 1)
end if
end if
if param_io(slot * 4 + 2).io_enabled = YES then
if analog_values(slot * 4 + 2) <> analog_last_values(slot * 4 + 2) then
analog_14_set_channel(slot, 2, analog_values(slot * 4 + 2))
analog_last_values(slot * 4 + 2) = analog_values(slot * 4 + 2)
end if
end if
if param_io(slot * 4 + 3).io_enabled = YES then
if analog_values(slot * 4 + 3) <> analog_last_values(slot * 4 + 3) then
analog_14_set_channel(slot, 3, analog_values(slot * 4 + 3))
analog_last_values(slot * 4 + 3) = analog_values(slot * 4 + 3)
end if
end if
case SLOT_OA_3: ' #16, #17
if param_io(slot * 4 + 0).io_enabled = YES then
if analog_pwm_change(slot * 4 + 0) = true then
analog_17_set_channel(slot, 0)
analog_pwm_change(slot * 4 + 0) = false
end if
end if
if param_io(slot * 4 + 1).io_enabled = YES then
if analog_pwm_change(slot * 4 + 1) = true then
analog_17_set_channel(slot, 1)
analog_pwm_change(slot * 4 + 1) = false
end if
end if
if param_io(slot * 4 + 2).io_enabled = YES then
if analog_pwm_change(slot * 4 + 2) = true then
analog_17_set_channel(slot, 2)
analog_pwm_change(slot * 4 + 2) = false
end if
end if
case SLOT_DP: ' #40x
if param_io(slot * 4 + 0).io_enabled = YES then
if analog_values(slot * 4 + 0) <> analog_last_values(slot * 4 + 0) then
analog_40_set(slot, analog_values(slot * 4 + 0))
analog_last_values(slot * 4 + 0) = analog_values(slot * 4 + 0)
end if
end if
case SLOT_IA_4_32:
dim _channels as string(7)
dim _values32 as TIBBIT43_VALUES
_channels = ""
if param_io(slot * 4 + 0).io_enabled = YES then
_channels = "1"
end if
if param_io(slot * 4 + 1).io_enabled = YES then
if _channels <> "" then
_channels = _channels + ",2"
else
_channels = "2"
end if
end if
if param_io(slot * 4 + 2).io_enabled = YES then
if _channels <> "" then
_channels = _channels + ",3"
else
_channels = "3"
end if
end if
if param_io(slot * 4 + 4).io_enabled = YES then
if _channels <> "" then
_channels = _channels + ",4"
else
_channels = "4"
end if
end if
if analog_43_read_data(slot, _channels, _values32) then
if param_io(slot * 4 + 0).io_enabled = YES then
analog_values(slot * 4 + 0) = 0
analog_float_values(slot * 4 + 0) = strtof(_values32.value(0))
analog_agg_send(slot, 0)
#if DEV_DEBUG_PRINT
dev_debugprint("#32 slot: " + str(slot) + ", value (ch 1):" + _values32.value(0))
#endif
end if
if param_io(slot * 4 + 1).io_enabled = YES then
analog_values(slot * 4 + 1) = 0
analog_float_values(slot * 4 + 1) = strtof(_values32.value(1))
analog_agg_send(slot, 1)
#if DEV_DEBUG_PRINT
dev_debugprint("#32 slot: " + str(slot) + ", value (ch 2):" + _values32.value(1))
#endif
end if
if param_io(slot * 4 + 2).io_enabled = YES then
analog_values(slot * 4 + 2) = 0
analog_float_values(slot * 4 + 2) = strtof(_values32.value(2))
analog_agg_send(slot, 2)
#if DEV_DEBUG_PRINT
dev_debugprint("#32 slot: " + str(slot) + ", value (ch 3):" + _values32.value(2))
#endif
end if
if param_io(slot * 4 + 3).io_enabled = YES then
analog_values(slot * 4 + 3) = 0
analog_float_values(slot * 4 + 3) = strtof(_values32.value(3))
analog_agg_send(slot, 3)
#if DEV_DEBUG_PRINT
dev_debugprint("#32 slot: " + str(slot) + ", value (ch 4):" + _values32.value(3))
#endif
end if
end if
end select
next slot
end sub
sub analog_agg_send(slot as byte, pin as byte)
if login_mode = CMD_MODE_AGGREGATE and param_aggEvents.agg_eventAnalog = true then
dim sTemp as string(32)
dim sEvent as string
sEvent = ""
agg_record_encode(sEvent, str(slot * 4 + pin + 1)) ' Num channel
agg_record_encode(sEvent, ftostr(analog_float_values(slot * 4 + pin), FTOSTR_MODE_AUTO, 5)) ' Analog value
agg_fire_instant_event("", "ai", sEvent, 2)
end if
end sub
function analog_set(channel as word, value as word, pwm_select as boolean) as boolean
dim slot as byte
dim pin as byte
dim io_state_new as boolean
slot = io_get_slot(channel)
analog_set = true
if slot <> 255 then
if param_io(channel).io_enabled = YES then
select case param_st(slot)
case SLOT_OA_4: ' #14
if analog_values(channel) <> value then
analog_values(channel) = value
analog_14_set_channel(slot, io_get_pin(channel), analog_values(channel))
analog_last_values(channel) = analog_values(channel)
end if
case SLOT_OA_3: ' #16, #17
if pwm_select = true then ' Set Period PWM
if analog_pwm_period(channel) <> value then
analog_pwm_period(channel) = value
analog_17_set_channel(slot, io_get_pin(channel))
end if
else ' Set Pulse PWM
if analog_pwm_pulse(channel) <> value then
analog_pwm_pulse(channel) = value
analog_17_set_channel(slot, io_get_pin(channel))
end if
end if
case SLOT_DP:
if io_get_pin(channel) = 0 then
if analog_values(channel) <> value then
analog_values(channel) = value
analog_40_set(slot, analog_values(channel))
analog_last_values(channel) = analog_values(channel)
end if
else
analog_set = false
end if
case SLOT_8BIT:
if param_io(channel).io_enabled = 1 then ' OUTPUT
' TBT41_ADDR_GPIO
io_tbt41_set_data(slot, value)
analog_values(channel) = value
end if
case else:
analog_set = false
end select
else
analog_set = false
end if
else
analog_set = false
end if
end function
function analog_13_read_channel(slot as byte, channel as byte) as integer
dim ch as byte
dim byte_hi, byte_lo as byte
select case channel
case 0:
ch = ADC_CH0
case 1:
ch = ADC_CH2
case 2:
ch = ADC_CH4
case 3:
ch = ADC_CH6
end select
analog_i2c_get(slot, SSI_NUM_13, SSI_BAUDRATE_13)
analog_i2c_start(slot)
analog_i2c_write(ADC_CODE_W)
analog_i2c_write(ch)
analog_i2c_stop(slot)
analog_i2c_start(slot)
analog_i2c_write(ADC_CODE_R)
byte_hi = analog_i2c_read(true)
byte_lo = analog_i2c_read(true)
analog_i2c_stop(slot)
analog_13_read_channel = byte_lo / 16 + byte_hi * 16
end function
sub analog_14_set_channel(slot as byte, channel as byte, value as integer)
'Programs a 12-bit value into one DAC channel.
'The range is from 0 (-10V) to 4095 (+10V).
dim ch,valueHi,valueLow as byte
dim resetCounter as byte = 0
dim resetFlag as boolean
do
resetFlag = false
analog_i2c_get(slot, SSI_NUM_14, SSI_BAUDRATE_14)
io.num = io_get_num(slot, BUSY_PIN)
sys.timercountms = 0
while io.state = LOW
if sys.timercountms > 100 then
' need Tibbit reset
resetFlag = true
resetCounter = resetCounter + 1
'reset Tibbit #14
analog_i2c_init(slot)
'set DAC control pin
io.num = io_get_num(slot, LOAD_PIN)
io.enabled = YES
io.lineset(io_get_num(slot, LOAD_PIN), HIGH)
'set RDY-BSY monitor pin
io.num = io_get_num(slot, BUSY_PIN)
io.enabled = NO
end if
wend
if resetFlag = false then
'The Fast Write command is used to update the input DAC register
'The EEPROM data is not affected by this command.
ch = &h40 + (channel mod 4) * 2
'To fill the DAC Input Register of Selected Channel
valueHi = &h90 + value / 256
valueLow = value and &h00FF
io.lineset(io_get_num(slot, LOAD_PIN), LOW)
analog_i2c_start(slot)
analog_i2c_write(DAC_CODE_W)
analog_i2c_write(ch)
analog_i2c_write(valueHi)
analog_i2c_write(valueLow)
analog_i2c_stop(slot)
io.lineset(io_get_num(slot, LOAD_PIN), HIGH)
io.num = io_get_num(slot, BUSY_PIN)
sys.timercountms = 0
while io.state = LOW
if sys.timercountms > 100 then
' need Tibbit reset
resetFlag = true
resetCounter = resetCounter + 1
'reset Tibbit #14
analog_i2c_init(slot)
'set DAC control pin
io.num = io_get_num(slot, LOAD_PIN)
io.enabled = YES
io.lineset(io_get_num(slot, LOAD_PIN), HIGH)
'set RDY-BSY monitor pin
io.num = io_get_num(slot, BUSY_PIN)