diff options
author | Christian Pointner <equinox@spreadspace.org> | 2013-02-06 01:17:12 +0000 |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2013-02-06 01:17:12 +0000 |
commit | 7ebd33cb40aa50f187d7eaa7e44ce3499a6a2a3b (patch) | |
tree | d767ba17ead755fefd0e68ffecdce2f7ed1e0dc7 /usb-i2c-sl018 | |
parent | added open and close command (diff) |
cleanup
git-svn-id: https://svn.spreadspace.org/avr/trunk@124 aa12f405-d877-488e-9caf-2d797e2a1cc7
Diffstat (limited to 'usb-i2c-sl018')
-rw-r--r-- | usb-i2c-sl018/heartbeat.c | 12 | ||||
-rw-r--r-- | usb-i2c-sl018/stepper.c | 33 | ||||
-rw-r--r-- | usb-i2c-sl018/stepper.h | 2 | ||||
-rw-r--r-- | usb-i2c-sl018/tuer-rfid.c | 5 |
4 files changed, 14 insertions, 38 deletions
diff --git a/usb-i2c-sl018/heartbeat.c b/usb-i2c-sl018/heartbeat.c index 6822320..fd9d5cb 100644 --- a/usb-i2c-sl018/heartbeat.c +++ b/usb-i2c-sl018/heartbeat.c @@ -50,13 +50,11 @@ void init_heartbeat(void) heartbeat_cnt = 0; heartbeat_flag = 1; - // timer 2: ~10 ms, timebase for heartbeat signal - TCCR0A = 1<<WGM01; // OC0A and OC0B as normal output, WGM = 2 (CTC) - TCCR0B = 1<<CS02 | 1<<CS00; // Prescaler 1:1024 - OCR0A = 155; // (1+155)*1024 = 159744 -> ~10 ms @ 16 MHz - //OCR2A = 194; // (1+194)*1024 = 199680 -> ~10 ms @ 20 MHz - TCNT2 = 0; // reseting timer - TIMSK0 = 1<<OCIE0A; // enable Interrupt + TCCR0A = 1<<WGM01; // OC0A and OC0B as normal output, WGM = 2 (CTC) + TCCR0B = 1<<CS02 | 1<<CS00; // Prescaler 1:1024 + OCR0A = 155; // (1+155)*1024 = 159744 -> ~10 ms @ 16 MHz + TCNT2 = 0; + TIMSK0 = 1<<OCIE0A; } void handle_heartbeat(void) 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(); - } } diff --git a/usb-i2c-sl018/stepper.h b/usb-i2c-sl018/stepper.h index 8e85dde..233423a 100644 --- a/usb-i2c-sl018/stepper.h +++ b/usb-i2c-sl018/stepper.h @@ -26,9 +26,7 @@ typedef enum { dir_open = 0, dir_close = 1 } stepper_direction_t; -//uint8_t handle_step(void); void init_stepper(void); uint8_t 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 7fa7d14..5182aa1 100644 --- a/usb-i2c-sl018/tuer-rfid.c +++ b/usb-i2c-sl018/tuer-rfid.c @@ -445,14 +445,15 @@ int main(void) led_init();
USB_Init();
TWI_Init(TWI_BIT_PRESCALE_1, TWI_BITLENGTH_FROM_FREQ(1, 200000));
- sei();
Serial_Init(115200,false);
Serial_CreateStream(&serial_stream);
CDC_Device_CreateStream(&VirtualSerial_CDC_Interface,&usb_stream);
+ sei();
+
init_heartbeat();
init_stepper();
-
+
sl018_reset();
for(;;) {
|