summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorroot <root@lumpy.lan>2021-11-27 19:32:49 +0000
committerroot <root@lumpy.lan>2021-11-27 19:32:49 +0000
commitc04969c3a5eff3f73840856f207f204414653da3 (patch)
treed40cd5ce4a28902297bf7349d732f68b2751e4ce
parentf75d0b7eabe275a4330eb72dc4a4c5d2af1fb13d (diff)
downloadmetric_clock-c04969c3a5eff3f73840856f207f204414653da3.tar.gz
metric_clock-c04969c3a5eff3f73840856f207f204414653da3.tar.bz2
metric_clock-c04969c3a5eff3f73840856f207f204414653da3.zip
laptop-to-desktop
-rw-r--r--stm32/app/hands.c9
-rw-r--r--stm32/app/motor.c106
-rw-r--r--stm32/app/project.h4
-rw-r--r--stm32/app/rtc.c2
4 files changed, 107 insertions, 14 deletions
diff --git a/stm32/app/hands.c b/stm32/app/hands.c
index 7ac8bb9..8261b1b 100644
--- a/stm32/app/hands.c
+++ b/stm32/app/hands.c
@@ -9,7 +9,7 @@ static unsigned calc_second_pos (MTIME *m)
{
uint64_t p;
- p += m->second;
+ p = m->second;
p *= 1000;
p += m->nanosecond / 1000000;
@@ -89,7 +89,13 @@ void hands_tick (void)
hands_pos[0] = calc_hour_pos (&m);
+
+if ((e.s & 31) <5) {
+ hands_pos[1] =hands_pos[0];
+} else {
hands_pos[1] = calc_minute_pos (&m);
+}
+
//hands_pos[1] = calc_second_pos (&m);
hands_ready = 1;
@@ -101,6 +107,7 @@ void hands_tick (void)
}
if (p) {
+ printf("Epoch %d.%09d\r\n",(unsigned) e.s,(unsigned) e.ns);
time_print_utc ("UTC: ", &u, NULL);
time_print_metric ("Metric: ", &m, NULL);
printf ("Hands: hour %4d/%4d min %4d/%4d\r\n", hands_pos[0], MOTOR_STEPS, hands_pos[1], MOTOR_STEPS);
diff --git a/stm32/app/motor.c b/stm32/app/motor.c
index 8ffc5e6..ca9fa13 100644
--- a/stm32/app/motor.c
+++ b/stm32/app/motor.c
@@ -2,6 +2,7 @@
static unsigned motor_pos[HANDS];
+static unsigned off[HANDS];
#define M1_A GPIO11
#define M1_A_PORT GPIOB
@@ -12,12 +13,33 @@ static unsigned motor_pos[HANDS];
#define M1_D GPIO14
#define M1_D_PORT GPIOB
+#define ADJUST_CCW GPIO0
+#define ADJUST_CCW_PORT GPIOC
+#define ADJUST_CW GPIO1
+#define ADJUST_CW_PORT GPIOC
+
+
static void coils (unsigned m, int a, int b, int c, int d)
{
if (!m) return;
+ c^=d;
+ d^=c;
+ c^=d;
+
+#if 0
+a^=c;
+c^=a;
+a^=c;
+
+b^=d;
+d^=b;
+b^=d;
+#endif
+
+
if (a)
SET (M1_A);
else
@@ -39,7 +61,7 @@ static void coils (unsigned m, int a, int b, int c, int d)
CLEAR (M1_D);
- printf ("Motor %d: %+d %+d\r\n", m, a - b, c - d);
+ //printf ("Motor %d: %+d %+d\r\n", m, a - b, c - d);
}
static void step (unsigned m, int d)
@@ -52,6 +74,8 @@ static void step (unsigned m, int d)
s %= MOTOR_STEPS;
+#if 0
+ // full step
switch (s & 3) {
case 0:
coils (m, 0, 1, 0, 1);
@@ -69,6 +93,35 @@ static void step (unsigned m, int d)
coils (m, 1, 0, 0, 1);
break;
}
+#endif
+#if 0
+// half step
+coils (m, !! ((s + 1) & 4), !! ((s + 6) & 4), !! ((s + 4) & 4), !! ((s + 7) & 4));
+#endif
+#if 1
+//60deg phase
+
+switch(s%6) {
+case 0:
+coils(m,0,0,1,0);
+break;
+case 1:
+coils(m,1,0,1,0);
+break;
+case 2:
+coils(m,1,0,0,0);
+break;
+case 3:
+coils(m,0,0,0,1);
+break;
+case 4:
+coils(m,0,1,0,1);
+break;
+case 5:
+coils(m,0,1,0,0);
+break;
+}
+#endif
@@ -82,33 +135,60 @@ static void step (unsigned m, int d)
+#define ADJ_P 2500
void motor_tick (void)
{
- static uint32_t last;
+ static uint32_t last,blast;
unsigned i, d;
- static unsigned wiggle = MOTOR_STEPS;
+ static unsigned adjusting = ADJ_P; /*5 seconds*/
+ unsigned hp[2];
+
+ if ((ticks - last) < 2) return;
+ last=ticks;
- if ((ticks - last) < 4) return;
- last = ticks;
+ if ((ticks - blast) > 100) {
- if (wiggle) {
- step (1, 1);
- wiggle--;
- return;
+ if (!GET(ADJUST_CCW)) {
+ adjusting=ADJ_P;
+
+ motor_pos[1]+=MOTOR_PHASES;
+ motor_pos[1]%=MOTOR_STEPS;
}
- if (!hands_ready) return;
+
+ if (!GET(ADJUST_CW)) {
+ adjusting=ADJ_P;
+
+ motor_pos[1]+=MOTOR_STEPS-MOTOR_PHASES;
+ motor_pos[1]%=MOTOR_STEPS;
+ }
+ blast=ticks;
+
+ }
+
+
+
+
+ if (adjusting || !hands_ready) {
+ if (adjusting) adjusting--;
+ hp[0]=0;
+ hp[1]=0;
+ } else {
+ hp[0]=hands_pos[0];
+ hp[1]=hands_pos[1];
+ }
//printf("HANDS: %d -> %d %d -> %d\r\n",hands_pos[0],motor_pos[0],hands_pos[1],motor_pos[1]);
for (i = 0; i < HANDS; ++i) {
- d = MOTOR_STEPS + hands_pos[i];
+ d = MOTOR_STEPS;
+ d+=hp[i];
d -= motor_pos[i];
d %= MOTOR_STEPS;
@@ -133,6 +213,10 @@ void motor_init (void)
MAP_OUTPUT_PP (M1_C);
MAP_OUTPUT_PP (M1_D);
+ MAP_INPUT_PU(ADJUST_CCW);
+ MAP_INPUT_PU(ADJUST_CW);
+
+
motor_pos[0] = BKP_DR8;
motor_pos[1] = BKP_DR9;
diff --git a/stm32/app/project.h b/stm32/app/project.h
index 0d73544..97b992c 100644
--- a/stm32/app/project.h
+++ b/stm32/app/project.h
@@ -36,7 +36,9 @@
#define HANDS 2
//#define MOTOR_STEPS (1080 * 2)
-#define MOTOR_STEPS (720 )
+//#define MOTOR_STEPS (720 )
+#define MOTOR_STEPS (1080 )
+#define MOTOR_PHASES 6
#include "board.h"
#include "ring.h"
diff --git a/stm32/app/rtc.c b/stm32/app/rtc.c
index 9c1bc47..c20bb8d 100644
--- a/stm32/app/rtc.c
+++ b/stm32/app/rtc.c
@@ -155,7 +155,7 @@ void rtc_init (void)
rtc_half = BKP_DR7;
#if 1
- rtc_offset.s = 1637490753;
+ rtc_offset.s = 1637490753 + 46850+ 48565+85980;
rtc_offset.ns = 498866999;
bkp_write_off (rtc_offset);
#endif