added BLDC Mode
This commit is contained in:
@@ -80,7 +80,7 @@ uint32_t get_voltage_in()
|
|||||||
int32_t get_current_ASC712(int ADC_pin)
|
int32_t get_current_ASC712(int ADC_pin)
|
||||||
{
|
{
|
||||||
int32_t adc_voltage = read_voltage(ADC_pin);
|
int32_t adc_voltage = read_voltage(ADC_pin);
|
||||||
int32_t current = (adc_voltage -2500)*5.405;
|
int32_t current = (adc_voltage +184)/(10.0/12)-2500;
|
||||||
ESP_LOGI("ADC", "ADC%d:voltage:%ldcurrent%ld", ADC_pin, adc_voltage, current);
|
ESP_LOGI("ADC", "ADC%d:voltage:%ldcurrent%ld", ADC_pin, adc_voltage, current);
|
||||||
return current;
|
return current;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ void app_main(void)
|
|||||||
//gpio_set_level(CONFIG_HIN_V_GPIO, 1);
|
//gpio_set_level(CONFIG_HIN_V_GPIO, 1);
|
||||||
while (1) {
|
while (1) {
|
||||||
menu_loop();
|
menu_loop();
|
||||||
|
|
||||||
//ssd1306_clear_screen(dev_pt, false);
|
//ssd1306_clear_screen(dev_pt, false);
|
||||||
/* Die Anzeige der OLED mit der richtigen Nachricht
|
/* Die Anzeige der OLED mit der richtigen Nachricht
|
||||||
Torque = get_torque();
|
Torque = get_torque();
|
||||||
|
|||||||
@@ -54,3 +54,31 @@ bool get_Hall(int HallSensorGPIO){
|
|||||||
}
|
}
|
||||||
return level;
|
return level;
|
||||||
}
|
}
|
||||||
|
HallState get_Hall_Combi(){
|
||||||
|
|
||||||
|
int hall_A = gpio_get_level(CONFIG_HALL_A_GPIO);
|
||||||
|
int hall_B = gpio_get_level(CONFIG_HALL_B_GPIO);
|
||||||
|
int hall_C = gpio_get_level(CONFIG_HALL_C_GPIO);
|
||||||
|
|
||||||
|
// Wandelt die GPIO-Levels in einen binären Wert um
|
||||||
|
return (HallState)((hall_A << 2) | (hall_B << 1) | hall_C);
|
||||||
|
|
||||||
|
}
|
||||||
|
OutCombis get_output_combination(HallState hall_state) {
|
||||||
|
switch (hall_state) {
|
||||||
|
case HALL_001:
|
||||||
|
return OUT_U_W;
|
||||||
|
case HALL_010:
|
||||||
|
return OUT_W_V;
|
||||||
|
case HALL_011:
|
||||||
|
return OUT_U_V;
|
||||||
|
case HALL_100:
|
||||||
|
return OUT_V_U;
|
||||||
|
case HALL_101:
|
||||||
|
return OUT_V_W;
|
||||||
|
case HALL_110:
|
||||||
|
return OUT_W_U;
|
||||||
|
default:
|
||||||
|
return COMBI_COUNT; // Ungültiger Zustand
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,9 +5,20 @@
|
|||||||
|
|
||||||
#include "ssd1306.h"
|
#include "ssd1306.h"
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include "mcpwm.h"
|
||||||
|
typedef enum {
|
||||||
|
HALL_000 = 0b000, // Ungültiger Zustand
|
||||||
|
HALL_001 = 0b001,
|
||||||
|
HALL_010 = 0b010,
|
||||||
|
HALL_011 = 0b011,
|
||||||
|
HALL_100 = 0b100,
|
||||||
|
HALL_101 = 0b101,
|
||||||
|
HALL_110 = 0b110,
|
||||||
|
HALL_111 = 0b111 // Ungültiger Zustand
|
||||||
|
} HallState;
|
||||||
|
|
||||||
bool get_Hall(int HallSensorGPIO);
|
bool get_Hall(int HallSensorGPIO);
|
||||||
SSD1306_t *configure_OLED_old();
|
SSD1306_t *configure_OLED_old();
|
||||||
|
HallState get_Hall_Combi();
|
||||||
|
OutCombis get_output_combination(HallState hall_state);
|
||||||
#endif
|
#endif
|
||||||
37
main/menu.c
37
main/menu.c
@@ -120,7 +120,8 @@ const char *mode_names[] = {
|
|||||||
"+W -V",
|
"+W -V",
|
||||||
" +U ",
|
" +U ",
|
||||||
" +V ",
|
" +V ",
|
||||||
" +W "
|
" +W ",
|
||||||
|
"ERROR"
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
@@ -233,8 +234,9 @@ static void check_button_pressed(){
|
|||||||
static void getset_bridge_state(){
|
static void getset_bridge_state(){
|
||||||
|
|
||||||
bool RFE_Pulled = !(gpio_get_level(CONFIG_RFE_GPIO));
|
bool RFE_Pulled = !(gpio_get_level(CONFIG_RFE_GPIO));
|
||||||
|
if(get_voltage_in()<18000){
|
||||||
if (RFE_Pulled){
|
current_bridge_state=STATE_UV;
|
||||||
|
}else if (RFE_Pulled){
|
||||||
current_bridge_state=STATE_OC;
|
current_bridge_state=STATE_OC;
|
||||||
}else if(!ShouldState){
|
}else if(!ShouldState){
|
||||||
current_bridge_state=STATE_DEAKTIVE;
|
current_bridge_state=STATE_DEAKTIVE;
|
||||||
@@ -244,7 +246,8 @@ bool RFE_Pulled = !(gpio_get_level(CONFIG_RFE_GPIO));
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void render_main_menu(){
|
static void render_main_menu(){
|
||||||
max_cursor_pos = 4;
|
if(current_mode == BLDC_MODE)max_cursor_pos = 3;else max_cursor_pos=4;
|
||||||
|
|
||||||
//Mode
|
//Mode
|
||||||
snprintf(display_message, sizeof(display_message), "Mode: %s", mode_names[current_mode]);
|
snprintf(display_message, sizeof(display_message), "Mode: %s", mode_names[current_mode]);
|
||||||
ssd1306_display_text(&dev, 1, display_message, strlen(display_message), cursor_position == 0);
|
ssd1306_display_text(&dev, 1, display_message, strlen(display_message), cursor_position == 0);
|
||||||
@@ -259,11 +262,11 @@ static void render_main_menu(){
|
|||||||
|
|
||||||
//More_Info_Menu
|
//More_Info_Menu
|
||||||
snprintf(display_message, sizeof(display_message), "Sensor Info ->");
|
snprintf(display_message, sizeof(display_message), "Sensor Info ->");
|
||||||
ssd1306_display_text(&dev, 4, display_message, strlen(display_message), cursor_position == 3);
|
ssd1306_display_text(&dev, 4, display_message, strlen(display_message),cursor_position == 3);
|
||||||
|
|
||||||
//Output Selection
|
//Output Selection
|
||||||
snprintf(display_message, sizeof(display_message), "Out: %s",OutCombi_names[current_out_combi]);
|
snprintf(display_message, sizeof(display_message), "Out: %s",OutCombi_names[current_out_combi]);
|
||||||
ssd1306_display_text(&dev, 5, display_message, strlen(display_message), cursor_position == 4);
|
ssd1306_display_text(&dev, 5, display_message, strlen(display_message), (current_mode == BLDC_MODE)|(cursor_position == 4));
|
||||||
|
|
||||||
|
|
||||||
//State
|
//State
|
||||||
@@ -280,6 +283,7 @@ max_cursor_pos = 3;
|
|||||||
|
|
||||||
switch(current_mode){
|
switch(current_mode){
|
||||||
case MCPWM_MODE:
|
case MCPWM_MODE:
|
||||||
|
case BLDC_MODE:
|
||||||
//Titel
|
//Titel
|
||||||
snprintf(display_message, sizeof(display_message), "Conf. MCPWM");
|
snprintf(display_message, sizeof(display_message), "Conf. MCPWM");
|
||||||
ssd1306_display_text(&dev, 1, display_message, strlen(display_message), false);
|
ssd1306_display_text(&dev, 1, display_message, strlen(display_message), false);
|
||||||
@@ -324,9 +328,7 @@ switch(current_mode){
|
|||||||
|
|
||||||
static void render_info_menu(){
|
static void render_info_menu(){
|
||||||
max_cursor_pos = 1;
|
max_cursor_pos = 1;
|
||||||
switch(current_mode){
|
|
||||||
case MCPWM_MODE:
|
|
||||||
|
|
||||||
//cur_U & Hall_A
|
//cur_U & Hall_A
|
||||||
snprintf(display_message, sizeof(display_message), "U:%ldmA H_A:%c", get_current_ASC712(CONFIG_I_SENSE_U_ADC),get_Hall(CONFIG_HALL_A_GPIO)?'1':'0');
|
snprintf(display_message, sizeof(display_message), "U:%ldmA H_A:%c", get_current_ASC712(CONFIG_I_SENSE_U_ADC),get_Hall(CONFIG_HALL_A_GPIO)?'1':'0');
|
||||||
ssd1306_display_text(&dev, 1, display_message, strlen(display_message), false);
|
ssd1306_display_text(&dev, 1, display_message, strlen(display_message), false);
|
||||||
@@ -351,17 +353,22 @@ switch(current_mode){
|
|||||||
snprintf(display_message, sizeof(display_message), "Back");
|
snprintf(display_message, sizeof(display_message), "Back");
|
||||||
ssd1306_display_text(&dev, 7, display_message, strlen(display_message), true);
|
ssd1306_display_text(&dev, 7, display_message, strlen(display_message), true);
|
||||||
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MenuState last_menu = MAIN_MENU; // Initialisiere mit dem Startmenü
|
MenuState last_menu = MAIN_MENU; // Initialisiere mit dem Startmenü
|
||||||
|
OutCombis last_out_combi = OUT_U_V;
|
||||||
void menu_loop(){
|
void menu_loop(){
|
||||||
|
if(current_mode== BLDC_MODE){
|
||||||
|
current_out_combi = get_output_combination(get_Hall_Combi());
|
||||||
|
|
||||||
|
if (current_out_combi != last_out_combi) {
|
||||||
|
configure_mcpwm_output(current_out_combi);
|
||||||
|
if(ShouldState){
|
||||||
|
start_mcpwm_output();
|
||||||
|
}
|
||||||
|
last_out_combi = current_out_combi; // Update to the new out_combi
|
||||||
|
}}
|
||||||
|
|
||||||
if(!in_editing){
|
if(!in_editing){
|
||||||
if (enc_in_counter<0){
|
if (enc_in_counter<0){
|
||||||
|
|||||||
Reference in New Issue
Block a user