langsam aber sicher komme ich mit den timer-funktionen des controllers etwas voran. Als erweiterung eines funktionierenden programmes wollte ich nun einen zweiten servo, der langsamer ist dazuhängen.

Hierzu hab ich ein paar wenige änderungen in dem programm welches in einem andren thread gefunden habe, vorgenommen. ich markiere die änderungen mal fett. Leider geht der 2 servo an entsprechendem pin nicht, vll hat jemand einen tip woran das liegt.


edit: leider erkennt es bei den code tags das fette nicht, daher ohne code tag, sorry
MFG

/************************************************** ***************************/
// Includes:

#include "RP6ControlLib.h" // The RP6 Control Library.
// Always needs to be included!

/************************************************** ***************************/
// Defines:

// RP6 Control Servo Connection:
#define SERVO_OUT IO_PD5 // PIND5 (OC1A) I/O Pin 9

// Servo movement limits (depending on servo type):
#define LEFT_TOUCH 550 // Left servo touch
#define RIGHT_TOUCH 1700 // Right servo touch
#define MIDDLE_POSITION (RIGHT_TOUCH / 2) // Middle servo position

/************************************************** ***************************/
// Variables:

uint16_t position;
uint16_t position2;

/************************************************** ***************************/
// Functions:

/**
* INIT SERVO
*
* Call this once before using the servo function.
* Timer 1 is configured to work in "Phase and Frequency
* Correct PWM Mode".
*
*/
void initSERVO(void)
{
//DDRD |= SERVO_OUT; // SERVO_OUT -> OUTPUT
DDRD = 0b01100000; // port 5 und 6 = outputrichtung
cli();
// Timer 1:
// Clear OC1A when up-counting and set OC1A when down-counting,
// mode 8 (PWM, Phase and Frequency Correct, TOP ICR1), clk/8
TCCR1A = (1 << COM1A1) //com-register A freischalten
| (0 << COM1A0)
| (1 << COM1B1) // com-register B freischalten
| (0 << COM1B0)
| (0 << FOC1A)
| (0 << FOC1B)
| (0 << WGM11)
| (0 << WGM10);
TCCR1B = (0 << ICNC1)
| (0 << ICES1)
| (1 << WGM13)
| (0 << WGM12)
| (0 << CS12)
| (1 << CS11) //clk/8
| (0 << CS10);
// Set servo pulse repetition to 50Hz (20ms):
ICR1 = 20000; // 50Hz = clk / (2 * prescaler * ICR1)
// Set servo pulse length to middle position (~1,5ms):
OCR1A = LEFT_TOUCH + MIDDLE_POSITION;
OCR1B = LEFT_TOUCH + MIDDLE_POSITION;
// Disable output compare A match interrupts:
TIMSK &= ~(1 << OCIE1A);
sei();
}

/**
* SET SERVO
*
* This is the servo positioning function.
* Because the servo is controlled by only one pulse
* each 20ms, it makes no sense calling this function
* at a higher frequency.
*
* pos = 0 : Left touch
* pos = MIDDLE_POSITION : Middle position
* pos = RIGHT_TOUCH : Right touch
*
* COMMENT: The pulse is generated by hardware PWM!
*
*/
void setSERVO(uint16_t pos,uint16_t pos2)
{
if (pos > RIGHT_TOUCH) {pos = RIGHT_TOUCH;}
OCR1A = LEFT_TOUCH + pos;
OCR1B = LEFT_TOUCH + pos2;
}

/**
* SERVO TASK
*
* This is the servo demo task.
* The positioning demo shows the servo lever rapidly
* moving to the left touch, then slowly moving to
* the right touch and so on ...
*
*/
void task_SERVO(void)
{
// -----------------------------------------------------------------------
// Your test code for positioning the servo here:
if (getStopwatch1() > 39) { // Change position every ~40ms
setCursorPosLCD(0, 0);
writeStringLCD_P("Servopos.: ");
writeIntegerLCD(position, DEC);
writeStringLCD_P(" ");
position += 50;
position2 += 8; // Next position to the right
if (position2 > RIGHT_TOUCH) {
position2 = 0; // position: 0..RIGHT_TOUCH
}
if (position > RIGHT_TOUCH) {
position = 0;
// position: 0..RIGHT_TOUCH
}
setStopwatch1(0);
// -----------------------------------------------------------------------
setSERVO(position,position2); // Set the new servo position

}
}

/************************************************** ***************************/
// Main function - The program starts here:

int main(void)
{
initRP6Control(); // Always call this first! The Processor will not
// work correctly otherwise.

initLCD(); // Initialize the LC-Display (LCD)
// Always call this before using the LCD!

// Write some text messages to the LCD:
showScreenLCD("################", "################");
mSleep(1500);
showScreenLCD("<<RP6 Control>>", "<<LC - DISPLAY>>");
mSleep(2500);
showScreenLCD(" Servo - Test 2 ", " Version 1.00 ");
mSleep(2500);
clearLCD(); // Clear the whole LCD Screen

// Clear the four Status LEDs:
setLEDs(0b0000);

initSERVO();
startStopwatch1(); // Used for the demo task

while(true)
{
task_SERVO();
mSleep(5);
}
return 0;
}