brazos-trapezoidal
Feedbacks.c
Go to the documentation of this file.
1
14//-------------------------------------- Include Files ----------------------------------------------------------------
15#include "Feedbacks.h"
16
17//-------------------------------------- PUBLIC (Variables) -----------------------------------------------------------
18
19
20//-------------------------------------- PRIVATE (Variables, Constants & Defines) -------------------------------------
21#define FEEDBACKS_GET_CURR() TrapSless__GetVars()->bus_curr
22#define FEEDBACKS_GET_MOD_IDX() TrapSless__GetVars()->dutyOut
23#define FEEDBACKS_GET_VBUS() TrapSless__GetVars()->bus_volt
24
25#define IRMS_TIME_CNTER_RELOAD 16 /* Call rate 16Khz - 1s*/
26
27FEEDBACKS_TYPE Feedbacks;
28uint32_t IrmsTimerCnter;
29uint32_t IrmsCnter;
30int64_t IrmsSum;
31int64_t VrmsSum;
32//-------------------------------------- PRIVATE (Function Prototypes) ------------------------------------------------
33
34//=====================================================================================================================
35//-------------------------------------- Public Functions -------------------------------------------------------------
36//=====================================================================================================================
37
38
39void Feedbacks__Init(void) {
40 IrmsCnter = 1;
41
42 Feedbacks.BaseAA = K2_CURR_BASE * K2_CURR_BASE;
43 Feedbacks.BaseA = K2_CURR_BASE;
44 Feedbacks.BaseV = K2_VOLT_BASE;
45 Feedbacks.BaseVV = K2_VOLT_BASE * K2_VOLT_BASE;
46 Feedbacks.BasePW = K2_VOLT_BASE * K2_CURR_BASE;
47 Feedbacks.BaseModIx = K2_TRAP_PWM_AT_DUTY_MAX_CNTS;
48}
49
50void Feedbacks__Handler(void) {
51 int32_t tmp;
52 int64_t tmp1;
53
54 if(IrmsTimerCnter) {
55 IrmsTimerCnter--;
56 /*Averaging*/
57 tmp = FEEDBACKS_GET_CURR();
58 IrmsSum += tmp * tmp;
59 tmp1= FEEDBACKS_GET_VBUS();
60 VrmsSum += tmp1 * tmp1;
61
62 IrmsCnter++;
63 }
64 else {
65 /*Calculation of Rms*/
66 if(IrmsCnter > 0) {
67 tmp = IrmsSum / IRMS_TIME_CNTER_RELOAD;
68 Feedbacks.IrmsIrmsPhase = tmp;
69
70 tmp = VrmsSum / IRMS_TIME_CNTER_RELOAD;
71
72 Feedbacks.VbusRms = tmp;
73 }
74
75 IrmsCnter = 0;
76 IrmsSum = 0;
77 VrmsSum = 0;
78 IrmsTimerCnter = IRMS_TIME_CNTER_RELOAD;
79 }
80
81 Feedbacks.ModIdx = FEEDBACKS_GET_MOD_IDX();
82
83
84 /*Getting the RMS from current
85 * Irms = SQRT( Feedbacks.IrmsIrmsPhase * Feedbacks.BaseAA / 32768 / 32768 )
86 * */
87 /*Getting the RMS from voltage
88 * Vrms = SQRT( Feedbacks.VbusRms * Feedbacks.BaseVV / 32768 / 32768 )
89 * */
90 /*Getting Power
91 * Pw = Vrms * Irms;
92 * */
93 /*Getting Mod Idx
94 * ModIdx = Feedbacks.ModIdx * 100 / Feedbacks.BaseModIx;
95 * */
96}
97
98FEEDBACKS_TYPE * Feedbacks__GetVars(void) {
99 return &Feedbacks;
100}
101
102
103//=====================================================================================================================
104//-------------------------------------- Private Functions ------------------------------------------------------------
105//=====================================================================================================================
#define FEEDBACKS_GET_CURR()
Definition: Feedbacks.c:21