From 02425b791000aa390839cabcc67707bd610a8bfb Mon Sep 17 00:00:00 2001 From: schodet Date: Wed, 6 Apr 2005 21:12:34 +0000 Subject: Ajout de define pour les sens moteurs. --- n/asserv/src/counter.c | 13 +++++++++++++ n/asserv/src/pwm.c | 49 +++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 52 insertions(+), 10 deletions(-) (limited to 'n') diff --git a/n/asserv/src/counter.c b/n/asserv/src/counter.c index 7fcfac5..774a9c8 100644 --- a/n/asserv/src/counter.c +++ b/n/asserv/src/counter.c @@ -23,6 +23,11 @@ * * }}} */ +/** Define to 1 to reverse the left counter. */ +#define COUNTER_REVERSE_LEFT 1 +/** Define to 1 to reverse the right counter. */ +#define COUNTER_REVERSE_RIGHT 0 + /** Forward and reverse counter values. */ static uint8_t counter_left_frw, counter_left_rev, counter_right_frw, counter_right_rev; @@ -79,7 +84,11 @@ counter_poll (void) uint8_t c; /* Read left counter. */ c = TCNT2; +#if COUNTER_REVERSE_LEFT == 0 if (PINE & _BV (4)) +#else + if (!(PINE & _BV (4))) +#endif { PORTD &= ~0x40; counter_left_frw += c - counter_left_old; @@ -92,7 +101,11 @@ counter_poll (void) counter_left_old = c; /* Read right counter. */ c = TCNT3L; +#if COUNTER_REVERSE_RIGHT == 0 if (PINE & _BV (5)) +#else + if (!(PINE & _BV (5))) +#endif { PORTD &= ~0x20; counter_right_frw += c - counter_right_old; diff --git a/n/asserv/src/pwm.c b/n/asserv/src/pwm.c index 04b9a57..6e90e65 100644 --- a/n/asserv/src/pwm.c +++ b/n/asserv/src/pwm.c @@ -23,6 +23,19 @@ * * }}} */ +/** Define the PWM output used for left motor. */ +#define PWM_LEFT_OCR OCR1C +/** Define the PWM output used for right motor. */ +#define PWM_RIGHT_OCR OCR1B +/** Define the direction output for left motor. */ +#define PWM_LEFT_DIR 3 +/** Define the direction output for right motor. */ +#define PWM_RIGHT_DIR 2 +/** Define the forward direction logic for left motor. */ +#define PWM_LEFT_DIR_FRW 0 +/** Define the forward direction logic for right motor. */ +#define PWM_RIGHT_DIR_FRW 0 + /** PWM values. */ int16_t pwm_left, pwm_right; @@ -77,32 +90,48 @@ pwm_update (void) /* Set left PWM. */ if (pwm_left == 0) { - OCR1B = 0; + PWM_LEFT_OCR = 0; } else if (pwm_left < 0) { - PORTB |= _BV (2); - OCR1B = pwm_preproc (-pwm_left); +#if PWM_LEFT_DIR_FRW == 1 + PORTB &= ~_BV (PWM_LEFT_DIR); +#else + PORTB |= _BV (PWM_LEFT_DIR); +#endif + PWM_LEFT_OCR = pwm_preproc (-pwm_left); } else { - PORTB &= ~_BV (2); - OCR1B = pwm_preproc (pwm_left); +#if PWM_LEFT_DIR_FRW == 1 + PORTB |= _BV (PWM_LEFT_DIR); +#else + PORTB &= ~_BV (PWM_LEFT_DIR); +#endif + PWM_LEFT_OCR = pwm_preproc (pwm_left); } /* Set right PWM. */ if (pwm_right == 0) { - OCR1C = 0; + PWM_RIGHT_OCR = 0; } else if (pwm_right < 0) { - PORTB &= ~_BV (3); - OCR1C = pwm_preproc (-pwm_right); +#if PWM_RIGHT_DIR_FRW == 1 + PORTB &= ~_BV (PWM_RIGHT_DIR); +#else + PORTB |= _BV (PWM_RIGHT_DIR); +#endif + PWM_RIGHT_OCR = pwm_preproc (-pwm_right); } else { - PORTB |= _BV (3); - OCR1C = pwm_preproc (pwm_right); +#if PWM_RIGHT_DIR_FRW == 1 + PORTB |= _BV (PWM_RIGHT_DIR); +#else + PORTB &= ~_BV (PWM_RIGHT_DIR); +#endif + PWM_RIGHT_OCR = pwm_preproc (pwm_right); } } -- cgit v1.2.3