Skip to content

Commit

Permalink
update for latest test procedure
Browse files Browse the repository at this point in the history
  • Loading branch information
sjkelly committed Jul 12, 2013
1 parent cb780f7 commit 8f42fa3
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 41 deletions.
85 changes: 52 additions & 33 deletions Test_Jig_Firmware.ino
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <SPI.h>

#define DEBUG 0 //send debug info over serial about what we are doing
#define DEBOUNCE 3
#define DEBOUNCE 2

#if DEBUG == 0
#define DEBUG_PRINT(x,y)
Expand All @@ -17,15 +17,14 @@
#define DOWN 1

char currentChar; //current char we are processing
uint8_t pin; //current pin we are playing with
uint32_t stepCount; //clamp
uint32_t stepFrequency; //clamp
int8_t pin; //current pin we are playing with
int stepCount; //clamp
int stepFrequency; //clamp
uint8_t dutyCycle; //analog write
uint8_t monitorTime;
uint16_t sampleFrequency;
int sampleFrequency;
unsigned long startMillis;
unsigned long lastMicros;
unsigned long period;
unsigned int period;
unsigned long stepsToHome = 0;
unsigned long testStart;
uint8_t i, j;
Expand All @@ -34,7 +33,7 @@ uint8_t posCounter[5] = {
uint8_t consecutiveReads[5] = {
0,0,0,0,0};
byte startReads = 0;
unsigned long stepperCount[5][10];
unsigned long stepperCount[5][5];
char port;
char state;

Expand Down Expand Up @@ -123,11 +122,27 @@ void loop()
pinMode(pin,INPUT);
digitalWrite(pin,HIGH);
Serial.println(digitalRead(pin));
pin = -1;
}
finished();
break;
}

//Analog Read
//Format: A<pin>
case 'A' :
{
if(isDigit(Serial.peek()))
{
pin = Serial.parseInt();
DEBUG_PRINT("Analog reading pin : ", pin);
Serial.println(analogRead(pin));
pin = -1;
}
finished();
break;
}

//Read Port or Pin
//Format: R<pin> or R<port char>
//Returns: <port int val>\n or <pin val>\n
Expand All @@ -143,6 +158,7 @@ void loop()
pin = Serial.parseInt();
pinMode(pin,INPUT);
Serial.println(digitalRead(pin));
pin = -1;
}
finished();
break;
Expand Down Expand Up @@ -174,6 +190,7 @@ void loop()
break;
}
}
pin = -1;
}
finished();
break;
Expand Down Expand Up @@ -223,20 +240,6 @@ void loop()
break;
}

//Analog Read
//Format: A<pin>
case 'A' :
{
if(isDigit(Serial.peek()))
{
pin = Serial.parseInt();
DEBUG_PRINT("Analog reading pin : ", pin);
Serial.println(analogRead(pin));
}
finished();
break;
}

//Set Microsteps
//Format: U<microsteps>
case 'U' :
Expand All @@ -246,29 +249,28 @@ void loop()
pin = Serial.parseInt();
DEBUG_PRINT("setting microsteps : ", pin);
rambo::portSetMicroSteps(pin);
pin = -1;
}
finished();
break;
}


//Monitor Stepper test
//Format: M<time>F<frequency>
//Format: M<pin to watch>F<frequency>
case 'M' :
{
if(isDigit(Serial.peek()))
{
monitorTime = Serial.parseInt();
DEBUG_PRINT("Monitoring stepper test time (s) : ", monitorTime);
pin = Serial.parseInt();
DEBUG_PRINT("Watching pin : ", pin);
if (Serial.peek() == 'F')
{
sampleFrequency = Serial.parseInt();
DEBUG_PRINT("Monitoring at frequency (hz) : ", sampleFrequency);
period = 1000000/sampleFrequency;
DEBUG_PRINT("Monitoring every (us) : ", period);
testStart = millis();
lastMicros = micros();
DEBUG_PRINT("Starting test", "");
uint8_t lastPortSample = B11111100;
for(i=0; i<=4; i++)
{
Expand All @@ -277,10 +279,14 @@ void loop()
}
for(i=0; i<=4; i++)
{
for(j = 0; j <= 9; j++)
for(j = 0; j <= 4; j++)
stepperCount[i][j] = 0;
}
while(millis()-testStart <= monitorTime*1000){
pinMode(pin,INPUT);
digitalWrite(pin,HIGH);
while(digitalRead(pin));
lastMicros = micros();
while(!digitalRead(pin)){
if ((micros()-lastMicros) >= period)
{
lastMicros = micros();
Expand All @@ -299,13 +305,13 @@ void loop()
}
DEBUG_PRINT("Ending Test", "");
for(i=0; i<=4; i++){
for(j = 0; j <= 9; j++){
for(j = 0; j <= 4; j++){
if(j==0){
Serial.print("{");
Serial.print(stepperCount[i][j]);
Serial.print(",");
}
else if(j==9){
else if(j==4){
Serial.print(stepperCount[i][j]);
Serial.println("}");
}
Expand All @@ -315,6 +321,7 @@ void loop()
}
}
}
pin = -1;
}
}
finished();
Expand All @@ -335,14 +342,15 @@ void loop()
DEBUG_PRINT("Analog write duty cycle : ", dutyCycle);
pinMode(pin,OUTPUT);
analogWrite(pin,dutyCycle);
pin = -1;
}
}
finished();
break;
}

//Clamp board
//Format: C<steps>F<frequency><Direction - D or U>
//Format: C<steps>F<frequency><Direction - D or U>P<pin to signal>
case 'C' :
{
if(isDigit(Serial.peek()))
Expand Down Expand Up @@ -374,6 +382,12 @@ void loop()
}
rambo::portEnable(1);
stepsToHome = 0;
if(Serial.peek() == 'P'){
pin = Serial.parseInt();
pinMode(pin,OUTPUT);
digitalWrite(pin,HIGH);
delay(20);
}
lastMicros = micros();
while(stepsToHome <= stepCount){
if ((micros()-lastMicros) >= period)
Expand All @@ -383,13 +397,17 @@ void loop()
stepsToHome++;
}
}
if(pin != -1){
delay(20);
digitalWrite(pin, LOW);
pin = -1;
}
}
}
finished();
break;
}
default :
Serial.println("Unknown command");
break;
}
}
Expand Down Expand Up @@ -433,3 +451,4 @@ void finished(void){




16 changes: 8 additions & 8 deletions pins.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#define ENDSTOP_PIN 10
#define START_PIN 11
#define ENDSTOP_PIN 15
#define START_PIN 14
#define POWER_PIN 3
#define X_MS1_PIN 40
#define X_MS2_PIN 41
Expand All @@ -17,12 +17,12 @@
#define Z_REF A5
#define E0_REF A4
#define E1_REF A3
#define MOS1 19 //PL5
#define MOS2 18 //PC5
#define MOS3 17 //PL4
#define MOS4 16 //PC6
#define MOS5 15 //PL3
#define MOS6 14 //PC7
#define MOS1 44 //PL5
#define MOS2 32 //PC5
#define MOS3 45 //PL4
#define MOS4 31 //PC6
#define MOS5 46 //PL3
#define MOS6 30 //PC7
/*
#define MOS1 44 //PL5
#define MOS2 32 //PC5
Expand Down

0 comments on commit 8f42fa3

Please sign in to comment.