Deep sleep cosmetics

master
Thomas Kolb 6 years ago
parent d313860804
commit 71c7cb57be
  1. 5
      src/lcd.c
  2. 1
      src/lcd.h
  3. 50
      src/main.c

@ -188,6 +188,11 @@ void lcd_send_string(char *data)
}
}
void lcd_clear(void)
{
lcd_enqueue(0x01, LCD_REG_CONTROL);
}
void lcd_set_cursor_pos(uint8_t line, uint8_t col)
{
lcd_enqueue(0x80 | (line << 6) | col, LCD_REG_CONTROL);

@ -24,6 +24,7 @@ void lcd_send_string(char *data);
int lcd_process(void);
int lcd_enqueue(uint8_t data, enum LCDRegType reg_type);
void lcd_clear(void);
void lcd_set_cursor_pos(uint8_t line, uint8_t col);
#endif // LCD_H

@ -23,6 +23,8 @@
#define TIM_CH_CONV TIM_OC1
#define TIM_CH_BOOTSTRAP TIM_OC2
#define MAX_SLEEP_TIME 3600
enum OperState {
Bootstrap,
ConvConstVoltage,
@ -350,6 +352,9 @@ int main(void)
int32_t testPWM[2];
int testPWMStep = 5;
uint32_t sleep_time = 10;
uint64_t force_display_update_time = 1000;
fxp_t PGAIN_CV = fxp_from_float( 50.000f);
fxp_t IGAIN_CV = fxp_from_float( 0.300f);
fxp_t IERR_LIMIT = fxp_from_int(4000);
@ -404,9 +409,7 @@ int main(void)
if(lcd_setup()) {
lcd_process();
if((timebase_ms % 500) == 0) {
fxp_t scaled_val;
if(timebase_ms == force_display_update_time) {
lcd_set_cursor_pos(1, 0);
fxp_format(vin_avg, number, 1);
@ -415,19 +418,20 @@ int main(void)
lcd_send_string(msg);
lcd_send_string("V ");
fxp_format(vout_avg, number, 1);
fxp_right_align(number, msg, 4, ' ');
fxp_format(vout_avg, number, 2);
fxp_right_align(number, msg, 5, ' ');
lcd_send_string("O:");
lcd_send_string(msg);
lcd_send_string("V ");
lcd_set_cursor_pos(0, 10);
scaled_val = fxp_mult(current_avg, fxp_from_int(1000)); // A -> mA
fxp_format(scaled_val, number, 0);
fxp_right_align(number, msg, 4, ' ');
fxp_format(power_avg, number, 2);
fxp_right_align(number, msg, 5, ' ');
lcd_send_string(msg);
lcd_send_string("mA");
lcd_send_string("W");
force_display_update_time += 500;
}
if((timebase_ms % 1000) == 10) {
@ -637,16 +641,34 @@ int main(void)
timer_set_oc_value(TIM1, TIM_CH_BOOTSTRAP, 0);
if(time_in_state > 1000 && vin_avg > vout_avg) {
sleep_time = 10;
operState = Bootstrap;
nextState = ConvMPP;
}
if(time_in_state > 10000) {
// not enough power for too long -> put system to deep sleep
lcd_set_cursor_pos(0, 0);
lcd_send_string("Sleep mode ");
lcd_send_string("Sleep(");
fxp_format_int(sleep_time, msg);
lcd_send_string(msg);
lcd_send_string(") ");
while(lcd_process() == 0); // send everything immediately
deepsleep(10);
time_in_state = 9500; // run the voltage test again
deepsleep(sleep_time);
// Woke up again.
lcd_set_cursor_pos(0, 0);
lcd_send_string(" ");
time_in_state = 9900; // run the voltage test again
sleep_time *= 2;
if(sleep_time > MAX_SLEEP_TIME) {
sleep_time = MAX_SLEEP_TIME;
}
force_display_update_time = timebase_ms + 20;
}
break;
@ -757,6 +779,10 @@ int main(void)
sentSomething = 0;
}
if((timebase_ms % 1000) == 490) {
report_status(vin_avg, vout_avg, current_avg, pwm, operState);
}
// cpu load = timer1 value after main loop operations
cpuload += timer_get_counter(TIM3);

Loading…
Cancel
Save