Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
8 years, 4 months ago.
ピン変化割込までの時間計測
お世話になります。 lpc1114を入手したので、これをキッカケにマイコンの世界に入ろうと思っていますが、入り口が見付けられず、なかなか手をつけられない初心者です。
ピン変化割り込みというものがあるようですが、このピン変化割り込みが発生してから、次のピン変化割り込みが発生するまでの時間を計測する、といった処理を行ってみたいのですが、どの様な手順(初期設定やプログラミング)を行えばよろしいでしょうか。
参考になる文献やヒントなどあればご教授いただきたいです。
よろしくお願いいたします。
1 Answer
8 years, 4 months ago.
You can use a Timer object.
#include "mbed.h"
EventQueue queue;
InterruptIn btn1(BUTTON1);
Timer interruptTimer;
bool isTimerRunning = false;
void btn1_fall() {
if (isTimerRunning) {
interruptTimer.stop();
// we're in an Interrupt Service Routine, calling printf() directly is not safe
// see https://developer.mbed.org/blog/entry/Simplify-your-code-with-mbed-events/
queue.call(printf, "Timer took %d ms.", interruptTimer.read_ms());
isTimerRunning = false;
}
else {
interruptTimer.reset();
interruptTimer.start();
queue.call(printf, "Timer was started");
isTimerRunning = true;
}
}
int main() {
Thread eventThread;
eventThread.start(callback(&queue, &EventQueue::dispatch_forever));
btn1.fall(&btn1_fall);
wait(osWaitForever);
}