summaryrefslogtreecommitdiffhomepage
path: root/analog/motor-power-avr/src/pwm.avr.c
diff options
context:
space:
mode:
authorGuillaume Chevillot2008-03-13 10:34:32 +0100
committerGuillaume Chevillot2008-03-13 10:34:32 +0100
commit65baffda4311b55c9d4026d84c1c1544d0ee7aa4 (patch)
treecef12af16ced96358a4cbf163db674d8ba8a4f14 /analog/motor-power-avr/src/pwm.avr.c
parent7e1e72e29349a8248901d4d4f466d1c9b556344d (diff)
- Add current limitation management (not tested yet !) :
- Add current limitation PWM generation - Add external current limitation interrupts management - Update current limitation software part - Update TODO list (try to reduce it...)
Diffstat (limited to 'analog/motor-power-avr/src/pwm.avr.c')
-rw-r--r--analog/motor-power-avr/src/pwm.avr.c127
1 files changed, 0 insertions, 127 deletions
diff --git a/analog/motor-power-avr/src/pwm.avr.c b/analog/motor-power-avr/src/pwm.avr.c
deleted file mode 100644
index 01195a8e..00000000
--- a/analog/motor-power-avr/src/pwm.avr.c
+++ /dev/null
@@ -1,127 +0,0 @@
-/* pwm.avr.c */
-/* asserv - Position & speed motor control on AVR. {{{
- *
- * Copyright (C) 2005 Nicolas Schodet
- *
- * Robot APB Team/Efrei 2006.
- * Web: http://assos.efrei.fr/robot/
- * Email: robot AT efrei DOT fr
- *
- * 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 "modules/utils/utils.avr.h"
-
-/** 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 absolute maximum PWM value. */
-#define PWM_MAX 0x3ff
-
-/** PWM values, this is an error if absolute value is greater than the
- * maximum. */
-int16_t pwm_left, pwm_right;
-/** PWM reverse direction, only set pwm dir bits or you will get weird results
- * on port B. */
-uint8_t pwm_dir = _BV (PWM_LEFT_DIR);
-
-/* +AutoDec */
-
-/** Initialise PWM generator. */
-static inline void
-pwm_init (void);
-
-/** Update the hardware PWM values. */
-static inline void
-pwm_update (void);
-
-/* -AutoDec */
-
-/** Initialise PWM generator. */
-static inline void
-pwm_init (void)
-{
- /* Fast PWM, TOP = 0x3ff, OC1B & OC1C with positive logic.
- f_IO without prescaler.
- Fpwm = f_IO / (prescaler * (1 + TOP)) = 14400 Hz. */
- TCCR1A =
- regv (COM1A1, COM1A0, COM1B1, COM1B0, COM1C1, COM1C0, WGM11, WGM10,
- 0, 0, 1, 0, 1, 0, 1, 1);
- TCCR1B = regv (ICNC1, ICES1, 5, WGM13, WGM12, CS12, CS11, CS10,
- 0, 0, 0, 0, 1, 0, 0, 1);
- /* Enable pwm and direction outputs in DDRB. */
- DDRB |= _BV (7) | _BV (6) | _BV (PWM_LEFT_DIR) | _BV (PWM_RIGHT_DIR);
-}
-
-/** Update the hardware PWM values. */
-static inline void
-pwm_update (void)
-{
- uint16_t left, right;
- uint8_t dir;
- /* Some assumption checks. */
- assert (pwm_left >= -PWM_MAX && pwm_left <= PWM_MAX);
- assert (pwm_right >= -PWM_MAX && pwm_right <= PWM_MAX);
- assert ((pwm_dir & ~(_BV (PWM_LEFT_DIR) | _BV (PWM_RIGHT_DIR))) == 0);
- /* Sample port B. */
- dir = PORTB & ~(_BV (PWM_LEFT_DIR) | _BV (PWM_RIGHT_DIR));
- /* Set left PWM. */
- if (pwm_left == 0)
- {
- left = 0;
- }
- else if (pwm_left < 0)
- {
- left = -pwm_left;
- }
- else
- {
- dir |= _BV (PWM_LEFT_DIR);
- left = pwm_left;
- }
- /* Set right PWM. */
- if (pwm_right == 0)
- {
- right = 0;
- }
- else if (pwm_right < 0)
- {
- right = -pwm_right;
- }
- else
- {
- dir |= _BV (PWM_RIGHT_DIR);
- right = pwm_right;
- }
- /* Setup registers. */
- /* Here, there could be a problem because OCRx are double buffered, not
- * PORTB! */
- /* Another problem arise if the OCR sampling is done between left and
- * right OCR: the right PWM is one cycle late. */
- /* A solution could be to use interrupts to update PWM or to synchronise
- * general timer with PWM. */
- dir ^= pwm_dir;
- PORTB = dir;
- PWM_LEFT_OCR = left;
- PWM_RIGHT_OCR = right;
-}
-