summaryrefslogtreecommitdiff
path: root/n/asserv/src/pwm.c
diff options
context:
space:
mode:
authorschodet2005-04-06 21:12:34 +0000
committerschodet2005-04-06 21:12:34 +0000
commit02425b791000aa390839cabcc67707bd610a8bfb (patch)
tree97d258d0795bb81ceaf0f4e59a001a3ce897f5d4 /n/asserv/src/pwm.c
parent0432e1772412d42036124a213663105eb52fb02a (diff)
Ajout de define pour les sens moteurs.
Diffstat (limited to 'n/asserv/src/pwm.c')
-rw-r--r--n/asserv/src/pwm.c49
1 files changed, 39 insertions, 10 deletions
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);
}
}