Controlling a Servo with Arduino is damn easy ! There are libraries to do things, you don't need to know what's going on with the control signal that commands the servo. There is an Arduino tutorial for those who might need
But how to do that with PSoC 4 ?
According to SG90 Micro Servo (Tower Pro) datasheet, you have to make PWM signal like this to control the Servo -
How Do you Make It?
The answer is TCPWM component, but wait ! How do I make a 50 Hz signal (20 mS) and vary the Duty cycle between 5% (1mS) to 10 % (2mS) ?
By Changing the Value of Period from "1 to 65535", we can vary PWM Frequency.
By Changing the Value of Compare from "1 to Period Value", we can vary Duty Cycle.
By Changing the Value of fclk ( Clock signal to PWM component ), we can vary the Frequency range, the larger the fclk, the higher frequency we can generate .
Formulas for this Configuration of PWM (center Aligned) -
Period = Fclk / (2 X Desired Frequency )
Compare = Period - ( Desired Duty X Period )
Here, Fclk for the PWM Component is chosen 480 kHz,
We need a PWM signal of 50 Hz ( Our Desired Freq )
So, Period = 480000 / ( 2 X 50 ) = 4800
and Compare (min) = 4800 - ( 10% X 4800 ) = 4320
Compare (max) = 4800 - ( 5% X 4800 ) = 4560
Varying the Compare value between 4320 to 4560, we can control the servo because it will generate the desired signal required to do the job !
PWM0_WriteCompare(value) API ( or Function) is used to change the Duty Cycle from C code, which controls the position of the servo !
Otherwise , there will be no output !
Sorry for the crappy quality video. Don't have a better camera right now!