summaryrefslogtreecommitdiffhomepage
path: root/digital/beacon/src/codewheel.c
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/beacon/src/codewheel.c
parent7c8f2999d8a61fa4f7666484a9ead9541121d4c0 (diff)
digital/beacon: split sensors.* into codewheel.* & laser.* and modify dedicated calls
Diffstat (limited to 'digital/beacon/src/codewheel.c')
-rw-r--r--digital/beacon/src/codewheel.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/digital/beacon/src/codewheel.c b/digital/beacon/src/codewheel.c
new file mode 100644
index 00000000..efcd9931
--- /dev/null
+++ b/digital/beacon/src/codewheel.c
@@ -0,0 +1,65 @@
+/* codewheel.c */
+/* Codewheel sensors 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 "codewheel.h"
+
+
+/* This function initializes the codewheel optical sensors and associated interrupt */
+void codewheel_init(void)
+{
+ /* Select external clock on rising edge for timer 3 */
+ TCCR3B |= (1<<CS30)|(1<<CS31)|(1<<CS32);
+
+ /* Use CTC mode */
+ TCCR3B |= (1<<WGM32);
+
+ /* Define the compare value */
+ OCR3A = CODEWHEEL_CPR;
+
+ /* Enable Interrupts */
+ TIMSK3 |= (1<<OCIE3A);
+ sei();
+}
+
+
+/* This function returns the wheel position */
+uint16_t codewheel_get_value(void)
+{
+ return TCNT3;
+}
+
+/* This function resets the wheel position */
+void codewheel_reset(void)
+{
+ TCNT3 = 0;
+}
+
+/* Codewheel complete turn IRQ vector for CodeWheel*/
+ISR(TIMER3_COMPA_vect)
+{
+}