Neues Rescue-Programm angefangen (2)
This commit is contained in:
commit
dc1306244e
7 changed files with 99 additions and 0 deletions
18
adc.c
Normal file
18
adc.c
Normal file
|
@ -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;
|
||||
}
|
10
adc.h
Normal file
10
adc.h
Normal file
|
@ -0,0 +1,10 @@
|
|||
#ifndef _ROBOCUP_ADC_H_
|
||||
#define _ROBOCUP_ADC_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
void initADC();
|
||||
uint16_t getADCValue(int port);
|
||||
|
||||
#endif
|
16
avr.c
Normal file
16
avr.c
Normal file
|
@ -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);
|
||||
}
|
16
avr.h
Normal file
16
avr.h
Normal file
|
@ -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
|
6
hardware.c
Normal file
6
hardware.c
Normal file
|
@ -0,0 +1,6 @@
|
|||
#include "hardware.h"
|
||||
|
||||
|
||||
void initHardware() {
|
||||
|
||||
}
|
24
hardware.h
Normal file
24
hardware.h
Normal file
|
@ -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
|
9
util.h
Normal file
9
util.h
Normal file
|
@ -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
|
Reference in a new issue