Nucleo F303K8とSG90を用いたサーボ信号変更における処理時間の測定

Dependencies:   mbed

main.cpp

Committer:
RyotaNakamura
Date:
2017-02-09
Revision:
0:e7072f95dcaf

File content as of revision 0:e7072f95dcaf:

#include "mbed.h"

#define ON  1
#define OFF 0

PwmOut servo1(D10);
Serial pc(USBTX, USBRX);
Timer timer1;
Timer timer2;

int main()
{
    float pwidth;
    int miri=1000;
    servo1.period_ms(20);// pulse cycle = 20ms

    while(1) {
        for(pwidth=0.001; pwidth<=0.002; pwidth+=0.000001) { // 1ms ~ 2ms
            timer1.reset();
            timer1.start();
            servo1.pulsewidth(pwidth); // pulse servo out
            timer1.stop();
            float t1=timer1.read();
            float time1=t1*miri;
            pc.printf("time1= %f ms\n",time1);
            wait(0.001);
        }

        for(pwidth=0.002; pwidth>=0.001; pwidth-=0.000001) { // 1ms ~ 2ms
            timer2.reset();
            timer2.start();
            servo1.pulsewidth(pwidth); // pulse servo out
            timer2.stop();
            float t2=timer2.read();
            float time2=t2*miri;
            pc.printf("time2= %f ms\n",time2);
            wait(0.001);
        }
    }
}