Servo (SG-90) test program using FRDM-KL25Z

Dependencies:   TSI mbed

Test program for SG-90 Servo, using FRDM-KL25Z's TSI and PWM.
Although the servo is supposed to work with 5V, getting 5V from FRDM, it can work with 3.3V PWM out.

秋月でみつけてきた格安サーボ SG-90 を FRDM-KL25Z の TSI と PWM で動かしてみました。
5V仕様のサーボですが、5V電源はFRDMからとって、信号は3.3Vでも動いちゃいました。
ねこは帰り道のガチャポンで・・・
http://akizukidenshi.com/catalog/g/gM-08761/

/media/uploads/Rhyme/tsi_cat_s6.jpg

Connection:
Servo FRDM-KL25Z
PWM=Orange D10(PTD0)
5V=RED FRDM 5V(J9-Pin10)
GND=Brown FRDM GND(J9-Pin12)

PWM spec
PWM Period 20ms (50Hz)
Duty Cycle (Positive Pulse) 1 ~ 2ms

Usage: (Do we really need it?)
使用方法: (いるのか?)

After downloading the program, touch your finger to TSI and move it.
プログラムをダウンロードしたら、TSIに指で触れて動かしてください。

/media/uploads/Rhyme/tsi_cat_s3.jpg /media/uploads/Rhyme/tsi_cat_s4.jpg /media/uploads/Rhyme/tsi_cat_s5.jpg

Revision:
0:22feb43e29c6
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Aug 05 10:25:10 2015 +0000
@@ -0,0 +1,30 @@
+#include "mbed.h"
+#include "TSISensor.h"
+
+/** TSI_Cat
+ * Test program for SG-90
+ * PWM = Orange : D10 (PTD0)
+ * Vcc = Red(+) : 5V
+ * GND = Brown(-) : GND
+ *
+ * PWM Period : 20ms (50Hz)
+ * Duty Cycle : 1 - 2 ms
+ * Note: when I set pulsewidth from 1000us to 2000us
+ * the servo did not move -90degree to 90degree
+ * so I chanced the value from 500us to 3500us
+ * by watching the movement.
+ */
+
+TSISensor tsi ; 
+PwmOut pwm(PTD0) ; // D10
+
+int main() {
+    float tsi_value ;
+    pwm.period_ms(20) ; // 20ms period
+    
+    while(1) {
+        tsi_value = tsi.readPercentage() ;
+        pwm.pulsewidth_us(500+ 3500*(tsi_value)) ;
+        wait(0.01) ;
+    }
+}