Compare commits
13 Commits
0fca4c6c20
...
f0bf10d91d
Author | SHA1 | Date | |
---|---|---|---|
f0bf10d91d | |||
cbd28f9a12 | |||
a33154b2d0 | |||
828b47f3be | |||
7b426c93c9 | |||
20fd7b41e6 | |||
f60545f664 | |||
679d4534cb | |||
372be53471 | |||
0cdc7448e4 | |||
43b4fd1e77 | |||
d178910594 | |||
6f4363e021 |
@ -25,9 +25,28 @@
|
||||
#include <stdbool.h>
|
||||
#include <reflow-controller/pid-controller.h>
|
||||
|
||||
enum oven_pid_error_report {
|
||||
OVEN_PID_NO_ERROR = 0,
|
||||
OVEN_PID_ERR_PT1000_ADC_WATCHDOG = (1<<0),
|
||||
OVEN_PID_ERR_PT1000_ADC_OFF = (1<<1),
|
||||
OVEN_PID_ERR_PT1000_OTHER = (1<<2),
|
||||
OVEN_PID_ERR_VREF_TOL = (1<<3),
|
||||
OVEN_PID_ERR_OVERTEMP = (1<<4),
|
||||
};
|
||||
|
||||
struct oven_pid_errors {
|
||||
bool generic_error;
|
||||
bool pt1000_adc_watchdog;
|
||||
bool pt1000_adc_off;
|
||||
bool pt1000_other;
|
||||
bool vref_tol;
|
||||
bool controller_overtemp;
|
||||
};
|
||||
|
||||
struct oven_pid_status {
|
||||
bool active;
|
||||
bool aborted;
|
||||
struct oven_pid_errors error_flags;
|
||||
float target_temp;
|
||||
float current_temp;
|
||||
uint64_t timestamp_last_run;
|
||||
@ -41,11 +60,11 @@ void oven_driver_disable(void);
|
||||
|
||||
void oven_pid_init(struct pid_controller *controller_to_copy);
|
||||
|
||||
void oven_pid_handle(float target_temp, float current_temp);
|
||||
void oven_pid_handle(float target_temp);
|
||||
|
||||
void oven_pid_stop();
|
||||
|
||||
void oven_pid_report_error(void);
|
||||
void oven_pid_report_error(enum oven_pid_error_report report);
|
||||
|
||||
const struct oven_pid_status *oven_pid_get_status(void);
|
||||
|
||||
|
@ -23,7 +23,7 @@
|
||||
|
||||
/**
|
||||
* @brief Handle the reflow controller's LCD Menu
|
||||
* @return 0 if a delay is requested, 1 if no delay is requested
|
||||
* @return 0 if no delay is requested, 1 if delay is requested
|
||||
*/
|
||||
int reflow_menu_handle(void);
|
||||
|
||||
|
@ -24,11 +24,10 @@
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define SAFETY_ADC_FRAC_BITS (8)
|
||||
#define SAFETY_ADC_VREF_VOLT (2.5)
|
||||
#define SAFETY_ADC_VREF_TOL (0.25)
|
||||
#define SAFETY_ADC_VREF_INT ()
|
||||
|
||||
#define SAFETY_ADC_VREF_MVOLT (2500.0f)
|
||||
#define SAFETY_ADC_VREF_TOL_MVOLT (100.0f)
|
||||
#define SAFETY_ADC_TEMP_LOW_LIM (0.0f)
|
||||
#define SAFETY_ADC_TEMP_HIGH_LIM (65.0f)
|
||||
|
||||
enum safety_adc_meas_channel {SAFETY_ADC_MEAS_VREF, SAFETY_ADC_MEAS_TEMP};
|
||||
enum safety_adc_check_result {
|
||||
|
@ -32,9 +32,9 @@
|
||||
* @brief Reload value for the systick timer.
|
||||
*
|
||||
* This value has to be configured to set the systick to a one milliscond tick interval
|
||||
* The default value is 168000, which results in a 1ms tick for 168 MHz CPU speed
|
||||
* The default value is 16800, which results in a 100us tick for 168 MHz CPU speed
|
||||
*/
|
||||
#define SYSTICK_RELOAD (168000UL)
|
||||
#define SYSTICK_RELOAD (16800UL)
|
||||
|
||||
/**
|
||||
* @brief Variable used by the systick_wait_ms function
|
||||
@ -52,7 +52,7 @@ extern volatile uint64_t global_tick_ms;
|
||||
/**
|
||||
* @brief Wait counter for the display. This must not be used anywhere else
|
||||
*/
|
||||
extern volatile uint32_t lcd_tick_ms;
|
||||
extern volatile uint32_t lcd_tick_100us;
|
||||
|
||||
/**
|
||||
* @brief Setup the Systick timer to generate a 1 ms tick
|
||||
@ -71,6 +71,8 @@ void systick_wait_ms(uint32_t ms);
|
||||
|
||||
uint64_t systick_get_global_tick();
|
||||
|
||||
void systick_get_uptime_from_tick(uint32_t *days, uint32_t *hours, uint32_t *minutes, uint32_t *seconds);
|
||||
|
||||
bool systick_ticks_have_passed(uint64_t start_timestamp, uint64_t ticks);
|
||||
|
||||
#endif /* __SYSTICK_H__ */
|
||||
|
@ -66,10 +66,16 @@ void menu_entry_dropback(struct lcd_menu *menu, menu_func_t parent_func);
|
||||
|
||||
void menu_entry_enter(struct lcd_menu *menu, menu_func_t entry, bool handle_immediately);
|
||||
|
||||
void menu_override_lcd_output(struct lcd_menu *menu, uint8_t row_num, const char *text);
|
||||
void menu_lcd_output(struct lcd_menu *menu, uint8_t row_num, const char *text);
|
||||
|
||||
void menu_lcd_outputf(struct lcd_menu *menu, uint8_t row_num, const char *format, ...);
|
||||
|
||||
void menu_list_display(struct menu_list *list, uint32_t top_row, uint32_t bottom_row);
|
||||
|
||||
int16_t menu_get_rotary_delta(const struct lcd_menu *menu);
|
||||
|
||||
enum button_state menu_get_button_state(const struct lcd_menu *menu);
|
||||
|
||||
void menu_list_compute_count(struct menu_list *list);
|
||||
|
||||
void menu_list_scroll_down(struct menu_list *list);
|
||||
|
@ -58,11 +58,8 @@ static void setup_nvic_priorities()
|
||||
NVIC_SetPriority(DMA2_Stream7_IRQn, 3);
|
||||
}
|
||||
|
||||
/* Process parameters are defined static globally to be watched in debugger from any context */
|
||||
static float target_temperature;
|
||||
|
||||
FATFS fs;
|
||||
FATFS *fs_ptr = &fs;
|
||||
FATFS * const fs_ptr = &fs;
|
||||
|
||||
static inline void uart_gpio_config()
|
||||
{
|
||||
@ -201,15 +198,17 @@ static void zero_ccm_ram(void)
|
||||
ptr[i] = 0UL;
|
||||
}
|
||||
|
||||
volatile bool error_state = false;
|
||||
volatile enum safety_adc_check_result safety_adc_status = SAFETY_ADC_CHECK_OK;
|
||||
|
||||
int main()
|
||||
{
|
||||
bool sd_card_mounted = false;
|
||||
shellmatta_handle_t shell_handle;
|
||||
int menu_wait_request;
|
||||
uint64_t quarter_sec_timestamp = 0ULL;
|
||||
enum safety_adc_check_result safety_adc_status;
|
||||
|
||||
target_temperature = 25.0f;
|
||||
const struct oven_pid_status *pid_status;
|
||||
enum adc_pt1000_error pt1000_status;
|
||||
|
||||
zero_ccm_ram();
|
||||
setup_system();
|
||||
@ -220,15 +219,47 @@ int main()
|
||||
while (1) {
|
||||
sd_card_mounted = mount_sd_card_if_avail(sd_card_mounted);
|
||||
|
||||
pid_status = oven_pid_get_status();
|
||||
|
||||
if(systick_ticks_have_passed(quarter_sec_timestamp, 250)) {
|
||||
safety_adc_status = handle_safety_adc();
|
||||
quarter_sec_timestamp = systick_get_global_tick();
|
||||
|
||||
if (safety_adc_status & SAFETY_ADC_CHECK_TEMP_LOW || safety_adc_status & SAFETY_ADC_CHECK_TEMP_HIGH) {
|
||||
oven_pid_report_error(OVEN_PID_ERR_OVERTEMP);
|
||||
}
|
||||
|
||||
if (safety_adc_status & SAFETY_ADC_CHECK_VREF_LOW || safety_adc_status & SAFETY_ADC_CHECK_VREF_HIGH) {
|
||||
oven_pid_report_error(OVEN_PID_ERR_VREF_TOL);
|
||||
}
|
||||
|
||||
if (safety_adc_status & SAFETY_ADC_INTERNAL_ERROR) {
|
||||
oven_pid_report_error(0);
|
||||
}
|
||||
|
||||
if (error_state) {
|
||||
led_set(0, !led_get(0));
|
||||
} else {
|
||||
led_set(0, 0);
|
||||
}
|
||||
|
||||
pt1000_status = adc_pt1000_check_error();
|
||||
|
||||
}
|
||||
|
||||
error_state = pid_status->aborted | !!safety_adc_status | !!pt1000_status;
|
||||
|
||||
menu_wait_request = reflow_menu_handle();
|
||||
|
||||
/* Deactivate oven output in case of error! */
|
||||
if (!pid_status->active || pid_status->aborted || error_state) {
|
||||
oven_pid_stop();
|
||||
oven_driver_set_power(0U);
|
||||
}
|
||||
|
||||
handle_shell_uart_input(shell_handle);
|
||||
|
||||
menu_wait_request = reflow_menu_handle();
|
||||
if (!menu_wait_request)
|
||||
if (menu_wait_request)
|
||||
__WFI();
|
||||
|
||||
}
|
||||
|
@ -22,6 +22,8 @@
|
||||
#include <reflow-controller/periph-config/oven-driver-hwcfg.h>
|
||||
#include <stm-periph/clock-enable-manager.h>
|
||||
#include <reflow-controller/systick.h>
|
||||
#include <reflow-controller/adc-meas.h>
|
||||
#include <reflow-controller/temp-converter.h>
|
||||
|
||||
static struct pid_controller oven_pid;
|
||||
|
||||
@ -76,29 +78,70 @@ void oven_pid_init(struct pid_controller *controller_to_copy)
|
||||
oven_pid.output_sat_max = 100.0f;
|
||||
oven_pid_current_status.timestamp_last_run = 0ULL;
|
||||
oven_pid_current_status.active = true;
|
||||
oven_pid_current_status.error_flags.vref_tol = false;
|
||||
oven_pid_current_status.error_flags.pt1000_other = false;
|
||||
oven_pid_current_status.error_flags.generic_error = false;
|
||||
oven_pid_current_status.error_flags.pt1000_adc_off = false;
|
||||
oven_pid_current_status.error_flags.controller_overtemp = false;
|
||||
oven_pid_current_status.error_flags.pt1000_adc_watchdog = false;
|
||||
}
|
||||
|
||||
void oven_pid_handle(float target_temp, float current_temp)
|
||||
void oven_pid_handle(float target_temp)
|
||||
{
|
||||
float pid_out;
|
||||
float current_temp;
|
||||
int resistance_status;
|
||||
enum adc_pt1000_error pt1000_error;
|
||||
|
||||
if (oven_pid_current_status.active) {
|
||||
if (oven_pid_current_status.active && !oven_pid_current_status.aborted) {
|
||||
if (systick_ticks_have_passed(oven_pid_current_status.timestamp_last_run,
|
||||
(uint64_t)(oven_pid.sample_period * 1000))) {
|
||||
|
||||
resistance_status = adc_pt1000_get_current_resistance(¤t_temp);
|
||||
if (resistance_status < 0) {
|
||||
oven_driver_set_power(0);
|
||||
pt1000_error = adc_pt1000_check_error();
|
||||
if (pt1000_error & ADC_PT1000_WATCHDOG_ERROR)
|
||||
oven_pid_report_error(OVEN_PID_ERR_PT1000_ADC_WATCHDOG);
|
||||
if (pt1000_error & ADC_PT1000_INACTIVE)
|
||||
oven_pid_report_error(OVEN_PID_ERR_PT1000_ADC_OFF);
|
||||
if (pt1000_error & ADC_PT1000_OVERFLOW)
|
||||
oven_pid_report_error(OVEN_PID_ERR_PT1000_OTHER);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
(void)temp_converter_convert_resistance_to_temp(current_temp, ¤t_temp);
|
||||
|
||||
pid_out = pid_sample(&oven_pid, target_temp - current_temp);
|
||||
oven_driver_set_power((uint8_t)pid_out);
|
||||
oven_pid_current_status.timestamp_last_run = systick_get_global_tick();
|
||||
oven_pid_current_status.active = true;
|
||||
oven_pid_current_status.target_temp = target_temp;
|
||||
oven_pid_current_status.current_temp = current_temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void oven_pid_report_error()
|
||||
void oven_pid_report_error(enum oven_pid_error_report report)
|
||||
{
|
||||
struct oven_pid_errors *e = &oven_pid_current_status.error_flags;
|
||||
|
||||
oven_pid_current_status.active = false;
|
||||
oven_pid_current_status.aborted = true;
|
||||
|
||||
if (report == 0) {
|
||||
e->generic_error = true;
|
||||
}
|
||||
if (report & OVEN_PID_ERR_OVERTEMP)
|
||||
e->controller_overtemp = true;
|
||||
if (report & OVEN_PID_ERR_VREF_TOL)
|
||||
e->controller_overtemp = true;
|
||||
if (report & OVEN_PID_ERR_PT1000_OTHER)
|
||||
e->pt1000_other = true;
|
||||
if (report & OVEN_PID_ERR_PT1000_ADC_OFF)
|
||||
e->pt1000_adc_off = true;
|
||||
if (report & OVEN_PID_ERR_PT1000_ADC_WATCHDOG)
|
||||
e->pt1000_adc_watchdog = true;
|
||||
}
|
||||
|
||||
const struct oven_pid_status *oven_pid_get_status()
|
||||
|
@ -27,14 +27,16 @@
|
||||
#include <reflow-controller/safety-adc.h>
|
||||
#include <reflow-controller/temp-converter.h>
|
||||
#include <helper-macros/helper-macros.h>
|
||||
#include <stm-periph/unique-id.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
static char __attribute__((section(".ccmram"))) display_buffer[4][21] = {0};
|
||||
static struct lcd_menu reflow_menu;
|
||||
static struct lcd_menu *reflow_menu_ptr = &reflow_menu;
|
||||
static struct lcd_menu * const reflow_menu_ptr = &reflow_menu;
|
||||
|
||||
static void update_display_buffer(uint8_t row, const char *data)
|
||||
{
|
||||
@ -106,29 +108,91 @@ static void reflow_menu_about(struct lcd_menu *menu, enum menu_entry_func_entry
|
||||
{
|
||||
static void *my_parent;
|
||||
static bool button_ready;
|
||||
char buff[20];
|
||||
static int page = 0;
|
||||
static uint32_t uptime_secs;
|
||||
uint32_t new_uptime_secs;
|
||||
uint32_t uptime_mins;
|
||||
uint32_t uptime_hours;
|
||||
uint32_t uptime_days;
|
||||
int16_t rot_delta;
|
||||
uint32_t ser1, ser2, ser3;
|
||||
enum button_state push_button;
|
||||
|
||||
if (entry_type == MENU_ENTRY_FIRST_ENTER) {
|
||||
uptime_secs = 0ULL;
|
||||
page = 0;
|
||||
my_parent = parent;
|
||||
button_ready = false;
|
||||
menu_display_clear(menu);
|
||||
|
||||
menu->update_display(0, LCD_SHIMATTA_STRING " Reflow");
|
||||
snprintf(buff, sizeof(buff), "%.*s", LCD_CHAR_WIDTH, xstr(GIT_VER));
|
||||
menu->update_display(1, buff);
|
||||
if (strlen(xstr(GIT_VER)) > LCD_CHAR_WIDTH) {
|
||||
snprintf(buff, sizeof(buff), "%s", &xstr(GIT_VER)[LCD_CHAR_WIDTH]);
|
||||
menu->update_display(2, buff);
|
||||
}
|
||||
|
||||
menu->update_display(3, __DATE__);
|
||||
menu_ack_rotary_delta(menu);
|
||||
}
|
||||
|
||||
if (menu->inputs.push_button == BUTTON_IDLE)
|
||||
rot_delta = menu_get_rotary_delta(menu);
|
||||
if (rot_delta >= 4) {
|
||||
menu_ack_rotary_delta(menu);
|
||||
if (page < 4) {
|
||||
page++;
|
||||
menu_display_clear(menu);
|
||||
}
|
||||
} else if (rot_delta <= -4) {
|
||||
menu_ack_rotary_delta(menu);
|
||||
if (page > 0) {
|
||||
page--;
|
||||
menu_display_clear(menu);
|
||||
}
|
||||
}
|
||||
|
||||
switch (page) {
|
||||
case 0:
|
||||
menu_lcd_output(menu, 0, LCD_SHIMATTA_STRING " Shimatta");
|
||||
menu_lcd_output(menu, 1, "Oven Controller");
|
||||
menu_lcd_output(menu, 2, "(c) Mario H\xF5ttel");
|
||||
menu_lcd_output(menu, 3, "Page 1/5");
|
||||
break;
|
||||
case 1:
|
||||
menu_lcd_output(menu, 0, "Version Number:");
|
||||
menu_lcd_outputf(menu, 1, "%.*s", LCD_CHAR_WIDTH, xstr(GIT_VER));
|
||||
if (strlen(xstr(GIT_VER)) > LCD_CHAR_WIDTH) {
|
||||
menu_lcd_outputf(menu, 2, "%s", &xstr(GIT_VER)[LCD_CHAR_WIDTH]);
|
||||
}
|
||||
menu_lcd_output(menu, 3, "Page 2/5");
|
||||
break;
|
||||
case 2:
|
||||
menu_lcd_output(menu, 0, "Compile Info");
|
||||
menu_lcd_output(menu, 1, __DATE__);
|
||||
menu_lcd_output(menu, 2, __TIME__);
|
||||
menu_lcd_output(menu, 3, "Page 3/5");
|
||||
break;
|
||||
case 3:
|
||||
unique_id_get(&ser1, &ser2, &ser3);
|
||||
|
||||
menu_lcd_outputf(menu, 0, "Serial: %08X", ser1);
|
||||
menu_lcd_outputf(menu, 1, " %08X", ser2);
|
||||
menu_lcd_outputf(menu, 2, " %08X", ser3);
|
||||
menu_lcd_output(menu, 3, "Page 4/5");
|
||||
break;
|
||||
case 4:
|
||||
systick_get_uptime_from_tick(&uptime_days, &uptime_hours, &uptime_mins, &new_uptime_secs);
|
||||
if (new_uptime_secs != uptime_secs) {
|
||||
uptime_secs = new_uptime_secs;
|
||||
menu_lcd_output(menu, 0, "Uptime:");
|
||||
menu_lcd_outputf(menu, 1, "%lu day%s %02lu:%02lu:%02lu",
|
||||
uptime_days, (uptime_days == 1 ? "" : "s"), uptime_hours, uptime_mins, uptime_secs);
|
||||
menu_lcd_output(menu, 3, "Page 5/5");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
page = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
push_button = menu_get_button_state(menu);
|
||||
|
||||
if (push_button == BUTTON_IDLE)
|
||||
button_ready = true;
|
||||
|
||||
if (button_ready &&
|
||||
(menu->inputs.push_button == BUTTON_SHORT_RELEASED || menu->inputs.push_button == BUTTON_LONG)) {
|
||||
(push_button == BUTTON_SHORT_RELEASED || push_button == BUTTON_LONG)) {
|
||||
menu_entry_dropback(menu, my_parent);
|
||||
}
|
||||
}
|
||||
@ -143,11 +207,12 @@ static void reflow_menu_root_entry(struct lcd_menu *menu, enum menu_entry_func_e
|
||||
"Monitoring",
|
||||
NULL
|
||||
};
|
||||
|
||||
static const menu_func_t root_entry_funcs[] = {
|
||||
reflow_menu_about,
|
||||
reflow_menu_monitor
|
||||
};
|
||||
enum button_state push_button;
|
||||
int16_t rot_delta;
|
||||
|
||||
if (entry_type != MENU_ENTRY_CONTINUE) {
|
||||
menu_display_clear(menu);
|
||||
@ -163,19 +228,20 @@ static void reflow_menu_root_entry(struct lcd_menu *menu, enum menu_entry_func_e
|
||||
}
|
||||
}
|
||||
|
||||
if (menu->inputs.push_button == BUTTON_IDLE) {
|
||||
push_button = menu_get_button_state(menu);
|
||||
rot_delta = menu_get_rotary_delta(menu);
|
||||
|
||||
if (push_button == BUTTON_IDLE) {
|
||||
button_valid = true;
|
||||
} else if (button_valid && menu->inputs.push_button == BUTTON_SHORT_RELEASED) {
|
||||
} else if (button_valid && push_button == BUTTON_SHORT_RELEASED) {
|
||||
/* Enter currently selected menu_entry */
|
||||
menu_list_enter_selected_entry(&list, menu);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (menu->inputs.rotary_encoder_delta >= 4) {
|
||||
if (rot_delta >= 4) {
|
||||
menu_list_scroll_down(&list);
|
||||
menu_ack_rotary_delta(menu);
|
||||
} else if (menu->inputs.rotary_encoder_delta <= -4) {
|
||||
} else if (rot_delta <= -4) {
|
||||
menu_list_scroll_up(&list);
|
||||
menu_ack_rotary_delta(menu);
|
||||
}
|
||||
@ -183,7 +249,6 @@ static void reflow_menu_root_entry(struct lcd_menu *menu, enum menu_entry_func_e
|
||||
menu_list_display(&list, 1, 3);
|
||||
}
|
||||
|
||||
|
||||
int reflow_menu_handle()
|
||||
{
|
||||
int32_t rot_delta;
|
||||
@ -195,15 +260,15 @@ int reflow_menu_handle()
|
||||
|
||||
menu_handle(reflow_menu_ptr, (int16_t)rot_delta, button);
|
||||
|
||||
if (lcd_ret != LCD_FSM_WAIT_CALL || lcd_tick_ms >= 1) {
|
||||
if (lcd_ret == LCD_FSM_CALL_AGAIN || lcd_tick_100us >= 5) {
|
||||
lcd_ret = lcd_fsm_write_buffer(display_buffer);
|
||||
lcd_tick_ms = 0UL;
|
||||
lcd_tick_100us = 0UL;
|
||||
}
|
||||
|
||||
if (lcd_ret == LCD_FSM_CALL_AGAIN)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
|
||||
void reflow_menu_init()
|
||||
|
@ -20,7 +20,7 @@
|
||||
|
||||
#include <reflow-controller/safety-adc.h>
|
||||
#include <reflow-controller/periph-config/safety-adc-hwcfg.h>
|
||||
|
||||
#include <helper-macros/helper-macros.h>
|
||||
#include <stm-periph/clock-enable-manager.h>
|
||||
|
||||
void safety_adc_init()
|
||||
@ -50,18 +50,32 @@ enum safety_adc_check_result safety_adc_check_results(uint16_t vref_result, uint
|
||||
float *vref_calculated, float *temp_calculated)
|
||||
{
|
||||
enum safety_adc_check_result res = SAFETY_ADC_CHECK_OK;
|
||||
float vref;
|
||||
float temp;
|
||||
|
||||
|
||||
vref = (SAFETY_ADC_INT_REF_MV * 4095.0f) / (float)vref_result;
|
||||
if (vref_calculated) {
|
||||
*vref_calculated = (SAFETY_ADC_INT_REF_MV * 4095.0f) / (float)vref_result;
|
||||
*vref_calculated = vref;
|
||||
}
|
||||
|
||||
temp = (((float)temp_result / 4095.0f * 2500.0f -
|
||||
SAFETY_ADC_TEMP_NOM_MV) / SAFETY_ADC_TEMP_MV_SLOPE) + SAFETY_ADC_TEMP_NOM;
|
||||
if (temp_calculated) {
|
||||
*temp_calculated = (((float)temp_result / 4095.0f * 2500.0f -
|
||||
SAFETY_ADC_TEMP_NOM_MV) / SAFETY_ADC_TEMP_MV_SLOPE) + SAFETY_ADC_TEMP_NOM;
|
||||
*temp_calculated = temp;
|
||||
}
|
||||
|
||||
/* TODO: Implement safety ADC checking */
|
||||
if (ABS(vref - SAFETY_ADC_VREF_MVOLT) > SAFETY_ADC_VREF_TOL_MVOLT) {
|
||||
if (vref > SAFETY_ADC_VREF_MVOLT)
|
||||
res |= SAFETY_ADC_CHECK_VREF_HIGH;
|
||||
else
|
||||
res |= SAFETY_ADC_CHECK_VREF_LOW;
|
||||
}
|
||||
|
||||
if (temp < SAFETY_ADC_TEMP_LOW_LIM)
|
||||
res |= SAFETY_ADC_CHECK_TEMP_LOW;
|
||||
else if (temp < SAFETY_ADC_CHECK_TEMP_HIGH)
|
||||
res |= SAFETY_ADC_CHECK_TEMP_HIGH;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
@ -189,8 +189,18 @@ static shellmatta_retCode_t shell_cmd_uptime(const shellmatta_handle_t handle,
|
||||
{
|
||||
(void)arguments;
|
||||
(void)length;
|
||||
uint32_t days;
|
||||
uint32_t hours;
|
||||
uint32_t mins;
|
||||
uint32_t secs;
|
||||
|
||||
shellmatta_printf(handle, "Uptime: %llu secs", global_tick_ms/1000);
|
||||
systick_get_uptime_from_tick(&days, &hours, &mins, &secs);
|
||||
|
||||
shellmatta_printf(handle, "Uptime: %u day%s %02u:%02u:%02u",
|
||||
days, (days == 1 ? "" : "s"),
|
||||
hours,
|
||||
mins,
|
||||
secs);
|
||||
return SHELLMATTA_OK;
|
||||
}
|
||||
|
||||
|
@ -28,11 +28,11 @@
|
||||
|
||||
volatile uint32_t wait_tick_ms = 0UL;
|
||||
volatile uint64_t global_tick_ms = 0ULL;
|
||||
volatile uint32_t lcd_tick_ms = 0UL;
|
||||
volatile uint32_t lcd_tick_100us = 0UL;
|
||||
|
||||
void systick_setup(void)
|
||||
{
|
||||
/* Setup Systick for 1ms tick @ 168 MHz Clock Speed */
|
||||
/* Setup Systick for 100us tick @ 168 MHz Clock Speed */
|
||||
SysTick_Config(SYSTICK_RELOAD);
|
||||
}
|
||||
|
||||
@ -53,6 +53,35 @@ uint64_t systick_get_global_tick()
|
||||
return temp;
|
||||
}
|
||||
|
||||
void systick_get_uptime_from_tick(uint32_t *days, uint32_t *hours, uint32_t *minutes, uint32_t *seconds)
|
||||
{
|
||||
uint64_t tick_secs;
|
||||
uint32_t secs;
|
||||
uint32_t mins;
|
||||
uint32_t hs;
|
||||
uint32_t ds;
|
||||
|
||||
|
||||
tick_secs = systick_get_global_tick() / 1000;
|
||||
secs = tick_secs % 60;
|
||||
tick_secs /= 60;
|
||||
mins = tick_secs % 60;
|
||||
tick_secs /= 60;
|
||||
hs = tick_secs % 60;
|
||||
tick_secs /= 24;
|
||||
ds = tick_secs;
|
||||
|
||||
if (days)
|
||||
*days = ds;
|
||||
if (hours)
|
||||
*hours = hs;
|
||||
if (minutes)
|
||||
*minutes = mins;
|
||||
if (seconds)
|
||||
*seconds = secs;
|
||||
|
||||
}
|
||||
|
||||
bool __attribute__((optimize("O3"))) systick_ticks_have_passed(uint64_t start_timestamp, uint64_t ticks)
|
||||
{
|
||||
uint64_t end_timestamp = start_timestamp + ticks;
|
||||
@ -82,8 +111,14 @@ bool __attribute__((optimize("O3"))) systick_ticks_have_passed(uint64_t start_ti
|
||||
*/
|
||||
void __attribute__((optimize("O3"))) SysTick_Handler()
|
||||
{
|
||||
/* Increase tick counters */
|
||||
wait_tick_ms++;
|
||||
global_tick_ms++;
|
||||
lcd_tick_ms++;
|
||||
static uint32_t pre_tick = 0UL;
|
||||
|
||||
pre_tick++;
|
||||
if (pre_tick == 10) {
|
||||
pre_tick = 0;
|
||||
/* Increase tick counters */
|
||||
wait_tick_ms++;
|
||||
global_tick_ms++;
|
||||
}
|
||||
lcd_tick_100us++;
|
||||
}
|
||||
|
@ -149,7 +149,7 @@ static void lcd_command(uint8_t data)
|
||||
// Set DD RAM Address --------- 0b1xxxxxxx (Display Data RAM)
|
||||
#define LCD_SET_DDADR 0x80
|
||||
|
||||
static char shadow_display[4][21];
|
||||
static char __attribute__((section(".ccmram"))) shadow_display[4][21];
|
||||
|
||||
void lcd_clear(void)
|
||||
{
|
||||
@ -403,7 +403,7 @@ enum lcd_fsm_ret lcd_fsm_write_buffer(const char (*display_buffer)[21])
|
||||
state_cnt++;
|
||||
break;
|
||||
case 4:
|
||||
if (!systick_ticks_have_passed(timestamp, 5)) {
|
||||
if (!systick_ticks_have_passed(timestamp, 4)) {
|
||||
ret = LCD_FSM_WAIT_CALL;
|
||||
} else {
|
||||
ret = LCD_FSM_CALL_AGAIN;
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include <reflow-controller/ui/menu.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
void menu_handle(struct lcd_menu *menu, int16_t rotary_encoder_delta, enum button_state push_button)
|
||||
{
|
||||
@ -88,7 +89,7 @@ void menu_entry_enter(struct lcd_menu *menu, menu_func_t entry, bool handle_imme
|
||||
menu_handle(menu, menu->inputs.rotary_encoder_delta, menu->inputs.push_button);
|
||||
}
|
||||
|
||||
void menu_override_lcd_output(struct lcd_menu *menu, uint8_t row_num, const char *text)
|
||||
void menu_lcd_output(struct lcd_menu *menu, uint8_t row_num, const char *text)
|
||||
{
|
||||
if (!menu || !menu->update_display)
|
||||
return;
|
||||
@ -96,6 +97,18 @@ void menu_override_lcd_output(struct lcd_menu *menu, uint8_t row_num, const char
|
||||
menu->update_display(row_num, text);
|
||||
}
|
||||
|
||||
void menu_lcd_outputf(struct lcd_menu *menu, uint8_t row_num, const char *format, ...)
|
||||
{
|
||||
char buff[64];
|
||||
va_list valist;
|
||||
|
||||
va_start(valist, format);
|
||||
vsnprintf(buff, sizeof(buff), format, valist);
|
||||
buff[sizeof(buff) - 1] = '\0';
|
||||
menu_lcd_output(menu, row_num, buff);
|
||||
va_end(valist);
|
||||
}
|
||||
|
||||
void menu_list_display(struct menu_list *list, uint32_t top_row, uint32_t bottom_row)
|
||||
{
|
||||
uint8_t row_count;
|
||||
@ -146,7 +159,8 @@ void menu_list_display(struct menu_list *list, uint32_t top_row, uint32_t bottom
|
||||
if (current_idx >= list->entry_count)
|
||||
break;
|
||||
|
||||
snprintf(workbuff, sizeof(workbuff), "%c%s", (current_idx == list->currently_selected ? '>' : ' '), list->entry_names[current_idx]);
|
||||
snprintf(workbuff, sizeof(workbuff), "%c%s", (current_idx == list->currently_selected ? '>' : ' '),
|
||||
list->entry_names[current_idx]);
|
||||
workbuff[sizeof(workbuff)-1] = 0;
|
||||
list->update_display((uint8_t)current_row, workbuff);
|
||||
}
|
||||
@ -209,6 +223,26 @@ void menu_ack_rotary_delta(struct lcd_menu *menu)
|
||||
menu->inputs.rotary_encoder_delta = 0;
|
||||
}
|
||||
|
||||
int16_t menu_get_rotary_delta(const struct lcd_menu *menu)
|
||||
{
|
||||
int16_t ret = 0;
|
||||
|
||||
if (menu)
|
||||
ret = menu->inputs.rotary_encoder_delta;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
enum button_state menu_get_button_state(const struct lcd_menu *menu)
|
||||
{
|
||||
enum button_state ret = BUTTON_IDLE;
|
||||
|
||||
if (menu)
|
||||
ret = menu->inputs.push_button;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void menu_display_clear(struct lcd_menu *menu)
|
||||
{
|
||||
uint8_t i;
|
||||
|
Loading…
x
Reference in New Issue
Block a user