hab sogar was zusammen bekommen.
so konnte ich zumindest schon rausfinden was die range für mein servo ist..
nur wie schaffe ich es 4 Servos anzusteuern..
komme über den einen nicht hinaus
Code:
/**********************/
/**********************/
/* INCLUDES */
/**********************/
/**********************/
#include <stdint.h>
#include <stdlib.h>
#include "lcd.h"
#include <avr/interrupt.h>
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <avr/eeprom.h>
#include <util/delay.h>
/**********************/
/**********************/
/* TYPES */
/**********************/
/**********************/
typedef uint8_t BYTE;
typedef uint16_t WORD;
typedef uint32_t DWORD;
typedef uint64_t QWORD;
/**********************/
/**********************/
/* DEFINES */
/**********************/
/**********************/
#define XTAL 4000000L
#define ODIV 8
#define O20ms (80000/ ODIV)
#define BORDER_LOW (2250 / ODIV)
#define BORDER_HIGH (8500/ ODIV)
#define RANGE (BORDER_HIGH - BORDER_LOW)
#define MIDDLE (BORDER_LOW + ((BORDER_HIGH-BORDER_LOW)/2))
/**********************/
/**********************/
/* VARIABLES */
/**********************/
/**********************/
volatile BYTE impuls = 0;
volatile WORD servo_value = MIDDLE; // Servo Mittelstellung
/**********************/
/**********************/
/* FUNCTIONS */
/**********************/
/**********************/
void init()
{
/*-------*/
/*-------*/
/* PORTS */
/*-------*/
/*-------*/
DDRD = ( 1 << PIND6);
DDRD = ( 1 << PIND5);
/*-------*/
/*-------*/
/* TIMER */
/*-------*/
/*-------*/
// compare match mode
TCCR1B = (1 << WGM12) | (1 << CS11);
// TIMER value
TCNT1 = 0x0000;
// COMPARE value
OCR1A = O20ms;
// ENABLE compare match interrupt
TIMSK = (1 << OCIE1A);
}
ISR(TIMER1_COMPA_vect)
{
// SERVO -> IMPULS
if(impuls == 0)
{
impuls = 1;
PORTD |= (1 << PIND6);
OCR1A = servo_value;
}
// SERVO -> KEIN IMPULS
else
{
impuls = 0;
PORTD &= ~(1 << PIND6);
OCR1A = O20ms - OCR1A;
}
}
int main(void)
{
char string[50];
int wert=0;
/* Initialisiere Display, Cursor aus */
lcd_init(LCD_DISP_ON);
/* loesche das LCD Display und Cursor auf 1 Zeile, 1 Spalte */
lcd_clrscr();
for(;;)
{
if ( !(PINB & (1<<PINB0)) ) {
init();
sei();
wert = wert + 1;
itoa(wert,string,10);
lcd_clrscr();
lcd_puts(string);
_delay_ms(200);
servo_value = ( BORDER_HIGH + wert );
}
if ( !(PINB & (1<<PINB1)) ) {
init();
sei();
wert = wert - 1;
itoa(wert,string,10);
lcd_clrscr();
lcd_puts(string);
_delay_ms(200);
servo_value = ( BORDER_HIGH + wert );
}
};
return 1;
}
Lesezeichen