Skip to content

Commit

Permalink
Added M113 gcode to set laser output power via PWM channel.
Browse files Browse the repository at this point in the history
  • Loading branch information
modmaker committed Nov 7, 2012
1 parent 9ea9292 commit af4d006
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 2 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
##############################################################################

DEFS ?=
#DEFS += -DPRU_ABS_COORDS -DLASER_CUTTER
DEFS += -DPRU_ABS_COORDS
ARCH ?= arm
CROSS_COMPILE ?= arm-arago-linux-gnueabi-
Expand Down
15 changes: 15 additions & 0 deletions bebopr_r2.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,17 @@
GENERATE_TAG( bed_thermistor);
GENERATE_TAG( extruder_thermistor);
GENERATE_TAG( spare_ain);
#ifdef LASER_CUTTER
GENERATE_TAG( pwm_laser_power);
#else
GENERATE_TAG( temp_extruder);
GENERATE_TAG( temp_bed);
GENERATE_TAG( heater_extruder);
GENERATE_TAG( heater_bed);
GENERATE_TAG( pwm_extruder);
GENERATE_TAG( pwm_bed);
GENERATE_TAG( pwm_fan);
#endif

static const analog_config_record analog_config_data[] = {
{
Expand All @@ -60,6 +64,7 @@ static const analog_config_record analog_config_data[] = {
};

static const temp_config_record temp_config_data[] = {
#ifndef LASER_CUTTER
{
.tag = temp_extruder,
.source = extruder_thermistor,
Expand All @@ -75,6 +80,13 @@ static const temp_config_record temp_config_data[] = {
};

static const pwm_config_record pwm_config_data[] = {
#ifdef LASER_CUTTER
{
.tag = pwm_laser_power,
.device_path = PWM_PATH_PREFIX "ehrpwm.2:0", // BEBOPR_R2_J3 - PWM1
.frequency = 10,
},
#else
{
.tag = pwm_extruder,
.device_path = PWM_PATH_PREFIX "ehrpwm.2:0", // BEBOPR_R2_J3 - PWM1
Expand All @@ -90,9 +102,11 @@ static const pwm_config_record pwm_config_data[] = {
.device_path = PWM_PATH_PREFIX "ehrpwm.1:0", // BEBOPR_R2_J4 - PWM2
.frequency = 10,
},
#endif
};

static const heater_config_record heater_config_data[] = {
#ifndef LASER_CUTTER
{
.tag = heater_extruder,
.analog_input = temp_extruder,
Expand Down Expand Up @@ -121,6 +135,7 @@ static const heater_config_record heater_config_data[] = {
.I_limit = 0.0,
},
},
#endif
};

static int use_pololu_drivers = 1;
Expand Down
4 changes: 4 additions & 0 deletions gcode_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,11 @@ void gcode_parse_char(uint8_t c) {
break;
case 'S':
if (next_target.seen_M && (next_target.M == 220 || next_target.M == 221)) {
// if this is a scaling factor, scale 1.0 to 1000
next_target.S = decfloat_to_int( &read_digit, 1000.0);
} else if (next_target.seen_M && (next_target.M == 113)) {
// if this is PWM output, scale 1.0 to 100(%)
next_target.S = decfloat_to_int( &read_digit, 100.0);
} else {
// if this is temperature, PID setting or anything else, scale 1:1
next_target.S = decfloat_to_int( &read_digit, 1.0);
Expand Down
17 changes: 16 additions & 1 deletion gcode_process.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ static channel_tag heater_extruder = NULL;
static channel_tag heater_bed = NULL;
static channel_tag temp_extruder = NULL;
static channel_tag temp_bed = NULL;
static channel_tag pwm_extruder = NULL;

static int extruder_temp_wait = 0;
static int bed_temp_wait = 0;
Expand Down Expand Up @@ -769,6 +770,18 @@ void process_gcode_command() {
break;
#endif
// M113- extruder PWM
case 113: {
//? ==== M113: Set (extruder) PWM ====
//?
//? Example: M113 S0.125
//?
//? Set the (raw) extruder heater output to the specified value: 0.0-1.0 gives 0-100% duty cycle.
//? Should only be used when there is no heater control loop configured for this output!!!
if (next_target.seen_S) {
pwm_set_output( pwm_extruder, next_target.S);
}
break;
}
// M114- report XYZEF to host
case 114:
//? ==== M114: Get Current Position ====
Expand Down Expand Up @@ -1107,7 +1120,9 @@ int gcode_process_init( void)
tag_name( heater_extruder), tag_name( heater_bed),
tag_name( temp_extruder), tag_name( temp_bed));
}
if (heater_extruder == NULL || temp_extruder == NULL) {
pwm_extruder = pwm_lookup_by_name( "pwm_laser_power");
// If there's no extruder, or no laser power there's probably a configuration error!
if ((heater_extruder == NULL || temp_extruder == NULL) && pwm_extruder == NULL) {
return -1;
}
gcode_current_pos.X = gcode_home_pos.X = 0;
Expand Down
12 changes: 12 additions & 0 deletions pwm.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,15 @@ int pwm_set_output( channel_tag pwm_channel, unsigned int percentage)
}
return -1;
}

channel_tag pwm_lookup_by_name( const char* name)
{
for (int ix = 0 ; ix < num_pwm_channels ; ++ix) {
channel_tag tag = pwm_channels[ ix].id;
if (strcmp( tag_name( tag), name) == 0) {
return tag;
}
}
return NULL;
}

2 changes: 1 addition & 1 deletion pwm.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ typedef const struct {
extern int pwm_init( void);
extern void pwm_exit( void);
extern int pwm_config( pwm_config_record* pconfig_data, int nr_config_items);

extern int pwm_set_output( channel_tag pwm_channel, unsigned int percentage);
extern channel_tag pwm_lookup_by_name( const char* name);

#endif

0 comments on commit af4d006

Please sign in to comment.