Skip to content

Commit 1c1fddc

Browse files
committed
Added support for the Rambo reprap electronics board. Added Mcodes to set
motor current and microstepping pins.
1 parent 0e58ef6 commit 1c1fddc

File tree

6 files changed

+261
-3
lines changed

6 files changed

+261
-3
lines changed

Marlin/Configuration.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@
3030
// Ultimaker = 7
3131
// Teensylu = 8
3232
// Gen3+ =9
33+
// Rambo = 301
3334

3435
#ifndef MOTHERBOARD
35-
#define MOTHERBOARD 7
36+
#define MOTHERBOARD 301
3637
#endif
3738

3839

Marlin/Configuration_adv.h

+14
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,20 @@
128128
// if unwanted behavior is observed on a user's machine when running at very slow speeds.
129129
#define MINIMUM_PLANNER_SPEED 0.05// (mm/sec)
130130

131+
// MS1 MS2 Stepper Driver Microstepping mode table
132+
#define MICROSTEP1 LOW,LOW
133+
#define MICROSTEP2 HIGH,LOW
134+
#define MICROSTEP4 LOW,HIGH
135+
#define MICROSTEP8 HIGH,HIGH
136+
#define MICROSTEP16 HIGH,HIGH
137+
138+
// Microstep setting (Only functional when stepper driver microstep pins are connected to MCU.
139+
#define MICROSTEP_MODES {16,16,16,16,16} // [1,2,4,8,16]
140+
141+
// Motor Current setting (Only functional when motor driver current ref pins are connected to a digital trimpot on supported boards)
142+
#define DIGIPOT_MOTOR_CURRENT {135,135,135,135,135} // Values 0-255 (RAMBO 135 = ~0.75A, 185 = ~1A)
143+
144+
131145
//===========================================================================
132146
//=============================Additional Features===========================
133147
//===========================================================================

Marlin/Marlin.pde

+53-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
It has preliminary support for Matthew Roberts advance algorithm
2727
http://reprap.org/pipermail/reprap-dev/2011-May/003323.html
2828
*/
29-
29+
#include <SPI.h>
3030
#include "Marlin.h"
3131

3232
#include "ultralcd.h"
@@ -120,6 +120,10 @@
120120
// M501 - reads parameters from EEPROM (if you need reset them after you changed them temporarily).
121121
// M502 - reverts to the default "factory settings". You still need to store them in EEPROM afterwards if you want to.
122122
// M503 - print the current settings (from memory not from eeprom)
123+
// M907 - Set digital trimpot motor current using axis codes.
124+
// M908 - Control digital trimpot directly.
125+
// M350 - Set microstepping mode.
126+
// M351 - Toggle MS1 MS2 pins directly.
123127
// M999 - Restart after being stopped by error
124128

125129
//Stepper Movement Variables
@@ -309,6 +313,8 @@ void setup()
309313
SERIAL_ECHOPGM(STRING_VERSION_CONFIG_H);
310314
SERIAL_ECHOPGM(MSG_AUTHOR);
311315
SERIAL_ECHOLNPGM(STRING_CONFIG_H_AUTHOR);
316+
SERIAL_ECHOPGM("Compiled: ");
317+
SERIAL_ECHOLNPGM(__DATE__);
312318
#endif
313319
#endif
314320
SERIAL_ECHO_START;
@@ -1466,6 +1472,52 @@ void process_commands()
14661472
EEPROM_printSettings();
14671473
}
14681474
break;
1475+
case 907: // Set digital trimpot motor current using axis codes.
1476+
{
1477+
#if DIGIPOTSS_PIN > -1
1478+
for(int i=0;i<=NUM_AXIS;i++) if(code_seen(axis_codes[i])) digipot_current(i,code_value());
1479+
if(code_seen('B')) digipot_current(4,code_value());
1480+
if(code_seen('S')) for(int i=0;i<=4;i++) digipot_current(i,code_value());
1481+
#endif
1482+
}
1483+
case 908: // Control digital trimpot directly.
1484+
{
1485+
#if DIGIPOTSS_PIN > -1
1486+
uint8_t channel,current;
1487+
if(code_seen('P')) channel=code_value();
1488+
if(code_seen('S')) current=code_value();
1489+
digitalPotWrite(channel, current);
1490+
#endif
1491+
}
1492+
break;
1493+
case 350: // Set microstepping mode. Warning: Steps per unit remains unchanged. S code sets stepping mode for all drivers.
1494+
{
1495+
#if X_MS1_PIN > -1
1496+
if(code_seen('S')) for(int i=0;i<=4;i++) microstep_mode(i,code_value());
1497+
for(int i=0;i<=NUM_AXIS;i++) if(code_seen(axis_codes[i])) microstep_mode(i,(uint8_t)code_value());
1498+
if(code_seen('B')) microstep_mode(4,code_value());
1499+
microstep_readings();
1500+
#endif
1501+
}
1502+
break;
1503+
case 351: // Toggle MS1 MS2 pins directly, S# determines MS1 or MS2, X# sets the pin high/low.
1504+
{
1505+
#if X_MS1_PIN > -1
1506+
if(code_seen('S')) switch((int)code_value())
1507+
{
1508+
case 1:
1509+
for(int i=0;i<=NUM_AXIS;i++) if(code_seen(axis_codes[i])) microstep_ms(i,code_value(),-1);
1510+
if(code_seen('B')) microstep_ms(4,code_value(),-1);
1511+
break;
1512+
case 2:
1513+
for(int i=0;i<=NUM_AXIS;i++) if(code_seen(axis_codes[i])) microstep_ms(i,-1,code_value());
1514+
if(code_seen('B')) microstep_ms(4,-1,code_value());
1515+
break;
1516+
}
1517+
microstep_readings();
1518+
#endif
1519+
}
1520+
break;
14691521
case 999: // Restart after being stopped
14701522
Stopped = false;
14711523
gcode_LastN = Stopped_gcode_LastN;

Marlin/pins.h

+82
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
#ifndef PINS_H
22
#define PINS_H
33

4+
#define X_MS1_PIN -1
5+
#define X_MS2_PIN -1
6+
#define Y_MS1_PIN -1
7+
#define Y_MS2_PIN -1
8+
#define Z_MS1_PIN -1
9+
#define Z_MS2_PIN -1
10+
#define E0_MS1_PIN -1
11+
#define E0_MS2_PIN -1
12+
#define E1_MS1_PIN -1
13+
#define E1_MS2_PIN -1
14+
#define DIGIPOTSS_PIN -1
15+
416
#if MOTHERBOARD == 99
517
#define KNOWN_BOARD 1
618

@@ -1128,6 +1140,76 @@
11281140

11291141
#endif
11301142

1143+
#if MOTHERBOARD == 301
1144+
#define KNOWN_BOARD
1145+
/*****************************************************************
1146+
* Rambo Pin Assignments
1147+
******************************************************************/
1148+
1149+
#ifndef __AVR_ATmega2560__
1150+
#error Oops! Make sure you have 'Arduino Mega 2560' selected from the 'Tools -> Boards' menu.
1151+
#endif
1152+
1153+
#define X_STEP_PIN 37
1154+
#define X_DIR_PIN 48
1155+
#define X_MIN_PIN 12
1156+
#define X_MAX_PIN 19
1157+
#define X_ENABLE_PIN 29
1158+
#define X_MS1_PIN 40
1159+
#define X_MS2_PIN 41
1160+
1161+
#define Y_STEP_PIN 36
1162+
#define Y_DIR_PIN 49
1163+
#define Y_MIN_PIN 11
1164+
#define Y_MAX_PIN 18
1165+
#define Y_ENABLE_PIN 28
1166+
#define Y_MS1_PIN 69
1167+
#define Y_MS2_PIN 39
1168+
1169+
#define Z_STEP_PIN 35
1170+
#define Z_DIR_PIN 47
1171+
#define Z_MIN_PIN 10
1172+
#define Z_MAX_PIN 15
1173+
#define Z_ENABLE_PIN 27
1174+
#define Z_MS1_PIN 68
1175+
#define Z_MS2_PIN 67
1176+
1177+
#define HEATER_BED_PIN 3
1178+
#define TEMP_BED_PIN 2
1179+
1180+
#define HEATER_0_PIN 9
1181+
#define TEMP_0_PIN 0
1182+
1183+
#define HEATER_1_PIN 7
1184+
#define TEMP_1_PIN 1
1185+
1186+
#define HEATER_2_PIN -1
1187+
#define TEMP_2_PIN -1
1188+
1189+
#define E0_STEP_PIN 34
1190+
#define E0_DIR_PIN 43
1191+
#define E0_ENABLE_PIN 26
1192+
#define E0_MS1_PIN 65
1193+
#define E0_MS2_PIN 66
1194+
1195+
#define E1_STEP_PIN 33
1196+
#define E1_DIR_PIN 42
1197+
#define E1_ENABLE_PIN 25
1198+
#define E1_MS1_PIN 63
1199+
#define E1_MS2_PIN 64
1200+
1201+
#define DIGIPOTSS_PIN 38
1202+
#define DIGIPOT_CHANNELS {4,5,3,0,1} // X Y Z E0 E1 digipot channels to stepper driver mapping
1203+
1204+
#define SDPOWER -1
1205+
#define SDSS 53
1206+
#define LED_PIN 13
1207+
#define FAN_PIN 8
1208+
#define PS_ON_PIN 4
1209+
#define KILL_PIN -1
1210+
#define SUICIDE_PIN -1 //PIN that has to be turned on right after start, to keep power flowing.
1211+
1212+
#endif
11311213

11321214
#ifndef KNOWN_BOARD
11331215
#error Unknown MOTHERBOARD value in configuration.h

Marlin/stepper.cpp

+101-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#include "ultralcd.h"
2929
#include "language.h"
3030
#include "speed_lookuptable.h"
31-
31+
#include <SPI.h>
3232

3333

3434
//===========================================================================
@@ -714,6 +714,9 @@ ISR(TIMER1_COMPA_vect)
714714

715715
void st_init()
716716
{
717+
digipot_init(); //Initialize Digipot Motor Current
718+
microstep_init(); //Initialize Microstepping Pins
719+
717720
//Initialize Dir Pins
718721
#if X_DIR_PIN > -1
719722
SET_OUTPUT(X_DIR_PIN);
@@ -951,3 +954,100 @@ void quickStop()
951954
ENABLE_STEPPER_DRIVER_INTERRUPT();
952955
}
953956

957+
int digitalPotWrite(int address, int value) // From Arduino DigitalPotControl example
958+
{
959+
#if DIGIPOTSS_PIN > -1
960+
digitalWrite(DIGIPOTSS_PIN,LOW); // take the SS pin low to select the chip
961+
SPI.transfer(address); // send in the address and value via SPI:
962+
SPI.transfer(value);
963+
digitalWrite(DIGIPOTSS_PIN,HIGH); // take the SS pin high to de-select the chip:
964+
//delay(10);
965+
#endif
966+
}
967+
968+
void digipot_init() //Initialize Digipot Motor Current
969+
{
970+
#if DIGIPOTSS_PIN > -1
971+
const uint8_t digipot_motor_current[] = DIGIPOT_MOTOR_CURRENT;
972+
973+
SPI.begin();
974+
pinMode(DIGIPOTSS_PIN, OUTPUT);
975+
for(int i=0;i<=4;i++)
976+
//digitalPotWrite(digipot_ch[i], digipot_motor_current[i]);
977+
digipot_current(i,digipot_motor_current[i]);
978+
#endif
979+
}
980+
981+
void digipot_current(uint8_t driver, int current)
982+
{
983+
#if DIGIPOTSS_PIN > -1
984+
const uint8_t digipot_ch[] = DIGIPOT_CHANNELS;
985+
digitalPotWrite(digipot_ch[driver], current);
986+
#endif
987+
}
988+
989+
void microstep_init()
990+
{
991+
#if X_MS1_PIN > -1
992+
const uint8_t microstep_modes[] = MICROSTEP_MODES;
993+
pinMode(X_MS2_PIN,OUTPUT);
994+
pinMode(Y_MS2_PIN,OUTPUT);
995+
pinMode(Z_MS2_PIN,OUTPUT);
996+
pinMode(E0_MS2_PIN,OUTPUT);
997+
pinMode(E1_MS2_PIN,OUTPUT);
998+
for(int i=0;i<=4;i++) microstep_mode(i,microstep_modes[i]);
999+
#endif
1000+
}
1001+
1002+
void microstep_ms(uint8_t driver, int8_t ms1, int8_t ms2)
1003+
{
1004+
if(ms1 > -1) switch(driver)
1005+
{
1006+
case 0: digitalWrite( X_MS1_PIN,ms1); break;
1007+
case 1: digitalWrite( Y_MS1_PIN,ms1); break;
1008+
case 2: digitalWrite( Z_MS1_PIN,ms1); break;
1009+
case 3: digitalWrite(E0_MS1_PIN,ms1); break;
1010+
case 4: digitalWrite(E1_MS1_PIN,ms1); break;
1011+
}
1012+
if(ms2 > -1) switch(driver)
1013+
{
1014+
case 0: digitalWrite( X_MS2_PIN,ms2); break;
1015+
case 1: digitalWrite( Y_MS2_PIN,ms2); break;
1016+
case 2: digitalWrite( Z_MS2_PIN,ms2); break;
1017+
case 3: digitalWrite(E0_MS2_PIN,ms2); break;
1018+
case 4: digitalWrite(E1_MS2_PIN,ms2); break;
1019+
}
1020+
}
1021+
1022+
void microstep_mode(uint8_t driver, uint8_t stepping_mode)
1023+
{
1024+
switch(stepping_mode)
1025+
{
1026+
case 1: microstep_ms(driver,MICROSTEP1); break;
1027+
case 2: microstep_ms(driver,MICROSTEP2); break;
1028+
case 4: microstep_ms(driver,MICROSTEP4); break;
1029+
case 8: microstep_ms(driver,MICROSTEP8); break;
1030+
case 16: microstep_ms(driver,MICROSTEP16); break;
1031+
}
1032+
}
1033+
1034+
void microstep_readings()
1035+
{
1036+
SERIAL_PROTOCOLPGM("MS1,MS2 Pins\n");
1037+
SERIAL_PROTOCOLPGM("X: ");
1038+
SERIAL_PROTOCOL( digitalRead(X_MS1_PIN));
1039+
SERIAL_PROTOCOLLN( digitalRead(X_MS2_PIN));
1040+
SERIAL_PROTOCOLPGM("Y: ");
1041+
SERIAL_PROTOCOL( digitalRead(Y_MS1_PIN));
1042+
SERIAL_PROTOCOLLN( digitalRead(Y_MS2_PIN));
1043+
SERIAL_PROTOCOLPGM("Z: ");
1044+
SERIAL_PROTOCOL( digitalRead(Z_MS1_PIN));
1045+
SERIAL_PROTOCOLLN( digitalRead(Z_MS2_PIN));
1046+
SERIAL_PROTOCOLPGM("E0: ");
1047+
SERIAL_PROTOCOL( digitalRead(E0_MS1_PIN));
1048+
SERIAL_PROTOCOLLN( digitalRead(E0_MS2_PIN));
1049+
SERIAL_PROTOCOLPGM("E1: ");
1050+
SERIAL_PROTOCOL( digitalRead(E1_MS1_PIN));
1051+
SERIAL_PROTOCOLLN( digitalRead(E1_MS2_PIN));
1052+
}
1053+

Marlin/stepper.h

+9
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,13 @@ void finishAndDisableSteppers();
6868
extern block_t *current_block; // A pointer to the block currently being traced
6969

7070
void quickStop();
71+
72+
int digitalPotWrite(int address, int value);
73+
void microstep_ms(uint8_t driver, int8_t ms1, int8_t ms2);
74+
void microstep_mode(uint8_t driver, uint8_t stepping);
75+
void digipot_init();
76+
void digipot_current(uint8_t driver, int current);
77+
void microstep_init();
78+
void microstep_readings();
79+
7180
#endif

0 commit comments

Comments
 (0)