From bc5f0ffc76161ad1eb9122f0bcc84b3372ed090a Mon Sep 17 00:00:00 2001 From: Othmar Gsenger Date: Tue, 5 Feb 2013 22:59:32 +0000 Subject: added basic stepper support git-svn-id: https://svn.spreadspace.org/avr/trunk@119 aa12f405-d877-488e-9caf-2d797e2a1cc7 --- usb-i2c-sl018/Makefile | 2 +- usb-i2c-sl018/stepper.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++ usb-i2c-sl018/stepper.h | 34 +++++++++++++++++++ usb-i2c-sl018/tuer-rfid.c | 1 + 4 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 usb-i2c-sl018/stepper.c create mode 100644 usb-i2c-sl018/stepper.h diff --git a/usb-i2c-sl018/Makefile b/usb-i2c-sl018/Makefile index 811648f..cb6e98b 100644 --- a/usb-i2c-sl018/Makefile +++ b/usb-i2c-sl018/Makefile @@ -23,7 +23,7 @@ NAME := tuer-rfid BOARD_TYPE := teensy2 -OBJ := $(NAME).o heartbeat.o +OBJ := $(NAME).o heartbeat.o stepper.o LIBS := util led lufa-descriptor-usbserial EXTERNAL_LIBS := lufa diff --git a/usb-i2c-sl018/stepper.c b/usb-i2c-sl018/stepper.c new file mode 100644 index 0000000..868fff0 --- /dev/null +++ b/usb-i2c-sl018/stepper.c @@ -0,0 +1,85 @@ +/* + * spreadspace avr utils + * + * + * Copyright (C) 2013 Christian Pointner + * Othmar Gsenger + * + * 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 . + */ + +#include +#include + +#include "stepper.h" + +uint8_t step_table [] = +{ + 10, // 1010 + 8, // 1000 + 9, // 1001 + 1, // 0001 + 5, // 0101 + 4, // 0100 + 6, // 0110 + 2, // 0010 +}; + +#define STEPPER_PORT PORTF +#define STEPPER_DDR DDRF +#define STEPPER_FIRST_BIT 4 +#define STEPPER_ENABLE_BIT 1 +#define LENGTH_STEP_TABLE (sizeof(step_table)/sizeof(uint8_t)) +#define STEPPER_OUTPUT_BITMASK (~(0xF << STEPPER_FIRST_BIT )) + +volatile uint16_t step_cnt = 0; +static uint16_t step_cnt_max = LENGTH_STEP_TABLE*20; +stepper_direction_t step_direction = dir_open; + +void handle_step(void) +{ + if(step_cnt < step_cnt_max) + { + step_cnt++; + uint8_t stepper_output=step_table[step_cnt % LENGTH_STEP_TABLE]; + stepper_output<<=STEPPER_FIRST_BIT; + STEPPER_PORT = (STEPPER_PORT & STEPPER_OUTPUT_BITMASK ) | stepper_output; + } else { + stop_stepper(); + } +} + +void init_stepper(void) +{ + STEPPER_PORT &= ~(0xF << STEPPER_FIRST_BIT | 1< + * Othmar Gsenger + * + * 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 . + */ + +#ifndef R3TUER_stepper_h_INCLUDED +#define R3TUER_stepper_h_INCLUDED + +typedef enum { dir_open = 0, dir_close = 1 } stepper_direction_t; + +void handle_step(void); +void init_stepper(void); +void start_stepper(stepper_direction_t direction); +void stop_stepper(void); + +#endif diff --git a/usb-i2c-sl018/tuer-rfid.c b/usb-i2c-sl018/tuer-rfid.c index 1c122af..7f41798 100644 --- a/usb-i2c-sl018/tuer-rfid.c +++ b/usb-i2c-sl018/tuer-rfid.c @@ -33,6 +33,7 @@ #include "led.h" #include "heartbeat.h" +#include "stepper.h" #include "LUFA/Drivers/Peripheral/TWI.h" #include "LUFA/Drivers/Peripheral/Serial.h" -- cgit v1.2.3