added onboard Encoder not working yet
This commit is contained in:
@@ -13,6 +13,7 @@ void app_main(void)
|
||||
int32_t Current_V = 0;
|
||||
int32_t Current_W = 0;
|
||||
int32_t Current_bridge =0;
|
||||
int16_t enc_counter = 0;
|
||||
bool Hall_A_On = false;
|
||||
bool Hall_B_On = false;
|
||||
bool Hall_C_On = false;
|
||||
@@ -45,7 +46,7 @@ void app_main(void)
|
||||
Speed_indx = get_speed_index();
|
||||
Speed_AB = get_speed_AB();
|
||||
direction = get_direction();
|
||||
|
||||
enc_counter = get_enc_in_counter();
|
||||
Current_bridge = get_current_bridge(adc1_handle, CONFIG_I_SENSE_ADC);
|
||||
if (Voltage_IN >= 20000){
|
||||
ssd1306_display_text(dev_pt, 1, "Bridge=ON", 10, false);
|
||||
@@ -78,10 +79,11 @@ void app_main(void)
|
||||
}
|
||||
|
||||
}else{
|
||||
ssd1306_display_text(dev_pt, 1, "Bridge=OFF", 10, false);
|
||||
|
||||
|
||||
}
|
||||
|
||||
snprintf(display_message, sizeof(display_message), "count: %d", enc_counter);
|
||||
ssd1306_display_text(dev_pt, 1, display_message, 10, false);
|
||||
snprintf(display_message, sizeof(display_message), "Torque: %lu", Torque);
|
||||
ssd1306_display_text(dev_pt, 2, display_message, 11, false);
|
||||
|
||||
|
||||
@@ -3,6 +3,11 @@
|
||||
uint64_t delta_index_time = 0;
|
||||
uint64_t last_index_time = 0;
|
||||
uint64_t delta_AB_time = 0;
|
||||
volatile int enc_in_counter = 0;
|
||||
volatile bool enc_in_b_flag=false;
|
||||
volatile bool enc_in_a_flag=false;
|
||||
portMUX_TYPE mux = portMUX_INITIALIZER_UNLOCKED;
|
||||
|
||||
uint64_t last_AB_time = 0; // Definition der Variablen
|
||||
|
||||
adc_cali_handle_t cali_handle= NULL;
|
||||
@@ -10,23 +15,30 @@ adc_cali_handle_t cali_handle= NULL;
|
||||
/*############################################*/
|
||||
/*############### GPIO-Setup #################*/
|
||||
/*############################################*/
|
||||
void IRAM_ATTR index_isr_handler(void *arg){
|
||||
uint64_t current_time = esp_timer_get_time();
|
||||
|
||||
if (last_index_time != 0){
|
||||
delta_index_time = current_time - last_index_time;
|
||||
void IRAM_ATTR enc_in_a_isr_handler(void *arg){
|
||||
|
||||
portENTER_CRITICAL_ISR(&mux);
|
||||
if (enc_in_b_flag){
|
||||
enc_in_counter++;
|
||||
enc_in_b_flag = false;
|
||||
}
|
||||
else{
|
||||
enc_in_a_flag = true;
|
||||
}
|
||||
last_index_time = current_time;
|
||||
portEXIT_CRITICAL_ISR(&mux);
|
||||
}
|
||||
void IRAM_ATTR enc_ab_isr_handler(void *arg){
|
||||
uint64_t current_time = esp_timer_get_time();
|
||||
void IRAM_ATTR enc_in_b_isr_handler(void *arg){
|
||||
|
||||
if (last_AB_time != 0){
|
||||
delta_AB_time = current_time - last_AB_time;
|
||||
portENTER_CRITICAL_ISR(&mux);
|
||||
if (enc_in_a_flag){
|
||||
enc_in_counter--;
|
||||
enc_in_a_flag = false;
|
||||
}
|
||||
else{
|
||||
enc_in_b_flag = true;
|
||||
}
|
||||
last_AB_time = current_time;
|
||||
portEXIT_CRITICAL_ISR(&mux);
|
||||
}
|
||||
|
||||
void configure_GPIO_dir(const char *TAG)
|
||||
{
|
||||
/* reset every used GPIO-pin *
|
||||
@@ -42,7 +54,7 @@ void configure_GPIO_dir(const char *TAG)
|
||||
gpio_reset_pin(CONFIG_HALL_B_GPIO);
|
||||
gpio_reset_pin(CONFIG_HALL_C_GPIO);
|
||||
|
||||
//gpio_reset_pin(CONFIG_IN_ENC_A_GPIO);
|
||||
gpio_reset_pin(CONFIG_IN_ENC_A_GPIO);
|
||||
gpio_reset_pin(CONFIG_IN_ENC_B_GPIO);
|
||||
gpio_reset_pin(CONFIG_IN_ENC_BUT_GPIO);
|
||||
//gpio_reset_pin(CONFIG_BUTTON_GPIO);
|
||||
@@ -65,7 +77,7 @@ void configure_GPIO_dir(const char *TAG)
|
||||
gpio_set_direction(CONFIG_HALL_B_GPIO, GPIO_MODE_INPUT);
|
||||
gpio_set_direction(CONFIG_HALL_C_GPIO, GPIO_MODE_INPUT);
|
||||
|
||||
//gpio_set_direction(CONFIG_IN_ENC_A_GPIO, GPIO_MODE_INPUT);
|
||||
gpio_set_direction(CONFIG_IN_ENC_A_GPIO, GPIO_MODE_INPUT);
|
||||
gpio_set_direction(CONFIG_IN_ENC_B_GPIO, GPIO_MODE_INPUT);
|
||||
gpio_set_direction(CONFIG_IN_ENC_BUT_GPIO, GPIO_MODE_INPUT);
|
||||
//gpio_set_direction(CONFIG_BUTTON_GPIO, GPIO_MODE_INPUT);
|
||||
@@ -78,15 +90,17 @@ void configure_GPIO_dir(const char *TAG)
|
||||
ESP_LOGI(TAG, "GPIO dirs configured for DIY power PCB");
|
||||
|
||||
gpio_config_t io_conf = {};
|
||||
io_conf.pin_bit_mask = (1ULL << CONFIG_EXT_ENC_INDX_GPIO)| (1ULL << CONFIG_HALL_A_GPIO);
|
||||
io_conf.pin_bit_mask = (1ULL << CONFIG_EXT_ENC_INDX_GPIO)| (1ULL << CONFIG_HALL_A_GPIO)| (1ULL << CONFIG_IN_ENC_A_GPIO)| (1ULL << CONFIG_IN_ENC_B_GPIO);
|
||||
io_conf.mode = GPIO_MODE_INPUT;
|
||||
io_conf.pull_up_en = GPIO_PULLUP_ENABLE;
|
||||
io_conf.intr_type = GPIO_INTR_POSEDGE; // Interrupt auf steigende Flanke
|
||||
io_conf.intr_type = GPIO_INTR_ANYEDGE; // Interrupt auf steigende Flanke
|
||||
gpio_config(&io_conf);
|
||||
|
||||
gpio_install_isr_service(0);
|
||||
gpio_isr_handler_add(CONFIG_EXT_ENC_INDX_GPIO, index_isr_handler, NULL);
|
||||
gpio_isr_handler_add(CONFIG_HALL_A_GPIO, enc_ab_isr_handler, NULL);
|
||||
gpio_isr_handler_add(CONFIG_IN_ENC_A_GPIO, enc_in_a_isr_handler, NULL);
|
||||
gpio_isr_handler_add(CONFIG_IN_ENC_B_GPIO, enc_in_b_isr_handler, NULL);
|
||||
}
|
||||
/*############################################*/
|
||||
/*################ ADC-Setup #################*/
|
||||
@@ -538,6 +552,9 @@ void conf_mcpwm_timers(){
|
||||
|
||||
|
||||
}
|
||||
/*############################################*/
|
||||
/*############ Blockkommutierung #############*/
|
||||
/*############################################*/
|
||||
bool get_Hall(int HallSensorGPIO){
|
||||
char* TAG="";
|
||||
|
||||
@@ -561,6 +578,26 @@ bool get_Hall(int HallSensorGPIO){
|
||||
}
|
||||
return level;
|
||||
}
|
||||
|
||||
/*############################################*/
|
||||
/*############### Ext Encoder ################*/
|
||||
/*############################################*/
|
||||
void IRAM_ATTR index_isr_handler(void *arg){
|
||||
uint64_t current_time = esp_timer_get_time();
|
||||
|
||||
if (last_index_time != 0){
|
||||
delta_index_time = current_time - last_index_time;
|
||||
}
|
||||
last_index_time = current_time;
|
||||
}
|
||||
void IRAM_ATTR enc_ab_isr_handler(void *arg){
|
||||
uint64_t current_time = esp_timer_get_time();
|
||||
|
||||
if (last_AB_time != 0){
|
||||
delta_AB_time = current_time - last_AB_time;
|
||||
}
|
||||
last_AB_time = current_time;
|
||||
}
|
||||
int get_direction(){//-1=Error,0=right,1=left
|
||||
bool right = gpio_get_level(CONFIG_EXT_ENC_RIGHT_GPIO);
|
||||
bool left = gpio_get_level(CONFIG_EXT_ENC_LEFT_GPIO);
|
||||
@@ -577,7 +614,6 @@ int get_direction(){//-1=Error,0=right,1=left
|
||||
}
|
||||
return direction;
|
||||
}
|
||||
|
||||
float get_speed_index(){
|
||||
uint64_t local_delta_time = delta_index_time;
|
||||
float speed_rpm = 0;
|
||||
@@ -596,6 +632,14 @@ float get_speed_AB(){
|
||||
}
|
||||
return speed_rpm;
|
||||
}
|
||||
/*############################################*/
|
||||
/*############ Internal Encoder ##############*/
|
||||
/*############################################*/
|
||||
|
||||
int16_t get_enc_in_counter(){
|
||||
ESP_LOGI("Encoder_Int","Counter:%i",enc_in_counter);
|
||||
return enc_in_counter;
|
||||
}
|
||||
|
||||
/*############################################*/
|
||||
/*################## MISC ####################*/
|
||||
|
||||
@@ -54,6 +54,11 @@ int get_direction();
|
||||
float get_speed_index();
|
||||
float get_speed_AB();
|
||||
void conf_mcpwm_timers();
|
||||
void IRAM_ATTR index_isr_handler(void *arg);
|
||||
void IRAM_ATTR enc_ab_isr_handler(void *arg);
|
||||
//void IRAM_ATTR enc_in_a_isr_handler(void *arg);
|
||||
//void IRAM_ATTR enc_in_b_isr_handler(void *arg);
|
||||
int16_t get_enc_in_counter();
|
||||
void parse_3pins(const char *TAG, const char *pin_string, int *pins);
|
||||
SSD1306_t *configure_OLED(const char *TAG);
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#
|
||||
# Automatically generated file. DO NOT EDIT.
|
||||
# Espressif IoT Development Framework (ESP-IDF) 5.3.0 Project Configuration
|
||||
# Espressif IoT Development Framework (ESP-IDF) 5.3.1 Project Configuration
|
||||
#
|
||||
CONFIG_SOC_BROWNOUT_RESET_SUPPORTED="Not determined"
|
||||
CONFIG_SOC_TWAI_BRP_DIV_SUPPORTED="Not determined"
|
||||
@@ -174,7 +174,7 @@ CONFIG_SOC_TIMER_GROUP_TOTAL_TIMERS=4
|
||||
CONFIG_SOC_TIMER_GROUP_SUPPORT_APB=y
|
||||
CONFIG_SOC_TOUCH_SENSOR_VERSION=1
|
||||
CONFIG_SOC_TOUCH_SENSOR_NUM=10
|
||||
CONFIG_SOC_TOUCH_SAMPLER_NUM=1
|
||||
CONFIG_SOC_TOUCH_SAMPLE_CFG_NUM=1
|
||||
CONFIG_SOC_TWAI_CONTROLLER_NUM=1
|
||||
CONFIG_SOC_TWAI_BRP_MIN=2
|
||||
CONFIG_SOC_TWAI_CLK_SUPPORT_APB=y
|
||||
@@ -725,6 +725,14 @@ CONFIG_SPI_MASTER_ISR_IN_IRAM=y
|
||||
CONFIG_SPI_SLAVE_ISR_IN_IRAM=y
|
||||
# end of ESP-Driver:SPI Configurations
|
||||
|
||||
#
|
||||
# ESP-Driver:Touch Sensor Configurations
|
||||
#
|
||||
# CONFIG_TOUCH_CTRL_FUNC_IN_IRAM is not set
|
||||
# CONFIG_TOUCH_ISR_IRAM_SAFE is not set
|
||||
# CONFIG_TOUCH_ENABLE_DEBUG_LOG is not set
|
||||
# end of ESP-Driver:Touch Sensor Configurations
|
||||
|
||||
#
|
||||
# ESP-Driver:UART Configurations
|
||||
#
|
||||
|
||||
Reference in New Issue
Block a user