Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
rufform
reform
Commits
e00dc655
Commit
e00dc655
authored
Oct 01, 2021
by
minute
Browse files
lpc: add cooldown state, try not to overheat discharge resistors when balancing
parent
f8925861
Changes
1
Hide whitespace changes
Inline
Side-by-side
reform2-lpc-fw/src/boards/reform2/board_reform2.c
View file @
e00dc655
...
...
@@ -135,6 +135,7 @@ uint8_t calc_pec(uint8_t d, uint8_t pec) {
enum
state_t
{
ST_CHARGE
,
ST_OVERVOLTED
,
ST_COOLDOWN
,
ST_UNDERVOLTED
,
ST_MISSING
,
ST_FULLY_CHARGED
,
...
...
@@ -182,7 +183,7 @@ uint8_t spir[64];
#endif
#define UNDERVOLTAGE_VALUE 2.45
#define UNDERVOLTAGE_CRITICAL_VALUE 2.3
#define MISSING_VALUE_HI 4.
3
#define MISSING_VALUE_HI 4.
5
#define MISSING_VALUE_LO 0.4
#if (REFORM_MOTHERBOARD_REV >= REFORM_MBREV_R3)
#define FULLY_CHARGED_VOLTAGE 3.4
...
...
@@ -664,6 +665,8 @@ void handle_commands() {
sprintf
(
uartBuffer
,
FW_REV
"normal,%d,%d,%d
\r
"
,
cycles_in_state
,
min_mah
,
acc_mah
);
}
else
if
(
state
==
ST_OVERVOLTED
)
{
sprintf
(
uartBuffer
,
FW_REV
"balancing,%d,%d,%d
\r
"
,
cycles_in_state
,
min_mah
,
acc_mah
);
}
else
if
(
state
==
ST_COOLDOWN
)
{
sprintf
(
uartBuffer
,
FW_REV
"cooldown,%d,%d,%d
\r
"
,
cycles_in_state
,
min_mah
,
acc_mah
);
}
else
if
(
state
==
ST_UNDERVOLTED
)
{
sprintf
(
uartBuffer
,
FW_REV
"undervolted,%d,%d,%d
\r
"
,
cycles_in_state
,
min_mah
,
acc_mah
);
}
else
if
(
state
==
ST_MISSING
)
{
...
...
@@ -938,7 +941,7 @@ int main(void)
}
}
else
if
(
num_overvolted_cells
>
0
)
{
if
(
cycles_in_state
>
5
)
{
if
(
cycles_in_state
>
2
)
{
// some cool-off time
next_state
=
ST_OVERVOLTED
;
cycles_in_state
=
0
;
...
...
@@ -969,9 +972,22 @@ int main(void)
discharge_overvolted_cells
();
// discharge
if
(
cycles_in_state
>
1
&&
(
num_overvolted_cells
==
0
||
num_undervolted_cells
>
0
))
{
if
(
cycles_in_state
>
3
&&
(
num_overvolted_cells
==
0
||
num_undervolted_cells
>
0
))
{
reset_discharge_bits
();
next_state
=
ST_COOLDOWN
;
cycles_in_state
=
0
;
}
else
if
(
cycles_in_state
>
5
)
{
// don't discharge for more than 5 cycles
next_state
=
ST_COOLDOWN
;
cycles_in_state
=
0
;
}
}
else
if
(
state
==
ST_COOLDOWN
)
{
// avoid overheating the resistors
reset_discharge_bits
();
if
(
cycles_in_state
>
3
)
{
next_state
=
ST_CHARGE
;
cycles_in_state
=
0
;
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment