brazos-trapezoidal
SRMCAtod.c
Go to the documentation of this file.
1
13//-------------------------------------- Include Files ----------------------------------------------------------------
14#include "uc.h"
15#include "Compiler_defs.h"
16#include "C_Extensions.h"
17#include "SRMicro.h"
18#include "SRMCAtod.h"
19
20//-------------------------------------- PUBLIC (Variables) -----------------------------------------------------------
21#define US10 167U // constant corresponding to 0.01 ms @100MHz
22
23#define FILTER_FC_HZ 212
24#define FILTER_FS_HZ 1000
25#define FILTER_TAU (1/(2*3.1416*FILTER_FC_HZ))
26#define FILTER_TS (1.0f/FILTER_FS_HZ)
27
28typedef struct
29{
31 float vol_ref;
33 float k_vref;
34
36
40 float SR_Vr_Ulpkt, NSR_Vr_Ulpkt;
41 // Reference variable for analog input
42 ANALOG_REF_TYPE SR_AdRef, NSR_AdRef;
43
44//-------------------------------------- PRIVATE (Variables, Constants & Defines) -------------------------------------
45 static SRMCATOD_DIAG_STATE_TYPE state = SR_WAITING_TO_CHECK;
46 static SRMCATOD_DIAG_ERROR_TYPE fault_holder = SR_TEST_NOT_PERFORMED;
47 static signed short int threshold;
48
49//-------------------------------------- PRIVATE (Function Prototypes) ------------------------------------------------
50static void SRInitializeS12AD0(void);
51static void SRInitializeS12AD1(void);
52static void EnableEndOfConversionInteruption(SRMCATOD_CONVERTER_TYPE engine);
53static void SREnableSelfDiagMode(SRMCATOD_CONVERTER_TYPE engine, SRMCATOD_DIAG_CONFIG_TYPE mode);
54static SRMCATOD_DIAG_ERROR_TYPE IsConverterSafe(SRMCATOD_CONVERTER_TYPE engine,signed short int thresold);
55static void SRUtilityDelay(unsigned long time);
56float SRCalcLPKT(float tau ,float tc );
57
58//=====================================================================================================================
59//-------------------------------------- Public Functions -------------------------------------------------------------
60//=====================================================================================================================
61//---------------------------------------------------------------------------------------------------------------------
62
68{
69
70}
71
75volatile unsigned short ForcedCurrA;
76void SRMCAtod__ISR(void)
77{
78#ifndef SIMU
79 mc_t vbus;
80 ABC_t curr;
81 mc_t curr_n;
82 ABC_t volt;
83
84
85 /* ADC values update*/
86// vbus = MATHLIB_MPY(SRMCATOD__GETDCBUSVOLTAGE(), CAL_GET_ADC_CNT_TO_VOLT(0));
87 vbus = SRMCATOD__GETDCBUSVOLTAGE();
88
89// curr.a = -MATHLIB_MPY(SRMCATOD__GETADC1()-CAL_GET_ADC_CNT_TO_AMP_OFFSET(0), CAL_GET_ADC_CNT_TO_AMP_SLOPE(0));
90 curr.a = SRMCATOD__GETADC1();
91 if(ForcedCurrA) {
92 curr.a = MATHLIB_MPY(ForcedCurrA-CAL_GET_ADC_CNT_TO_AMP_OFFSET(0), CAL_GET_ADC_CNT_TO_AMP_SLOPE(0));
93 }
94// curr.b = -MATHLIB_MPY(SRMCATOD__GETADC2()-CAL_GET_ADC_CNT_TO_AMP_OFFSET(0), CAL_GET_ADC_CNT_TO_AMP_SLOPE(0));
95 curr.b = SRMCATOD__GETADC2();
96 curr.c = -curr.a-curr.b;//MATHLIB_MPY(SRMCATOD__GETADC3()-CAL_GET_ADC_CNT_TO_AMP_OFFSET(), CAL_GET_ADC_CNT_TO_AMP_SLOPE());
97
98// volt.a = MATHLIB_MPY(SRMCATOD__GETPOLE1(), CAL_GET_ADC_CNT_TO_VOLT(0));
99// volt.b = MATHLIB_MPY(SRMCATOD__GETPOLE2(), CAL_GET_ADC_CNT_TO_VOLT(0));
100// volt.c = MATHLIB_MPY(SRMCATOD__GETPOLE3(), CAL_GET_ADC_CNT_TO_VOLT(0));
101 volt.a = SRMCATOD__GETPOLE1();
102 volt.b = SRMCATOD__GETPOLE2();
103 volt.c = SRMCATOD__GETPOLE3();
104
105 Ctrl_setAtoD(0, vbus, curr, volt);
106
107 curr_n = (curr.a + curr.b + curr.c)/3;
108 curr.a -= curr_n;
109 curr.b -= curr_n;
110 curr.c -= curr_n;
111
112 if( (MATHLIB_ABS(curr.a) > CAL_GET_MAX_CURRENT(0)) ||
113 (MATHLIB_ABS(curr.b) > CAL_GET_MAX_CURRENT(0)) ||
114 (MATHLIB_ABS(curr.c) > CAL_GET_MAX_CURRENT(0)) ) {
115 //StateMachine_ExternalFault(0);
116 }
117#endif
118}
119
120void SRMCAtod__ISR2(void)
121{
122#ifndef SIMU
123 mc_t vbus;
124 ABC_t curr;
125 mc_t curr_n;
126 ABC_t volt;
127
128 /* ADC values update*/
129 vbus = MATHLIB_MPY(SRMCATOD__GETDCBUSVOLTAGE(), CAL_GET_ADC_CNT_TO_VOLT(1));
130
131 curr.a = -MATHLIB_MPY(SRMCATOD__GETADC3()-CAL_GET_ADC_CNT_TO_AMP_OFFSET(1), CAL_GET_ADC_CNT_TO_AMP_SLOPE(1));
132 if(ForcedCurrA) {
133 curr.a = MATHLIB_MPY(ForcedCurrA-CAL_GET_ADC_CNT_TO_AMP_OFFSET(1), CAL_GET_ADC_CNT_TO_AMP_SLOPE(1));
134 }
135 curr.b = -MATHLIB_MPY(SRMCATOD__GETADC4()-CAL_GET_ADC_CNT_TO_AMP_OFFSET(1), CAL_GET_ADC_CNT_TO_AMP_SLOPE(1));
136 curr.c = -curr.a-curr.b;//MATHLIB_MPY(SRMCATOD__GETADC3()-CAL_GET_ADC_CNT_TO_AMP_OFFSET(), CAL_GET_ADC_CNT_TO_AMP_SLOPE());
137
138 volt.a = MATHLIB_MPY(SRMCATOD__GETPOLE4(), CAL_GET_ADC_CNT_TO_VOLT(1));
139 volt.b = MATHLIB_MPY(SRMCATOD__GETPOLE5(), CAL_GET_ADC_CNT_TO_VOLT(1));
140 volt.c = MATHLIB_MPY(SRMCATOD__GETPOLE6(), CAL_GET_ADC_CNT_TO_VOLT(1));
141
142 Ctrl_setAtoD(1, vbus, curr, volt);
143 curr_n = (curr.a + curr.b + curr.c)/3;
144 curr.a -= curr_n;
145 curr.b -= curr_n;
146 curr.c -= curr_n;
147
148 if( (MATHLIB_ABS(curr.a) > CAL_GET_MAX_CURRENT(1)) ||
149 (MATHLIB_ABS(curr.b) > CAL_GET_MAX_CURRENT(1)) ||
150 (MATHLIB_ABS(curr.c) > CAL_GET_MAX_CURRENT(1)) ) {
151// StateMachine_ExternalFault(1);
152 }
153#endif
154}
155
163{
164
165}
166
171void SRMCAtod__EnableDiagnostic(signed short int commanded_threshold)
172{
173 // Defines new threshold for this verification
174}
175
181SRMCATOD_DIAG_ERROR_TYPE SRMCAtod__GetDiagnosticFeedback(void)
182{
183 return(0); // Returns status
184}
185
186//=====================================================================================================================
187//-------------------------------------- Private Functions ------------------------------------------------------------
188//=====================================================================================================================
189
194static void SRInitializeS12AD0(void)
195{
196
197} // Enables only end of conversion from S12AD0 since S12AD1 will finish at the same time
198
203static void EnableEndOfConversionInteruption(SRMCATOD_CONVERTER_TYPE engine)
204{
205
206}
207
212static void SRInitializeS12AD1(void)
213{
214
215} // This is triggered by MCPwm in down counting mode (see MTU4.TADCR)
216
224static void SREnableSelfDiagMode(SRMCATOD_CONVERTER_TYPE engine, SRMCATOD_DIAG_CONFIG_TYPE mode)
225{
226}
227
236static SRMCATOD_DIAG_ERROR_TYPE IsConverterSafe(SRMCATOD_CONVERTER_TYPE engine,signed short int local_threshold)
237{ // Returns status
238 return(0);
239}
240
241
247static void SRUtilityDelay(unsigned long time)
248{
249
250}
251
252
253
254
259{
260
261}
262
263
264
270{
271
272
273}
274
275
281{
282 return(0);
283}
284
This file contains the definition of commonly used Macro and Enumerators.
Basic description of file contents.
float SR_Off_Ulpkt
current offsets filter time constant (1/x)
Definition: SRMCAtod.c:38
void SRMCAtod__EnableDiagnostic(signed short int commanded_threshold)
Definition: SRMCAtod.c:171
void SRMCAtod__DiagnosticHandler(void)
Definition: SRMCAtod.c:162
void SRMCAtod__InitReadVref(void)
It read the Vref voltage at the start up.
Definition: SRMCAtod.c:258
float SRMCAtod__GetKRef(void)
This function is used to get the ad correction related the VREF.
Definition: SRMCAtod.c:280
volatile unsigned short ForcedCurrA
Definition: SRMCAtod.c:75
float SR_Vr_Ulpkt
reference voltage filter time constant (1/x)
Definition: SRMCAtod.c:40
SRMCATOD_DIAG_ERROR_TYPE SRMCAtod__GetDiagnosticFeedback(void)
Definition: SRMCAtod.c:181
void SRMCAtod__Initialize(void)
Definition: SRMCAtod.c:67
void SRMCAtod__Read_Vref(void)
voltage reference reading, filtering and A/D conversion constants correction
Definition: SRMCAtod.c:269
Header for motor control analog conversions.
float k_vref
constant related to vol_ref
Definition: SRMCAtod.c:33
float vol_ref
reference voltage
Definition: SRMCAtod.c:31