Rev 1638 | Rev 1793 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1638 | Rev 1672 | ||
---|---|---|---|
Line 68... | Line 68... | ||
68 | void Capacity_Init(void) |
68 | void Capacity_Init(void) |
69 | { |
69 | { |
70 | Capacity.ActualCurrent = 0; |
70 | Capacity.ActualCurrent = 0; |
71 | Capacity.UsedCapacity = 0; |
71 | Capacity.UsedCapacity = 0; |
72 | Capacity.ActualPower = 0; |
72 | Capacity.ActualPower = 0; |
- | 73 | Capacity.MinOfMaxPWM = 0; |
|
73 | update_timer = SetDelay(CAPACITY_UPDATE_INTERVAL); |
74 | update_timer = SetDelay(CAPACITY_UPDATE_INTERVAL); |
74 | } |
75 | } |
Line 75... | Line 76... | ||
75 | 76 | ||
Line 79... | Line 80... | ||
79 | { |
80 | { |
80 | unsigned short Current, SetSum; // max value will be 255 * 12 = 3060 |
81 | unsigned short Current, SetSum; // max value will be 255 * 12 = 3060 |
81 | static unsigned short SubCounter = 0; |
82 | static unsigned short SubCounter = 0; |
82 | static unsigned short CurrentOffset = 0; |
83 | static unsigned short CurrentOffset = 0; |
83 | static unsigned long SumCurrentOffset = 0; |
84 | static unsigned long SumCurrentOffset = 0; |
84 | unsigned char i, NumOfMotors; |
85 | unsigned char i, NumOfMotors, MinOfMaxPWM; |
Line 85... | Line 86... | ||
85 | 86 | ||
86 | if(CheckDelay(update_timer)) |
87 | if(CheckDelay(update_timer)) |
87 | { |
88 | { |
88 | update_timer += CAPACITY_UPDATE_INTERVAL; // do not use SetDelay to avoid timing leaks |
89 | update_timer += CAPACITY_UPDATE_INTERVAL; // do not use SetDelay to avoid timing leaks |
89 | // determine sum of all present BL currents and setpoints |
90 | // determine sum of all present BL currents and setpoints |
90 | Current = 0; |
91 | Current = 0; |
91 | SetSum = 0; |
92 | SetSum = 0; |
- | 93 | NumOfMotors = 0; |
|
92 | NumOfMotors = 0; |
94 | MinOfMaxPWM = 255; |
93 | for(i = 0; i < MAX_MOTORS; i++) |
95 | for(i = 0; i < MAX_MOTORS; i++) |
94 | { |
96 | { |
95 | if(Motor[i].State & MOTOR_STATE_PRESENT_MASK) |
97 | if(Motor[i].State & MOTOR_STATE_PRESENT_MASK) |
96 | { |
98 | { |
97 | NumOfMotors++; |
99 | NumOfMotors++; |
98 | Current += (unsigned int)(Motor[i].Current); |
100 | Current += (unsigned int)(Motor[i].Current); |
- | 101 | SetSum += (unsigned int)(Motor[i].SetPoint); |
|
99 | SetSum += (unsigned int)(Motor[i].SetPoint); |
102 | if(Motor[i].MaxPWM < MinOfMaxPWM) MinOfMaxPWM = Motor[i].MaxPWM; |
100 | } |
103 | } |
- | 104 | } |
|
- | 105 | Capacity.MinOfMaxPWM = MinOfMaxPWM; |
|
101 | } |
106 | |
102 | if(SetSum == 0) // if all setpoints are 0 |
107 | if(SetSum == 0) // if all setpoints are 0 |
103 | { // determine offsets of motor currents |
108 | { // determine offsets of motor currents |
104 | #define CURRENT_AVERAGE 8 // 8bit = 256 * 10 ms = 2.56s average time |
109 | #define CURRENT_AVERAGE 8 // 8bit = 256 * 10 ms = 2.56s average time |
105 | CurrentOffset = (unsigned int)(SumCurrentOffset>>CURRENT_AVERAGE); |
110 | CurrentOffset = (unsigned int)(SumCurrentOffset>>CURRENT_AVERAGE); |