From e2cfa9a1399d81b83c7d00a9304df46df807320c Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Mon, 23 Sep 2013 00:32:20 +0000 Subject: limits work now with ADC value moved ajar sensor dor PORTC7 git-svn-id: https://svn.spreadspace.org/avr/trunk@226 aa12f405-d877-488e-9caf-2d797e2a1cc7 --- tuer-rfid/limits.c | 78 +++++++++++++++++------------------------------------- 1 file changed, 25 insertions(+), 53 deletions(-) (limited to 'tuer-rfid/limits.c') diff --git a/tuer-rfid/limits.c b/tuer-rfid/limits.c index 027a3b5..6f567af 100644 --- a/tuer-rfid/limits.c +++ b/tuer-rfid/limits.c @@ -23,72 +23,44 @@ #include #include "limits.h" +#include -#define LIMITS_PIN PINC -#define LIMITS_PORT PORTC -#define LIMITS_DDR DDRC -#define LIMITS_OPEN 6 -#define LIMITS_CLOSE 7 +#define LIMITS_ADC_CHAN_NUM 8 +#define LIMITS_ADC_CHAN ADC_CHANNEL8 -#define LIMITS_LP_MAX 255 +#define LIMITS_RINGBUF_SIZE 5 +/* HINT: this is compared to a sliding sum not an average! */ +#define LIMITS_TH_CLOSE 250 +#define LIMITS_TH_OPEN 1000 void limits_init(void) { - LIMITS_DDR = LIMITS_DDR & ~(1<= LIMITS_LP_MAX) { - last_state = state; - lp_cnt = 0; + if(ADC_IsReadingComplete()) { + r[idx] = (ADC_GetResult()>>8); + idx = (idx + 1) % LIMITS_RINGBUF_SIZE; + s = 0; + uint8_t i; + for(i=0; i= LIMITS_LP_MAX) { - last_state = state; - lp_cnt = 0; - } - - return last_state; -} - -limits_t limits_get(void) -{ - uint8_t tmp = LIMITS_PIN & (1<