[Solved] ATTINY13A, Servo only makes half a sweep

Earthbound Ruben Asks: ATTINY13A, Servo only makes half a sweep
I have been trying to get a servo to sweep using an attiny13A. And i managed to get the servo to (kindoff) work by the help of a previous thread. But i’m now getting an issue. The servo only goes to 180 degrees and does not return to 0 degrees, instead it just keeps trying to go further then 180 degrees eventhough its not mechanicly capabel of doing so. Anyone have any idea how i can solve this? ( I need it for a small animatronic part) (also the servo is a generic 9gram servo and i have tested it on multiple servos, its the same result) thanks in advance

Code:
#define F_CPU 9600000
int servo = PB1;  //connect servo to PB1
long angle;
int pwm;
int counter = 0;
int LED = PB3;
#include <avr/io.h>
void adc_setup (void) 
{
    // Set the ADC input to PB2/ADC1
  ADMUX |= (1 << MUX0);
  ADMUX |= (1 << ADLAR);
  // Set the prescaler to clock/128 & enable ADC
  // At 9.6 MHz this is 75 kHz.
  ADCSRA |= (1 << ADPS1) | (1 << ADPS0) | (1 << ADEN);
}
int adc_read (void)
{
  // Start the conversion
  ADCSRA |= (1 << ADSC);
  // Wait for it to finish
  while (ADCSRA & (1 << ADSC));
  return ADCH; // return the value
}
void setup()
{
  pinMode(LED, OUTPUT);
  pinMode(servo, OUTPUT);  // set servo as output pin
  digitalWrite(LED, HIGH);
  delay(3000);
  pinMode(LED, LOW); //blink LED

}
void loop ()
{
 for(counter = 0; counter < 180; counter++)  //scan fril 0 degrees to 180 degrees
  {
    servoPulse(servo, counter);  // call the servoPulse function.   
    delay(15);                                              
  }                  

delay(1000);
  
 for(counter = 180; counter > 0; counter--)  // now scan back from 180 to 0 degrees  
  { 
    servoPulse(servo, counter);  // call the servoPulse function.    
    delay(15);      
 }
}
void servoPulse (int servo, int counter)
{
  pwm = (angle * 11) + 500;    // Convert angle to microseconds
  digitalWrite(servo, HIGH);
  delayMicroseconds(pwm);
  digitalWrite(servo, LOW);
  delay(50); // Refresh cycle of servo
}

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.