bugfixed last checkin
authorOthmar Gsenger <otti@realraum.at>
Tue, 9 Oct 2012 15:29:01 +0000 (15:29 +0000)
committerOthmar Gsenger <otti@realraum.at>
Tue, 9 Oct 2012 15:29:01 +0000 (15:29 +0000)
avr-projects/r3cam-steppermotor/r3cam-steppermotor.c

index 1bcad56..bd67374 100644 (file)
@@ -81,7 +81,10 @@ void EVENT_USB_Device_ControlRequest(void)
 #define M_RESET 3\r
 #define M_FULLSTEPS 4\r
 \r
-static uint8_t m_clk_divisor_ = 0;\r
+#define M_START_DIVISOR 2;\r
+\r
+static uint8_t cur_speed = 0xFF - M_START_DIVISOR;\r
+static uint8_t m_clk_divisor_ = M_START_DIVISOR;\r
 static uint8_t m_clk_divisor_counter_ = 0;\r
 static uint16_t m_steps_to_go_ = 0;\r
 \r
@@ -116,10 +119,14 @@ ISR(TIMER0_OVF_vect)
         m_clk_divisor_counter_--;\r
 }\r
 \r
+static char set_speed_msg[] = "m_clk_divisor_ = %d\n\r";\r
+\r
 void motor_set_speed(uint8_t speed)\r
 {\r
     m_clk_divisor_ = 0xFF - speed;\r
-    CDC_Device_SendString(&VirtualSerial_CDC_Interface, "m_clk_divisor_ = %d\n",m_clk_divisor_);\r
+    char tmp[sizeof(set_speed_msg)+4];\r
+    sprintf(tmp, set_speed_msg,m_clk_divisor_);\r
+    CDC_Device_SendString(&VirtualSerial_CDC_Interface, tmp);\r
 }\r
 \r
 void motor_run(uint16_t steps, uint8_t direction)\r
@@ -157,7 +164,6 @@ void init_pins()
     OCR0A = 255;        // (1+139)*8 = 1120 -> 70us @ 16 MHz -> 1*alpha\r
 }\r
 \r
-uint8_t cur_speed = 0xFF;\r
 void handle_cmd(uint8_t cmd)\r
 {\r
   switch(cmd) {\r
@@ -172,9 +178,9 @@ void handle_cmd(uint8_t cmd)
   case 'W': motor_run(300,1); break;\r
   case '+': motor_set_speed(++cur_speed); break;\r
   case '-': motor_set_speed(--cur_speed); break;\r
-  default: CDC_Device_SendString(&VirtualSerial_CDC_Interface, "error\n"); return;\r
+  default: CDC_Device_SendString(&VirtualSerial_CDC_Interface, "error\n\r"); return;\r
   }\r
-  CDC_Device_SendString(&VirtualSerial_CDC_Interface, "ok\n");\r
+  CDC_Device_SendString(&VirtualSerial_CDC_Interface, "ok\n\r");\r
 }\r
 \r
 \r