summaryrefslogtreecommitdiff
path: root/digital
diff options
context:
space:
mode:
authorFlorent Duchon2012-04-21 16:42:16 +0200
committerFlorent Duchon2012-04-21 18:05:03 +0200
commit90527d1cf27582b1e7bb8588afbed8989453f606 (patch)
tree85a51ed6b31de8698bf7ff0b6b9d504e1c4d5626 /digital
parent7c8f2999d8a61fa4f7666484a9ead9541121d4c0 (diff)
digital/beacon: split sensors.* into codewheel.* & laser.* and modify dedicated calls
Diffstat (limited to 'digital')
-rw-r--r--digital/beacon/src/codewheel.c (renamed from digital/beacon/src/sensors.c)33
-rw-r--r--digital/beacon/src/codewheel.h (renamed from digital/beacon/src/sensors.h)19
-rw-r--r--digital/beacon/src/debug.c44
-rw-r--r--digital/beacon/src/debug.h1
-rw-r--r--digital/beacon/src/laser.c121
-rw-r--r--digital/beacon/src/laser.h55
-rw-r--r--digital/beacon/src/main_avr.c7
7 files changed, 236 insertions, 44 deletions
diff --git a/digital/beacon/src/sensors.c b/digital/beacon/src/codewheel.c
index d1418440..efcd9931 100644
--- a/digital/beacon/src/sensors.c
+++ b/digital/beacon/src/codewheel.c
@@ -1,5 +1,5 @@
-/* sensors.c */
-/* Beacon sensors management. {{{
+/* codewheel.c */
+/* Codewheel sensors management. {{{
*
* Copyright (C) 2012 Florent Duchon
*
@@ -25,24 +25,12 @@
#include <types.h>
#include <avr/interrupt.h>
-#include "sensors.h"
#include "debug.h"
-#include "led.h"
-
-/********************************************************/
-
-/* This function initializes the laser pin input and associated interrupt */
-void sensors_laser_init(void)
-{
- /* Configure Input compare interrupts for Laser Interrupt*/
- TCCR3B |= (1<<ICNC3)|(1<<ICES3);
- TIMSK3 |= (1<<ICIE3);
- sei();
-}
+#include "codewheel.h"
/* This function initializes the codewheel optical sensors and associated interrupt */
-void sensors_codewheel_init(void)
+void codewheel_init(void)
{
/* Select external clock on rising edge for timer 3 */
TCCR3B |= (1<<CS30)|(1<<CS31)|(1<<CS32);
@@ -60,25 +48,18 @@ void sensors_codewheel_init(void)
/* This function returns the wheel position */
-uint16_t sensors_codewheel_get_value(void)
+uint16_t codewheel_get_value(void)
{
return TCNT3;
}
/* This function resets the wheel position */
-void sensors_codewheel_reset(void)
+void codewheel_reset(void)
{
TCNT3 = 0;
}
-/* IRQ vector for CodeWheel complete turn */
+/* Codewheel complete turn IRQ vector for CodeWheel*/
ISR(TIMER3_COMPA_vect)
{
- //Top tour ++
-}
-
-/* IRQ vector for Laser Interrupt */
-ISR(TIMER3_CAPT_vect)
-{
- // LASER
}
diff --git a/digital/beacon/src/sensors.h b/digital/beacon/src/codewheel.h
index f2aa3c3b..a0ff00bd 100644
--- a/digital/beacon/src/sensors.h
+++ b/digital/beacon/src/codewheel.h
@@ -1,5 +1,5 @@
-/* sensors.h */
-/* Beacon sensors management. {{{
+/* codewheel.h */
+/* Codewheel sensors management. {{{
*
* Copyright (C) 2012 Florent Duchon
*
@@ -23,21 +23,18 @@
*
* }}} */
-#ifndef _SENSORS_H
-#define _SENSORS_H
+#ifndef _CODEWHEEL_H
+#define _CODEWHEEL_H
#define CODEWHEEL_CPR 499
-/* This function initializes the laser pin input and associated interrupt */
-void sensors_laser_init(void);
-
/* This function initializes the codewheel optical sensors and associated interrupt */
-void sensors_codewheel_init(void);
+void codewheel_init(void);
/* This function returns the wheel position */
-uint16_t sensors_codewheel_get_value(void);
+uint16_t codewheel_get_value(void);
/* This function resets the wheel position */
-void sensors_codewheel_reset(void);
+void codewheel_reset(void);
-#endif \ No newline at end of file
+#endif
diff --git a/digital/beacon/src/debug.c b/digital/beacon/src/debug.c
index 42fc0e29..fb2cf589 100644
--- a/digital/beacon/src/debug.c
+++ b/digital/beacon/src/debug.c
@@ -29,11 +29,13 @@
#include "calibration.h"
#include "debug.h"
#include "servo.h"
-#include "sensors.h"
+#include "codewheel.h"
+#include "laser.h"
#include "network.h"
HAL_UsartDescriptor_t appUsartDescriptor; // USART descriptor (required by stack)
HAL_AppTimer_t debugTimer; // TIMER descripor used by the DEBUG task
+HAL_AppTimer_t wheelTimer; // TIMER descripor used by the DEBUG task
uint8_t usartRxBuffer[APP_USART_RX_BUFFER_SIZE]; // USART Rx buffer
uint8_t usartTxBuffer[APP_USART_TX_BUFFER_SIZE]; // USART Tx buffer
@@ -111,13 +113,13 @@ void usartRXCallback(uint16_t bytesToRead)
uprintf("SERVO_2 = %d\r\n",servo_angle_decrease(SERVO_2));
break;
case 'a':
- uprintf("CodeWheel Value = %d\r\n",sensors_codewheel_get_value());
+ uprintf("CodeWheel Value = %d\r\n",codewheel_get_value());
break;
case 'd':
debug_start_stop_task();
break;
case 'z':
- sensors_codewheel_reset();
+ codewheel_reset();
break;
case 'c':
calibration_start_stop_task();
@@ -125,6 +127,15 @@ void usartRXCallback(uint16_t bytesToRead)
case 'q':
calibration_set_laser_flag(SET);
break;
+ case 'w':
+// wheel_start_stop_task();
+// uprintf("TCNT3 = %d\r\n",TCNT3);
+ TIMSK3 &= ~(1<<OCIE3B);
+ case 'r':
+ led_off(1);
+ led_off(2);
+ led_off(3);
+ break;
/* Default */
default :
uprintf(" ?? Unknown command ??\r\n");
@@ -175,6 +186,31 @@ void debug_start_stop_task(void)
debug_task_running = 0;
}
}
+void wheel_task(void)
+{
+ TCNT3++;
+}
+
+void wheel_start_stop_task(void)
+{
+ static bool wheel_task_running = 0;
+ if(wheel_task_running == 0)
+ {
+ led_on(2);
+ wheelTimer.interval = WHEEL_TASK_PERIOD;
+ wheelTimer.mode = TIMER_REPEAT_MODE;
+ wheelTimer.callback = wheel_task;
+ HAL_StartAppTimer(&wheelTimer);
+ wheel_task_running = 1;
+ }
+ else
+ {
+ led_off(2);
+ HAL_StopAppTimer(&wheelTimer);
+ TCNT3=0;
+ wheel_task_running = 0;
+ }
+}
/* Debug task callback */
void debug_task(void)
@@ -184,7 +220,7 @@ void debug_task(void)
#ifdef TYPE_END
uprintf("[1] Scanning State = %d -- Value = %d\r\n",servo_get_state(SERVO_1),servo_get_value(SERVO_1));
uprintf("[2] Scanning State = %d -- Value = %d\r\n",servo_get_state(SERVO_2),servo_get_value(SERVO_2));
- uprintf("CodeWheel = %d\r\n",sensors_codewheel_get_value());
+ uprintf("CodeWheel = %d\r\n",codewheel_get_value());
uprintf("Calibration state = %d\r\n",calibration_get_state());
#endif
}
diff --git a/digital/beacon/src/debug.h b/digital/beacon/src/debug.h
index 3110e07f..73beab06 100644
--- a/digital/beacon/src/debug.h
+++ b/digital/beacon/src/debug.h
@@ -34,6 +34,7 @@
#define READ_USART HAL_ReadUsart
#define USART_CHANNEL APP_USART_CHANNEL
#define DEBUG_TASK_PERIOD 700L
+#define WHEEL_TASK_PERIOD 1000L
// #define DEBUG_POSITION_ENABLE
// #define DEBUG_UPDATE_ENABLE
diff --git a/digital/beacon/src/laser.c b/digital/beacon/src/laser.c
new file mode 100644
index 00000000..9d9d1fe0
--- /dev/null
+++ b/digital/beacon/src/laser.c
@@ -0,0 +1,121 @@
+/* laser.c */
+/* laser sensor management. {{{
+ *
+ * Copyright (C) 2012 Florent Duchon
+ *
+ * APBTeam:
+ * Web: http://apbteam.org/
+ * Email: team AT apbteam DOT org
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * }}} */
+
+#include <types.h>
+#include <avr/interrupt.h>
+#include "debug.h"
+#include "laser.h"
+
+
+/* This function initializes the laser pin input and associated interrupt */
+void laser_init(void)
+{
+ /* Configure Input compare interrupts for Laser Interrupt*/
+ TCCR3B |= (1<<ICNC3)|(1<<ICES3);
+ TIMSK3 |= (1<<ICIE3);
+ TIMSK3 &= ~(1<<OCIE3B);
+ sei();
+}
+
+
+/* This function returns the edge type trigged by the AVR IC module*/
+TLaser_edge_type laser_get_edge_type(void)
+{
+ if(RISING_EDGE)
+ {
+ if(SENDING_ENGAGED)
+ {
+ return LASER_RISING_EDGE;
+ }
+ else
+ {
+ return LASER_FIRST_RISING_EDGE;
+ }
+ }
+ else
+ {
+ return LASER_FALLING_EDGE;
+ }
+}
+
+
+/* This function inverts the trigged edge of the AVR IC module */
+void laser_invert_IRQ_edge_trigger(void)
+{
+ TCCR3B ^= 1<<ICES3;
+}
+
+
+/* This function deactivates the angle sending */
+void laser_inhibit_angle_sending(void)
+{
+ TIMSK3 &= ~(1<<OCIE3B);
+ sei();
+}
+
+
+/* This function configures the AVR OC3B interrupt that will send the angle LASER_SENDING_OFFSET after the latest rising edge */
+void laser_engage_angle_sending(uint16_t value)
+{
+ OCR3A = value + LASER_SENDING_OFFSET;
+ TIMSK3 |= (1<<OCIE3B);
+ sei();
+}
+
+
+/* Zigbee sending IRQ vector */
+ISR(TIMER3_COMPB_vect)
+{
+// TIMSK3 &= ~OCIE3B;
+// sei();
+}
+
+
+/* Laser IRQ vector */
+ISR(TIMER3_CAPT_vect)
+{
+ static uint16_t angle = 0;
+ TLaser_edge_type current_edge;
+
+ current_edge = laser_get_edge_type();
+
+ switch(current_edge)
+ {
+ case LASER_FIRST_RISING_EDGE:
+ angle = ICR3;
+ break;
+ case LASER_RISING_EDGE:
+ laser_inhibit_angle_sending();
+ angle = (angle + ICR3) / 2;
+ break;
+ case LASER_FALLING_EDGE:
+ angle = (angle + ICR3) / 2;
+ laser_engage_angle_sending(ICR3);
+ break;
+ default:
+ break;
+ }
+ laser_invert_IRQ_edge_trigger();
+}
diff --git a/digital/beacon/src/laser.h b/digital/beacon/src/laser.h
new file mode 100644
index 00000000..661c32b8
--- /dev/null
+++ b/digital/beacon/src/laser.h
@@ -0,0 +1,55 @@
+/* laser.h */
+/* laser sensor management. {{{
+ *
+ * Copyright (C) 2012 Florent Duchon
+ *
+ * APBTeam:
+ * Web: http://apbteam.org/
+ * Email: team AT apbteam DOT org
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * }}} */
+
+#ifndef _LASER_H
+#define _LASER_H
+
+#define RISING_EDGE TCCR3B & (1<<ICES3)
+#define SENDING_ENGAGED TIMSK3&(1<<OCIE3B)
+#define LASER_SENDING_OFFSET 10
+
+typedef enum
+{
+ LASER_FIRST_RISING_EDGE,
+ LASER_RISING_EDGE,
+ LASER_FALLING_EDGE
+} TLaser_edge_type;
+
+/* This function initializes the laser pin input and associated interrupt */
+void laser_init(void);
+
+/* This function returns the edge type trigged by the AVR IC module*/
+TLaser_edge_type laser_get_edge_type(void);
+
+/* This function inverts the trigged edge of the AVR IC module */
+void laser_invert_IRQ_edge_trigger(void);
+
+/* This function deactivates the angle sending */
+void laser_inhibit_angle_sending(void);
+
+/* This function configures the AVR OC3B interrupt that will send the angle LASER_SENDING_OFFSET after the latest rising edge */
+void laser_engage_angle_sending(uint16_t value);
+
+#endif
diff --git a/digital/beacon/src/main_avr.c b/digital/beacon/src/main_avr.c
index 9b892c3a..7e38a6f3 100644
--- a/digital/beacon/src/main_avr.c
+++ b/digital/beacon/src/main_avr.c
@@ -27,9 +27,10 @@
#include <util/delay.h>
#include "configuration.h"
#include "calibration.h"
+#include "codewheel.h"
#include "network.h"
#include "position.h"
-#include "sensors.h"
+#include "laser.h"
#include "debug.h"
#include "servo.h"
#include "led.h"
@@ -88,8 +89,8 @@ void APL_TaskHandler(void)
break;
case DEVICE_TYPE_END_DEVICE:
servo_init();
- sensors_codewheel_init();
- sensors_laser_init();
+ codewheel_init();
+ laser_init();
network_init();
uprintf("LOL_%d initialisation OK !\n\r",CS_NWK_ADDR);
break;