constant current illumination control
This commit is contained in:
parent
d3920988b5
commit
9df96aae9f
2 changed files with 60 additions and 11 deletions
|
|
@ -77,17 +77,62 @@ void illumination_setup()
|
|||
register_module(illumination_commands, NULL);
|
||||
}
|
||||
|
||||
#ifdef WIRING_CC_LED
|
||||
|
||||
//these functions are useful testing
|
||||
float multi_read(uint8_t pin, uint16_t reads)
|
||||
{
|
||||
float total = 0;
|
||||
for(uint16_t i = 0; i<reads; i++)
|
||||
total += analogRead(pin);
|
||||
|
||||
return total/reads;
|
||||
}
|
||||
|
||||
void cc_test()
|
||||
{
|
||||
analogReadResolution(12);
|
||||
cc_set_value(0);
|
||||
|
||||
for (float v = 0; v <= 1; v+=0.02)
|
||||
{
|
||||
|
||||
Serial.print(v);
|
||||
Serial.print(" ");
|
||||
cc_set_value(v);
|
||||
Serial.print(" ");
|
||||
delay(2000);
|
||||
float current = multi_read(A0, 1000)/4095.0*3.3;
|
||||
Serial.println(current*1000);
|
||||
}
|
||||
|
||||
cc_set_value(0);
|
||||
}
|
||||
#endif
|
||||
|
||||
void cc_set(String command)
|
||||
{
|
||||
#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
|
||||
|
||||
char * args[1];
|
||||
parse_arguments(args, command, 1);
|
||||
float val = atof(args[0]);
|
||||
|
||||
free(args[0]);
|
||||
cc_set_value(val);
|
||||
}
|
||||
|
||||
void cc_set_value(float val)
|
||||
{
|
||||
#ifdef WIRING_CC_LED
|
||||
if (val<0)
|
||||
{
|
||||
cc_test();
|
||||
return;
|
||||
}
|
||||
|
||||
const uint8_t td = 3; // >= 1.5 us
|
||||
const uint8_t tup = 2; // 1-75 us
|
||||
const uint8_t tdown = 180; //180-300us
|
||||
const uint8_t tstart = 110; //100-150us
|
||||
|
||||
//reset the device
|
||||
digitalWrite(WIRING_CC_LED, LOW);
|
||||
|
|
@ -95,11 +140,11 @@ void cc_set(String command)
|
|||
return;
|
||||
|
||||
uint8_t setting = val*32;
|
||||
delayMicroseconds(650);
|
||||
delayMicroseconds(650); //reset device
|
||||
|
||||
//start sequence
|
||||
digitalWrite(WIRING_CC_LED, HIGH);
|
||||
delayMicroseconds(130);
|
||||
delayMicroseconds(tstart);
|
||||
|
||||
uint8_t stepd = tup;
|
||||
uint8_t dir = 1;
|
||||
|
|
@ -111,14 +156,16 @@ void cc_set(String command)
|
|||
}
|
||||
|
||||
//step up
|
||||
uint8_t steps_done =0;
|
||||
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
|
||||
steps_done++;
|
||||
}
|
||||
Serial.print(steps_done);
|
||||
#else
|
||||
SERIAL_PORT.println("CC LED not supported");
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@ void illumination_pwm(String command);
|
|||
void illumination_pwm_freq(String command);
|
||||
|
||||
void cc_set(String command);
|
||||
void cc_set_value(float val);
|
||||
|
||||
|
||||
void illumination_setup();
|
||||
extern const Command illumination_commands[];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue