From e532558c6f6fb1e07dbc28fdac6441c981d72907 Mon Sep 17 00:00:00 2001 From: Florent Duchon Date: Sun, 22 Apr 2012 22:39:48 +0200 Subject: digital/beacon: add codewheel rebase mechanismes --- digital/beacon/src/codewheel.c | 25 ++++++++++++++++++++++--- digital/beacon/src/codewheel.h | 9 +++++++-- 2 files changed, 29 insertions(+), 5 deletions(-) (limited to 'digital') diff --git a/digital/beacon/src/codewheel.c b/digital/beacon/src/codewheel.c index 84ca69f6..092f6b57 100644 --- a/digital/beacon/src/codewheel.c +++ b/digital/beacon/src/codewheel.c @@ -50,6 +50,12 @@ void codewheel_init(void) sei(); } +/* This function resets the wheel position */ +void codewheel_reset(void) +{ + TCNT3 = 0; +} + /* This function returns the codewheel state */ TCodewheel_state codewheel_get_state(void) { @@ -68,13 +74,26 @@ uint16_t codewheel_get_value(void) return TCNT3; } -/* This function resets the wheel position */ -void codewheel_reset(void) +/* This function returns the offset value */ +uint16_t codewheel_get_rebase_offset(void) { - TCNT3 = 0; + return codewheel.rebase_offset; +} + +/* This function saves the counter value used when a codewheel reset is requested */ +void codewheel_set_rebase_offset(uint16_t offset) +{ + codewheel.rebase_offset = offset; } /* Codewheel complete turn IRQ vector for CodeWheel*/ ISR(TIMER3_COMPA_vect) { + if(codewheel_get_state() == CODEWHEEL_REQUEST_REBASE) + { + OCR3A = codewheel_get_rebase_offset(); + codewheel_set_state(CODEWHEEL_REBASED); + } + else + OCR3A = CODEWHEEL_CPR; } diff --git a/digital/beacon/src/codewheel.h b/digital/beacon/src/codewheel.h index 57b4a7b5..7abe3f0e 100644 --- a/digital/beacon/src/codewheel.h +++ b/digital/beacon/src/codewheel.h @@ -44,6 +44,8 @@ typedef struct /* This function initializes the codewheel optical sensors and associated interrupt */ void codewheel_init(void); +/* This function resets the wheel position */ +void codewheel_reset(void); /* This function returns the codewheel state */ TCodewheel_state codewheel_get_state(void); @@ -54,7 +56,10 @@ void codewheel_set_state(TCodewheel_state state); /* This function returns the wheel position */ uint16_t codewheel_get_value(void); -/* This function resets the wheel position */ -void codewheel_reset(void); +/* This function returns the offset value */ +uint16_t codewheel_get_rebase_offset(void); + +/* This function saves the counter value used when a codewheel reset is requested */ +void codewheel_set_rebase_offset(uint16_t offset); #endif -- cgit v1.2.3