diff options
Diffstat (limited to 'source/AVR_Studio')
-rwxr-xr-x | source/AVR_Studio/Soccer/hal/board.c | 57 | ||||
-rwxr-xr-x | source/AVR_Studio/Soccer/hal/board.h | 25 |
2 files changed, 48 insertions, 34 deletions
diff --git a/source/AVR_Studio/Soccer/hal/board.c b/source/AVR_Studio/Soccer/hal/board.c index d60834b..438973a 100755 --- a/source/AVR_Studio/Soccer/hal/board.c +++ b/source/AVR_Studio/Soccer/hal/board.c @@ -115,46 +115,45 @@ void Board::motor(int i, int speed) if((i < 0) || (i > 3)) return;
const int OFFSET = 40; // Motor does not work with very low ratio
const int PWM_MAX = 255;
+ int pwm = 0; // PWM-Speed - int pwm = abs(speed)+OFFSET;
+ if(speed != 0) pwm = abs(speed)+OFFSET;
if(pwm > PWM_MAX) pwm = PWM_MAX;
- if(i == 0)
- {
+ if(i == 0) {
MOTOR0_PWM = pwm;
if(speed > 0)
{
- PORTD |= (1 << 5);//In 1 ein
- PORTD &= ~(1 << 4);//In 2 aus
+ MOTOR0_PORT |= MOTOR0_A;//In 1 ein
+ MOTOR0_PORT &= ~MOTOR0_B;//In 2 aus
}
else if(speed < 0)
{
- PORTD |= (1 << 4);//In 2 ein
- PORTD &= ~(1 << 5);//In 1 aus
+ MOTOR0_PORT |= MOTOR0_B;//In 2 ein
+ MOTOR0_PORT &= ~MOTOR0_A;//In 1 aus
}
else
{
- PORTD |= (1 << 4);//In 2 ein
- PORTD |= (1 << 5);//In 1 ein
+ MOTOR0_PORT |= MOTOR0_B;//In 2 ein
+ MOTOR0_PORT |= MOTOR0_A;//In 1 ein
}
}
- else if(i == 1)
- {
+ else if(i == 1) {
MOTOR1_PWM = pwm;
if(speed > 0)
{
- PORTD |= (1 << 6);//In 1 ein
- PORTD &= ~(1 << 7);//In 2 aus
+ MOTOR1_PORT |= MOTOR1_A;//In 1 ein
+ MOTOR1_PORT &= ~MOTOR1_B;//In 2 aus
}
else if(speed < 0)
{
- PORTD |= (1 << 7);//In 2 ein
- PORTD &= ~(1 << 6);//In 1 aus
+ MOTOR1_PORT |= MOTOR1_B;//In 2 ein
+ MOTOR1_PORT &= ~MOTOR1_A;//In 1 aus
}
else
{
- PORTD |= (1 << 6);//In 2 ein
- PORTD |= (1 << 7);//In 1 ein
+ MOTOR1_PORT |= MOTOR1_B;//In 2 ein
+ MOTOR1_PORT |= MOTOR1_A;//In 1 ein
}
}
else if(i == 2)
@@ -162,18 +161,18 @@ void Board::motor(int i, int speed) MOTOR2_PWM = pwm;
if(speed > 0)
{
- PORTB |= (1 << 0);//In 1 ein
- PORTB &= ~(1 << 1);//In 2 aus
+ MOTOR2_PORT |= MOTOR2_A;//In 1 ein
+ MOTOR2_PORT &= ~MOTOR2_B;//In 2 aus
}
else if(speed < 0)
{
- PORTB |= (1 << 1);//In 2 ein
- PORTB &= ~(1 << 0);//In 1 aus
+ MOTOR2_PORT |= MOTOR2_B;//In 2 ein
+ MOTOR2_PORT &= ~MOTOR2_A;//In 1 aus
}
else
{
- PORTB |= (1 << 1);//In 2 ein
- PORTB |= (1 << 0);//In 1 ein
+ MOTOR2_PORT |= MOTOR2_B;//In 2 ein
+ MOTOR2_PORT |= MOTOR2_A;//In 1 ein
}
}
else if(i == 3)
@@ -181,18 +180,18 @@ void Board::motor(int i, int speed) DRIBBLER_PWM = pwm;
if(speed > 0)
{
- PORTB |= (1 << 2);//In 1 ein
- PORTB &= ~(1 << 3);//In 2 aus
+ DRIBBLER_PORT |= DRIBBLER_A;//In 1 ein
+ DRIBBLER_PORT &= ~DRIBBLER_B;//In 2 aus
}
else if(speed < 0)
{
- PORTB |= (1 << 3);//In 2 ein
- PORTB &= ~(1 << 2);//In 1 aus
+ DRIBBLER_PORT |= DRIBBLER_B;//In 2 ein
+ DRIBBLER_PORT &= ~DRIBBLER_A;//In 1 aus
}
else
{
- PORTB |= (1 << 2);//In 2 ein
- PORTB |= (1 << 3);//In 1 ein
+ DRIBBLER_PORT |= DRIBBLER_B;//In 2 ein
+ DRIBBLER_PORT |= DRIBBLER_A;//In 1 ein
}
}
}
diff --git a/source/AVR_Studio/Soccer/hal/board.h b/source/AVR_Studio/Soccer/hal/board.h index dd177f1..03df24f 100755 --- a/source/AVR_Studio/Soccer/hal/board.h +++ b/source/AVR_Studio/Soccer/hal/board.h @@ -10,11 +10,26 @@ #define BEEPER_PIN PG2
-// Definiere PWM-Ports für die Motoren/Dribbler
-#define MOTOR0_PWM OCR3A
-#define MOTOR1_PWM OCR3B
-#define MOTOR2_PWM OCR1A
-#define DRIBBLER_PWM OCR1C
+// Definiere Konstanten für die Motoren/Dribbler +#define MOTOR0_PORT PORTD
+#define MOTOR0_PWM OCR3A +#define MOTOR0_A (1 << 5) +#define MOTOR0_B (1 << 4) + +#define MOTOR1_PORT PORTD
+#define MOTOR1_PWM OCR3B +#define MOTOR1_A (1 << 6) +#define MOTOR1_B (1 << 7) + +#define MOTOR2_PORT PORTB
+#define MOTOR2_PWM OCR1A +#define MOTOR2_A (1 << 0) +#define MOTOR2_B (1 << 1) + +#define DRIBBLER_PORT PORTB
+#define DRIBBLER_PWM OCR1C +#define DRIBBLER_A (1 << 2) +#define DRIBBLER_B (1 << 3)
#define UART_BAUD_RATE 9600
|