]> jspc29.x-matter.uni-frankfurt.de Git - coral.git/commitdiff
move_plate() now in timer 1 interrup routine, plate_ready() signal to main loop
authorMichael Wiebusch <m.wiebusch@gsi.de>
Mon, 15 Dec 2014 15:59:26 +0000 (16:59 +0100)
committerMichael Wiebusch <m.wiebusch@gsi.de>
Mon, 15 Dec 2014 15:59:26 +0000 (16:59 +0100)
firmware/main.c
firmware/plate.c
firmware/plate.h

index a192a88edc9aac58c07dd13251e11fd8a2432e65..56bc262aeab4ff134b815b62c6b2c955b22dfce9 100644 (file)
@@ -226,7 +226,7 @@ int main(void){
   init_motors();
   
   SetupHardware();
-
+  init_plate_timer();
   touchpad_init(); // you need to call this to setup the I/O pin!
   _delay_ms(500);
   sei();
@@ -236,10 +236,10 @@ int main(void){
   while (1) {
     Usb2SerialTask();
     parse_command(); // read data from virtual comport
-    touchpad_read(); // read data from touchpad
-    inc_target_plate_pos_x(4*delta_x());
-    inc_target_plate_pos_y(-4*delta_y());
-    if(move_plate()){
+//     touchpad_read(); // read data from touchpad
+//     inc_target_plate_pos_x(4*delta_x());
+//     inc_target_plate_pos_y(-4*delta_y());
+    if(plate_ready()){
       pos_report();
     }
   }
index aeb7be5fb1d246f7439ffa59640f683966c8ce73..e1d3274f6f3fbb07223a7ff582d640c532152676 100644 (file)
@@ -1,5 +1,6 @@
 #include <avr/io.h> 
 #include <stdlib.h>
+#include <avr/interrupt.h>
 #include <util/delay.h>
 #include "motors.h"
 #include "plate.h"
@@ -13,6 +14,8 @@
 int32_t plate_pos_x = 0,plate_pos_y = 0;
 int32_t target_plate_pos_x = 0,target_plate_pos_y = 0;
 
+uint8_t ready = 0;
+
 int32_t get_plate_pos_x(void){
   return plate_pos_x;
 }
@@ -44,6 +47,16 @@ void inc_target_plate_pos_y(int32_t value){
   target_plate_pos_y += value;
 }
 
+uint8_t plate_ready(void){
+  if(ready){
+    ready = 0;
+    return 1;
+  } else {
+    return 0;
+  }
+}
+
+
 
 uint8_t move_plate(void){
   int32_t todo_x,todo_y = 0;
@@ -105,8 +118,19 @@ uint8_t move_plate(void){
 
 
 
+void init_plate_timer(void){
+  TCCR1B |= (1<<CS10) | (1<<CS12) | (1<<WGM12);
+  TCCR1C |= (1<<FOC1A);
+  OCR1A = 32;
+  TIMSK1 |= (1<<OCIE1A);
+  
+}
 
-
+ISR( TIMER1_COMPA_vect ) {
+  if(move_plate()){
+    ready = 1;
+  }
+}
 
   
 
index 55fad924c54da1b636a0995be161e4f24ce1a053..7a57922f1b83a7d324e74c52fb0bebe989137c4d 100644 (file)
@@ -5,10 +5,10 @@
 
 
 uint8_t move_plate(void);
+uint8_t plate_ready(void);
 
-
-
-
+ISR( TIMER1_COMPA_vect );
+void init_plate_timer(void);
 int32_t get_plate_pos_x(void);
 int32_t get_plate_pos_y(void);
 void set_plate_pos_x(int32_t value);