Permalink
Browse files

corrected code for F_CPU 8MHz

  • Loading branch information...
1 parent f1c0c84 commit 0c52eed9d5c4377e2f59ce3d8cf759ed2582c98e @g4lvanix committed Apr 8, 2012
Showing with 23 additions and 9 deletions.
  1. +23 −9 main.c
View
32 main.c
@@ -1,21 +1,35 @@
#include <avr/io.h>
#include <util/delay.h>
-/* create alii for servo pulsewidth */
-#define right_fwd 1050
-#define left_fwd 4500
-#define right_bwd 4500
-#define left_bwd 1050
-#define stop 2666
+/* create alii for servo pulsewidth
+ *
+ * These values are calculated by this formula:
+ * TOP = ((F_CPU / 50) / 8) = 20000
+ *
+ * left = 20000 / 20 = 1000
+ * stop = 20000 / 15 = 1333
+ * right = 20000 / 10 = 2000
+ */
+#define right_fwd 1000
+#define right_bwd 2000
+
+#define left_fwd 2000
+#define left_bwd 1000
+
+#define stop 1333
+
+/* define pulsewidth register for each motor */
+#define m_right OCR1A
+#define m_left OCR1B
void init_t1(void){
TCCR1A = (1<<COM1A1) | (1<<COM1B1) | (1<<WGM11);
TCCR1B = (1<<WGM13) | (1<<CS11);
- ICR1 = 40000;
+ ICR1 = 20000;
- OCR1A = stop;
- OCR1B = stop;
+ m_right = stop;
+ m_left = stop;
/* set OC1A and OC1B to output */
DDRB |= (1<<PB6) | (1<<PB5);

0 comments on commit 0c52eed

Please sign in to comment.