3 Commits

Author SHA1 Message Date
jonny_l480
5a3c6b15bc Merge branch 'display'
- merge display branch with outsourced and reworked display code
- resolve merge conflict caused by new ENCODER_TEST feature in main
2022-08-26 14:04:50 +02:00
jonny_l480
248668c526 Add encoder-test, calibrate distance conversion
Add encoder test:
  - used for calibrating the length measurement by counting the steps
    per meter
  - enabled with #define ENCODER_TEST  in config.hpp
  - display1: enocder steps
  - display2: converted length in meter

Distance conversion:
  - defining STEPS_PER_METER instead of MEASURING_ROLL_DIAMETER in
    config.hpp
  - defining the steps per meter by issuing 3 test measurements with
    4mm2 solar cable in the new encoder test mode
2022-08-26 13:24:51 +02:00
jonny_ji7
9d416d29e6 Switch from 7.5kw vfd to 700W vfd
Already switched earlier, now optimized code and connection plan to work
best with new vfd (T130750W).
Previous 7.5kw vfd will work too without using all 7 speed levels as at
first.

connection plan: changed pin assignment (1 free pin)

Code:
  - vfd.cpp, main.cpp: remove not used D2 pin (only used with 7.5kw vfd)
  - config.hpp: change pin assignment
2022-08-26 11:24:27 +02:00
7 changed files with 58 additions and 22 deletions

File diff suppressed because one or more lines are too long

Binary file not shown.

View File

@@ -11,11 +11,11 @@ extern "C" {
//===================================
//4x stepper mosfet outputs for VFD
#define GPIO_VFD_FWD GPIO_NUM_4 //ST4
#define GPIO_VFD_D0 GPIO_NUM_16 //ST3
#define GPIO_VFD_D1 GPIO_NUM_2 //ST2
#define GPIO_VFD_D2 GPIO_NUM_15 //ST1
#define GPIO_VFD_REV GPIO_NUM_16 //ST3
#define GPIO_VFD_D0 GPIO_NUM_2 //ST2
#define GPIO_VFD_D1 GPIO_NUM_15 //ST1
//#define GPIO_VFD_D2 GPIO_NUM_15 //ST1 (D2 only used with 7.5kw vfd)
#define GPIO_VFD_REV GPIO_NUM_18 //mos1
#define GPIO_MOS2 GPIO_NUM_5 //mos2
#define GPIO_RELAY GPIO_NUM_13
#define GPIO_BUZZER GPIO_NUM_12
@@ -56,9 +56,14 @@ extern "C" {
#define ENABLE_HALF_STEPS false // Set to true to enable tracking of rotary encoder at half step resolution
#define FLIP_DIRECTION false // Set to true to reverse the clockwise/counterclockwise sense
//#define MEASURING_ROLL_DIAMETER 44 //roll v2 glued
#define MEASURING_ROLL_DIAMETER 86.6 //roll v3 large
#define PI 3.14159265358979323846
//--------------------------
//------ calibration -------
//--------------------------
//use encoder test for calibration and calculate STEPS_PER_METER
//#define ENCODER_TEST //show encoder count instead of converted meters
#define STEPS_PER_METER 2127 //roll-v3-gummi-86.6mm - d=89.8mm
//#define MEASURING_ROLL_DIAMETER 86.6 //roll v3 large
//#define PI 3.14159265358979323846

View File

@@ -71,6 +71,8 @@ int lengthRemaining = 0; //(target - now) length needed for reaching the target
int potiRead = 0; //voltage read from adc
uint32_t timestamp_motorStarted = 0; //timestamp winding started
int lengthBeeped = 0; //only beep once per meter during encoder test
//===== change State =====
//function for changing the controlState with log output
@@ -186,7 +188,8 @@ void task_control(void *pvParameter)
// Poll current position and direction
rotary_encoder_get_state(&encoder, &encoderState);
//--- calculate distance ---
lengthNow = (float)encoderState.position * (MEASURING_ROLL_DIAMETER * PI) / 600; //TODO dont calculate constant factor every time FIXME: ROUNDING ISSUE float-int?
//lengthNow = (float)encoderState.position * (MEASURING_ROLL_DIAMETER * PI) / 600; //TODO dont calculate constant factor every time FIXME: ROUNDING ISSUE float-int?
lengthNow = (float)encoderState.position * 1000 / STEPS_PER_METER;
@@ -353,6 +356,30 @@ void task_control(void *pvParameter)
//--------------------------
//------ encoder test ------
//--------------------------
#ifdef ENCODER_TEST
//run display handle functions
displayTop.handle();
displayBot.handle();
//-- show encoder steps on display1 ---
sprintf(buf_disp1, "EN %05d", encoderState.position); //count
displayTop.showString(buf_disp1);
//--- show converted distance on display2 ---
sprintf(buf_disp2, "Met %5.3f", (float)lengthNow/1000); //m
displayBot.showString(buf_disp2);
//--- beep every 1m ---
//note: only works precicely in forward/positive direction
if (lengthNow % 1000 < 50) { //with tolerance in case of missed exact value
if (fabs(lengthNow - lengthBeeped) >= 900) { //dont beep multiple times at same meter
//TODO: add case for reverse direction. currently beeps 0.1 too early
buzzer.beep(1, 400, 100 );
lengthBeeped = lengthNow;
}
}
#else
//--------------------------
//-------- display1 --------
//--------------------------
@@ -389,6 +416,8 @@ void task_control(void *pvParameter)
}
#endif
//TODO: blink disp2 when set button pressed
//TODO: blink disp2 when preset button pressed (exept manual mode)
//TODO: write "MAN CTL" to disp2 when in manual mode

View File

@@ -30,7 +30,7 @@ void init_gpios(){
gpio_configure_output(GPIO_VFD_FWD);
gpio_configure_output(GPIO_VFD_D0);
gpio_configure_output(GPIO_VFD_D1);
gpio_configure_output(GPIO_VFD_D2);
//gpio_configure_output(GPIO_VFD_D2); only used with 7.5kw vfd
//2x power mosfets
gpio_configure_output(GPIO_VFD_REV);
gpio_configure_output(GPIO_MOS2);

View File

@@ -77,12 +77,13 @@ void vfd_setSpeedLevel(uint8_t levelNew){
//7 1 1 1 70
//limit to 7
if (level > 7) {
level = 7;
if (level > 3) {
level = 3;
}
//variables for logging the pin state
bool D0, D1, D2;
//bool D0, D1, D2;
bool D0, D1;
//set output state according to corresponding bit state
if CHECK_BIT(level, 0) {
@@ -101,14 +102,15 @@ void vfd_setSpeedLevel(uint8_t levelNew){
gpio_set_level(GPIO_VFD_D1, 0);
}
if CHECK_BIT(level, 2) {
D2 = true;
gpio_set_level(GPIO_VFD_D2, 1);
} else {
D2 = false;
gpio_set_level(GPIO_VFD_D2, 0);
}
// if CHECK_BIT(level, 2) {
// D2 = true;
// gpio_set_level(GPIO_VFD_D2, 1);
// } else {
// D2 = false;
// gpio_set_level(GPIO_VFD_D2, 0);
// }
//log pin state
ESP_LOGI(TAG, " - pin state: D2=%i, D1=%i, D0=%i", (int)D2, (int)D1, (int)D0);
//ESP_LOGI(TAG, " - pin state: D2=%i, D1=%i, D0=%i", (int)D2, (int)D1, (int)D0);
ESP_LOGI(TAG, " - pin state: D1=%i, D0=%i", (int)D1, (int)D0);
}

View File

@@ -19,5 +19,5 @@ extern const char* vfd_directionStr[2];
//function for setting the state and optional direction of the motor: on/off, FWD/REV (default FWD)
void vfd_setState(bool stateNew, vfd_direction_t direction = FWD);
//function for setting the speed level (1-7)
//function for setting the speed level (0-3)
void vfd_setSpeedLevel(uint8_t levelNew = 0);