summaryrefslogtreecommitdiff
path: root/usb-i2c-sl018/stepper.c
diff options
context:
space:
mode:
Diffstat (limited to 'usb-i2c-sl018/stepper.c')
-rw-r--r--usb-i2c-sl018/stepper.c33
1 files changed, 6 insertions, 27 deletions
diff --git a/usb-i2c-sl018/stepper.c b/usb-i2c-sl018/stepper.c
index 4258da7..d6508e7 100644
--- a/usb-i2c-sl018/stepper.c
+++ b/usb-i2c-sl018/stepper.c
@@ -25,21 +25,7 @@
#include <avr/interrupt.h>
#include "stepper.h"
-//half steps
-/*
-uint8_t step_table [] =
-{
- 10, // 1010
- 8, // 1000
- 9, // 1001
- 1, // 0001
- 5, // 0101
- 4, // 0100
- 6, // 0110
- 2, // 0010
-};
-*/
-//Full steps
+
uint8_t step_table [] =
{
10, // 1010
@@ -62,7 +48,6 @@ stepper_direction_t step_direction = dir_open;
inline void stop_stepper(void)
{
- // stop timer here
STEPPER_PORT &= ~(0xF << STEPPER_FIRST_BIT | 1<<STEPPER_ENABLE_BIT);
TCCR1B = 0; // no clock source
TIMSK1 = 0; // disable timer interrupt
@@ -82,9 +67,8 @@ inline uint8_t handle_step(void)
STEPPER_PORT = (STEPPER_PORT & STEPPER_OUTPUT_BITMASK ) | stepper_output;
step_cnt++;
- if(step_cnt >= STEP_CNT_OFF) {
+ if(step_cnt >= STEP_CNT_OFF)
return 0;
- }
return 1;
}
@@ -103,22 +87,17 @@ uint8_t start_stepper(stepper_direction_t direction)
step_cnt = 0;
step_direction = direction;
STEPPER_PORT |= 1<<STEPPER_ENABLE_BIT;
- //start timer here
- // timer 1: 2 ms, between stepper output state changes
TCCR1A = 0; // prescaler 1:256, WGM = 4 (CTC)
TCCR1B = 1<<WGM12 | 1<<CS12; //
- OCR1A = 124; // (1+124)*256 = 32000 -> 2 ms @ 16 MHz
- //OCR1A = 155; // (1+155)*256 = 40000 -> 2 ms @ 20 MHz
- TCNT1 = 0; // reseting timer
- TIMSK1 = 1<<OCIE1A; // enable Interrupt
+ OCR1A = 124; // (1+124)*256 = 32000 -> 2 ms @ 16 MHz
+ TCNT1 = 0;
+ TIMSK1 = 1<<OCIE1A;
return 1;
}
-
ISR(TIMER1_COMPA_vect)
{
- if(!handle_step()) {
+ if(!handle_step())
stop_stepper();
- }
}