From dc1306244e3a7853c31cd94c5ac3d97aa6e6c0d5 Mon Sep 17 00:00:00 2001 From: neoraider Date: Tue, 3 Apr 2007 12:48:00 +0000 Subject: Neues Rescue-Programm angefangen (2) --- adc.c | 18 ++++++++++++++++++ adc.h | 10 ++++++++++ avr.c | 16 ++++++++++++++++ avr.h | 16 ++++++++++++++++ hardware.c | 6 ++++++ hardware.h | 24 ++++++++++++++++++++++++ util.h | 9 +++++++++ 7 files changed, 99 insertions(+) create mode 100644 adc.c create mode 100644 adc.h create mode 100644 avr.c create mode 100644 avr.h create mode 100644 hardware.c create mode 100644 hardware.h create mode 100644 util.h diff --git a/adc.c b/adc.c new file mode 100644 index 0000000..192d36c --- /dev/null +++ b/adc.c @@ -0,0 +1,18 @@ +#include "adc.h" + +#include + + +void initADC() { + ADMUX = (1< + + +void initADC(); +uint16_t getADCValue(int port); + +#endif diff --git a/avr.c b/avr.c new file mode 100644 index 0000000..ac303d0 --- /dev/null +++ b/avr.c @@ -0,0 +1,16 @@ +#include "avr.h" +#include "util.h" + +void setMotorSpeed(MOTOR *motor, int speed) { + if(speed > 0) { + *motor->port &= ~motor->revMask; + *motor->port |= motor->fwdMask; + } + else if(speed < 0) { + *motor->port &= ~motor->fwdMask; + *motor->port |= motor->revMask; + } + else *motor->port |= motor->fwdMask|motor->revMask; + + *motor->pwmPort = CLAMP(0, ABS(speed), 255); +} diff --git a/avr.h b/avr.h new file mode 100644 index 0000000..3727bdf --- /dev/null +++ b/avr.h @@ -0,0 +1,16 @@ +#ifndef _ROBOCUP_AVR_H_ +#define _ROBOCUP_AVR_H_ + +#include + + +typedef struct { + volatile uint8_t *port; + volatile uint8_t *pwmPort; + uint8_t fwdMask; + uint8_t revMask; +} MOTOR; + +void setMotorSpeed(MOTOR *motor, int speed); + +#endif diff --git a/hardware.c b/hardware.c new file mode 100644 index 0000000..6bc329e --- /dev/null +++ b/hardware.c @@ -0,0 +1,6 @@ +#include "hardware.h" + + +void initHardware() { + +} diff --git a/hardware.h b/hardware.h new file mode 100644 index 0000000..9b2bcb7 --- /dev/null +++ b/hardware.h @@ -0,0 +1,24 @@ +#ifndef _ROBOCUP_HARDWARE_H_ +#define _ROBOCUP_HARDWARE_H_ + +#include "avr.h" + +#include + + +static const MOTOR MOTOR1 = { + &PORTD, &OCR1BL, 0x01, 0x02 +}; + +static const MOTOR MOTOR2 = { + &PORTD, &OCR1AL, 0x04, 0x08 +}; + +static const MOTOR MOTOR3 = { + &PORTB, &OCR0, 0x01, 0x02 +}; + + +void initHardware(); + +#endif diff --git a/util.h b/util.h new file mode 100644 index 0000000..1fea3ae --- /dev/null +++ b/util.h @@ -0,0 +1,9 @@ +#ifndef _ROBOCUP_UTIL_H_ +#define _ROBOCUP_UTIL_H_ + +#define MIN(a,b) ((ab)?a:b) +#define CLAMP(min,x,max) ((xmax)?max:x) +#define ABS(a) ((a<0)?-a:a) + +#endif -- cgit v1.2.3