Yeongsoo Kim / Mbed 2 deprecated Mecha_Hall_Sensor

Dependencies:   mbed

Committer:
yeongsookim
Date:
Sat Oct 31 07:12:28 2020 +0000
Revision:
1:d43df9a7cef2
Parent:
0:3ead6014ad51
2020 Hall Sensor

Who changed what in which revision?

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