Main Site Documentation

Servo on Fez Mini turns too much


I used this code to connect Servo Analog HK15138 Standard on Fez Mini:

Copyright 2010 GHI Electronics LLC
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 

using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using GHIElectronics.NETMF.Hardware;

namespace GHIElectronics.NETMF.FEZ
    public static partial class FEZ_Components
        public class ServoMotor : IDisposable
            OutputCompare oc;
            uint[] timings = new uint[5];
            public void Dispose()
            public ServoMotor(FEZ_Pin.Digital pin)
                oc = new OutputCompare((Cpu.Pin)pin, true, 5);
            public void SetPosition(byte angle_degree)
                uint pos = (uint)(((float)((2500-400) / 180) * (angle_degree)) + 400);
                timings[0] = pos;
                timings[1] = 10000;
                oc.Set(true, timings, 0, 2, true);

Servo is connected to

FEZ_Components.ServoMotor myServo = new FEZ_Components.ServoMotor(FEZ_Pin.Digital.Di7);
myServo.SetPosition(pos);//pos: 0-180

And when I set position of the servo between 0-90 it works well, but when I set position to 180 it turns more than 180.
I would appreciate any advice.


Servos are unique, each one responds to a different duty cycle. You have to experiment with the values into this:

uint pos = (uint)(((float)((2500-400) / 180) * (angle_degree)) + 400)

Which is where the calculation occurs.