/* ServoPWM * --------------- * * Comments * * (copyright notice) 2007 by Moe * * * */ int val = 0; void setup(void) { pinMode(10,OUTPUT); // Servo Pin pinMode(5,OUTPUT); // Servo Pin Serial.begin(9600); TCCR1A = 0x00; // sets timer control bits to PWM Phase and Frequency Correct mode TCCR1B = 0x12; // sets timer control bits to Prescaler N = 8 //ICR1 = 0x0FA0;; // Upper Timer Limit = 4000 (in hex) equals 4ms => 1/5 of servo frequency ICR1 = 0x4E20; // My own frequency of the PWM: Upper Timer Limit = 20000 (in hex) equals 20ms => 1/1 of servo frequency TCCR0A = 0x01; // sets timer control bits to PWM Phase and Frequency Correct mode TCCR0B = 0x0D; // sets timer control bits to Prescaler N = 8 //ICR1 = 0x0FA0;; // Upper Timer Limit = 4000 (in hex) equals 4ms => 1/5 of servo frequency OCR0A = 156; //0x3F; // My own frequency of the PWM: Upper Timer Limit = 20000 (in hex) equals 20ms => 1/1 of servo frequencyâ } void loop(void) { val = analogRead(0); // read potentiometer Serial.print ("Poti-value: " ); Serial.println( val); // poti servo value: must be from 0-1024 (=10 bit) val = (val * 1.38) + 600; // convert potentiometer reading to value in microseconds (my servo responds to signals in the 600us - 2400us range > use 1.6 as factor) // the conrad servor responds to 600-2020us range > so i used 1.38 analogWrite(10,val); // pulse servo analogWrite(5,20); // pulse servo Serial.print ("Servo-value: " ); Serial.println( val); // output servo value }