Constant current driver fixes
This commit is contained in:
parent
0f4e4b5289
commit
84b06972fc
4 changed files with 84 additions and 41 deletions
21
src/boards.h
21
src/boards.h
|
|
@ -16,6 +16,9 @@
|
|||
#endif
|
||||
#endif
|
||||
|
||||
//TODO: deal with default values better
|
||||
//Kconfig is probably too complicated
|
||||
//maybe having a series of #ifndef <option> #def <option> default #endif at the end?
|
||||
#if defined(BOARD_SANGABOARDv3)
|
||||
#define BOARD_STRING "Sangaboard v0.3"
|
||||
#define WIRING_MOTOR_X 8, 9, 10, 11
|
||||
|
|
@ -26,6 +29,8 @@
|
|||
#define WIRING_ENDSTOPS_MIN {A0,A1,A2}
|
||||
#define WIRING_ENDSTOPS_MAX {A3,A4,A5}
|
||||
#define SERIAL_PORT Serial
|
||||
#define PWM_NUM 0
|
||||
#define WIRING_PWM_LEDS {}
|
||||
#elif defined(BOARD_SANGABOARDv2)
|
||||
#define BOARD_STRING "Sangaboard v0.2"
|
||||
#define WIRING_MOTOR_X 13, 12, 11, 10
|
||||
|
|
@ -36,6 +41,8 @@
|
|||
#define WIRING_ENDSTOPS_MIN {A0,A1,A2}
|
||||
#define WIRING_ENDSTOPS_MAX {A3,A4,A5}
|
||||
#define SERIAL_PORT Serial
|
||||
#define PWM_NUM 0
|
||||
#define WIRING_PWM_LEDS {}
|
||||
#elif defined(BOARD_CUSTOM_BLUEPILL)
|
||||
#define BOARD_STRING "Custom Bluepill board"
|
||||
#define WIRING_MOTOR_X PB11, PB10, PB1, PB0
|
||||
|
|
@ -46,6 +53,8 @@
|
|||
#define WIRING_ENDSTOPS_MIN {A0,A1,A2}
|
||||
#define WIRING_ENDSTOPS_MAX {A3,A4,A5}
|
||||
#define SERIAL_PORT Serial
|
||||
#define PWM_NUM 0
|
||||
#define WIRING_PWM_LEDS {}
|
||||
#elif defined(BOARD_CUSTOM_PICO)
|
||||
#define BOARD_STRING "Custom Pico board"
|
||||
#define WIRING_MOTOR_X 2, 3, 4, 5
|
||||
|
|
@ -58,8 +67,9 @@
|
|||
#define ADDITIONAL_STEPPERS 1
|
||||
#define WIRING_ADDITIONAL_STEPPERS = {{0, 1, 22, 23}}
|
||||
#define WIRING_STEPSTICK {13,14,15} //enable, step, dir todo: move to boards.h
|
||||
//TODO: illumination, 4th motor wiring
|
||||
#define SERIAL_PORT Serial
|
||||
#define PWM_NUM 0
|
||||
#define WIRING_PWM_LEDS {}
|
||||
#elif defined(BOARD_SANGABOARDv5)
|
||||
#define BOARD_STRING "Sangaboard v0.5"
|
||||
#define WIRING_MOTOR_X 2, 3, 4, 5
|
||||
|
|
@ -79,7 +89,10 @@
|
|||
#else
|
||||
#define SERIAL_PORT Serial2
|
||||
#endif
|
||||
//TODO: move illumination wiring here, 4th motor support
|
||||
#define PWM_NUM 2
|
||||
#define WIRING_PWM_LEDS {25, 29}
|
||||
#define WIRING_CC_LED 24
|
||||
//TODO: 4th motor support
|
||||
#elif defined(BOARD_CUSTOM_ESP32)
|
||||
#define BOARD_STRING "Custom ESP32 board"
|
||||
#define WIRING_MOTOR_X 34, 32, 25, 27
|
||||
|
|
@ -91,6 +104,8 @@
|
|||
#define WIRING_ENDSTOPS_MAX {A3,A4,A5}
|
||||
#define WIRING_STEPSTICK {13,12,27}
|
||||
#define SERIAL_PORT Serial
|
||||
#define PWM_NUM 0
|
||||
#define WIRING_PWM_LEDS {}
|
||||
#elif defined(BOARD_CUSTOM)
|
||||
#define BOARD_STRING "Custom board"
|
||||
#define WIRING_MOTOR_X 2, 3, 4, 5
|
||||
|
|
@ -104,4 +119,6 @@
|
|||
#define WIRING_ADDITIONAL_STEPPERS = {{0, 1, 22, 23}}
|
||||
#define WIRING_STEPSTICK {8,9,10} //enable, step, dir todo: move to boards.h
|
||||
#define SERIAL_PORT Serial
|
||||
#define PWM_NUM 0
|
||||
#define WIRING_PWM_LEDS {}
|
||||
#endif
|
||||
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
//without this, default to HW serial where available
|
||||
//the details are board specific and configured in boards.h
|
||||
//#define USB_SERIAL
|
||||
#define USB_SERIAL
|
||||
|
||||
#include <boards.h> //defines wiring
|
||||
|
||||
|
|
|
|||
|
|
@ -7,23 +7,23 @@
|
|||
#include "dummyEEPROM.h"
|
||||
#endif
|
||||
|
||||
#define PWM_NUM 1
|
||||
#define WIRING_PWM_LEDS {25}
|
||||
|
||||
const uint8_t pwm_led_pins[] = WIRING_PWM_LEDS;
|
||||
void illumination_pwm_freq(String command)
|
||||
{
|
||||
char * args[1];
|
||||
parse_arguments(args, command, 2);
|
||||
parse_arguments(args, command, 1);
|
||||
#ifdef MCU_PICO
|
||||
analogWriteFreq(atol(args[0]));//32khz seems sensible
|
||||
analogWriteRange(65535);
|
||||
|
||||
SERIAL_PORT.print("Frequency set: ");
|
||||
SERIAL_PORT.print(atol(args[0]));
|
||||
SERIAL_PORT.println("Hz");
|
||||
#else
|
||||
SERIAL_PORT.println("Feature not supported");
|
||||
#endif
|
||||
|
||||
SERIAL_PORT.println("Frequency set");
|
||||
free(args[0]);
|
||||
free(args[1]);
|
||||
}
|
||||
|
||||
void illumination_pwm(String command)
|
||||
|
|
@ -41,7 +41,7 @@ void illumination_pwm(String command)
|
|||
|
||||
if (val < 0.00001)
|
||||
{
|
||||
digitalWrite(pwm_led_pins[index], LOW);//start with motor disabled
|
||||
digitalWrite(pwm_led_pins[index], LOW);
|
||||
}
|
||||
#ifdef MCU_PICO
|
||||
uint32_t pwm_val = val * 65535;
|
||||
|
|
@ -50,54 +50,83 @@ void illumination_pwm(String command)
|
|||
#endif
|
||||
|
||||
analogWrite(pwm_led_pins[index], pwm_val);
|
||||
SERIAL_PORT.println("Illumination set");
|
||||
SERIAL_PORT.print("Illumination set");
|
||||
SERIAL_PORT.println(pwm_val);
|
||||
|
||||
free(args[0]);
|
||||
free(args[1]);
|
||||
#endif
|
||||
}
|
||||
|
||||
#define CC_EN_PIN 24 //TODO: Move to boards
|
||||
void illumination_setup()
|
||||
{
|
||||
#ifdef MCU_PICO
|
||||
analogWriteRange(65535);
|
||||
analogWriteFreq(32000);//32khz seems sensible
|
||||
#endif
|
||||
pinMode(pwm_led_pins[0], OUTPUT);
|
||||
pinMode(CC_EN_PIN, OUTPUT);
|
||||
for (uint8_t i = 0; i < PWM_NUM; i++)
|
||||
{
|
||||
pinMode(pwm_led_pins[i], OUTPUT);
|
||||
digitalWrite(pwm_led_pins[i], LOW);
|
||||
}
|
||||
|
||||
#ifdef WIRING_CC_LED
|
||||
pinMode(WIRING_CC_LED, OUTPUT);
|
||||
#endif
|
||||
|
||||
register_module(illumination_commands, NULL);
|
||||
}
|
||||
|
||||
void cc_on(String command)
|
||||
void cc_set(String command)
|
||||
{
|
||||
digitalWrite(CC_EN_PIN, HIGH);
|
||||
}
|
||||
#ifdef WIRING_CC_LED
|
||||
const uint8_t td = 3; // >= 1.5 us
|
||||
const uint8_t tup = 25; // 1-75 us
|
||||
const uint8_t tdown = 230; //180-300us
|
||||
|
||||
void cc_off(String command)
|
||||
{
|
||||
digitalWrite(CC_EN_PIN, LOW);
|
||||
}
|
||||
char * args[1];
|
||||
parse_arguments(args, command, 1);
|
||||
float val = atof(args[0]);
|
||||
free(args[0]);
|
||||
|
||||
void cc_up(String command)
|
||||
{
|
||||
digitalWrite(CC_EN_PIN, LOW);
|
||||
delayMicroseconds(30); //1-75us
|
||||
digitalWrite(CC_EN_PIN, HIGH);
|
||||
}
|
||||
//reset the device
|
||||
digitalWrite(WIRING_CC_LED, LOW);
|
||||
if (val < 0.02)
|
||||
return;
|
||||
|
||||
void cc_down(String command)
|
||||
{
|
||||
digitalWrite(CC_EN_PIN, LOW);
|
||||
delayMicroseconds(240); //180-300us
|
||||
digitalWrite(CC_EN_PIN, HIGH);
|
||||
uint8_t setting = val*32;
|
||||
delayMicroseconds(650);
|
||||
|
||||
//start sequence
|
||||
digitalWrite(WIRING_CC_LED, HIGH);
|
||||
delayMicroseconds(130);
|
||||
|
||||
uint8_t stepd = tup;
|
||||
uint8_t dir = 1;
|
||||
|
||||
if (setting < 16)
|
||||
{
|
||||
dir = -1;
|
||||
stepd = tdown;
|
||||
}
|
||||
|
||||
//step up
|
||||
for (uint8_t i=16; i!=setting; i+=dir)
|
||||
{
|
||||
digitalWrite(WIRING_CC_LED, LOW);
|
||||
delayMicroseconds(stepd);
|
||||
digitalWrite(WIRING_CC_LED, HIGH);
|
||||
delayMicroseconds(td);
|
||||
Serial.println("Stepping CC"); //TODO remove debug print
|
||||
}
|
||||
#else
|
||||
SERIAL_PORT.println("CC LED not supported");
|
||||
#endif
|
||||
}
|
||||
|
||||
extern const Command illumination_commands[] = {
|
||||
{"led_pwm", illumination_pwm},
|
||||
{"led_pwm_freq", illumination_pwm_freq},
|
||||
{"led_cc_up", cc_up},
|
||||
{"led_cc_down", cc_down},
|
||||
{"led_cc_on", cc_down},
|
||||
{"led_cc_off", cc_off},
|
||||
{"led_freq", illumination_pwm_freq},
|
||||
{"led_cc_set", cc_set},
|
||||
END_COMMAND};
|
||||
#endif
|
||||
|
|
@ -8,10 +8,7 @@
|
|||
void illumination_pwm(String command);
|
||||
void illumination_pwm_freq(String command);
|
||||
|
||||
void cc_on(String command);
|
||||
void cc_off(String command);
|
||||
void cc_up(String command);
|
||||
void cc_down(String command);
|
||||
void cc_set(String command);
|
||||
|
||||
void illumination_setup();
|
||||
extern const Command illumination_commands[];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue