diff options
author | neoraider <devnull@localhost> | 2007-04-03 14:48:00 +0200 |
---|---|---|
committer | neoraider <devnull@localhost> | 2007-04-03 14:48:00 +0200 |
commit | dc1306244e3a7853c31cd94c5ac3d97aa6e6c0d5 (patch) | |
tree | 758cc525af6b6fca0af22482ec51c70017dbb7fc | |
download | rc2007-rescue-dc1306244e3a7853c31cd94c5ac3d97aa6e6c0d5.tar rc2007-rescue-dc1306244e3a7853c31cd94c5ac3d97aa6e6c0d5.zip |
Neues Rescue-Programm angefangen (2)
-rw-r--r-- | adc.c | 18 | ||||
-rw-r--r-- | adc.h | 10 | ||||
-rw-r--r-- | avr.c | 16 | ||||
-rw-r--r-- | avr.h | 16 | ||||
-rw-r--r-- | hardware.c | 6 | ||||
-rw-r--r-- | hardware.h | 24 | ||||
-rw-r--r-- | util.h | 9 |
7 files changed, 99 insertions, 0 deletions
@@ -0,0 +1,18 @@ +#include "adc.h" + +#include <avr/io.h> + + +void initADC() { + ADMUX = (1<<REFS0);
+ ADCSRA = (1<<ADEN)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0); +} + +uint16_t getADCValue(int port) { + ADMUX = (1<<REFS0)|(1<<ADLAR)|(port&0x07); + ADCSRA |= (1<<ADSC); + + while(!(ADCSRA & (1<<ADIF))); + + return ADC; +} @@ -0,0 +1,10 @@ +#ifndef _ROBOCUP_ADC_H_ +#define _ROBOCUP_ADC_H_ + +#include <stdint.h> + + +void initADC(); +uint16_t getADCValue(int port); + +#endif @@ -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); +} @@ -0,0 +1,16 @@ +#ifndef _ROBOCUP_AVR_H_ +#define _ROBOCUP_AVR_H_ + +#include <stdint.h> + + +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 <avr/io.h> + + +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 @@ -0,0 +1,9 @@ +#ifndef _ROBOCUP_UTIL_H_ +#define _ROBOCUP_UTIL_H_ + +#define MIN(a,b) ((a<b)?a:b) +#define MAX(a,b) ((a>b)?a:b) +#define CLAMP(min,x,max) ((x<min)?min:(x>max)?max:x) +#define ABS(a) ((a<0)?-a:a) + +#endif |