summaryrefslogtreecommitdiff
path: root/tube-rotator
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2014-05-18 02:06:16 +0200
committerChristian Pointner <equinox@spreadspace.org>2014-05-18 02:06:16 +0200
commit65906a6df773c8ff5b657d95b8620d5d5a82a26e (patch)
tree47de3af67ceddcd7882680801f489a90e4dba54c /tube-rotator
parentfixed keypad (diff)
added tube-rotator project
Diffstat (limited to 'tube-rotator')
-rw-r--r--tube-rotator/Makefile46
-rw-r--r--tube-rotator/stepper.c92
-rw-r--r--tube-rotator/stepper.h30
-rw-r--r--tube-rotator/tube-rotator.c75
4 files changed, 243 insertions, 0 deletions
diff --git a/tube-rotator/Makefile b/tube-rotator/Makefile
new file mode 100644
index 0000000..c75c022
--- /dev/null
+++ b/tube-rotator/Makefile
@@ -0,0 +1,46 @@
+##
+## spreadspace avr utils
+##
+##
+## Copyright (C) 2014 Christian Pointner <equinox@spreadspace.org>
+##
+## This file is part of spreadspace avr utils.
+##
+## spreadspace avr utils is free software: you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation, either version 3 of the License, or
+## any later version.
+##
+## spreadspace avr utils is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with spreadspace avr utils. If not, see <http://www.gnu.org/licenses/>.
+##
+
+NAME := tube-rotator
+BOARD_TYPE := teenstep
+OBJ := $(NAME).o stepper.o
+LIBS := util led lufa-descriptor-usbserial anyio
+EXTERNAL_LIBS := lufa
+RESET_FUNC := ../tools/reset_lufa_cdc
+RESET_PARAM := '!'
+
+LUFA_PATH := ../contrib/LUFA-120219
+LUFA_OPTS = -D USB_DEVICE_ONLY
+LUFA_OPTS += -D DEVICE_STATE_AS_GPIOR=0
+LUFA_OPTS += -D ORDERED_EP_CONFIG
+LUFA_OPTS += -D FIXED_CONTROL_ENDPOINT_SIZE=8
+LUFA_OPTS += -D FIXED_NUM_CONFIGURATIONS=1
+LUFA_OPTS += -D USE_FLASH_DESCRIPTORS
+LUFA_OPTS += -D USE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)"
+LUFA_OPTS += -D INTERRUPT_CONTROL_ENDPOINT
+
+LUFA_OPTS += -D USB_MANUFACTURER="L\"equinox\"" -D USB_MANUFACTURER_LEN=7
+LUFA_OPTS += -D USB_PRODUCT="L\"realraum tube rotator\"" -D USB_PRODUCT_LEN=21
+
+LUFA_COMPONENTS := USB USBCLASS SERIAL
+
+include ../include.mk
diff --git a/tube-rotator/stepper.c b/tube-rotator/stepper.c
new file mode 100644
index 0000000..1bb9cae
--- /dev/null
+++ b/tube-rotator/stepper.c
@@ -0,0 +1,92 @@
+/*
+ * spreadspace avr utils
+ *
+ *
+ * Copyright (C) 2014 Christian Pointner <equinox@spreadspace.org>
+ *
+ * This file is part of spreadspace avr utils.
+ *
+ * spreadspace avr utils is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * spreadspace avr utils is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with spreadspace avr utils. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <avr/sfr_defs.h>
+#include <avr/interrupt.h>
+
+#include "stepper.h"
+
+uint8_t step_table [] =
+{
+ /* full steps */
+ /* 6, // 0110 */
+ /* 5, // 0101 */
+ /* 9, // 1001 */
+ /* 10, // 1010 */
+
+ /* half steps */
+ 2, // 0010
+ 6, // 0110
+ 4, // 0100
+ 5, // 0101
+ 1, // 0001
+ 9, // 1001
+ 8, // 1000
+ 10, // 1010
+};
+
+#define STEPPER_PORT PORTF
+#define STEPPER_DDR DDRF
+#define STEPPER_FIRST_BIT 4
+#define STEPPER_ENABLE_A_BIT 0
+#define STEPPER_ENABLE_B_BIT 1
+#define LENGTH_STEP_TABLE (sizeof(step_table)/sizeof(uint8_t))
+#define STEPPER_OUTPUT_BITMASK (~(0xF << STEPPER_FIRST_BIT ))
+
+void stepper_init(void)
+{
+ STEPPER_PORT &= ~(0xF << STEPPER_FIRST_BIT | 1<<STEPPER_ENABLE_A_BIT | 1<<STEPPER_ENABLE_B_BIT);
+ STEPPER_DDR |= (0xF << STEPPER_FIRST_BIT) | (1<<STEPPER_ENABLE_A_BIT) | (1<<STEPPER_ENABLE_B_BIT);
+}
+
+void stepper_start(void)
+{
+ STEPPER_PORT |= (1<<STEPPER_ENABLE_A_BIT) | (1<<STEPPER_ENABLE_B_BIT);
+ TCCR1A = 0; // prescaler 1:256, WGM = 4 (CTC)
+ TCCR1B = 1<<WGM12 | 1<<CS12; //
+ OCR1A = 150;
+ TCNT1 = 0;
+ TIMSK1 = 1<<OCIE1A;
+}
+
+void stepper_stop(void)
+{
+ STEPPER_PORT &= ~(0xF << STEPPER_FIRST_BIT | 1<<STEPPER_ENABLE_A_BIT | 1<<STEPPER_ENABLE_B_BIT);
+ TCCR1B = 0; // no clock source
+ TIMSK1 = 0; // disable timer interrupt
+}
+
+static inline void stepper_handle(void)
+{
+ static uint8_t step_idx = 0;
+
+ uint8_t stepper_output = step_table[step_idx];
+ stepper_output <<= STEPPER_FIRST_BIT;
+ STEPPER_PORT = (STEPPER_PORT & STEPPER_OUTPUT_BITMASK ) | stepper_output;
+ step_idx++;
+ step_idx %= LENGTH_STEP_TABLE;
+}
+
+ISR(TIMER1_COMPA_vect)
+{
+ stepper_handle();
+}
diff --git a/tube-rotator/stepper.h b/tube-rotator/stepper.h
new file mode 100644
index 0000000..7fb70ec
--- /dev/null
+++ b/tube-rotator/stepper.h
@@ -0,0 +1,30 @@
+/*
+ * spreadspace avr utils
+ *
+ *
+ * Copyright (C) 2014 Christian Pointner <equinox@spreadspace.org>
+ *
+ * This file is part of spreadspace avr utils.
+ *
+ * spreadspace avr utils is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * spreadspace avr utils is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with spreadspace avr utils. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef R3TUBE_stepper_h_INCLUDED
+#define R3TUBE_stepper_h_INCLUDED
+
+void stepper_init(void);
+void stepper_start(void);
+void stepper_stop(void);
+
+#endif
diff --git a/tube-rotator/tube-rotator.c b/tube-rotator/tube-rotator.c
new file mode 100644
index 0000000..7a0e2ec
--- /dev/null
+++ b/tube-rotator/tube-rotator.c
@@ -0,0 +1,75 @@
+/*
+ * spreadspace avr utils
+ *
+ *
+ * Copyright (C) 2014 Christian Pointner <equinox@spreadspace.org>
+ *
+ * This file is part of spreadspace avr utils.
+ *
+ * spreadspace avr utils is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * spreadspace avr utils is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with spreadspace avr utils. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <avr/io.h>
+#include <avr/wdt.h>
+#include <avr/interrupt.h>
+#include <avr/power.h>
+
+#include <stdio.h>
+#include <string.h>
+
+#include "util.h"
+#include "led.h"
+#include "anyio.h"
+
+#include "stepper.h"
+
+void handle_cmd(uint8_t cmd)
+{
+ switch(cmd) {
+ case '!':
+ reset2bootloader();
+ break;
+ case 'r':
+ led_on();
+ stepper_start();
+ break;
+ case 's':
+ stepper_stop();
+ led_off();
+ break;
+ default: printf("Error(cmd): unknown command %02X '%c'\r\n", cmd, cmd); return;
+ }
+}
+
+int main(void)
+{
+ MCUSR &= ~(1 << WDRF);
+ wdt_disable();
+
+ cpu_init();
+ jtag_disable();
+ led_init();
+ anyio_init(115200, 0);
+
+ stepper_init();
+ sei();
+
+ for(;;) {
+ anyio_task();
+
+ int16_t bytes_received = anyio_bytes_received();
+ if(bytes_received > 0)
+ handle_cmd(fgetc(stdin));
+ }
+}