Constant current driver fixes
This commit is contained in:
parent
0f4e4b5289
commit
84b06972fc
4 changed files with 84 additions and 41 deletions
|
|
@ -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
|
||||
Loading…
Add table
Add a link
Reference in a new issue