Servo (SG-90) test program using FRDM-KL25Z
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/
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に指で触れて動かしてください。
main.cpp@0:22feb43e29c6, 2015-08-05 (annotated)
- Committer:
- Rhyme
- Date:
- Wed Aug 05 10:25:10 2015 +0000
- Revision:
- 0:22feb43e29c6
First working version;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Rhyme | 0:22feb43e29c6 | 1 | #include "mbed.h" |
Rhyme | 0:22feb43e29c6 | 2 | #include "TSISensor.h" |
Rhyme | 0:22feb43e29c6 | 3 | |
Rhyme | 0:22feb43e29c6 | 4 | /** TSI_Cat |
Rhyme | 0:22feb43e29c6 | 5 | * Test program for SG-90 |
Rhyme | 0:22feb43e29c6 | 6 | * PWM = Orange : D10 (PTD0) |
Rhyme | 0:22feb43e29c6 | 7 | * Vcc = Red(+) : 5V |
Rhyme | 0:22feb43e29c6 | 8 | * GND = Brown(-) : GND |
Rhyme | 0:22feb43e29c6 | 9 | * |
Rhyme | 0:22feb43e29c6 | 10 | * PWM Period : 20ms (50Hz) |
Rhyme | 0:22feb43e29c6 | 11 | * Duty Cycle : 1 - 2 ms |
Rhyme | 0:22feb43e29c6 | 12 | * Note: when I set pulsewidth from 1000us to 2000us |
Rhyme | 0:22feb43e29c6 | 13 | * the servo did not move -90degree to 90degree |
Rhyme | 0:22feb43e29c6 | 14 | * so I chanced the value from 500us to 3500us |
Rhyme | 0:22feb43e29c6 | 15 | * by watching the movement. |
Rhyme | 0:22feb43e29c6 | 16 | */ |
Rhyme | 0:22feb43e29c6 | 17 | |
Rhyme | 0:22feb43e29c6 | 18 | TSISensor tsi ; |
Rhyme | 0:22feb43e29c6 | 19 | PwmOut pwm(PTD0) ; // D10 |
Rhyme | 0:22feb43e29c6 | 20 | |
Rhyme | 0:22feb43e29c6 | 21 | int main() { |
Rhyme | 0:22feb43e29c6 | 22 | float tsi_value ; |
Rhyme | 0:22feb43e29c6 | 23 | pwm.period_ms(20) ; // 20ms period |
Rhyme | 0:22feb43e29c6 | 24 | |
Rhyme | 0:22feb43e29c6 | 25 | while(1) { |
Rhyme | 0:22feb43e29c6 | 26 | tsi_value = tsi.readPercentage() ; |
Rhyme | 0:22feb43e29c6 | 27 | pwm.pulsewidth_us(500+ 3500*(tsi_value)) ; |
Rhyme | 0:22feb43e29c6 | 28 | wait(0.01) ; |
Rhyme | 0:22feb43e29c6 | 29 | } |
Rhyme | 0:22feb43e29c6 | 30 | } |