Yeongsoo Kim / Mbed 2 deprecated Mecha_Speed_control

Dependencies:   mbed

Committer:
yeongsookim
Date:
Wed Nov 06 01:17:46 2019 +0000
Revision:
0:c88a81d07287
Child:
1:d7a26e14bc4d
First commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yeongsookim 0:c88a81d07287 1 #include "HallSensor.h"
yeongsookim 0:c88a81d07287 2 #define RPM 23400.0
yeongsookim 0:c88a81d07287 3 #define MIN 60.0
yeongsookim 0:c88a81d07287 4 #define SEC_PERIOD (1.0 / (RPM*2 / MIN ))
yeongsookim 0:c88a81d07287 5
yeongsookim 0:c88a81d07287 6 HallSensor::HallSensor (PinName a) : m_hallSensor (a,PullUp)
yeongsookim 0:c88a81d07287 7 {
yeongsookim 0:c88a81d07287 8 float fDummy_sec = 1000.0;
yeongsookim 0:c88a81d07287 9 m_hallSensor.rise (callback (this, &HallSensor::risingCallback));
yeongsookim 0:c88a81d07287 10 m_period_sec = fDummy_sec;
yeongsookim 0:c88a81d07287 11 m_timer_sec.start ();
yeongsookim 0:c88a81d07287 12 }
yeongsookim 0:c88a81d07287 13
yeongsookim 0:c88a81d07287 14 float HallSensor::getSpeed_rps ()
yeongsookim 0:c88a81d07287 15 {
yeongsookim 0:c88a81d07287 16 float fSpeed_rps;
yeongsookim 0:c88a81d07287 17
yeongsookim 0:c88a81d07287 18 if (m_timer_sec.read () > 0.1 || m_period_sec > 0.1) {
yeongsookim 0:c88a81d07287 19 fSpeed_rps = 0.0f;
yeongsookim 0:c88a81d07287 20 } else {
yeongsookim 0:c88a81d07287 21 fSpeed_rps = 2.0f*PI/m_period_sec;
yeongsookim 0:c88a81d07287 22 }
yeongsookim 0:c88a81d07287 23 return fSpeed_rps;
yeongsookim 0:c88a81d07287 24 }
yeongsookim 0:c88a81d07287 25
yeongsookim 0:c88a81d07287 26 void HallSensor::risingCallback()
yeongsookim 0:c88a81d07287 27 {
yeongsookim 0:c88a81d07287 28 if(m_timer_sec.read() > SEC_PERIOD) {
yeongsookim 0:c88a81d07287 29 m_period_sec = m_timer_sec.read();
yeongsookim 0:c88a81d07287 30 m_timer_sec.reset();
yeongsookim 0:c88a81d07287 31 }
yeongsookim 0:c88a81d07287 32 }
yeongsookim 0:c88a81d07287 33
yeongsookim 0:c88a81d07287 34 int HallSensor::getPinState ()
yeongsookim 0:c88a81d07287 35 {
yeongsookim 0:c88a81d07287 36 return m_hallSensor;
yeongsookim 0:c88a81d07287 37 }