reworeked some stuff in ADC.c
added geter for comparators of mcpwm.c for ADC synchromisation
This commit is contained in:
30
main/ADC.c
30
main/ADC.c
@@ -6,16 +6,15 @@
|
||||
#include "parsed_pins.h"
|
||||
|
||||
|
||||
portMUX_TYPE mux = portMUX_INITIALIZER_UNLOCKED;
|
||||
adc_cali_handle_t cali_handle = NULL;
|
||||
static portMUX_TYPE mux = portMUX_INITIALIZER_UNLOCKED;
|
||||
static adc_cali_handle_t cali_handle = NULL;
|
||||
static adc_oneshot_unit_handle_t adc1_handle = NULL;
|
||||
|
||||
/*############################################*/
|
||||
/*################ ADC-Setup #################*/
|
||||
/*############################################*/
|
||||
adc_oneshot_unit_handle_t configure_ADC1()
|
||||
{
|
||||
adc_oneshot_unit_handle_t adc1_handle;
|
||||
|
||||
void configure_ADC1()
|
||||
{
|
||||
// ADC1 Initialisierung
|
||||
adc_oneshot_unit_init_cfg_t init_config = {
|
||||
.unit_id = ADC_UNIT_1,
|
||||
@@ -48,10 +47,9 @@ adc_oneshot_unit_handle_t configure_ADC1()
|
||||
cali_handle = NULL; // Keine Kalibrierung verfügbar
|
||||
}
|
||||
|
||||
return adc1_handle;
|
||||
}
|
||||
|
||||
static uint32_t read_voltage(adc_oneshot_unit_handle_t adc1_handle, int channel) {
|
||||
static uint32_t read_voltage(int channel) {
|
||||
int adc_raw = 0;
|
||||
int voltage_calibrated = 0; // Verwende int für die Kalibrierungsfunktion
|
||||
uint32_t voltage = 0; // Konvertiere später zu uint32_t
|
||||
@@ -71,31 +69,31 @@ static uint32_t read_voltage(adc_oneshot_unit_handle_t adc1_handle, int channel)
|
||||
}
|
||||
|
||||
// Funktion zur Umrechnung in spezifische Spannung
|
||||
uint32_t get_voltage_in(adc_oneshot_unit_handle_t adc1_handle)
|
||||
uint32_t get_voltage_in()
|
||||
{
|
||||
uint32_t adc_voltage = read_voltage(adc1_handle, CONFIG_U_SENSE_ADC);
|
||||
uint32_t adc_voltage = read_voltage(CONFIG_U_SENSE_ADC);
|
||||
ESP_LOGI("ADC", "ADC%d:voltage:%ld", CONFIG_U_SENSE_ADC, adc_voltage);
|
||||
uint32_t voltage_in = adc_voltage / 0.0909;
|
||||
return voltage_in;
|
||||
}
|
||||
|
||||
int32_t get_current_ASC712(adc_oneshot_unit_handle_t adc1_handle, int ADC_pin)
|
||||
int32_t get_current_ASC712(int ADC_pin)
|
||||
{
|
||||
int32_t adc_voltage = read_voltage(adc1_handle,ADC_pin);
|
||||
int32_t adc_voltage = read_voltage(ADC_pin);
|
||||
int32_t current = (adc_voltage -2500)*5.405;
|
||||
ESP_LOGI("ADC", "ADC%d:voltage:%ldcurrent%ld", ADC_pin, adc_voltage, current);
|
||||
return current;
|
||||
}
|
||||
|
||||
uint32_t get_torque(adc_oneshot_unit_handle_t adc1_handle)
|
||||
uint32_t get_torque()
|
||||
{
|
||||
uint32_t adc_voltage =read_voltage(adc1_handle,CONFIG_TORQUE_ADC);
|
||||
uint32_t adc_voltage =read_voltage(CONFIG_TORQUE_ADC);
|
||||
uint32_t torque = adc_voltage/33;
|
||||
|
||||
return torque;
|
||||
}
|
||||
int32_t get_current_bridge(adc_oneshot_unit_handle_t adc1_handle, int ADC_pin){
|
||||
int32_t adc_voltage = read_voltage(adc1_handle,ADC_pin);
|
||||
int32_t get_current_bridge(int ADC_pin){
|
||||
int32_t adc_voltage = read_voltage(ADC_pin);
|
||||
ESP_LOGI("CurrentBridge", "ADC:%ld",adc_voltage);
|
||||
int32_t current = ((adc_voltage- 142)/6.77)/0.007;
|
||||
return current;
|
||||
|
||||
@@ -48,17 +48,17 @@ void app_main(void)
|
||||
mcpwm_init();
|
||||
set_mcpwm_output(PHASE_U,PHASE_V,duty);
|
||||
set_enc_in_counter(menu_counter);
|
||||
|
||||
|
||||
|
||||
//gpio_set_level(CONFIG_HIN_V_GPIO, 1);
|
||||
while (1) {
|
||||
//ssd1306_clear_screen(dev_pt, false);
|
||||
/* Die Anzeige der OLED mit der richtigen Nachricht
|
||||
Torque = get_torque(adc1_handle);
|
||||
Voltage_IN = get_voltage_in(adc1_handle);
|
||||
Current_U = get_current_ASC712(adc1_handle,CONFIG_I_SENSE_U_ADC);
|
||||
Current_V = get_current_ASC712(adc1_handle,CONFIG_I_SENSE_V_ADC);
|
||||
Current_W = get_current_ASC712(adc1_handle,CONFIG_I_SENSE_W_ADC);
|
||||
Torque = get_torque();
|
||||
Voltage_IN = get_voltage_in();
|
||||
Current_U = get_current_ASC712(CONFIG_I_SENSE_U_ADC);
|
||||
Current_V = get_current_ASC712(CONFIG_I_SENSE_V_ADC);
|
||||
Current_W = get_current_ASC712(CONFIG_I_SENSE_W_ADC);
|
||||
*/
|
||||
/* Hall_A_On = get_Hall(CONFIG_HALL_A_GPIO);
|
||||
Hall_B_On = get_Hall(CONFIG_HALL_B_GPIO);
|
||||
@@ -103,7 +103,7 @@ void app_main(void)
|
||||
snprintf(display_message, sizeof(display_message), "PWMFreq.: %ik ", (CONFIG_FREQ_PWM/1000));
|
||||
ssd1306_display_text(dev_pt, 3, display_message, 14, !(menu_counter));
|
||||
|
||||
snprintf(display_message, sizeof(display_message), "Duty: %.1f ", duty);
|
||||
snprintf(display_message, sizeof(display_message), "Duty: %.1f%% ", duty);
|
||||
ssd1306_display_text(dev_pt, 4, display_message, 14, !(menu_counter-1));
|
||||
|
||||
snprintf(display_message, sizeof(display_message), "DeadTime: %i ", CONFIG_DEAD_TIME_PWM);
|
||||
|
||||
@@ -3,11 +3,10 @@
|
||||
|
||||
#include "esp_adc/adc_oneshot.h"
|
||||
|
||||
extern adc_cali_handle_t cali_handle;
|
||||
|
||||
adc_oneshot_unit_handle_t configure_ADC1();
|
||||
uint32_t get_voltage_in(adc_oneshot_unit_handle_t adc1_handle);
|
||||
uint32_t get_torque(adc_oneshot_unit_handle_t adc1_handle);
|
||||
int32_t get_current_ASC712(adc_oneshot_unit_handle_t adc1_handle, int ADC_pin);
|
||||
int32_t get_current_bridge(adc_oneshot_unit_handle_t adc1_handle, int ADC_pin);
|
||||
void configure_ADC1();
|
||||
uint32_t get_voltage_in();
|
||||
uint32_t get_torque();
|
||||
int32_t get_current_ASC712(int ADC_pin);
|
||||
int32_t get_current_bridge(int ADC_pin);
|
||||
#endif
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef MCPWM_H
|
||||
#define MCPWM_H
|
||||
|
||||
#include "hal/mcpwm_types.h"
|
||||
#include "driver/mcpwm_prelude.h"
|
||||
typedef enum {
|
||||
PHASE_U,
|
||||
PHASE_V,
|
||||
@@ -10,5 +11,5 @@ typedef enum {
|
||||
void mcpwm_init();
|
||||
void set_mcpwm_output(Phase highside, Phase lowside, float Duty);
|
||||
void set_mcpwm_duty(float Duty);
|
||||
|
||||
void get_comps(mcpwm_cmpr_handle_t comps[3]);
|
||||
#endif
|
||||
@@ -1,6 +1,4 @@
|
||||
#include "mcpwm.h"
|
||||
#include "hal/mcpwm_types.h"
|
||||
#include "driver/mcpwm_prelude.h"
|
||||
#include "esp_timer.h"
|
||||
#include "esp_log.h"
|
||||
#include "math.h"
|
||||
@@ -256,4 +254,10 @@ void set_mcpwm_output(Phase highside, Phase lowside, float Duty){
|
||||
|
||||
void set_mcpwm_duty(float Duty){
|
||||
set_highside(HighsidePhase, Duty);
|
||||
}
|
||||
|
||||
void get_comps(mcpwm_cmpr_handle_t comps[3]) {
|
||||
comps[0] = comperator_U;
|
||||
comps[1] = comperator_V;
|
||||
comps[2] = comperator_W;
|
||||
}
|
||||
Reference in New Issue
Block a user