-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadc_internal.c
1776 lines (1395 loc) · 50.4 KB
/
adc_internal.c
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 <stdbool.h>
#include <stdint.h>
#include <math.h>
#include "inc/hw_memmap.h"
#include "driverlib/adc.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.h"
#include "adc_internal.h"
/////////////////////////////////////////////////////////////////////////////////////////////
static int Adc_Value = 0;
/////////////////////////////////////////////////////////////////////////////////////////////
adc_t VoltageCh1;
adc_t VoltageCh2;
adc_t VoltageCh3;
adc_t VoltageCh4;
adc_t CurrentCh1;
adc_t CurrentCh2;
adc_t CurrentCh3;
adc_t CurrentCh4;
adc_t LvCurrentCh1;
adc_t LvCurrentCh2;
adc_t LvCurrentCh3;
adc_t DriverVolt;
adc_t Driver1Curr;
adc_t Driver2Curr;
/////////////////////////////////////////////////////////////////////////////////////////////
static uint32_t adc_0_value[7];
static uint32_t adc_1_value[7];
/////////////////////////////////////////////////////////////////////////////////////////////
void AdcsInit(void)
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOK);
// Enable ADC0 and ADC1
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC1);
while(!SysCtlPeripheralReady(SYSCTL_PERIPH_ADC0));
while(!SysCtlPeripheralReady(SYSCTL_PERIPH_ADC1));
// Config ADC as a external voltage reference
ADCReferenceSet(ADC0_BASE, ADC_REF_EXT_3V);
ADCReferenceSet(ADC1_BASE, ADC_REF_EXT_3V);
// Select the analog ADC function for these pins.
GPIOPinTypeADC(GPIO_PORTD_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 |
GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7);
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2);
GPIOPinTypeADC(GPIO_PORTK_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2);
// Enable sample sequence 0 (Max 8 samples) for ADC0 and
// enable sample sequence 1 (Max 4 samples) for ADC1
// Both with a processor trigger signal
ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_PROCESSOR, 0);
ADCSequenceConfigure(ADC1_BASE, 0, ADC_TRIGGER_PROCESSOR, 0);
// Configure steps on sequence 0 and 1. Here, we are using 7 channels
// for ADC0 and 4 channels for ADC1
ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_CH5); // VOLTAGE_1
ADCSequenceStepConfigure(ADC0_BASE, 0, 1, ADC_CTL_CH4); // VOLTAGE_2
ADCSequenceStepConfigure(ADC0_BASE, 0, 2, ADC_CTL_CH6); // VOLTAGE_3
ADCSequenceStepConfigure(ADC0_BASE, 0, 3, ADC_CTL_CH7); // VOLTAGE_4
ADCSequenceStepConfigure(ADC0_BASE, 0, 4, ADC_CTL_CH13); // LV_2X_SIGNAL1
ADCSequenceStepConfigure(ADC0_BASE, 0, 5, ADC_CTL_CH14); // LV_2X_SIGNAL2
ADCSequenceStepConfigure(ADC0_BASE, 0, 6, ADC_CTL_CH15 | ADC_CTL_IE |
ADC_CTL_END); // LV_2X_SIGNAL3
ADCSequenceStepConfigure(ADC1_BASE, 0, 0, ADC_CTL_CH3); // CURRENT_1
ADCSequenceStepConfigure(ADC1_BASE, 0, 1, ADC_CTL_CH2); // CURRENT_2
ADCSequenceStepConfigure(ADC1_BASE, 0, 2, ADC_CTL_CH1); // CURRENT_3
ADCSequenceStepConfigure(ADC1_BASE, 0, 3, ADC_CTL_CH12); // CURRENT_4
ADCSequenceStepConfigure(ADC1_BASE, 0, 4, ADC_CTL_CH16); // DRIVER_VOLT
ADCSequenceStepConfigure(ADC1_BASE, 0, 5, ADC_CTL_CH17); // DRIVER2_AMP
ADCSequenceStepConfigure(ADC1_BASE, 0, 6, ADC_CTL_CH18 | ADC_CTL_IE |
ADC_CTL_END); // DRIVER1_AMP
// Enable sample sequences.
ADCSequenceEnable(ADC0_BASE, 0);
ADCSequenceEnable(ADC1_BASE, 0);
// Clear the interrupt status flag. This is done to make sure the
// interrupt flag is cleared before we sample.
ADCIntClear(ADC0_BASE, 0);
ADCIntClear(ADC1_BASE, 0);
VoltageCh1.Enable = 0;
VoltageCh2.Enable = 0;
VoltageCh3.Enable = 0;
VoltageCh4.Enable = 0;
CurrentCh1.Enable = 0;
CurrentCh2.Enable = 0;
CurrentCh3.Enable = 0;
CurrentCh4.Enable = 0;
LvCurrentCh1.Enable = 0;
LvCurrentCh2.Enable = 0;
LvCurrentCh3.Enable = 0;
DriverVolt.Enable = 0;
Driver1Curr.Enable = 0;
Driver2Curr.Enable = 0;
}
/////////////////////////////////////////////////////////////////////////////////////////////
void sample_adc(void)
{
// Trigger the ADC0 conversion.
ADCProcessorTrigger(ADC0_BASE, 0);
// Wait for conversion to be completed.
while(!ADCIntStatus(ADC0_BASE, 0, false)){}
// Clear the ADC interrupt flag.
ADCIntClear(ADC0_BASE, 0);
// Read ADC Value.
ADCSequenceDataGet(ADC0_BASE, 0, adc_0_value);
// Trigger the ADC1 conversion.
ADCProcessorTrigger(ADC1_BASE, 0);
// Wait for conversion to be completed.
while(!ADCIntStatus(ADC1_BASE, 0, false)){}
// Clear the ADC interrupt flag.
ADCIntClear(ADC1_BASE, 0);
// Read ADC Value.
ADCSequenceDataGet(ADC1_BASE, 0, adc_1_value);
}
/////////////////////////////////////////////////////////////////////////////////////////////
void VoltageCh1Init(float nValue, unsigned int Delay)
{
VoltageCh1.Ch = 1;
VoltageCh1.Enable = 0;
VoltageCh1.Gain = (nValue/2048.0);
VoltageCh1.Value = 0.0;
VoltageCh1.Offset = 0x0800; //OffsetRead(OFFSET_VOLT_CH1);
VoltageCh1.AlarmLimit = 10; //VoltCh1AlarmLevelMemmoryRead();
VoltageCh1.TripLimit = 10; //VoltCh1TripLevelMemmoryRead();
VoltageCh1.Alarm = 0;
VoltageCh1.Trip = 0;
VoltageCh1.InvertPol = 0;
VoltageCh1.Alarm_Delay_ms = Delay;
VoltageCh1.Alarm_DelayCount = 0;
VoltageCh1.Itlk_Delay_ms = Delay;
VoltageCh1.Itlk_DelayCount = 0;
}
/////////////////////////////////////////////////////////////////////////////////////////////
void VoltageCh2Init(float nValue, unsigned int Delay)
{
VoltageCh2.Ch = 2;
VoltageCh2.Enable = 0;
VoltageCh2.Gain = (nValue/2048.0);
VoltageCh2.Value = 0.0;
VoltageCh2.Offset = 0x0800; //OffsetRead(OFFSET_VOLT_CH2);
VoltageCh2.AlarmLimit = 10; //VoltCh2AlarmLevelMemmoryRead();
VoltageCh2.TripLimit = 10; //VoltCh2TripLevelMemmoryRead();
VoltageCh2.Alarm = 0;
VoltageCh2.Trip = 0;
VoltageCh2.InvertPol = 0;
VoltageCh2.Alarm_Delay_ms = Delay;
VoltageCh2.Alarm_DelayCount = 0;
VoltageCh2.Itlk_Delay_ms = Delay;
VoltageCh2.Itlk_DelayCount = 0;
}
/////////////////////////////////////////////////////////////////////////////////////////////
void VoltageCh3Init(float nValue, unsigned int Delay)
{
VoltageCh3.Ch = 3;
VoltageCh3.Enable = 0;
VoltageCh3.Gain = (nValue/2048.0);
VoltageCh3.Value = 0.0;
VoltageCh3.Offset = 0x0800; //OffsetRead(OFFSET_VOLT_CH3);
VoltageCh3.AlarmLimit = 10; //VoltCh3AlarmLevelMemmoryRead();
VoltageCh3.TripLimit = 10; //VoltCh3TripLevelMemmoryRead();
VoltageCh3.Alarm = 0;
VoltageCh3.Trip = 0;
VoltageCh3.InvertPol = 0;
VoltageCh3.Alarm_Delay_ms = Delay;
VoltageCh3.Alarm_DelayCount = 0;
VoltageCh3.Itlk_Delay_ms = Delay;
VoltageCh3.Itlk_DelayCount = 0;
}
/////////////////////////////////////////////////////////////////////////////////////////////
void VoltageCh4Init(float nValue, unsigned int Delay)
{
VoltageCh4.Ch = 4;
VoltageCh4.Enable = 0;
VoltageCh4.Gain = (nValue/2048.0);
VoltageCh4.Value = 0.0;
VoltageCh4.Offset = 0x0800; //OffsetRead(OFFSET_VOLT_CH4);
VoltageCh4.AlarmLimit = 10; //VoltCh4AlarmLevelMemmoryRead();
VoltageCh4.TripLimit = 10; //VoltCh4TripLevelMemmoryRead();
VoltageCh4.Alarm = 0;
VoltageCh4.Trip = 0;
VoltageCh4.InvertPol = 0;
VoltageCh4.Alarm_Delay_ms = Delay;
VoltageCh4.Alarm_DelayCount = 0;
VoltageCh4.Itlk_Delay_ms = Delay;
VoltageCh4.Itlk_DelayCount = 0;
}
/////////////////////////////////////////////////////////////////////////////////////////////
float CurrentRange(float nFstCurr, float nSecCurr, float nBurden, float MaxVoltInput)
{
float Ix, Xv = 0.0;
Xv = nSecCurr*nBurden;
Ix = nFstCurr*MaxVoltInput;
Ix = Ix/Xv;
return Ix;
}
/////////////////////////////////////////////////////////////////////////////////////////////
void CurrentCh1Init(float nFstCurr, float nSecCurr, float nBurden, unsigned int delay_ms)
{
CurrentCh1.Ch = 1;
CurrentCh1.Enable = 0;
CurrentCh1.Gain = (CurrentRange(nFstCurr, nSecCurr, nBurden, 7.5)/2048.0);
CurrentCh1.Value = 0.0;
CurrentCh1.Offset = 0x0800; //OffsetRead(OFFSET_HALL_CH1);
CurrentCh1.AlarmLimit = 10.0; //CurrCh1AlarmLevelMemmoryRead();
CurrentCh1.TripLimit = 10.0; //CurrCh1TripLevelMemmoryRead();
CurrentCh1.Alarm = 0;
CurrentCh1.Trip = 0;
CurrentCh1.InvertPol = 0;
CurrentCh1.Alarm_Delay_ms = delay_ms;
CurrentCh1.Alarm_DelayCount = 0;
CurrentCh1.Itlk_Delay_ms = delay_ms;
CurrentCh1.Itlk_DelayCount = 0;
}
/////////////////////////////////////////////////////////////////////////////////////////////
void CurrentCh2Init(float nFstCurr, float nSecCurr, float nBurden, unsigned int delay_ms)
{
CurrentCh2.Ch = 2;
CurrentCh2.Enable = 0;
CurrentCh2.Gain = (CurrentRange(nFstCurr, nSecCurr, nBurden, 7.5)/2048.0);
CurrentCh2.Value = 0.0;
CurrentCh2.Offset = 0x0800; //OffsetRead(OFFSET_HALL_CH2);
CurrentCh2.AlarmLimit = 10.0; //CurrCh2AlarmLevelMemmoryRead();
CurrentCh2.TripLimit = 10.0; //CurrCh2TripLevelMemmoryRead();
CurrentCh2.Alarm = 0;
CurrentCh2.Trip = 0;
CurrentCh2.InvertPol = 0;
CurrentCh2.Alarm_Delay_ms = delay_ms;
CurrentCh2.Alarm_DelayCount = 0;
CurrentCh2.Itlk_Delay_ms = delay_ms;
CurrentCh2.Itlk_DelayCount = 0;
}
/////////////////////////////////////////////////////////////////////////////////////////////
void CurrentCh3Init(float nFstCurr, float nSecCurr, float nBurden, unsigned int delay_ms)
{
CurrentCh3.Ch = 3;
CurrentCh3.Enable = 0;
CurrentCh3.Gain = (CurrentRange(nFstCurr, nSecCurr, nBurden, 7.5)/2048.0);
CurrentCh3.Value = 0.0;
CurrentCh3.Offset = 0x0800; //OffsetRead(OFFSET_HALL_CH3);
CurrentCh3.AlarmLimit = 10.0; //CurrCh3AlarmLevelMemmoryRead();
CurrentCh3.TripLimit = 10.0; //CurrCh3TripLevelMemmoryRead();
CurrentCh3.Alarm = 0;
CurrentCh3.Trip = 0;
CurrentCh3.InvertPol = 0;
CurrentCh3.Alarm_Delay_ms = delay_ms;
CurrentCh3.Alarm_DelayCount = 0;
CurrentCh3.Itlk_Delay_ms = delay_ms;
CurrentCh3.Itlk_DelayCount = 0;
}
/////////////////////////////////////////////////////////////////////////////////////////////
void CurrentCh4Init(float nFstCurr, float nSecCurr, float nBurden, unsigned int delay_ms)
{
CurrentCh4.Ch = 4;
CurrentCh4.Enable = 0;
CurrentCh4.Gain = (CurrentRange(nFstCurr, nSecCurr, nBurden, 7.5)/2048.0);
CurrentCh4.Value = 0.0;
CurrentCh4.Offset = 0x0800; //OffsetRead(OFFSET_HALL_CH4);
CurrentCh4.AlarmLimit = 10.0; //CurrCh4AlarmLevelMemmoryRead();
CurrentCh4.TripLimit = 10.0; //CurrCh4TripLevelMemmoryRead();
CurrentCh4.Alarm = 0;
CurrentCh4.Trip = 0;
CurrentCh4.InvertPol = 0;
CurrentCh4.Alarm_Delay_ms = delay_ms;
CurrentCh4.Alarm_DelayCount = 0;
CurrentCh4.Itlk_Delay_ms = delay_ms;
CurrentCh4.Itlk_DelayCount = 0;
}
/////////////////////////////////////////////////////////////////////////////////////////////
void LvCurrentCh1Init(float nFstCurr, float nSecCurr, float nBurden, unsigned int delay_ms)
{
LvCurrentCh1.Ch = 1;
LvCurrentCh1.Enable = 0;
LvCurrentCh1.Gain = (CurrentRange(nFstCurr, nSecCurr, nBurden, 3.0)/2048.0);
LvCurrentCh1.Value = 0.0;
LvCurrentCh1.Offset = 0x0800; //OffsetRead(OFFSET_HALL_CH1);
LvCurrentCh1.AlarmLimit = 10.0; //LvCurrentCh1AlarmLevelMemmoryRead();
LvCurrentCh1.TripLimit = 10.0; //LvCurrentCh1TripLevelMemmoryRead();
LvCurrentCh1.Alarm = 0;
LvCurrentCh1.Trip = 0;
LvCurrentCh1.InvertPol = 0;
LvCurrentCh1.Alarm_Delay_ms = delay_ms;
LvCurrentCh1.Alarm_DelayCount = 0;
LvCurrentCh1.Itlk_Delay_ms = delay_ms;
LvCurrentCh1.Itlk_DelayCount = 0;
}
/////////////////////////////////////////////////////////////////////////////////////////////
void LvCurrentCh2Init(float nFstCurr, float nSecCurr, float nBurden, unsigned int delay_ms)
{
LvCurrentCh2.Ch = 2;
LvCurrentCh2.Enable = 0;
LvCurrentCh2.Gain = (CurrentRange(nFstCurr, nSecCurr, nBurden, 3.0)/2048.0);
LvCurrentCh2.Value = 0.0;
LvCurrentCh2.Offset = 0x0800; //OffsetRead(OFFSET_HALL_CH2);
LvCurrentCh2.AlarmLimit = 10.0; //LvCurrentCh2AlarmLevelMemmoryRead();
LvCurrentCh2.TripLimit = 10.0; //LvCurrentCh2TripLevelMemmoryRead();
LvCurrentCh2.Alarm = 0;
LvCurrentCh2.Trip = 0;
LvCurrentCh2.InvertPol = 0;
LvCurrentCh2.Alarm_Delay_ms = delay_ms;
LvCurrentCh2.Alarm_DelayCount = 0;
LvCurrentCh2.Itlk_Delay_ms = delay_ms;
LvCurrentCh2.Itlk_DelayCount = 0;
}
/////////////////////////////////////////////////////////////////////////////////////////////
void LvCurrentCh3Init(float nFstCurr, float nSecCurr, float nBurden, unsigned int delay_ms)
{
LvCurrentCh3.Ch = 3;
LvCurrentCh3.Enable = 0;
LvCurrentCh3.Gain = (CurrentRange(nFstCurr, nSecCurr, nBurden, 3.0)/2048.0);
LvCurrentCh3.Value = 0.0;
LvCurrentCh3.Offset = 0x0800; //OffsetRead(OFFSET_HALL_CH3);
LvCurrentCh3.AlarmLimit = 10.0; //LvCurrentCh3AlarmLevelMemmoryRead();
LvCurrentCh3.TripLimit = 10.0; //LvCurrentCh3TripLevelMemmoryRead();
LvCurrentCh3.Alarm = 0;
LvCurrentCh3.Trip = 0;
LvCurrentCh3.InvertPol = 0;
LvCurrentCh3.Alarm_Delay_ms = delay_ms;
LvCurrentCh3.Alarm_DelayCount = 0;
LvCurrentCh3.Itlk_Delay_ms = delay_ms;
LvCurrentCh3.Itlk_DelayCount = 0;
}
/////////////////////////////////////////////////////////////////////////////////////////////
void DriverVoltageInit(void)
{
DriverVolt.Ch = 1;
DriverVolt.Enable = 0;
DriverVolt.Gain = 0.00439453125; // 18V/4096
DriverVolt.Value = 0.0;
DriverVolt.Offset = 0x0000;
DriverVolt.AlarmLimit = 16.0;
DriverVolt.TripLimit = 17.0;
DriverVolt.Alarm = 0;
DriverVolt.Trip = 0;
DriverVolt.InvertPol = 0;
DriverVolt.Alarm_Delay_ms = 0;
DriverVolt.Alarm_DelayCount = 0;
DriverVolt.Itlk_Delay_ms = 0;
DriverVolt.Itlk_DelayCount = 0;
}
/////////////////////////////////////////////////////////////////////////////////////////////
void DriverCurrentInit(void)
{
Driver1Curr.Ch = 1;
Driver1Curr.Enable = 0;
Driver1Curr.Gain = 0.003662109375; // 7,5A/2048
Driver1Curr.Value = 0.0;
Driver1Curr.Offset = 0x0800; //OffsetRead(OFFSET_DRIVE_CURRENT1);
Driver1Curr.AlarmLimit = 2.0;
Driver1Curr.TripLimit = 2.0;
Driver1Curr.Alarm = 0;
Driver1Curr.Trip = 0;
Driver1Curr.InvertPol = 0;
Driver1Curr.Alarm_Delay_ms = 0;
Driver1Curr.Alarm_DelayCount = 0;
Driver1Curr.Itlk_Delay_ms = 0;
Driver1Curr.Itlk_DelayCount = 0;
Driver2Curr.Ch = 1;
Driver2Curr.Enable = 0;
Driver2Curr.Gain = 0.003662109375; // 7,5A/2048
Driver2Curr.Value = 0.0;
Driver2Curr.Offset = 0x0800; //OffsetRead(OFFSET_DRIVE_CURRENT2);
Driver2Curr.AlarmLimit = 2.0;
Driver2Curr.TripLimit = 2.0;
Driver2Curr.Alarm = 0;
Driver2Curr.Trip = 0;
Driver2Curr.InvertPol = 0;
Driver2Curr.Alarm_Delay_ms = 0;
Driver2Curr.Alarm_DelayCount = 0;
Driver2Curr.Itlk_Delay_ms = 0;
Driver2Curr.Itlk_DelayCount = 0;
}
/////////////////////////////////////////////////////////////////////////////////////////////
void VoltageCh1Sample(void)
{
Adc_Value = adc_0_value[0];
Adc_Value = Adc_Value - VoltageCh1.Offset;
VoltageCh1.Value = (float)Adc_Value * VoltageCh1.Gain;
if(VoltageCh1.InvertPol) VoltageCh1.Value = VoltageCh1.Value * -1.0;
if(VoltageCh1.Value > VoltageCh1.AlarmLimit || VoltageCh1.Value < -VoltageCh1.AlarmLimit)
{
if(VoltageCh1.Alarm_DelayCount < VoltageCh1.Alarm_Delay_ms) VoltageCh1.Alarm_DelayCount++;
else
{
VoltageCh1.Alarm_DelayCount = 0;
VoltageCh1.Alarm = 1;
}
}
else VoltageCh1.Alarm_DelayCount = 0;
if(VoltageCh1.Value > VoltageCh1.TripLimit || VoltageCh1.Value < -VoltageCh1.TripLimit)
{
if(VoltageCh1.Itlk_DelayCount < VoltageCh1.Itlk_Delay_ms) VoltageCh1.Itlk_DelayCount++;
else
{
VoltageCh1.Itlk_DelayCount = 0;
VoltageCh1.Trip = 1;
}
}
else VoltageCh1.Itlk_DelayCount = 0;
}
/////////////////////////////////////////////////////////////////////////////////////////////
void VoltageCh2Sample(void)
{
Adc_Value = adc_0_value[1];
Adc_Value = Adc_Value - VoltageCh2.Offset;
VoltageCh2.Value = (float)Adc_Value * VoltageCh2.Gain;
if(VoltageCh2.InvertPol) VoltageCh2.Value = VoltageCh2.Value * -1.0;
if(VoltageCh2.Value > VoltageCh2.AlarmLimit || VoltageCh2.Value < -VoltageCh2.AlarmLimit)
{
if(VoltageCh2.Alarm_DelayCount < VoltageCh2.Alarm_Delay_ms) VoltageCh2.Alarm_DelayCount++;
else
{
VoltageCh2.Alarm_DelayCount = 0;
VoltageCh2.Alarm = 1;
}
}
else VoltageCh2.Alarm_DelayCount = 0;
if(VoltageCh2.Value > VoltageCh2.TripLimit || VoltageCh2.Value < -VoltageCh2.TripLimit)
{
if(VoltageCh2.Itlk_DelayCount < VoltageCh2.Itlk_Delay_ms) VoltageCh2.Itlk_DelayCount++;
else
{
VoltageCh2.Itlk_DelayCount = 0;
VoltageCh2.Trip = 1;
}
}
else VoltageCh2.Itlk_DelayCount = 0;
}
/////////////////////////////////////////////////////////////////////////////////////////////
void VoltageCh3Sample(void)
{
Adc_Value = adc_0_value[2];
Adc_Value = Adc_Value - VoltageCh3.Offset;
VoltageCh3.Value = (float)Adc_Value * VoltageCh3.Gain;
if(VoltageCh3.InvertPol) VoltageCh3.Value = VoltageCh3.Value * -1.0;
if(VoltageCh3.Value > VoltageCh3.AlarmLimit || VoltageCh3.Value < -VoltageCh3.AlarmLimit)
{
if(VoltageCh3.Alarm_DelayCount < VoltageCh3.Alarm_Delay_ms) VoltageCh3.Alarm_DelayCount++;
else
{
VoltageCh3.Alarm_DelayCount = 0;
VoltageCh3.Alarm = 1;
}
}
else VoltageCh3.Alarm_DelayCount = 0;
if(VoltageCh3.Value > VoltageCh3.TripLimit || VoltageCh3.Value < -VoltageCh3.TripLimit)
{
if(VoltageCh3.Itlk_DelayCount < VoltageCh3.Itlk_Delay_ms) VoltageCh3.Itlk_DelayCount++;
else
{
VoltageCh3.Itlk_DelayCount = 0;
VoltageCh3.Trip = 1;
}
}
else VoltageCh3.Itlk_DelayCount = 0;
}
/////////////////////////////////////////////////////////////////////////////////////////////
void VoltageCh4Sample(void)
{
Adc_Value = adc_0_value[3];
Adc_Value = Adc_Value - VoltageCh4.Offset;
VoltageCh4.Value = (float)Adc_Value * VoltageCh4.Gain;
if(VoltageCh4.InvertPol) VoltageCh4.Value = VoltageCh4.Value * -1.0;
if(VoltageCh4.Value > VoltageCh4.AlarmLimit || VoltageCh4.Value < -VoltageCh4.AlarmLimit)
{
if(VoltageCh4.Alarm_DelayCount < VoltageCh4.Alarm_Delay_ms) VoltageCh4.Alarm_DelayCount++;
else
{
VoltageCh4.Alarm_DelayCount = 0;
VoltageCh4.Alarm = 1;
}
}
else VoltageCh4.Alarm_DelayCount = 0;
if(VoltageCh4.Value > VoltageCh4.TripLimit || VoltageCh4.Value < -VoltageCh4.TripLimit)
{
if(VoltageCh4.Itlk_DelayCount < VoltageCh4.Itlk_Delay_ms) VoltageCh4.Itlk_DelayCount++;
else
{
VoltageCh4.Itlk_DelayCount = 0;
VoltageCh4.Trip = 1;
}
}
else VoltageCh4.Itlk_DelayCount = 0;
}
/////////////////////////////////////////////////////////////////////////////////////////////
void CurrentCh1Sample(void)
{
Adc_Value = adc_1_value[0];
Adc_Value = Adc_Value - CurrentCh1.Offset;
CurrentCh1.Value = (float)Adc_Value * CurrentCh1.Gain;
if(CurrentCh1.InvertPol) CurrentCh1.Value = CurrentCh1.Value * -1.0;
if(CurrentCh1.Value > CurrentCh1.AlarmLimit || CurrentCh1.Value < -CurrentCh1.AlarmLimit)
{
if(CurrentCh1.Alarm_DelayCount < CurrentCh1.Alarm_Delay_ms) CurrentCh1.Alarm_DelayCount++;
else
{
CurrentCh1.Alarm_DelayCount = 0;
CurrentCh1.Alarm = 1;
}
}
else CurrentCh1.Alarm_DelayCount = 0;
if(CurrentCh1.Value > CurrentCh1.TripLimit || CurrentCh1.Value < -CurrentCh1.TripLimit)
{
if(CurrentCh1.Itlk_DelayCount < CurrentCh1.Itlk_Delay_ms) CurrentCh1.Itlk_DelayCount++;
else
{
CurrentCh1.Itlk_DelayCount = 0;
CurrentCh1.Trip = 1;
}
}
else CurrentCh1.Itlk_DelayCount = 0;
}
/////////////////////////////////////////////////////////////////////////////////////////////
void CurrentCh2Sample(void)
{
Adc_Value = adc_1_value[1];
Adc_Value = Adc_Value - CurrentCh2.Offset;
CurrentCh2.Value = (float)Adc_Value * CurrentCh2.Gain;
if(CurrentCh2.InvertPol) CurrentCh2.Value = CurrentCh2.Value * -1.0;
if(CurrentCh2.Value > CurrentCh2.AlarmLimit || CurrentCh2.Value < -CurrentCh2.AlarmLimit)
{
if(CurrentCh2.Alarm_DelayCount < CurrentCh2.Alarm_Delay_ms) CurrentCh2.Alarm_DelayCount++;
else
{
CurrentCh2.Alarm_DelayCount = 0;
CurrentCh2.Alarm = 1;
}
}
else CurrentCh2.Alarm_DelayCount = 0;
if(CurrentCh2.Value > CurrentCh2.TripLimit || CurrentCh2.Value < -CurrentCh2.TripLimit)
{
if(CurrentCh2.Itlk_DelayCount < CurrentCh2.Itlk_Delay_ms) CurrentCh2.Itlk_DelayCount++;
else
{
CurrentCh2.Itlk_DelayCount = 0;
CurrentCh2.Trip = 1;
}
}
else CurrentCh2.Itlk_DelayCount = 0;
}
/////////////////////////////////////////////////////////////////////////////////////////////
void CurrentCh3Sample(void)
{
Adc_Value = adc_1_value[2];
Adc_Value = Adc_Value - CurrentCh3.Offset;
CurrentCh3.Value = (float)Adc_Value * CurrentCh3.Gain;
if(CurrentCh3.InvertPol) CurrentCh3.Value = CurrentCh3.Value * -1.0;
if(CurrentCh3.Value > CurrentCh3.AlarmLimit || CurrentCh3.Value < -CurrentCh3.AlarmLimit)
{
if(CurrentCh3.Alarm_DelayCount < CurrentCh3.Alarm_Delay_ms) CurrentCh3.Alarm_DelayCount++;
else
{
CurrentCh3.Alarm_DelayCount = 0;
CurrentCh3.Alarm = 1;
}
}
else CurrentCh3.Alarm_DelayCount = 0;
if(CurrentCh3.Value > CurrentCh3.TripLimit || CurrentCh3.Value < -CurrentCh3.TripLimit)
{
if(CurrentCh3.Itlk_DelayCount < CurrentCh3.Itlk_Delay_ms) CurrentCh3.Itlk_DelayCount++;
else
{
CurrentCh3.Itlk_DelayCount = 0;
CurrentCh3.Trip = 1;
}
}
else CurrentCh3.Itlk_DelayCount = 0;
}
/////////////////////////////////////////////////////////////////////////////////////////////
void CurrentCh4Sample(void)
{
Adc_Value = adc_1_value[3];
Adc_Value = Adc_Value - CurrentCh4.Offset;
CurrentCh4.Value = (float)Adc_Value * CurrentCh4.Gain;
if(CurrentCh4.InvertPol) CurrentCh4.Value = CurrentCh4.Value * -1.0;
if(CurrentCh4.Value > CurrentCh4.AlarmLimit || CurrentCh4.Value < -CurrentCh4.AlarmLimit)
{
if(CurrentCh4.Alarm_DelayCount < CurrentCh4.Alarm_Delay_ms) CurrentCh4.Alarm_DelayCount++;
else
{
CurrentCh4.Alarm_DelayCount = 0;
CurrentCh4.Alarm = 1;
}
}
else CurrentCh4.Alarm_DelayCount = 0;
if(CurrentCh4.Value > CurrentCh4.TripLimit || CurrentCh4.Value < -CurrentCh4.TripLimit)
{
if(CurrentCh4.Itlk_DelayCount < CurrentCh4.Itlk_Delay_ms) CurrentCh4.Itlk_DelayCount++;
else
{
CurrentCh4.Itlk_DelayCount = 0;
CurrentCh4.Trip = 1;
}
}
else CurrentCh4.Itlk_DelayCount = 0;
}
/////////////////////////////////////////////////////////////////////////////////////////////
void LvCurrentCh1Sample(void)
{
Adc_Value = adc_0_value[4];
Adc_Value = Adc_Value - LvCurrentCh1.Offset;
LvCurrentCh1.Value = (float)Adc_Value * LvCurrentCh1.Gain;
if(LvCurrentCh1.InvertPol) LvCurrentCh1.Value = LvCurrentCh1.Value * -1.0;
if(LvCurrentCh1.Value > LvCurrentCh1.AlarmLimit || LvCurrentCh1.Value < -LvCurrentCh1.AlarmLimit)
{
if(LvCurrentCh1.Alarm_DelayCount < LvCurrentCh1.Alarm_Delay_ms) LvCurrentCh1.Alarm_DelayCount++;
else
{
LvCurrentCh1.Alarm_DelayCount = 0;
LvCurrentCh1.Alarm = 1;
}
}
else LvCurrentCh1.Alarm_DelayCount = 0;
if(LvCurrentCh1.Value > LvCurrentCh1.TripLimit || LvCurrentCh1.Value < -LvCurrentCh1.TripLimit)
{
if(LvCurrentCh1.Itlk_DelayCount < LvCurrentCh1.Itlk_Delay_ms) LvCurrentCh1.Itlk_DelayCount++;
else
{
LvCurrentCh1.Itlk_DelayCount = 0;
LvCurrentCh1.Trip = 1;
}
}
else LvCurrentCh1.Itlk_DelayCount = 0;
}
/////////////////////////////////////////////////////////////////////////////////////////////
void LvCurrentCh2Sample(void)
{
Adc_Value = adc_0_value[5];
Adc_Value = Adc_Value - LvCurrentCh2.Offset;
LvCurrentCh2.Value = (float)Adc_Value * LvCurrentCh2.Gain;
if(LvCurrentCh2.InvertPol) LvCurrentCh2.Value = LvCurrentCh2.Value * -1.0;
if(LvCurrentCh2.Value > LvCurrentCh2.AlarmLimit || LvCurrentCh2.Value < -LvCurrentCh2.AlarmLimit)
{
if(LvCurrentCh2.Alarm_DelayCount < LvCurrentCh2.Alarm_Delay_ms) LvCurrentCh2.Alarm_DelayCount++;
else
{
LvCurrentCh2.Alarm_DelayCount = 0;
LvCurrentCh2.Alarm = 1;
}
}
else LvCurrentCh2.Alarm_DelayCount = 0;
if(LvCurrentCh2.Value > LvCurrentCh2.TripLimit || LvCurrentCh2.Value < -LvCurrentCh2.TripLimit)
{
if(LvCurrentCh2.Itlk_DelayCount < LvCurrentCh2.Itlk_Delay_ms) LvCurrentCh2.Itlk_DelayCount++;
else
{
LvCurrentCh2.Itlk_DelayCount = 0;
LvCurrentCh2.Trip = 1;
}
}
else LvCurrentCh2.Itlk_DelayCount = 0;
}
/////////////////////////////////////////////////////////////////////////////////////////////
void LvCurrentCh3Sample(void)
{
Adc_Value = adc_0_value[6];
Adc_Value = Adc_Value - LvCurrentCh3.Offset;
LvCurrentCh3.Value = (float)Adc_Value * LvCurrentCh3.Gain;
if(LvCurrentCh3.InvertPol) LvCurrentCh3.Value = LvCurrentCh3.Value * -1.0;
if(LvCurrentCh3.Value > LvCurrentCh3.AlarmLimit || LvCurrentCh3.Value < -LvCurrentCh3.AlarmLimit)
{
if(LvCurrentCh3.Alarm_DelayCount < LvCurrentCh3.Alarm_Delay_ms) LvCurrentCh3.Alarm_DelayCount++;
else
{
LvCurrentCh3.Alarm_DelayCount = 0;
LvCurrentCh3.Alarm = 1;
}
}
else LvCurrentCh3.Alarm_DelayCount = 0;
if(LvCurrentCh3.Value > LvCurrentCh3.TripLimit || LvCurrentCh3.Value < -LvCurrentCh3.TripLimit)
{
if(LvCurrentCh3.Itlk_DelayCount < LvCurrentCh3.Itlk_Delay_ms) LvCurrentCh3.Itlk_DelayCount++;
else
{
LvCurrentCh3.Itlk_DelayCount = 0;
LvCurrentCh3.Trip = 1;
}
}
else LvCurrentCh3.Itlk_DelayCount = 0;
}
/////////////////////////////////////////////////////////////////////////////////////////////
void DriverVoltageSample(void)
{
Adc_Value = adc_1_value[4];
DriverVolt.Value = (float)Adc_Value * DriverVolt.Gain;
if(DriverVolt.Value > DriverVolt.AlarmLimit)
{
if(DriverVolt.Alarm_DelayCount < DriverVolt.Alarm_Delay_ms) DriverVolt.Alarm_DelayCount++;
else
{
DriverVolt.Alarm_DelayCount = 0;
DriverVolt.Alarm = 1;
}
}
else DriverVolt.Alarm_DelayCount = 0;
if(DriverVolt.Value > DriverVolt.TripLimit)
{
if(DriverVolt.Itlk_DelayCount < DriverVolt.Itlk_Delay_ms) DriverVolt.Itlk_DelayCount++;
else
{
DriverVolt.Itlk_DelayCount = 0;
DriverVolt.Trip = 1;
}
}
else DriverVolt.Itlk_DelayCount = 0;
}
/////////////////////////////////////////////////////////////////////////////////////////////
void Driver1CurrentSample(void)
{
Adc_Value = adc_1_value[6];
Adc_Value = Adc_Value - Driver1Curr.Offset;
Driver1Curr.Value = (float)Adc_Value * Driver1Curr.Gain;
if(Driver1Curr.Value > Driver1Curr.AlarmLimit)
{
if(Driver1Curr.Alarm_DelayCount < Driver1Curr.Alarm_Delay_ms) Driver1Curr.Alarm_DelayCount++;
else
{
Driver1Curr.Alarm_DelayCount = 0;
Driver1Curr.Alarm = 1;
}
}
else Driver1Curr.Alarm_DelayCount = 0;
if(Driver1Curr.Value > Driver1Curr.TripLimit)
{
if(Driver1Curr.Itlk_DelayCount < Driver1Curr.Itlk_Delay_ms) Driver1Curr.Itlk_DelayCount++;
else
{
Driver1Curr.Itlk_DelayCount = 0;
Driver1Curr.Trip = 1;
}
}
else Driver1Curr.Itlk_DelayCount = 0;
}
/////////////////////////////////////////////////////////////////////////////////////////////
void Driver2CurrentSample(void)
{
Adc_Value = adc_1_value[5];
Adc_Value = Adc_Value - Driver2Curr.Offset;
Driver2Curr.Value = (float)Adc_Value * Driver2Curr.Gain;
if(Driver2Curr.Value > Driver2Curr.AlarmLimit)
{
if(Driver2Curr.Alarm_DelayCount < Driver2Curr.Alarm_Delay_ms) Driver2Curr.Alarm_DelayCount++;
else
{
Driver2Curr.Alarm_DelayCount = 0;
Driver2Curr.Alarm = 1;
}
}
else Driver2Curr.Alarm_DelayCount = 0;
if(Driver2Curr.Value > Driver2Curr.TripLimit)
{
if(Driver2Curr.Itlk_DelayCount < Driver2Curr.Itlk_Delay_ms) Driver2Curr.Itlk_DelayCount++;
else
{
Driver2Curr.Itlk_DelayCount = 0;
Driver2Curr.Trip = 1;
}
}
else Driver2Curr.Itlk_DelayCount = 0;
}
/////////////////////////////////////////////////////////////////////////////////////////////
void ConfigPolVoltCh1(unsigned char sts)
{
VoltageCh1.InvertPol = sts;
}
/////////////////////////////////////////////////////////////////////////////////////////////
void ConfigPolVoltCh2(unsigned char sts)
{
VoltageCh2.InvertPol = sts;
}
/////////////////////////////////////////////////////////////////////////////////////////////
void ConfigPolVoltCh3(unsigned char sts)
{
VoltageCh3.InvertPol = sts;
}
/////////////////////////////////////////////////////////////////////////////////////////////
void ConfigPolVoltCh4(unsigned char sts)
{
VoltageCh4.InvertPol = sts;
}
/////////////////////////////////////////////////////////////////////////////////////////////
void ConfigPolCurrCh1(unsigned char sts)
{
CurrentCh1.InvertPol = sts;
}
/////////////////////////////////////////////////////////////////////////////////////////////
void ConfigPolCurrCh2(unsigned char sts)
{
CurrentCh2.InvertPol = sts;
}
/////////////////////////////////////////////////////////////////////////////////////////////
void ConfigPolCurrCh3(unsigned char sts)
{
CurrentCh3.InvertPol = sts;
}
/////////////////////////////////////////////////////////////////////////////////////////////
void ConfigPolCurrCh4(unsigned char sts)
{
CurrentCh4.InvertPol = sts;
}
/////////////////////////////////////////////////////////////////////////////////////////////
void ConfigPolLvCurrCh1(unsigned char sts)
{
LvCurrentCh1.InvertPol = sts;
}
/////////////////////////////////////////////////////////////////////////////////////////////
void ConfigPolLvCurrCh2(unsigned char sts)
{
LvCurrentCh2.InvertPol = sts;
}
/////////////////////////////////////////////////////////////////////////////////////////////
void ConfigPolLvCurrCh3(unsigned char sts)
{
LvCurrentCh3.InvertPol = sts;
}
/////////////////////////////////////////////////////////////////////////////////////////////
void VoltageCh1Enable(void)
{
VoltageCh1.Enable = 1;
}
/////////////////////////////////////////////////////////////////////////////////////////////
void VoltageCh1Disable(void)
{
VoltageCh1.Enable = 0;
}
/////////////////////////////////////////////////////////////////////////////////////////////
void VoltageCh2Enable(void)
{
VoltageCh2.Enable = 1;
}
/////////////////////////////////////////////////////////////////////////////////////////////
void VoltageCh2Disable(void)
{
VoltageCh2.Enable = 0;
}