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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
|
/**************************************************************************//**
* @file epwm.c
* @version V3.00
* @brief M2354 series EPWM driver source file
*
* @copyright SPDX-License-Identifier: Apache-2.0
* @copyright Copyright (C) 2020 Nuvoton Technology Corp. All rights reserved.
*****************************************************************************/
#include "NuMicro.h"
/** @addtogroup Standard_Driver Standard Driver
@{
*/
/** @addtogroup EPWM_Driver EPWM Driver
@{
*/
/** @addtogroup EPWM_EXPORTED_FUNCTIONS EPWM Exported Functions
@{
*/
/**
* @brief Configure EPWM capture and get the nearest unit time.
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
* @param[in] u32UnitTimeNsec The unit time of counter
* @param[in] u32CaptureEdge The condition to latch the counter. This parameter is not used
* @return The nearest unit time in nano second.
* @details This function is used to Configure EPWM capture and get the nearest unit time.
*/
uint32_t EPWM_ConfigCaptureChannel(EPWM_T *epwm, uint32_t u32ChannelNum, uint32_t u32UnitTimeNsec, uint32_t u32CaptureEdge)
{
uint32_t u32PWMClockSrc;
uint32_t u32NearestUnitTimeNsec = 0;
uint32_t u32Prescale = 1U, u32CNR = 0xFFFFU;
uint8_t u8BreakLoop = 0U;
(void)u32CaptureEdge;
/* clock source is from PCLK */
if((epwm == EPWM0) || (epwm == EPWM0_NS))
{
u32PWMClockSrc = CLK_GetPCLK0Freq();
}
else /* if((epwm == EPWM1)||(epwm == EPWM1_NS)) */
{
u32PWMClockSrc = CLK_GetPCLK1Freq();
}
u32PWMClockSrc /= 1000UL;
for(u32Prescale = 1U; u32Prescale <= 0x1000U; u32Prescale++)
{
u32NearestUnitTimeNsec = (1000000UL * u32Prescale) / u32PWMClockSrc;
if(u32NearestUnitTimeNsec < u32UnitTimeNsec)
{
if(u32Prescale == 0x1000U) /* limit to the maximum unit time(nano second) */
{
u8BreakLoop = 1U;
}
if(!((1000000UL * (u32Prescale + 1UL) > (u32NearestUnitTimeNsec * u32PWMClockSrc))))
{
u8BreakLoop = 1U;
}
}
else
{
u8BreakLoop = 1U;
}
if(u8BreakLoop)
{
break;
}
}
/* convert to real register value */
u32Prescale = u32Prescale - 1U;
/* every two channels share a prescaler */
EPWM_SET_PRESCALER(epwm, u32ChannelNum, u32Prescale);
/* set EPWM to down count type(edge aligned) */
(epwm)->CTL1 = ((epwm)->CTL1 & ~(EPWM_CTL1_CNTTYPE0_Msk << (u32ChannelNum << 1))) | (1UL << (u32ChannelNum << 1));
/* set EPWM to auto-reload mode */
(epwm)->CTL1 &= ~(EPWM_CTL1_CNTMODE0_Msk << u32ChannelNum);
EPWM_SET_CNR(epwm, u32ChannelNum, u32CNR);
return (u32NearestUnitTimeNsec);
}
/**
* @brief This function Configure EPWM generator and get the nearest frequency in edge aligned(up counter type) auto-reload mode
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
* @param[in] u32Frequency Target generator frequency
* @param[in] u32DutyCycle Target generator duty cycle percentage. Valid range are between 0 ~ 100. 10 means 10%, 20 means 20%...
* @return Nearest frequency clock in nano second
* @note Since every two channels, (0 & 1), (2 & 3), shares a prescaler. Call this API to configure EPWM frequency may affect
* existing frequency of other channel.
* @note This function is used for initial stage.
* To change duty cycle later, it should get the configured period value and calculate the new comparator value.
*/
uint32_t EPWM_ConfigOutputChannel(EPWM_T *epwm, uint32_t u32ChannelNum, uint32_t u32Frequency, uint32_t u32DutyCycle)
{
uint32_t u32PWMClockSrc;
uint32_t i;
uint32_t u32Prescale = 1U, u32CNR = 0xFFFFU;
/* clock source is from PCLK */
if((epwm == EPWM0) || (epwm == EPWM0_NS))
{
u32PWMClockSrc = CLK_GetPCLK0Freq();
}
else /* if((epwm == EPWM1)||(epwm == EPWM1_NS)) */
{
u32PWMClockSrc = CLK_GetPCLK1Freq();
}
for(u32Prescale = 1U; u32Prescale < 0xFFFU; u32Prescale++)/* prescale could be 0~0xFFF */
{
i = (u32PWMClockSrc / u32Frequency) / u32Prescale;
/* If target value is larger than CNR, need to use a larger prescaler */
if(i <= (0x10000U))
{
u32CNR = i;
break;
}
}
/* Store return value here 'cos we're gonna change u32Prescale & u32CNR to the real value to fill into register */
i = u32PWMClockSrc / (u32Prescale * u32CNR);
/* convert to real register value */
u32Prescale = u32Prescale - 1U;
/* every two channels share a prescaler */
EPWM_SET_PRESCALER(epwm, u32ChannelNum, u32Prescale);
/* set EPWM to up counter type(edge aligned) and auto-reload mode */
(epwm)->CTL1 = ((epwm)->CTL1 & ~((EPWM_CTL1_CNTTYPE0_Msk << (u32ChannelNum << 1)) | (EPWM_CTL1_CNTMODE0_Msk << u32ChannelNum)));
u32CNR = u32CNR - 1U;
EPWM_SET_CNR(epwm, u32ChannelNum, u32CNR);
EPWM_SET_CMR(epwm, u32ChannelNum, u32DutyCycle * (u32CNR + 1UL) / 100UL);
(epwm)->WGCTL0 = ((epwm)->WGCTL0 & ~((EPWM_WGCTL0_PRDPCTL0_Msk | EPWM_WGCTL0_ZPCTL0_Msk) << (u32ChannelNum << 1))) | \
(EPWM_OUTPUT_HIGH << (u32ChannelNum << 1UL << EPWM_WGCTL0_ZPCTL0_Pos));
(epwm)->WGCTL1 = ((epwm)->WGCTL1 & ~((EPWM_WGCTL1_CMPDCTL0_Msk | EPWM_WGCTL1_CMPUCTL0_Msk) << (u32ChannelNum << 1))) | \
(EPWM_OUTPUT_LOW << (u32ChannelNum << 1UL << EPWM_WGCTL1_CMPUCTL0_Pos));
return(i);
}
/**
* @brief Start EPWM module
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelMask Combination of enabled channels. Each bit corresponds to a channel.
* Bit 0 is channel 0, bit 1 is channel 1...
* @return None
* @details This function is used to start EPWM module.
*/
void EPWM_Start(EPWM_T *epwm, uint32_t u32ChannelMask)
{
(epwm)->CNTEN |= u32ChannelMask;
}
/**
* @brief Stop EPWM module
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelMask Combination of enabled channels. Each bit corresponds to a channel.
* Bit 0 is channel 0, bit 1 is channel 1...
* @return None
* @details This function is used to stop EPWM module.
*/
void EPWM_Stop(EPWM_T *epwm, uint32_t u32ChannelMask)
{
uint32_t i;
for(i = 0UL; i < EPWM_CHANNEL_NUM; i ++)
{
if(u32ChannelMask & (1UL << i))
{
(epwm)->PERIOD[i] = 0UL;
}
}
}
/**
* @brief Stop EPWM generation immediately by clear channel enable bit
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelMask Combination of enabled channels. Each bit corresponds to a channel.
* Bit 0 is channel 0, bit 1 is channel 1...
* @return None
* @details This function is used to stop EPWM generation immediately by clear channel enable bit.
*/
void EPWM_ForceStop(EPWM_T *epwm, uint32_t u32ChannelMask)
{
(epwm)->CNTEN &= ~u32ChannelMask;
}
/**
* @brief Enable selected channel to trigger ADC
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
* @param[in] u32Condition The condition to trigger ADC. Combination of following conditions:
* - \ref EPWM_TRG_ADC_EVEN_ZERO
* - \ref EPWM_TRG_ADC_EVEN_PERIOD
* - \ref EPWM_TRG_ADC_EVEN_ZERO_PERIOD
* - \ref EPWM_TRG_ADC_EVEN_COMPARE_UP
* - \ref EPWM_TRG_ADC_EVEN_COMPARE_DOWN
* - \ref EPWM_TRG_ADC_ODD_ZERO
* - \ref EPWM_TRG_ADC_ODD_PERIOD
* - \ref EPWM_TRG_ADC_ODD_ZERO_PERIOD
* - \ref EPWM_TRG_ADC_ODD_COMPARE_UP
* - \ref EPWM_TRG_ADC_ODD_COMPARE_DOWN
* - \ref EPWM_TRG_ADC_CH_0_FREE_CMP_UP
* - \ref EPWM_TRG_ADC_CH_0_FREE_CMP_DOWN
* - \ref EPWM_TRG_ADC_CH_2_FREE_CMP_UP
* - \ref EPWM_TRG_ADC_CH_2_FREE_CMP_DOWN
* - \ref EPWM_TRG_ADC_CH_4_FREE_CMP_UP
* - \ref EPWM_TRG_ADC_CH_4_FREE_CMP_DOWN
* @return None
* @details This function is used to enable selected channel to trigger ADC.
*/
void EPWM_EnableADCTrigger(EPWM_T *epwm, uint32_t u32ChannelNum, uint32_t u32Condition)
{
if(u32ChannelNum < 4UL)
{
(epwm)->EADCTS0 &= ~((EPWM_EADCTS0_TRGSEL0_Msk) << (u32ChannelNum << 3));
(epwm)->EADCTS0 |= ((EPWM_EADCTS0_TRGEN0_Msk | u32Condition) << (u32ChannelNum << 3));
}
else
{
(epwm)->EADCTS1 &= ~((EPWM_EADCTS1_TRGSEL4_Msk) << ((u32ChannelNum - 4UL) << 3));
(epwm)->EADCTS1 |= ((EPWM_EADCTS1_TRGEN4_Msk | u32Condition) << ((u32ChannelNum - 4UL) << 3));
}
}
/**
* @brief Disable selected channel to trigger ADC
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
* @return None
* @details This function is used to disable selected channel to trigger ADC.
*/
void EPWM_DisableADCTrigger(EPWM_T *epwm, uint32_t u32ChannelNum)
{
if(u32ChannelNum < 4UL)
{
(epwm)->EADCTS0 &= ~(EPWM_EADCTS0_TRGEN0_Msk << (u32ChannelNum << 3));
}
else
{
(epwm)->EADCTS1 &= ~(EPWM_EADCTS1_TRGEN4_Msk << ((u32ChannelNum - 4UL) << 3));
}
}
/**
* @brief Enable and configure trigger ADC prescale
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5.
* @param[in] u32Prescale ADC prescale. Valid values are between 0 to 0xF.
* @param[in] u32PrescaleCnt ADC prescale counter. Valid values are between 0 to 0xF.
* @retval 0 Success.
* @retval -1 Failed.
* @details This function is used to enable and configure trigger ADC prescale.
* @note User can configure only when ADC trigger prescale is disabled.
* @note ADC prescale counter must less than ADC prescale.
*/
int32_t EPWM_EnableADCTriggerPrescale(EPWM_T *epwm, uint32_t u32ChannelNum, uint32_t u32Prescale, uint32_t u32PrescaleCnt)
{
/* User can write only when PSCENn(n = 0 ~ 5) is 0 */
if((epwm)->EADCPSCCTL & (1UL << u32ChannelNum))
return (-1);
if(u32ChannelNum < 4UL)
{
(epwm)->EADCPSC0 = ((epwm)->EADCPSC0 & ~((EPWM_EADCPSC0_EADCPSC0_Msk) << (u32ChannelNum << 3))) | \
(u32Prescale << (u32ChannelNum << 3));
(epwm)->EADCPSCNT0 = ((epwm)->EADCPSCNT0 & ~((EPWM_EADCPSCNT0_PSCNT0_Msk) << (u32ChannelNum << 3))) | \
(u32PrescaleCnt << (u32ChannelNum << 3));
}
else
{
(epwm)->EADCPSC1 = ((epwm)->EADCPSC1 & ~((EPWM_EADCPSC1_EADCPSC4_Msk) << ((u32ChannelNum - 4UL) << 3))) | \
(u32Prescale << ((u32ChannelNum - 4UL) << 3));
(epwm)->EADCPSCNT1 = ((epwm)->EADCPSCNT1 & ~((EPWM_EADCPSCNT1_PSCNT4_Msk) << ((u32ChannelNum - 4UL) << 3))) | \
(u32PrescaleCnt << ((u32ChannelNum - 4UL) << 3));
}
(epwm)->EADCPSCCTL |= EPWM_EADCPSCCTL_PSCEN0_Msk << u32ChannelNum;
return 0;
}
/**
* @brief Disable Trigger ADC prescale function
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
* @return None
* @details This function is used to disable trigger ADC prescale.
*/
void EPWM_DisableADCTriggerPrescale(EPWM_T *epwm, uint32_t u32ChannelNum)
{
(epwm)->EADCPSCCTL &= ~(EPWM_EADCPSCCTL_PSCEN0_Msk << u32ChannelNum);
}
/**
* @brief Clear selected channel trigger ADC flag
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
* @param[in] u32Condition This parameter is not used
* @return None
* @details This function is used to clear selected channel trigger ADC flag.
*/
void EPWM_ClearADCTriggerFlag(EPWM_T *epwm, uint32_t u32ChannelNum, uint32_t u32Condition)
{
(void)u32Condition;
(epwm)->STATUS = (EPWM_STATUS_EADCTRGF0_Msk << u32ChannelNum);
}
/**
* @brief Get selected channel trigger ADC flag
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
* @retval 0 The specified channel trigger ADC to start of conversion flag is not set
* @retval 1 The specified channel trigger ADC to start of conversion flag is set
* @details This function is used to get EPWM trigger ADC to start of conversion flag for specified channel.
*/
uint32_t EPWM_GetADCTriggerFlag(EPWM_T *epwm, uint32_t u32ChannelNum)
{
return (((epwm)->STATUS & (EPWM_STATUS_EADCTRGF0_Msk << u32ChannelNum)) ? 1UL : 0UL);
}
/**
* @brief Enable selected channel to trigger DAC
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
* @param[in] u32Condition The condition to trigger DAC. Combination of following conditions:
* - \ref EPWM_TRIGGER_DAC_ZERO
* - \ref EPWM_TRIGGER_DAC_PERIOD
* - \ref EPWM_TRIGGER_DAC_COMPARE_UP
* - \ref EPWM_TRIGGER_DAC_COMPARE_DOWN
* @return None
* @details This function is used to enable selected channel to trigger DAC.
*/
void EPWM_EnableDACTrigger(EPWM_T *epwm, uint32_t u32ChannelNum, uint32_t u32Condition)
{
(epwm)->DACTRGEN |= (u32Condition << u32ChannelNum);
}
/**
* @brief Disable selected channel to trigger DAC
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
* @return None
* @details This function is used to disable selected channel to trigger DAC.
*/
void EPWM_DisableDACTrigger(EPWM_T *epwm, uint32_t u32ChannelNum)
{
(epwm)->DACTRGEN &= ~((EPWM_TRIGGER_DAC_ZERO | EPWM_TRIGGER_DAC_PERIOD | EPWM_TRIGGER_DAC_COMPARE_UP | EPWM_TRIGGER_DAC_COMPARE_DOWN) << u32ChannelNum);
}
/**
* @brief Clear selected channel trigger DAC flag
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelNum EPWM channel number. This parameter is not used
* @param[in] u32Condition The condition to trigger DAC. This parameter is not used
* @return None
* @details This function is used to clear selected channel trigger DAC flag.
*/
void EPWM_ClearDACTriggerFlag(EPWM_T *epwm, uint32_t u32ChannelNum, uint32_t u32Condition)
{
(void)u32ChannelNum;
(void)u32Condition;
(epwm)->STATUS = EPWM_STATUS_DACTRGF_Msk;
}
/**
* @brief Get selected channel trigger DAC flag
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelNum EPWM channel number. This parameter is not used
* @retval 0 The specified channel trigger DAC to start of conversion flag is not set
* @retval 1 The specified channel trigger DAC to start of conversion flag is set
* @details This function is used to get selected channel trigger DAC flag.
*/
uint32_t EPWM_GetDACTriggerFlag(EPWM_T *epwm, uint32_t u32ChannelNum)
{
(void)u32ChannelNum;
return (((epwm)->STATUS & EPWM_STATUS_DACTRGF_Msk) ? 1UL : 0UL);
}
/**
* @brief This function enable fault brake of selected channel(s)
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelMask Combination of enabled channels. Each bit corresponds to a channel.
* @param[in] u32LevelMask Output high or low while fault brake occurs, each bit represent the level of a channel
* while fault brake occurs. Bit 0 represents channel 0, bit 1 represents channel 1...
* @param[in] u32BrakeSource Fault brake source, could be one of following source
* - \ref EPWM_FB_EDGE_ADCRM
* - \ref EPWM_FB_EDGE_ACMP0
* - \ref EPWM_FB_EDGE_ACMP1
* - \ref EPWM_FB_EDGE_BKP0
* - \ref EPWM_FB_EDGE_BKP1
* - \ref EPWM_FB_EDGE_SYS_CSS
* - \ref EPWM_FB_EDGE_SYS_BOD
* - \ref EPWM_FB_EDGE_SYS_RAM
* - \ref EPWM_FB_EDGE_SYS_COR
* - \ref EPWM_FB_LEVEL_ADCRM
* - \ref EPWM_FB_LEVEL_ACMP0
* - \ref EPWM_FB_LEVEL_ACMP1
* - \ref EPWM_FB_LEVEL_BKP0
* - \ref EPWM_FB_LEVEL_BKP1
* - \ref EPWM_FB_LEVEL_SYS_CSS
* - \ref EPWM_FB_LEVEL_SYS_BOD
* - \ref EPWM_FB_LEVEL_SYS_RAM
* - \ref EPWM_FB_LEVEL_SYS_COR
* @return None
* @details This function is used to enable fault brake of selected channel(s).
* The write-protection function should be disabled before using this function.
*/
void EPWM_EnableFaultBrake(EPWM_T *epwm, uint32_t u32ChannelMask, uint32_t u32LevelMask, uint32_t u32BrakeSource)
{
uint32_t i;
for(i = 0UL; i < EPWM_CHANNEL_NUM; i++)
{
if(u32ChannelMask & (1UL << i))
{
if((u32BrakeSource == EPWM_FB_EDGE_SYS_CSS) || (u32BrakeSource == EPWM_FB_EDGE_SYS_BOD) || \
(u32BrakeSource == EPWM_FB_EDGE_SYS_RAM) || (u32BrakeSource == EPWM_FB_EDGE_SYS_COR) || \
(u32BrakeSource == EPWM_FB_LEVEL_SYS_CSS) || (u32BrakeSource == EPWM_FB_LEVEL_SYS_BOD) || \
(u32BrakeSource == EPWM_FB_LEVEL_SYS_RAM) || (u32BrakeSource == EPWM_FB_LEVEL_SYS_COR))
{
(epwm)->BRKCTL[i >> 1] |= (u32BrakeSource & (EPWM_BRKCTL0_1_SYSEBEN_Msk | EPWM_BRKCTL0_1_SYSLBEN_Msk));
(epwm)->FAILBRK |= (u32BrakeSource & 0xFUL);
}
else
{
(epwm)->BRKCTL[i >> 1] |= u32BrakeSource;
}
}
if(u32LevelMask & (1UL << i))
{
if((i & 0x1UL) == 0UL)
{
/* set brake action as high level for even channel */
(epwm)->BRKCTL[i >> 1] &= ~EPWM_BRKCTL0_1_BRKAEVEN_Msk;
(epwm)->BRKCTL[i >> 1] |= ((3UL) << EPWM_BRKCTL0_1_BRKAEVEN_Pos);
}
else
{
/* set brake action as high level for odd channel */
(epwm)->BRKCTL[i >> 1] &= ~EPWM_BRKCTL0_1_BRKAODD_Msk;
(epwm)->BRKCTL[i >> 1] |= ((3UL) << EPWM_BRKCTL0_1_BRKAODD_Pos);
}
}
else
{
if((i & 0x1UL) == 0UL)
{
/* set brake action as low level for even channel */
(epwm)->BRKCTL[i >> 1] &= ~EPWM_BRKCTL0_1_BRKAEVEN_Msk;
(epwm)->BRKCTL[i >> 1] |= ((2UL) << EPWM_BRKCTL0_1_BRKAEVEN_Pos);
}
else
{
/* set brake action as low level for odd channel */
(epwm)->BRKCTL[i >> 1] &= ~EPWM_BRKCTL0_1_BRKAODD_Msk;
(epwm)->BRKCTL[i >> 1] |= ((2UL) << EPWM_BRKCTL0_1_BRKAODD_Pos);
}
}
}
}
/**
* @brief Enable capture of selected channel(s)
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelMask Combination of enabled channels. Each bit corresponds to a channel.
* Bit 0 is channel 0, bit 1 is channel 1...
* @return None
* @details This function is used to enable capture of selected channel(s).
*/
void EPWM_EnableCapture(EPWM_T *epwm, uint32_t u32ChannelMask)
{
(epwm)->CAPINEN |= u32ChannelMask;
(epwm)->CAPCTL |= u32ChannelMask;
}
/**
* @brief Disable capture of selected channel(s)
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelMask Combination of enabled channels. Each bit corresponds to a channel.
* Bit 0 is channel 0, bit 1 is channel 1...
* @return None
* @details This function is used to disable capture of selected channel(s).
*/
void EPWM_DisableCapture(EPWM_T *epwm, uint32_t u32ChannelMask)
{
(epwm)->CAPINEN &= ~u32ChannelMask;
(epwm)->CAPCTL &= ~u32ChannelMask;
}
/**
* @brief Enables EPWM output generation of selected channel(s)
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelMask Combination of enabled channels. Each bit corresponds to a channel.
* Set bit 0 to 1 enables channel 0 output, set bit 1 to 1 enables channel 1 output...
* @return None
* @details This function is used to enable EPWM output generation of selected channel(s).
*/
void EPWM_EnableOutput(EPWM_T *epwm, uint32_t u32ChannelMask)
{
(epwm)->POEN |= u32ChannelMask;
}
/**
* @brief Disables EPWM output generation of selected channel(s)
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelMask Combination of enabled channels. Each bit corresponds to a channel
* Set bit 0 to 1 disables channel 0 output, set bit 1 to 1 disables channel 1 output...
* @return None
* @details This function is used to disable EPWM output generation of selected channel(s).
*/
void EPWM_DisableOutput(EPWM_T *epwm, uint32_t u32ChannelMask)
{
(epwm)->POEN &= ~u32ChannelMask;
}
/**
* @brief Enables PDMA transfer of selected channel for EPWM capture
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelNum EPWM channel number.
* @param[in] u32RisingFirst The capture order is rising, falling first. Every two channels share the same setting. Valid values are TRUE and FALSE.
* @param[in] u32Mode Captured data transferred by PDMA interrupt type. It could be either
* - \ref EPWM_CAPTURE_PDMA_RISING_LATCH
* - \ref EPWM_CAPTURE_PDMA_FALLING_LATCH
* - \ref EPWM_CAPTURE_PDMA_RISING_FALLING_LATCH
* @return None
* @details This function is used to enable PDMA transfer of selected channel(s) for EPWM capture.
* @note This function can only selects even or odd channel of pairs to do PDMA transfer.
*/
void EPWM_EnablePDMA(EPWM_T *epwm, uint32_t u32ChannelNum, uint32_t u32RisingFirst, uint32_t u32Mode)
{
uint32_t u32IsOddCh;
u32IsOddCh = u32ChannelNum & 0x1UL;
(epwm)->PDMACTL = ((epwm)->PDMACTL & ~((EPWM_PDMACTL_CHSEL0_1_Msk | EPWM_PDMACTL_CAPORD0_1_Msk | EPWM_PDMACTL_CAPMOD0_1_Msk) << ((u32ChannelNum >> 1) << 3))) | \
(((u32IsOddCh << EPWM_PDMACTL_CHSEL0_1_Pos) | (u32RisingFirst << EPWM_PDMACTL_CAPORD0_1_Pos) | \
u32Mode | EPWM_PDMACTL_CHEN0_1_Msk) << ((u32ChannelNum >> 1) << 3));
}
/**
* @brief Disables PDMA transfer of selected channel for EPWM capture
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelNum EPWM channel number.
* @return None
* @details This function is used to enable PDMA transfer of selected channel(s) for EPWM capture.
*/
void EPWM_DisablePDMA(EPWM_T *epwm, uint32_t u32ChannelNum)
{
(epwm)->PDMACTL &= ~(EPWM_PDMACTL_CHEN0_1_Msk << ((u32ChannelNum >> 1) << 3));
}
/**
* @brief Enable Dead zone of selected channel
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
* @param[in] u32Duration Dead zone length in EPWM clock count, valid values are between 0~0xFFF, but 0 means there is no Dead zone.
* @return None
* @details This function is used to enable Dead zone of selected channel.
* The write-protection function should be disabled before using this function.
* @note Every two channels share the same setting.
*/
void EPWM_EnableDeadZone(EPWM_T *epwm, uint32_t u32ChannelNum, uint32_t u32Duration)
{
/* every two channels share the same setting */
(epwm)->DTCTL[(u32ChannelNum) >> 1] &= ~EPWM_DTCTL0_1_DTCNT_Msk;
(epwm)->DTCTL[(u32ChannelNum) >> 1] |= EPWM_DTCTL0_1_DTEN_Msk | u32Duration;
}
/**
* @brief Disable Dead zone of selected channel
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
* @return None
* @details This function is used to disable Dead zone of selected channel.
* The write-protection function should be disabled before using this function.
*/
void EPWM_DisableDeadZone(EPWM_T *epwm, uint32_t u32ChannelNum)
{
/* every two channels shares the same setting */
(epwm)->DTCTL[(u32ChannelNum) >> 1] &= ~EPWM_DTCTL0_1_DTEN_Msk;
}
/**
* @brief Enable capture interrupt of selected channel.
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
* @param[in] u32Edge Rising or falling edge to latch counter.
* - \ref EPWM_CAPTURE_INT_RISING_LATCH
* - \ref EPWM_CAPTURE_INT_FALLING_LATCH
* @return None
* @details This function is used to enable capture interrupt of selected channel.
*/
void EPWM_EnableCaptureInt(EPWM_T *epwm, uint32_t u32ChannelNum, uint32_t u32Edge)
{
(epwm)->CAPIEN |= (u32Edge << u32ChannelNum);
}
/**
* @brief Disable capture interrupt of selected channel.
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
* @param[in] u32Edge Rising or falling edge to latch counter.
* - \ref EPWM_CAPTURE_INT_RISING_LATCH
* - \ref EPWM_CAPTURE_INT_FALLING_LATCH
* @return None
* @details This function is used to disable capture interrupt of selected channel.
*/
void EPWM_DisableCaptureInt(EPWM_T *epwm, uint32_t u32ChannelNum, uint32_t u32Edge)
{
(epwm)->CAPIEN &= ~(u32Edge << u32ChannelNum);
}
/**
* @brief Clear capture interrupt of selected channel.
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
* @param[in] u32Edge Rising or falling edge to latch counter.
* - \ref EPWM_CAPTURE_INT_RISING_LATCH
* - \ref EPWM_CAPTURE_INT_FALLING_LATCH
* @return None
* @details This function is used to clear capture interrupt of selected channel.
*/
void EPWM_ClearCaptureIntFlag(EPWM_T *epwm, uint32_t u32ChannelNum, uint32_t u32Edge)
{
(epwm)->CAPIF = (u32Edge << u32ChannelNum);
}
/**
* @brief Get capture interrupt of selected channel.
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
* @retval 0 No capture interrupt
* @retval 1 Rising edge latch interrupt
* @retval 2 Falling edge latch interrupt
* @retval 3 Rising and falling latch interrupt
* @details This function is used to get capture interrupt of selected channel.
*/
uint32_t EPWM_GetCaptureIntFlag(EPWM_T *epwm, uint32_t u32ChannelNum)
{
uint32_t u32CapIf = 0UL;
u32CapIf = ((((epwm)->CAPIF & (EPWM_CAPIF_CFLIF0_Msk << u32ChannelNum)) ? 1UL : 0UL) << 1);
u32CapIf |= (((epwm)->CAPIF & (EPWM_CAPIF_CRLIF0_Msk << u32ChannelNum)) ? 1UL : 0UL);
return u32CapIf;
}
/**
* @brief Enable duty interrupt of selected channel
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
* @param[in] u32IntDutyType Duty interrupt type, could be either
* - \ref EPWM_DUTY_INT_DOWN_COUNT_MATCH_CMP
* - \ref EPWM_DUTY_INT_UP_COUNT_MATCH_CMP
* @return None
* @details This function is used to enable duty interrupt of selected channel.
*/
void EPWM_EnableDutyInt(EPWM_T *epwm, uint32_t u32ChannelNum, uint32_t u32IntDutyType)
{
(epwm)->INTEN0 |= (u32IntDutyType << u32ChannelNum);
}
/**
* @brief Disable duty interrupt of selected channel
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
* @return None
* @details This function is used to disable duty interrupt of selected channel.
*/
void EPWM_DisableDutyInt(EPWM_T *epwm, uint32_t u32ChannelNum)
{
(epwm)->INTEN0 &= ~((EPWM_DUTY_INT_DOWN_COUNT_MATCH_CMP | EPWM_DUTY_INT_UP_COUNT_MATCH_CMP) << u32ChannelNum);
}
/**
* @brief Clear duty interrupt flag of selected channel
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
* @return None
* @details This function is used to clear duty interrupt flag of selected channel.
*/
void EPWM_ClearDutyIntFlag(EPWM_T *epwm, uint32_t u32ChannelNum)
{
(epwm)->INTSTS0 = (EPWM_INTSTS0_CMPUIF0_Msk | EPWM_INTSTS0_CMPDIF0_Msk) << u32ChannelNum;
}
/**
* @brief Get duty interrupt flag of selected channel
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
* @return Duty interrupt flag of specified channel
* @retval 0 Duty interrupt did not occur
* @retval 1 Duty interrupt occurred
* @details This function is used to get duty interrupt flag of selected channel.
*/
uint32_t EPWM_GetDutyIntFlag(EPWM_T *epwm, uint32_t u32ChannelNum)
{
return ((((epwm)->INTSTS0 & ((EPWM_INTSTS0_CMPDIF0_Msk | EPWM_INTSTS0_CMPUIF0_Msk) << u32ChannelNum))) ? 1UL : 0UL);
}
/**
* @brief This function enable fault brake interrupt
* @param[in] epwm The pointer of the specified EPWM module
* @param[in] u32BrakeSource Fault brake source.
* - \ref EPWM_FB_EDGE
* - \ref EPWM_FB_LEVEL
* @return None
* @details This function is used to enable fault brake interrupt.
* The write-protection function should be disabled before using this function.
* @note Every two channels share the same setting.
*/
void EPWM_EnableFaultBrakeInt(EPWM_T *epwm, uint32_t u32BrakeSource)
{
(epwm)->INTEN1 |= (0x7UL << u32BrakeSource);
}
/**
* @brief This function disable fault brake interrupt
* @param[in] epwm The pointer of the specified EPWM module
* @param[in] u32BrakeSource Fault brake source.
* - \ref EPWM_FB_EDGE
* - \ref EPWM_FB_LEVEL
* @return None
* @details This function is used to disable fault brake interrupt.
* The write-protection function should be disabled before using this function.
* @note Every two channels share the same setting.
*/
void EPWM_DisableFaultBrakeInt(EPWM_T *epwm, uint32_t u32BrakeSource)
{
(epwm)->INTEN1 &= ~(0x7UL << u32BrakeSource);
}
/**
* @brief This function clear fault brake interrupt of selected source
* @param[in] epwm The pointer of the specified EPWM module
* @param[in] u32BrakeSource Fault brake source.
* - \ref EPWM_FB_EDGE
* - \ref EPWM_FB_LEVEL
* @return None
* @details This function is used to clear fault brake interrupt of selected source.
* The write-protection function should be disabled before using this function.
*/
void EPWM_ClearFaultBrakeIntFlag(EPWM_T *epwm, uint32_t u32BrakeSource)
{
(epwm)->INTSTS1 = (0x3fUL << u32BrakeSource);
}
/**
* @brief This function get fault brake interrupt flag of selected source
* @param[in] epwm The pointer of the specified EPWM module
* @param[in] u32BrakeSource Fault brake source, could be either
* - \ref EPWM_FB_EDGE
* - \ref EPWM_FB_LEVEL
* @return Fault brake interrupt flag of specified source
* @retval 0 Fault brake interrupt did not occurred
* @retval 1 Fault brake interrupt occurred
* @details This function is used to get fault brake interrupt flag of selected source.
*/
uint32_t EPWM_GetFaultBrakeIntFlag(EPWM_T *epwm, uint32_t u32BrakeSource)
{
return (((epwm)->INTSTS1 & (0x3fUL << u32BrakeSource)) ? 1UL : 0UL);
}
/**
* @brief Enable period interrupt of selected channel
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
* @param[in] u32IntPeriodType Period interrupt type. This parameter is not used.
* @return None
* @details This function is used to enable period interrupt of selected channel.
*/
void EPWM_EnablePeriodInt(EPWM_T *epwm, uint32_t u32ChannelNum, uint32_t u32IntPeriodType)
{
(void)u32IntPeriodType;
(epwm)->INTEN0 |= (EPWM_INTEN0_PIEN0_Msk << u32ChannelNum);
}
/**
* @brief Disable period interrupt of selected channel
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
* @return None
* @details This function is used to disable period interrupt of selected channel.
*/
void EPWM_DisablePeriodInt(EPWM_T *epwm, uint32_t u32ChannelNum)
{
(epwm)->INTEN0 &= ~(EPWM_INTEN0_PIEN0_Msk << u32ChannelNum);
}
/**
* @brief Clear period interrupt of selected channel
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
* @return None
* @details This function is used to clear period interrupt of selected channel.
*/
void EPWM_ClearPeriodIntFlag(EPWM_T *epwm, uint32_t u32ChannelNum)
{
(epwm)->INTSTS0 = (EPWM_INTSTS0_PIF0_Msk << u32ChannelNum);
}
/**
* @brief Get period interrupt of selected channel
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
* @return Period interrupt flag of specified channel
* @retval 0 Period interrupt did not occur
* @retval 1 Period interrupt occurred
* @details This function is used to get period interrupt of selected channel.
*/
uint32_t EPWM_GetPeriodIntFlag(EPWM_T *epwm, uint32_t u32ChannelNum)
{
return ((((epwm)->INTSTS0 & (EPWM_INTSTS0_PIF0_Msk << u32ChannelNum))) ? 1UL : 0UL);
}
/**
* @brief Enable zero interrupt of selected channel
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
* @return None
* @details This function is used to enable zero interrupt of selected channel.
*/
void EPWM_EnableZeroInt(EPWM_T *epwm, uint32_t u32ChannelNum)
{
(epwm)->INTEN0 |= (EPWM_INTEN0_ZIEN0_Msk << u32ChannelNum);
}
/**
* @brief Disable zero interrupt of selected channel
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
* @return None
* @details This function is used to disable zero interrupt of selected channel.
*/
void EPWM_DisableZeroInt(EPWM_T *epwm, uint32_t u32ChannelNum)
{
(epwm)->INTEN0 &= ~(EPWM_INTEN0_ZIEN0_Msk << u32ChannelNum);
}
/**
* @brief Clear zero interrupt of selected channel
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
* @return None
* @details This function is used to clear zero interrupt of selected channel.
*/
void EPWM_ClearZeroIntFlag(EPWM_T *epwm, uint32_t u32ChannelNum)
{
(epwm)->INTSTS0 = (EPWM_INTSTS0_ZIF0_Msk << u32ChannelNum);
}
/**
* @brief Get zero interrupt of selected channel
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
* @return Zero interrupt flag of specified channel
* @retval 0 Zero interrupt did not occur
* @retval 1 Zero interrupt occurred
* @details This function is used to get zero interrupt of selected channel.
*/
uint32_t EPWM_GetZeroIntFlag(EPWM_T *epwm, uint32_t u32ChannelNum)
{
return ((((epwm)->INTSTS0 & (EPWM_INTSTS0_ZIF0_Msk << u32ChannelNum))) ? 1UL : 0UL);
}
/**
* @brief Enable interrupt flag accumulator of selected channel
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
* @param[in] u32IntFlagCnt Interrupt flag counter. Valid values are between 0~65535.
* @param[in] u32IntAccSrc Interrupt flag accumulator source selection.
* - \ref EPWM_IFA_ZERO_POINT
* - \ref EPWM_IFA_PERIOD_POINT
* - \ref EPWM_IFA_COMPARE_UP_COUNT_POINT
* - \ref EPWM_IFA_COMPARE_DOWN_COUNT_POINT
* @return None
* @details This function is used to enable interrupt flag accumulator of selected channel.
*/
void EPWM_EnableAcc(EPWM_T *epwm, uint32_t u32ChannelNum, uint32_t u32IntFlagCnt, uint32_t u32IntAccSrc)
{
(epwm)->IFA[u32ChannelNum] = (((epwm)->IFA[u32ChannelNum] & ~((EPWM_IFA0_IFACNT_Msk | EPWM_IFA0_IFASEL_Msk))) | \
(EPWM_IFA0_IFAEN_Msk | (u32IntAccSrc << EPWM_IFA0_IFASEL_Pos) | u32IntFlagCnt));
}
/**
* @brief Disable interrupt flag accumulator of selected channel
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
* @return None
* @details This function is used to Disable interrupt flag accumulator of selected channel.
*/
void EPWM_DisableAcc(EPWM_T *epwm, uint32_t u32ChannelNum)
{
(epwm)->IFA[u32ChannelNum] = ((epwm)->IFA[u32ChannelNum] & ~(EPWM_IFA0_IFAEN_Msk));
}
/**
* @brief Enable interrupt flag accumulator interrupt of selected channel
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
* @return None
* @details This function is used to enable interrupt flag accumulator interrupt of selected channel.
*/
void EPWM_EnableAccInt(EPWM_T *epwm, uint32_t u32ChannelNum)
{
(epwm)->AINTEN |= (1UL << (u32ChannelNum));
}
/**
* @brief Disable interrupt flag accumulator interrupt of selected channel
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
* @return None
* @details This function is used to disable interrupt flag accumulator interrupt of selected channel.
*/
void EPWM_DisableAccInt(EPWM_T *epwm, uint32_t u32ChannelNum)
{
(epwm)->AINTEN &= ~(1UL << (u32ChannelNum));
}
/**
* @brief Clear interrupt flag accumulator interrupt of selected channel
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
* @return None
* @details This function is used to clear interrupt flag accumulator interrupt of selected channel.
*/
void EPWM_ClearAccInt(EPWM_T *epwm, uint32_t u32ChannelNum)
{
(epwm)->AINTSTS = (1UL << (u32ChannelNum));
}
/**
* @brief Get interrupt flag accumulator interrupt of selected channel
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
* @retval 0 Accumulator interrupt did not occur
* @retval 1 Accumulator interrupt occurred
* @details This function is used to Get interrupt flag accumulator interrupt of selected channel.
*/
uint32_t EPWM_GetAccInt(EPWM_T *epwm, uint32_t u32ChannelNum)
{
return (((epwm)->AINTSTS & (1UL << (u32ChannelNum))) ? 1UL : 0UL);
}
/**
* @brief Enable accumulator PDMA of selected channel
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
* @return None
* @details This function is used to enable accumulator interrupt trigger PDMA of selected channel.
*/
void EPWM_EnableAccPDMA(EPWM_T *epwm, uint32_t u32ChannelNum)
{
(epwm)->APDMACTL |= (1UL << (u32ChannelNum));
}
/**
* @brief Disable accumulator PDMA of selected channel
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
* @return None
* @details This function is used to disable accumulator interrupt trigger PDMA of selected channel.
*/
void EPWM_DisableAccPDMA(EPWM_T *epwm, uint32_t u32ChannelNum)
{
(epwm)->APDMACTL &= ~(1UL << (u32ChannelNum));
}
/**
* @brief Enable interrupt flag accumulator stop mode of selected channel
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
* @return None
* @details This function is used to enable interrupt flag accumulator stop mode of selected channel.
*/
void EPWM_EnableAccStopMode(EPWM_T *epwm, uint32_t u32ChannelNum)
{
(epwm)->IFA[u32ChannelNum] |= EPWM_IFA0_STPMOD_Msk;
}
/**
* @brief Disable interrupt flag accumulator stop mode of selected channel
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
* @return None
* @details This function is used to disable interrupt flag accumulator stop mode of selected channel.
*/
void EPWM_DisableAccStopMode(EPWM_T *epwm, uint32_t u32ChannelNum)
{
(epwm)->IFA[u32ChannelNum] &= ~EPWM_IFA0_STPMOD_Msk;
}
/**
* @brief Clear free trigger duty interrupt flag of selected channel
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
* @return None
* @details This function is used to clear free trigger duty interrupt flag of selected channel.
*/
void EPWM_ClearFTDutyIntFlag(EPWM_T *epwm, uint32_t u32ChannelNum)
{
(epwm)->FTCI = ((EPWM_FTCI_FTCMU0_Msk | EPWM_FTCI_FTCMD0_Msk) << (u32ChannelNum >> 1));
}
/**
* @brief Get free trigger duty interrupt flag of selected channel
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
* @return Duty interrupt flag of specified channel
* @retval 0 Free trigger duty interrupt did not occur
* @retval 1 Free trigger duty interrupt occurred
* @details This function is used to get free trigger duty interrupt flag of selected channel.
*/
uint32_t EPWM_GetFTDutyIntFlag(EPWM_T *epwm, uint32_t u32ChannelNum)
{
return (((epwm)->FTCI & ((EPWM_FTCI_FTCMU0_Msk | EPWM_FTCI_FTCMD0_Msk) << (u32ChannelNum >> 1))) ? 1UL : 0UL);
}
/**
* @brief Enable load mode of selected channel
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
* @param[in] u32LoadMode EPWM counter loading mode.
* - \ref EPWM_LOAD_MODE_IMMEDIATE
* - \ref EPWM_LOAD_MODE_WINDOW
* - \ref EPWM_LOAD_MODE_CENTER
* @return None
* @details This function is used to enable load mode of selected channel.
*/
void EPWM_EnableLoadMode(EPWM_T *epwm, uint32_t u32ChannelNum, uint32_t u32LoadMode)
{
(epwm)->CTL0 |= (u32LoadMode << u32ChannelNum);
}
/**
* @brief Disable load mode of selected channel
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
* @param[in] u32LoadMode EPWM counter loading mode.
* - \ref EPWM_LOAD_MODE_IMMEDIATE
* - \ref EPWM_LOAD_MODE_WINDOW
* - \ref EPWM_LOAD_MODE_CENTER
* @return None
* @details This function is used to disable load mode of selected channel.
*/
void EPWM_DisableLoadMode(EPWM_T *epwm, uint32_t u32ChannelNum, uint32_t u32LoadMode)
{
(epwm)->CTL0 &= ~(u32LoadMode << u32ChannelNum);
}
/**
* @brief Configure synchronization phase of selected channel
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
* @param[in] u32SyncSrc EPWM synchronize source selection.
* - \ref EPWM_SYNC_OUT_FROM_SYNCIN_SWSYNC
* - \ref EPWM_SYNC_OUT_FROM_COUNT_TO_ZERO
* - \ref EPWM_SYNC_OUT_FROM_COUNT_TO_COMPARATOR
* - \ref EPWM_SYNC_OUT_DISABLE
* @param[in] u32Direction Phase direction. Control EPWM counter count decrement or increment after synchronizing.
* - \ref EPWM_PHS_DIR_DECREMENT
* - \ref EPWM_PHS_DIR_INCREMENT
* @param[in] u32StartPhase Synchronous start phase value. Valid values are between 0~65535.
* @return None
* @details This function is used to configure synchronization phase of selected channel.
* @note Every two channels share the same setting.
*/
void EPWM_ConfigSyncPhase(EPWM_T *epwm, uint32_t u32ChannelNum, uint32_t u32SyncSrc, uint32_t u32Direction, uint32_t u32StartPhase)
{
/* every two channels shares the same setting */
u32ChannelNum >>= 1;
(epwm)->SYNC = (((epwm)->SYNC & ~((EPWM_SYNC_SINSRC0_Msk << (u32ChannelNum << 1)) | (EPWM_SYNC_PHSDIR0_Msk << u32ChannelNum))) | \
(u32Direction << EPWM_SYNC_PHSDIR0_Pos << u32ChannelNum) | (u32SyncSrc << EPWM_SYNC_SINSRC0_Pos) << (u32ChannelNum << 1));
(epwm)->PHS[(u32ChannelNum)] = u32StartPhase;
}
/**
* @brief Enable SYNC phase of selected channel(s)
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelMask Combination of enabled channels. Each bit corresponds to a channel.
* Bit 0 is channel 0, bit 1 is channel 1...
* @return None
* @details This function is used to enable SYNC phase of selected channel(s).
* @note Every two channels share the same setting.
*/
void EPWM_EnableSyncPhase(EPWM_T *epwm, uint32_t u32ChannelMask)
{
uint32_t i;
for(i = 0UL; i < EPWM_CHANNEL_NUM; i ++)
{
if(u32ChannelMask & (1UL << i))
{
(epwm)->SYNC |= (EPWM_SYNC_PHSEN0_Msk << (i >> 1));
}
}
}
/**
* @brief Disable SYNC phase of selected channel(s)
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelMask Combination of enabled channels. Each bit corresponds to a channel.
* Bit 0 is channel 0, bit 1 is channel 1...
* @return None
* @details This function is used to disable SYNC phase of selected channel(s).
* @note Every two channels share the same setting.
*/
void EPWM_DisableSyncPhase(EPWM_T *epwm, uint32_t u32ChannelMask)
{
uint32_t i;
for(i = 0UL; i < EPWM_CHANNEL_NUM; i ++)
{
if(u32ChannelMask & (1UL << i))
{
(epwm)->SYNC &= ~(EPWM_SYNC_PHSEN0_Msk << (i >> 1));
}
}
}
/**
* @brief Enable EPWM SYNC_IN noise filter function
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ClkCnt SYNC Edge Detector Filter Count. This controls the counter number of edge detector.
* The valid value is 0~7.
* @param[in] u32ClkDivSel SYNC Edge Detector Filter Clock Selection.
* - \ref EPWM_NF_CLK_DIV_1
* - \ref EPWM_NF_CLK_DIV_2
* - \ref EPWM_NF_CLK_DIV_4
* - \ref EPWM_NF_CLK_DIV_8
* - \ref EPWM_NF_CLK_DIV_16
* - \ref EPWM_NF_CLK_DIV_32
* - \ref EPWM_NF_CLK_DIV_64
* - \ref EPWM_NF_CLK_DIV_128
* @return None
* @details This function is used to enable EPWM SYNC_IN noise filter function.
*/
void EPWM_EnableSyncNoiseFilter(EPWM_T *epwm, uint32_t u32ClkCnt, uint32_t u32ClkDivSel)
{
(epwm)->SYNC = ((epwm)->SYNC & ~(EPWM_SYNC_SFLTCNT_Msk | EPWM_SYNC_SFLTCSEL_Msk)) | \
((u32ClkCnt << EPWM_SYNC_SFLTCNT_Pos) | (u32ClkDivSel << EPWM_SYNC_SFLTCSEL_Pos) | EPWM_SYNC_SNFLTEN_Msk);
}
/**
* @brief Disable EPWM SYNC_IN noise filter function
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @return None
* @details This function is used to Disable EPWM SYNC_IN noise filter function.
*/
void EPWM_DisableSyncNoiseFilter(EPWM_T *epwm)
{
(epwm)->SYNC &= ~EPWM_SYNC_SNFLTEN_Msk;
}
/**
* @brief Enable EPWM SYNC input pin inverse function
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @return None
* @details This function is used to enable EPWM SYNC input pin inverse function.
*/
void EPWM_EnableSyncPinInverse(EPWM_T *epwm)
{
(epwm)->SYNC |= EPWM_SYNC_SINPINV_Msk;
}
/**
* @brief Disable EPWM SYNC input pin inverse function
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @return None
* @details This function is used to Disable EPWM SYNC input pin inverse function.
*/
void EPWM_DisableSyncPinInverse(EPWM_T *epwm)
{
(epwm)->SYNC &= (~EPWM_SYNC_SINPINV_Msk);
}
/**
* @brief Set EPWM clock source
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
* @param[in] u32ClkSrcSel EPWM external clock source.
* - \ref EPWM_CLKSRC_EPWM_CLK
* - \ref EPWM_CLKSRC_TIMER0
* - \ref EPWM_CLKSRC_TIMER1
* - \ref EPWM_CLKSRC_TIMER2
* - \ref EPWM_CLKSRC_TIMER3
* @return None
* @details This function is used to set EPWM clock source.
* @note Every two channels share the same setting.
* @note If the clock source of EPWM counter is selected from TIMERn interrupt events, the TRGEPWM(TIMERn_TRGCTL[1], n=0,1..3) bit must be set as 1.
*/
void EPWM_SetClockSource(EPWM_T *epwm, uint32_t u32ChannelNum, uint32_t u32ClkSrcSel)
{
(epwm)->CLKSRC = ((epwm)->CLKSRC & ~(EPWM_CLKSRC_ECLKSRC0_Msk << ((u32ChannelNum >> 1) << 3))) | \
(u32ClkSrcSel << ((u32ChannelNum >> 1) << 3));
}
/**
* @brief Enable EPWM brake noise filter function
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32BrakePinNum Brake pin selection. Valid values are 0 or 1.
* @param[in] u32ClkCnt SYNC Edge Detector Filter Count. This controls the counter number of edge detector
* @param[in] u32ClkDivSel SYNC Edge Detector Filter Clock Selection.
* - \ref EPWM_NF_CLK_DIV_1
* - \ref EPWM_NF_CLK_DIV_2
* - \ref EPWM_NF_CLK_DIV_4
* - \ref EPWM_NF_CLK_DIV_8
* - \ref EPWM_NF_CLK_DIV_16
* - \ref EPWM_NF_CLK_DIV_32
* - \ref EPWM_NF_CLK_DIV_64
* - \ref EPWM_NF_CLK_DIV_128
* @return None
* @details This function is used to enable EPWM brake noise filter function.
*/
void EPWM_EnableBrakeNoiseFilter(EPWM_T *epwm, uint32_t u32BrakePinNum, uint32_t u32ClkCnt, uint32_t u32ClkDivSel)
{
(epwm)->BNF = ((epwm)->BNF & ~((EPWM_BNF_BRK0FCNT_Msk | EPWM_BNF_BRK0NFSEL_Msk) << (u32BrakePinNum << 3))) | \
(((u32ClkCnt << EPWM_BNF_BRK0FCNT_Pos) | (u32ClkDivSel << EPWM_BNF_BRK0NFSEL_Pos) | EPWM_BNF_BRK0NFEN_Msk) << (u32BrakePinNum << 3));
}
/**
* @brief Disable EPWM brake noise filter function
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32BrakePinNum Brake pin selection. Valid values are 0 or 1.
* @return None
* @details This function is used to disable EPWM brake noise filter function.
*/
void EPWM_DisableBrakeNoiseFilter(EPWM_T *epwm, uint32_t u32BrakePinNum)
{
(epwm)->BNF &= ~(EPWM_BNF_BRK0NFEN_Msk << (u32BrakePinNum << 3));
}
/**
* @brief Enable EPWM brake pin inverse function
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32BrakePinNum Brake pin selection. Valid values are 0 or 1.
* @return None
* @details This function is used to enable EPWM brake pin inverse function.
*/
void EPWM_EnableBrakePinInverse(EPWM_T *epwm, uint32_t u32BrakePinNum)
{
(epwm)->BNF |= (EPWM_BNF_BRK0PINV_Msk << (u32BrakePinNum << 3));
}
/**
* @brief Disable EPWM brake pin inverse function
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32BrakePinNum Brake pin selection. Valid values are 0 or 1.
* @return None
* @details This function is used to disable EPWM brake pin inverse function.
*/
void EPWM_DisableBrakePinInverse(EPWM_T *epwm, uint32_t u32BrakePinNum)
{
(epwm)->BNF &= ~(EPWM_BNF_BRK0PINV_Msk << (u32BrakePinNum * (uint32_t)EPWM_BNF_BRK1NFEN_Pos));
}
/**
* @brief Set EPWM brake pin source
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32BrakePinNum Brake pin selection. Valid values are 0 or 1.
* @param[in] u32SelAnotherModule Select to another module. Valid values are TRUE or FALSE.
* @return None
* @details This function is used to set EPWM brake pin source.
*/
void EPWM_SetBrakePinSource(EPWM_T *epwm, uint32_t u32BrakePinNum, uint32_t u32SelAnotherModule)
{
(epwm)->BNF = ((epwm)->BNF & ~(EPWM_BNF_BK0SRC_Msk << (u32BrakePinNum << 3))) | (u32SelAnotherModule << ((uint32_t)EPWM_BNF_BK0SRC_Pos + (u32BrakePinNum << 3)));
}
/**
* @brief Set EPWM leading edge blanking function
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32TrigSrcSel Leading edge blanking source selection.
* - \ref EPWM_LEBCTL_SRCEN0
* - \ref EPWM_LEBCTL_SRCEN2
* - \ref EPWM_LEBCTL_SRCEN4
* - \ref EPWM_LEBCTL_SRCEN0_2
* - \ref EPWM_LEBCTL_SRCEN0_4
* - \ref EPWM_LEBCTL_SRCEN2_4
* - \ref EPWM_LEBCTL_SRCEN0_2_4
* @param[in] u32TrigType Leading edge blanking trigger type.
* - \ref EPWM_LEBCTL_TRGTYPE_RISING
* - \ref EPWM_LEBCTL_TRGTYPE_FALLING
* - \ref EPWM_LEBCTL_TRGTYPE_RISING_OR_FALLING
* @param[in] u32BlankingCnt Leading Edge Blanking Counter. Valid values are between 1~512.
This counter value decides leading edge blanking window size, and this counter clock base is ECLK.
* @param[in] u32BlankingEnable Enable EPWM leading edge blanking function. Valid values are TRUE (ENABLE) or FALSE (DISABLE).
* - \ref FALSE
* - \ref TRUE
* @return None
* @details This function is used to configure EPWM leading edge blanking function that blank the false trigger from ACMP brake source which may cause by EPWM output transition.
* @note EPWM leading edge blanking function is only used for brake source from ACMP.
*/
void EPWM_SetLeadingEdgeBlanking(EPWM_T *epwm, uint32_t u32TrigSrcSel, uint32_t u32TrigType, uint32_t u32BlankingCnt, uint32_t u32BlankingEnable)
{
(epwm)->LEBCTL = (u32TrigType) | (u32TrigSrcSel) | (u32BlankingEnable);
/* Blanking window size = LEBCNT + 1, so LEBCNT = u32BlankingCnt - 1 */
(epwm)->LEBCNT = (u32BlankingCnt) - 1UL;
}
/**
* @brief Get the time-base counter reached its maximum value flag of selected channel
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
* @return Count to max interrupt flag of specified channel
* @retval 0 Count to max interrupt did not occur
* @retval 1 Count to max interrupt occurred
* @details This function is used to get the time-base counter reached its maximum value flag of selected channel.
*/
uint32_t EPWM_GetWrapAroundFlag(EPWM_T *epwm, uint32_t u32ChannelNum)
{
return (((epwm)->STATUS & (EPWM_STATUS_CNTMAXF0_Msk << u32ChannelNum)) ? 1UL : 0UL);
}
/**
* @brief Clear the time-base counter reached its maximum value flag of selected channel
* @param[in] epwm The pointer of the specified EPWM module
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
* @return None
* @details This function is used to clear the time-base counter reached its maximum value flag of selected channel.
*/
void EPWM_ClearWrapAroundFlag(EPWM_T *epwm, uint32_t u32ChannelNum)
{
(epwm)->STATUS = (EPWM_STATUS_CNTMAXF0_Msk << u32ChannelNum);
}
/**
* @brief Enable fault detect of selected channel.
* @param[in] epwm The pointer of the specified EPWM module.
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5.
* @param[in] u32AfterPrescaler Fault Detect Clock Source is from prescaler output. Valid values are TRUE (after prescaler) or FALSE (before prescaler).
* @param[in] u32ClkSel Fault Detect Clock Select.
* - \ref EPWM_FDCTL_FDCKSEL_CLK_DIV_1
* - \ref EPWM_FDCTL_FDCKSEL_CLK_DIV_2
* - \ref EPWM_FDCTL_FDCKSEL_CLK_DIV_4
* - \ref EPWM_FDCTL_FDCKSEL_CLK_DIV_8
* @return None
* @details This function is used to enable fault detect of selected channel.
*/
void EPWM_EnableFaultDetect(EPWM_T *epwm, uint32_t u32ChannelNum, uint32_t u32AfterPrescaler, uint32_t u32ClkSel)
{
(epwm)->FDEN = ((epwm)->FDEN & ~(EPWM_FDEN_FDCKS0_Msk << (u32ChannelNum))) | \
((EPWM_FDEN_FDEN0_Msk | ((u32AfterPrescaler) << EPWM_FDEN_FDCKS0_Pos)) << (u32ChannelNum));
(epwm)->FDCTL[(u32ChannelNum)] = ((epwm)->FDCTL[(u32ChannelNum)] & ~EPWM_FDCTL0_FDCKSEL_Msk) | (u32ClkSel);
}
/**
* @brief Disable fault detect of selected channel.
* @param[in] epwm The pointer of the specified EPWM module.
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5.
* @return None
* @details This function is used to disable fault detect of selected channel.
*/
void EPWM_DisableFaultDetect(EPWM_T *epwm, uint32_t u32ChannelNum)
{
(epwm)->FDEN &= ~(EPWM_FDEN_FDEN0_Msk << (u32ChannelNum));
}
/**
* @brief Enable fault detect output of selected channel.
* @param[in] epwm The pointer of the specified EPWM module.
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5.
* @return None
* @details This function is used to enable fault detect output of selected channel.
*/
void EPWM_EnableFaultDetectOutput(EPWM_T *epwm, uint32_t u32ChannelNum)
{
(epwm)->FDEN &= ~(EPWM_FDEN_FDODIS0_Msk << (u32ChannelNum));
}
/**
* @brief Disable fault detect output of selected channel.
* @param[in] epwm The pointer of the specified EPWM module.
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5.
* @return None
* @details This function is used to disable fault detect output of selected channel.
*/
void EPWM_DisableFaultDetectOutput(EPWM_T *epwm, uint32_t u32ChannelNum)
{
(epwm)->FDEN |= (EPWM_FDEN_FDODIS0_Msk << (u32ChannelNum));
}
/**
* @brief Enable fault detect deglitch function of selected channel.
* @param[in] epwm The pointer of the specified EPWM module.
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5.
* @param[in] u32DeglitchSmpCycle Deglitch Sampling Cycle. Valid values are between 0~7.
* @return None
* @details This function is used to enable fault detect deglitch function of selected channel.
*/
void EPWM_EnableFaultDetectDeglitch(EPWM_T *epwm, uint32_t u32ChannelNum, uint32_t u32DeglitchSmpCycle)
{
(epwm)->FDCTL[(u32ChannelNum)] = ((epwm)->FDCTL[(u32ChannelNum)] & (~EPWM_FDCTL0_DGSMPCYC_Msk)) | \
(EPWM_FDCTL0_FDDGEN_Msk | ((u32DeglitchSmpCycle) << EPWM_FDCTL0_DGSMPCYC_Pos));
}
/**
* @brief Disable fault detect deglitch function of selected channel.
* @param[in] epwm The pointer of the specified EPWM module.
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5.
* @return None
* @details This function is used to disable fault detect deglitch function of selected channel.
*/
void EPWM_DisableFaultDetectDeglitch(EPWM_T *epwm, uint32_t u32ChannelNum)
{
(epwm)->FDCTL[(u32ChannelNum)] &= ~EPWM_FDCTL0_FDDGEN_Msk;
}
/**
* @brief Enable fault detect mask function of selected channel.
* @param[in] epwm The pointer of the specified EPWM module.
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5.
* @param[in] u32MaskCnt Transition mask counter. Valid values are between 0~0x7F.
* @return None
* @details This function is used to enable fault detect mask function of selected channel.
*/
void EPWM_EnableFaultDetectMask(EPWM_T *epwm, uint32_t u32ChannelNum, uint32_t u32MaskCnt)
{
(epwm)->FDCTL[(u32ChannelNum)] = ((epwm)->FDCTL[(u32ChannelNum)] & (~EPWM_FDCTL0_TRMSKCNT_Msk)) | (EPWM_FDCTL0_FDMSKEN_Msk | (u32MaskCnt));
}
/**
* @brief Disable fault detect mask function of selected channel.
* @param[in] epwm The pointer of the specified EPWM module.
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5.
* @return None
* @details This function is used to disable fault detect mask function of selected channel.
*/
void EPWM_DisableFaultDetectMask(EPWM_T *epwm, uint32_t u32ChannelNum)
{
(epwm)->FDCTL[(u32ChannelNum)] &= ~EPWM_FDCTL0_FDMSKEN_Msk;
}
/**
* @brief Enable fault detect interrupt of selected channel.
* @param[in] epwm The pointer of the specified EPWM module.
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5.
* @return None
* @details This function is used to enable fault detect interrupt of selected channel.
*/
void EPWM_EnableFaultDetectInt(EPWM_T *epwm, uint32_t u32ChannelNum)
{
(epwm)->FDIEN |= (EPWM_FDIEN_FDIEN0_Msk << (u32ChannelNum));
}
/**
* @brief Disable fault detect interrupt of selected channel.
* @param[in] epwm The pointer of the specified EPWM module.
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5.
* @return None
* @details This function is used to disable fault detect interrupt of selected channel.
*/
void EPWM_DisableFaultDetectInt(EPWM_T *epwm, uint32_t u32ChannelNum)
{
(epwm)->FDIEN &= ~(EPWM_FDIEN_FDIEN0_Msk << (u32ChannelNum));
}
/**
* @brief Clear fault detect interrupt of selected channel.
* @param[in] epwm The pointer of the specified EPWM module.
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5.
* @return None
* @details This function is used to clear fault detect interrupt of selected channel.
*/
void EPWM_ClearFaultDetectInt(EPWM_T *epwm, uint32_t u32ChannelNum)
{
(epwm)->FDSTS = (EPWM_FDSTS_FDIF0_Msk << (u32ChannelNum));
}
/**
* @brief Get fault detect interrupt of selected channel.
* @param[in] epwm The pointer of the specified EPWM module.
* - EPWM0 : EPWM Group 0
* - EPWM1 : EPWM Group 1
* @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5.
* @retval 0 Fault detect interrupt did not occur.
* @retval 1 Fault detect interrupt occurred.
* @details This function is used to Get fault detect interrupt of selected channel.
*/
uint32_t EPWM_GetFaultDetectInt(EPWM_T *epwm, uint32_t u32ChannelNum)
{
return (((epwm)->FDSTS & (EPWM_FDSTS_FDIF0_Msk << (u32ChannelNum))) ? 1UL : 0UL);
}
/**@}*/ /* end of group EPWM_EXPORTED_FUNCTIONS */
/**@}*/ /* end of group EPWM_Driver */
/**@}*/ /* end of group Standard_Driver */
|