mirror of
https://github.com/caperren/school_archives.git
synced 2025-11-09 21:51:15 +00:00
Added old firmware and pcb design files
These are all design documents that I thought I had lost. It's may make me cringe, but it's still cool to use it to see how far I've come.
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
#include "AxisClass.h"
|
||||
#include <Arduino.h>
|
||||
extern const unsigned char Microstep[6][3];
|
||||
|
||||
Axis::Axis (unsigned char AxisStep, unsigned char AxisDir, unsigned char AxisM0, unsigned char AxisM1, unsigned char AxisM2, unsigned char AxisFault){
|
||||
p_Step = AxisStep;
|
||||
p_Dir = AxisDir;
|
||||
p_M0 = AxisM0;
|
||||
p_M1 = AxisM1;
|
||||
p_M2 = AxisM2;
|
||||
p_Fault = AxisFault;
|
||||
DelVal = 8;
|
||||
|
||||
pinMode(p_Step, OUTPUT);
|
||||
pinMode(p_Dir, OUTPUT);
|
||||
pinMode(p_M0, OUTPUT);
|
||||
pinMode(p_M1, OUTPUT);
|
||||
pinMode(p_M2, OUTPUT);
|
||||
pinMode(p_Fault, INPUT);
|
||||
|
||||
SetMicrostep(8);
|
||||
}
|
||||
|
||||
|
||||
void Axis::SetMicrostep(unsigned char Level){
|
||||
unsigned char row = -1;
|
||||
switch (Level){
|
||||
case 1:
|
||||
row = 0;
|
||||
break;
|
||||
case 2:
|
||||
row = 1;
|
||||
break;
|
||||
case 4:
|
||||
row = 2;
|
||||
break;
|
||||
case 8:
|
||||
row = 3;
|
||||
break;
|
||||
case 16:
|
||||
row = 4;
|
||||
break;
|
||||
case 32:
|
||||
row = 5;
|
||||
break;
|
||||
}
|
||||
|
||||
digitalWrite(p_M0, Microstep[row][0]);
|
||||
digitalWrite(p_M1, Microstep[row][1]);
|
||||
digitalWrite(p_M2, Microstep[row][2]);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void Axis::StepForward(){
|
||||
digitalWrite(p_Dir, HIGH);
|
||||
digitalWrite(p_Step, HIGH);
|
||||
digitalWrite(p_Step, LOW);
|
||||
}
|
||||
|
||||
void Axis::StepBackward(){
|
||||
digitalWrite(p_Dir, LOW);
|
||||
digitalWrite(p_Step, HIGH);
|
||||
digitalWrite(p_Step, LOW);
|
||||
}
|
||||
|
||||
int Axis::SetRPM(int RPM){
|
||||
int CountVal = ((16000000L/8)/((200L*8*RPM)/60));
|
||||
cli();
|
||||
OCR1A = CountVal;
|
||||
sei();
|
||||
return CountVal;
|
||||
|
||||
}
|
||||
|
||||
void Axis::SetDelay(unsigned int delLen){
|
||||
DelVal = delLen;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
#ifndef AXIS_CLASS_H
|
||||
#define AXIS_CLASS_H
|
||||
const unsigned char Microstep[6][3] = {
|
||||
{
|
||||
0, 0, 0
|
||||
}
|
||||
,
|
||||
{
|
||||
1, 0, 0
|
||||
}
|
||||
,
|
||||
{
|
||||
0, 1, 0
|
||||
}
|
||||
,
|
||||
{
|
||||
1, 1, 0
|
||||
}
|
||||
,
|
||||
{
|
||||
0, 0, 1
|
||||
}
|
||||
,
|
||||
{
|
||||
1, 0, 1
|
||||
}
|
||||
};
|
||||
|
||||
class Axis {
|
||||
private:
|
||||
unsigned char p_Step;
|
||||
unsigned char p_Dir;
|
||||
unsigned char p_M0;
|
||||
unsigned char p_M1;
|
||||
unsigned char p_M2;
|
||||
unsigned char p_Fault;
|
||||
|
||||
unsigned int DelVal;
|
||||
|
||||
public:
|
||||
Axis (unsigned char AxisStep, unsigned char AxisDir, unsigned char AxisM0, unsigned char AxisM1, unsigned char AxisM2, unsigned char AxisFault);
|
||||
void SetMicrostep(unsigned char Level);
|
||||
void StepForward();
|
||||
void StepBackward();
|
||||
int SetRPM(int RPM);
|
||||
void SetDelay(unsigned int delLen);
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
#include "DriverBoardClass.h"
|
||||
#include <Arduino.h>
|
||||
|
||||
DriverBoard::DriverBoard(Axis *XAxisPt,Axis *YAxisPt, Axis *ZAxisPt, unsigned char ServoP, unsigned char StatusLed, unsigned char ErrorLed, unsigned char M_Enable, unsigned char ESTOP, unsigned char LimitESTOP, unsigned char X1_Lim, unsigned char X2_Lim, unsigned char Y1_Lim,
|
||||
unsigned char Y2_Lim, unsigned char Z1_Lim, unsigned char Z2_Lim, unsigned char A1_Lim, unsigned char A2_Lim, unsigned char XJL, unsigned char XJR, unsigned char YJF, unsigned char YJB, unsigned char ZJU,
|
||||
unsigned char ZJD, unsigned char AJF, unsigned char AJB, unsigned char JSI, unsigned char JSD){
|
||||
//Assign Pins to Class Variables
|
||||
XAxis = XAxisPt;
|
||||
YAxis = YAxisPt;
|
||||
ZAxis = ZAxisPt;
|
||||
p_Servo = ServoP;
|
||||
p_StatusLed = StatusLed;
|
||||
p_ErrorLed = ErrorLed;
|
||||
p_M_Enable = M_Enable;
|
||||
p_ESTOP = ESTOP;
|
||||
p_LimitESTOP = LimitESTOP;
|
||||
p_X1_Lim = X1_Lim;
|
||||
p_X2_Lim = X2_Lim;
|
||||
p_Y1_Lim = Y1_Lim;
|
||||
p_Y2_Lim = Y2_Lim;
|
||||
p_Z1_Lim = Z1_Lim;
|
||||
p_Z2_Lim = Z2_Lim;
|
||||
p_A1_Lim = A1_Lim;
|
||||
p_A2_Lim = A2_Lim;
|
||||
p_XJL = XJL;
|
||||
p_XJR = XJR;
|
||||
p_YJF = YJF;
|
||||
p_YJB = YJB;
|
||||
p_ZJU = ZJU;
|
||||
p_ZJD = ZJD;
|
||||
p_AJF = AJF;
|
||||
p_AJB = AJB;
|
||||
p_JSI = JSI;
|
||||
p_JSD = JSD;
|
||||
|
||||
//Set pin modes for output pins
|
||||
pinMode(p_Servo, OUTPUT);
|
||||
pinMode(p_StatusLed, OUTPUT);
|
||||
pinMode(p_ErrorLed, OUTPUT);
|
||||
pinMode(p_M_Enable, OUTPUT);
|
||||
|
||||
//Set pin modes for input pins
|
||||
pinMode(p_ESTOP, INPUT);
|
||||
pinMode(p_LimitESTOP, INPUT);
|
||||
pinMode(p_X1_Lim, INPUT);
|
||||
pinMode(p_X2_Lim, INPUT);
|
||||
pinMode(p_Y1_Lim, INPUT);
|
||||
pinMode(p_Y2_Lim, INPUT);
|
||||
pinMode(p_Z1_Lim, INPUT);
|
||||
pinMode(p_Z2_Lim, INPUT);
|
||||
pinMode(p_A1_Lim, INPUT);
|
||||
pinMode(p_A2_Lim, INPUT);
|
||||
pinMode(p_XJL, INPUT);
|
||||
pinMode(p_XJR, INPUT);
|
||||
pinMode(p_YJF, INPUT);
|
||||
pinMode(p_YJB, INPUT);
|
||||
pinMode(p_ZJU, INPUT);
|
||||
pinMode(p_ZJD, INPUT);
|
||||
pinMode(p_AJF, INPUT);
|
||||
pinMode(p_AJB, INPUT);
|
||||
pinMode(p_JSI, INPUT);
|
||||
pinMode(p_JSD, INPUT);
|
||||
|
||||
digitalWrite(p_M_Enable, LOW); //Enable motor drivers
|
||||
|
||||
};
|
||||
|
||||
void DriverBoard::MoveToPosition(long XPos){
|
||||
XAxis->StepForward();
|
||||
YAxis->StepForward();
|
||||
ZAxis->StepForward();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
#ifndef DRIVERBOARD_CLASS_H
|
||||
#define DRIVERBOARD_CLASS_H
|
||||
|
||||
#include "AxisClass.h"
|
||||
|
||||
//extern Axis XAxis;
|
||||
///extern Axis YAxis;
|
||||
//extern Axis ZAxis;
|
||||
|
||||
class DriverBoard{
|
||||
private:
|
||||
float CurXPos;
|
||||
float CurYPos;
|
||||
float CurZPos;
|
||||
|
||||
unsigned char p_Servo;
|
||||
unsigned char p_StatusLed;
|
||||
unsigned char p_ErrorLed;
|
||||
unsigned char p_M_Enable;
|
||||
unsigned char p_ESTOP;
|
||||
unsigned char p_LimitESTOP;
|
||||
unsigned char p_X1_Lim;
|
||||
unsigned char p_X2_Lim;
|
||||
unsigned char p_Y1_Lim;
|
||||
unsigned char p_Y2_Lim;
|
||||
unsigned char p_Z1_Lim;
|
||||
unsigned char p_Z2_Lim;
|
||||
unsigned char p_A1_Lim;
|
||||
unsigned char p_A2_Lim;
|
||||
unsigned char p_XJL;
|
||||
unsigned char p_XJR;
|
||||
unsigned char p_YJF;
|
||||
unsigned char p_YJB;
|
||||
unsigned char p_ZJU;
|
||||
unsigned char p_ZJD;
|
||||
unsigned char p_AJF;
|
||||
unsigned char p_AJB;
|
||||
unsigned char p_JSI;
|
||||
unsigned char p_JSD;
|
||||
|
||||
Axis *XAxis;
|
||||
Axis *YAxis;
|
||||
Axis *ZAxis;
|
||||
|
||||
public:
|
||||
DriverBoard(Axis *XAxisPt, Axis *YAxisPt, Axis *ZAxisPt, unsigned char ServoP, unsigned char StatusLed, unsigned char ErrorLed, unsigned char M_Enable, unsigned char ESTOP, unsigned char LimitESTOP, unsigned char X1_Lim, unsigned char X2_Lim, unsigned char Y1_Lim,
|
||||
unsigned char Y2_Lim, unsigned char Z1_Lim, unsigned char Z2_Lim, unsigned char A1_Lim, unsigned char A2_Lim, unsigned char XJL, unsigned char XJR, unsigned char YJF, unsigned char YJB, unsigned char ZJU,
|
||||
unsigned char ZJD, unsigned char AJF, unsigned char AJB, unsigned char JSI, unsigned char JSD);
|
||||
|
||||
void MoveToPosition(long XPos);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,159 @@
|
||||
#include <SoftwareSerial.h>
|
||||
#include "DriverBoardClass.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//Pin Definitions
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//Inputs/////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
const unsigned char p_ESTOP = 2;
|
||||
const unsigned char p_LimitESTOP = 3;
|
||||
|
||||
const unsigned char p_XFault = 27;
|
||||
const unsigned char p_YFault = 33;
|
||||
const unsigned char p_AFault = 41;
|
||||
const unsigned char p_SFault = A13;
|
||||
|
||||
const unsigned char p_X1_Lim = A0;
|
||||
const unsigned char p_X2_Lim = A1;
|
||||
const unsigned char p_Y1_Lim = A2;
|
||||
const unsigned char p_Y2_Lim = A3;
|
||||
const unsigned char p_Z1_Lim = A4;
|
||||
const unsigned char p_Z2_Lim = A5;
|
||||
const unsigned char p_A1_Lim = A6;
|
||||
const unsigned char p_A2_Lim = A7;
|
||||
|
||||
const unsigned char p_XJL = 42;
|
||||
const unsigned char p_XJR = 43;
|
||||
const unsigned char p_YJF = 44;
|
||||
const unsigned char p_YJB = 45;
|
||||
const unsigned char p_ZJU = 46;
|
||||
const unsigned char p_ZJD = 47;
|
||||
const unsigned char p_AJF = 48;
|
||||
const unsigned char p_AJB = 49;
|
||||
const unsigned char p_JSI = A14;
|
||||
const unsigned char p_JSD = A15;
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
//Outputs////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
const unsigned char p_M_Enable = 13;
|
||||
|
||||
const unsigned char p_StatusLed = 8;
|
||||
const unsigned char p_ErrorLed = 9;
|
||||
|
||||
const unsigned char p_XStep = 22;
|
||||
const unsigned char p_XDir = 23;
|
||||
const unsigned char p_XM0 = 24;
|
||||
const unsigned char p_XM1 = 25;
|
||||
const unsigned char p_XM2 = 26;
|
||||
|
||||
const unsigned char p_YStep = 28;
|
||||
const unsigned char p_YDir = 29;
|
||||
const unsigned char p_YM0 = 30;
|
||||
const unsigned char p_YM1 = 31;
|
||||
const unsigned char p_YM2 = 32;
|
||||
|
||||
const unsigned char p_AStep = 34;
|
||||
const unsigned char p_ADir = 35;
|
||||
const unsigned char p_AM0 = 36;
|
||||
const unsigned char p_AM1 = 37;
|
||||
const unsigned char p_AM2 = 40;
|
||||
|
||||
const unsigned char p_SStep = A8;
|
||||
const unsigned char p_SDir = A9;
|
||||
const unsigned char p_SM0 = A10;
|
||||
const unsigned char p_SM1 = A11;
|
||||
const unsigned char p_SM2 = A12;
|
||||
|
||||
const unsigned char p_Servo = 5;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//Global Variables and Instantiations
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
Axis XAxis(p_XStep, p_XDir, p_XM0, p_XM1, p_XM2, p_XFault);
|
||||
Axis YAxis(p_YStep, p_YDir, p_YM0, p_YM1, p_YM2, p_YFault);
|
||||
Axis ZAxis(p_AStep, p_ADir, p_AM0, p_AM1, p_AM2, p_AFault);
|
||||
DriverBoard myDriver(&XAxis, &YAxis, &ZAxis, p_Servo, p_StatusLed, p_ErrorLed, p_M_Enable, p_ESTOP, p_LimitESTOP, p_X1_Lim, p_X2_Lim, p_Y1_Lim, p_Y2_Lim,
|
||||
p_Z1_Lim, p_Z2_Lim, p_A1_Lim, p_A2_Lim, p_XJL, p_XJR, p_YJF, p_YJB, p_ZJU, p_ZJD, p_AJF, p_AJB, p_JSI, p_JSD);
|
||||
|
||||
|
||||
SoftwareSerial MySerial(10, 12);
|
||||
|
||||
String ReceiveBuffer = "";
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//Interrupt Service Routines
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
ISR(TIMER1_COMPA_vect){
|
||||
myDriver.MoveToPosition(1);
|
||||
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//Arduino Setup Function
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void setup(){
|
||||
// cli();
|
||||
Serial.begin(4800);
|
||||
MySerial.begin(4800);
|
||||
|
||||
TCCR1A = 0;
|
||||
TCCR1B = 0;
|
||||
TCNT1 = 0;
|
||||
|
||||
PRR1 &= ~(1 << PRTIM1); //Disable power reduction mode on timer 1 ((Might need to be changed...))
|
||||
TCCR1B |= ((1 << WGM12) | (1 << CS11));// | (1 << CS10)); //Set prescalaer to 64
|
||||
OCR1A = 2358; //Set count value
|
||||
TIMSK1 = (1 << OCIE1A);
|
||||
|
||||
sei();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//Arduino Main Program Loop
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void loop(){
|
||||
if(MySerial.available()){
|
||||
ReceiveBuffer = "";
|
||||
while(MySerial.available()){
|
||||
int temp = MySerial.read();
|
||||
if(isDigit(temp)){
|
||||
ReceiveBuffer += char(temp);
|
||||
}
|
||||
}
|
||||
//XAxis.SetDelay(ReceiveBuffer.toInt());
|
||||
//YAxis.SetDelay(ReceiveBuffer.toInt());
|
||||
//ZAxis.SetDelay(ReceiveBuffer.toInt());
|
||||
|
||||
MySerial.println(XAxis.SetRPM(ReceiveBuffer.toInt()));
|
||||
|
||||
}
|
||||
|
||||
|
||||
//ZAxis.StepForward();
|
||||
|
||||
|
||||
if(digitalRead(p_XJL)){
|
||||
myDriver.MoveToPosition(1);
|
||||
}
|
||||
else if(digitalRead(p_XJR)){
|
||||
//myDriver.MoveToPosition(1);
|
||||
}
|
||||
|
||||
if(digitalRead(p_YJF)){
|
||||
//YAxis.StepForward();
|
||||
}
|
||||
else if(digitalRead(p_YJB)){
|
||||
//YAxis.StepBackward();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user