make it work
This commit is contained in:
69
src/main.c
69
src/main.c
@ -64,6 +64,9 @@ volatile uint8_t valid = 0;
|
|||||||
volatile uint8_t tack = 0;
|
volatile uint8_t tack = 0;
|
||||||
volatile uint8_t step = 0;
|
volatile uint8_t step = 0;
|
||||||
|
|
||||||
|
extern uint8_t bufferReadIdx;
|
||||||
|
extern uint8_t bufferWriteIdx;
|
||||||
|
|
||||||
ISR(TIMER2_OVF_vect) {
|
ISR(TIMER2_OVF_vect) {
|
||||||
clock.second++;
|
clock.second++;
|
||||||
|
|
||||||
@ -508,20 +511,22 @@ int main() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("% 4d:%02d:%02d %02d:%02d:%02d %02d.%02d.%02d %d %d %02d %d %d %d %d %d\n",
|
printf("% 4d:%02d:%02d %02d:%02d:%02d %02d.%02d.%02d %d %d %02d %d %d %d %d %d %d %d\n",
|
||||||
opTime.hour, opTime.minute, opTime.second,
|
opTime.hour, opTime.minute, opTime.second,
|
||||||
clock.hour, clock.minute, clock.second,
|
clock.hour, clock.minute, clock.second,
|
||||||
clock.day, clock.month, clock.year, clock.weekday,
|
clock.day, clock.month, clock.year, clock.weekday,
|
||||||
valid, state, bit, pulse, gap, validCnt, timeValidCnt);
|
valid, state, bit, pulse, gap, validCnt, timeValidCnt,
|
||||||
|
bufferReadIdx, bufferWriteIdx);
|
||||||
|
|
||||||
state++;
|
state++;
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
printf("% 4d:%02d:%02d %02d:%02d:%02d %02d.%02d.%02d %d %d %02d %d %d %d %d %d\n",
|
printf("% 4d:%02d:%02d %02d:%02d:%02d %02d.%02d.%02d %d %d %02d %d %d %d %d %d %d %d\n",
|
||||||
opTime.hour, opTime.minute, opTime.second,
|
opTime.hour, opTime.minute, opTime.second,
|
||||||
clock.hour, clock.minute, clock.second,
|
clock.hour, clock.minute, clock.second,
|
||||||
clock.day, clock.month, clock.year, clock.weekday,
|
clock.day, clock.month, clock.year, clock.weekday,
|
||||||
valid, state, bit, pulse, gap, validCnt, timeValidCnt);
|
valid, state, bit, pulse, gap, validCnt, timeValidCnt,
|
||||||
|
bufferReadIdx, bufferWriteIdx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -539,44 +544,48 @@ int main() {
|
|||||||
static uint8_t stepperState = 0;
|
static uint8_t stepperState = 0;
|
||||||
|
|
||||||
static uint8_t currentMinutePosition = 0;
|
static uint8_t currentMinutePosition = 0;
|
||||||
uint8_t minuteStepPosition = 0;
|
static uint8_t minuteStepPosition = 0;
|
||||||
int8_t minuteDirection = 0;
|
static int8_t minuteDirection = 0;
|
||||||
|
|
||||||
static uint8_t currentHourPosition = 0;
|
static uint8_t currentHourPosition = 0;
|
||||||
uint8_t hourStepPosition = clock.hour * STEPS_PER_HOUR;
|
static uint8_t hourStepPosition = 0;
|
||||||
int8_t hourDirection = 0;
|
static int8_t hourDirection = 0;
|
||||||
|
|
||||||
switch (stepperState) {
|
switch (stepperState) {
|
||||||
case 0:
|
case 0:
|
||||||
|
//printf("0 ");
|
||||||
// is current minute position different from desired one?
|
// is current minute position different from desired one?
|
||||||
|
minuteStepPosition = clock.minute * STEPS_PER_MINUTE;
|
||||||
|
|
||||||
if (currentMinutePosition != minuteStepPosition) {
|
if (currentMinutePosition != minuteStepPosition) {
|
||||||
printf("M: ");
|
printf("M:\n");
|
||||||
|
|
||||||
stepperState = 1;
|
stepperState = 1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
|
printf("1 ");
|
||||||
// switch on the minute motor and set the direction
|
// switch on the minute motor and set the direction
|
||||||
PORTA |= (1 << PA1);
|
PORTA |= (1 << PA1);
|
||||||
|
|
||||||
minuteStepPosition = clock.minute * STEPS_PER_MINUTE;
|
|
||||||
|
|
||||||
if (currentMinutePosition > minuteStepPosition) {
|
if (currentMinutePosition > minuteStepPosition) {
|
||||||
printf("b ");
|
printf("b\n");
|
||||||
minuteDirection = -1;
|
minuteDirection = -1;
|
||||||
PORTC |= (1 << PC2);
|
|
||||||
} else {
|
|
||||||
printf("f ");
|
|
||||||
minuteDirection = 1;
|
|
||||||
PORTC &= ~(1 << PC2);
|
PORTC &= ~(1 << PC2);
|
||||||
|
} else {
|
||||||
|
printf("f\n");
|
||||||
|
minuteDirection = 1;
|
||||||
|
PORTC |= (1 << PC2);
|
||||||
}
|
}
|
||||||
|
|
||||||
stepperState = 2;
|
stepperState = 2;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
|
printf("2 ");
|
||||||
|
|
||||||
// move one step
|
// move one step
|
||||||
|
|
||||||
printf("d: %d, c: %d, ", minuteStepPosition, currentMinutePosition);
|
printf("d: %d, c: %d\n", minuteStepPosition, currentMinutePosition);
|
||||||
|
|
||||||
currentMinutePosition += minuteDirection;
|
currentMinutePosition += minuteDirection;
|
||||||
|
|
||||||
@ -589,15 +598,21 @@ int main() {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
|
printf("3\n");
|
||||||
|
|
||||||
// switch off the minute motor
|
// switch off the minute motor
|
||||||
PORTA &= ~(1 << PA1);
|
PORTA &= ~(1 << PA1);
|
||||||
|
|
||||||
stepperState = 4;
|
stepperState = 4;
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
|
printf("4 ");
|
||||||
|
|
||||||
// is current hour position different from desired one?
|
// is current hour position different from desired one?
|
||||||
|
hourStepPosition = clock.hour * STEPS_PER_HOUR;
|
||||||
|
|
||||||
if (currentHourPosition != hourStepPosition) {
|
if (currentHourPosition != hourStepPosition) {
|
||||||
printf(" H: ");
|
printf(" H:\n");
|
||||||
|
|
||||||
stepperState = 5;
|
stepperState = 5;
|
||||||
} else {
|
} else {
|
||||||
@ -607,17 +622,17 @@ int main() {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
|
printf("5 ");
|
||||||
|
|
||||||
// switch on the hour motor and set the direction
|
// switch on the hour motor and set the direction
|
||||||
PORTA |= (1 << PA0);
|
PORTA |= (1 << PA0);
|
||||||
|
|
||||||
hourStepPosition = clock.hour * STEPS_PER_HOUR;
|
|
||||||
|
|
||||||
if (currentHourPosition > hourStepPosition) {
|
if (currentHourPosition > hourStepPosition) {
|
||||||
printf("b ");
|
printf("b\n");
|
||||||
hourDirection = -1;
|
hourDirection = -1;
|
||||||
PORTC |= (1 << PC0);
|
PORTC |= (1 << PC0);
|
||||||
} else {
|
} else {
|
||||||
printf("f ");
|
printf("f\n");
|
||||||
hourDirection = 1;
|
hourDirection = 1;
|
||||||
PORTC &= ~(1 << PC0);
|
PORTC &= ~(1 << PC0);
|
||||||
}
|
}
|
||||||
@ -625,9 +640,11 @@ int main() {
|
|||||||
stepperState = 6;
|
stepperState = 6;
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
|
printf("6 ");
|
||||||
|
|
||||||
// move one step
|
// move one step
|
||||||
|
|
||||||
printf("d: %d, c: %d, ", hourStepPosition, currentHourPosition);
|
printf("d: %d, c: %d\n", hourStepPosition, currentHourPosition);
|
||||||
|
|
||||||
currentHourPosition += hourDirection;
|
currentHourPosition += hourDirection;
|
||||||
|
|
||||||
@ -640,17 +657,21 @@ int main() {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 7:
|
case 7:
|
||||||
|
printf("7\n");
|
||||||
|
|
||||||
// switch off the hour motor
|
// switch off the hour motor
|
||||||
PORTA &= ~(1 << PA0);
|
PORTA &= ~(1 << PA0);
|
||||||
|
|
||||||
stepperState = 8;
|
stepperState = 8;
|
||||||
break;
|
break;
|
||||||
case 8:
|
case 8:
|
||||||
|
printf("8\n");
|
||||||
|
|
||||||
// done
|
// done
|
||||||
printf("\n");
|
|
||||||
stepperState = 0;
|
stepperState = 0;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
printf("default\n");
|
||||||
stepperState = 0;
|
stepperState = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user