Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5a3c6b15bc | ||
|
|
248668c526 | ||
|
|
9d416d29e6 |
File diff suppressed because one or more lines are too long
Binary file not shown.
@@ -11,11 +11,11 @@ extern "C" {
|
|||||||
//===================================
|
//===================================
|
||||||
//4x stepper mosfet outputs for VFD
|
//4x stepper mosfet outputs for VFD
|
||||||
#define GPIO_VFD_FWD GPIO_NUM_4 //ST4
|
#define GPIO_VFD_FWD GPIO_NUM_4 //ST4
|
||||||
#define GPIO_VFD_D0 GPIO_NUM_16 //ST3
|
#define GPIO_VFD_REV GPIO_NUM_16 //ST3
|
||||||
#define GPIO_VFD_D1 GPIO_NUM_2 //ST2
|
#define GPIO_VFD_D0 GPIO_NUM_2 //ST2
|
||||||
#define GPIO_VFD_D2 GPIO_NUM_15 //ST1
|
#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_MOS2 GPIO_NUM_5 //mos2
|
||||||
#define GPIO_RELAY GPIO_NUM_13
|
#define GPIO_RELAY GPIO_NUM_13
|
||||||
#define GPIO_BUZZER GPIO_NUM_12
|
#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 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 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
|
//------ calibration -------
|
||||||
#define PI 3.14159265358979323846
|
//--------------------------
|
||||||
|
//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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -70,6 +70,8 @@ int lengthTarget = 3000; //target length in mm
|
|||||||
int lengthRemaining = 0; //(target - now) length needed for reaching the target
|
int lengthRemaining = 0; //(target - now) length needed for reaching the target
|
||||||
int potiRead = 0; //voltage read from adc
|
int potiRead = 0; //voltage read from adc
|
||||||
uint32_t timestamp_motorStarted = 0; //timestamp winding started
|
uint32_t timestamp_motorStarted = 0; //timestamp winding started
|
||||||
|
|
||||||
|
int lengthBeeped = 0; //only beep once per meter during encoder test
|
||||||
|
|
||||||
|
|
||||||
//===== change State =====
|
//===== change State =====
|
||||||
@@ -186,7 +188,8 @@ void task_control(void *pvParameter)
|
|||||||
// Poll current position and direction
|
// Poll current position and direction
|
||||||
rotary_encoder_get_state(&encoder, &encoderState);
|
rotary_encoder_get_state(&encoder, &encoderState);
|
||||||
//--- calculate distance ---
|
//--- 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 --------
|
//-------- display1 --------
|
||||||
//--------------------------
|
//--------------------------
|
||||||
@@ -389,6 +416,8 @@ void task_control(void *pvParameter)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
//TODO: blink disp2 when set button pressed
|
//TODO: blink disp2 when set button pressed
|
||||||
//TODO: blink disp2 when preset button pressed (exept manual mode)
|
//TODO: blink disp2 when preset button pressed (exept manual mode)
|
||||||
//TODO: write "MAN CTL" to disp2 when in manual mode
|
//TODO: write "MAN CTL" to disp2 when in manual mode
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ void init_gpios(){
|
|||||||
gpio_configure_output(GPIO_VFD_FWD);
|
gpio_configure_output(GPIO_VFD_FWD);
|
||||||
gpio_configure_output(GPIO_VFD_D0);
|
gpio_configure_output(GPIO_VFD_D0);
|
||||||
gpio_configure_output(GPIO_VFD_D1);
|
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
|
//2x power mosfets
|
||||||
gpio_configure_output(GPIO_VFD_REV);
|
gpio_configure_output(GPIO_VFD_REV);
|
||||||
gpio_configure_output(GPIO_MOS2);
|
gpio_configure_output(GPIO_MOS2);
|
||||||
|
|||||||
24
main/vfd.cpp
24
main/vfd.cpp
@@ -77,12 +77,13 @@ void vfd_setSpeedLevel(uint8_t levelNew){
|
|||||||
//7 1 1 1 70
|
//7 1 1 1 70
|
||||||
|
|
||||||
//limit to 7
|
//limit to 7
|
||||||
if (level > 7) {
|
if (level > 3) {
|
||||||
level = 7;
|
level = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
//variables for logging the pin state
|
//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
|
//set output state according to corresponding bit state
|
||||||
if CHECK_BIT(level, 0) {
|
if CHECK_BIT(level, 0) {
|
||||||
@@ -101,14 +102,15 @@ void vfd_setSpeedLevel(uint8_t levelNew){
|
|||||||
gpio_set_level(GPIO_VFD_D1, 0);
|
gpio_set_level(GPIO_VFD_D1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if CHECK_BIT(level, 2) {
|
// if CHECK_BIT(level, 2) {
|
||||||
D2 = true;
|
// D2 = true;
|
||||||
gpio_set_level(GPIO_VFD_D2, 1);
|
// gpio_set_level(GPIO_VFD_D2, 1);
|
||||||
} else {
|
// } else {
|
||||||
D2 = false;
|
// D2 = false;
|
||||||
gpio_set_level(GPIO_VFD_D2, 0);
|
// gpio_set_level(GPIO_VFD_D2, 0);
|
||||||
}
|
// }
|
||||||
|
|
||||||
//log pin state
|
//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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)
|
//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);
|
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);
|
void vfd_setSpeedLevel(uint8_t levelNew = 0);
|
||||||
|
|||||||
Reference in New Issue
Block a user