Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Sensor/HallSensor.cpp
- Committer:
- yeongsookim
- Date:
- 2020-10-31
- Revision:
- 1:d43df9a7cef2
- Parent:
- 0:3ead6014ad51
File content as of revision 1:d43df9a7cef2:
#include "HallSensor.h"
#define REF 23400.0
#define MIN 60.0
#define SEC_PERIOD (1.0 / (2.0 * REF / MIN ))
HallSensor::HallSensor (PinName a) : m_hallSensor (a,PullUp)
{
float fDummy_sec = 1000.0;
m_hallSensor.rise (callback (this, &HallSensor::risingCallback));
m_period_sec = fDummy_sec;
m_timer_sec.start ();
}
float HallSensor::getSpeed_rps ()
{
float fSpeed_rps;
if (m_timer_sec.read () > 0.1 || m_period_sec > 0.1) {
fSpeed_rps = 0.0f;
} else {
fSpeed_rps = 2.0f*PI/m_period_sec;
}
return fSpeed_rps;
}
void HallSensor::risingCallback()
{
if(m_timer_sec.read() > SEC_PERIOD) {
m_period_sec = m_timer_sec.read();
m_timer_sec.reset();
}
}
int HallSensor::getPinState ()
{
return m_hallSensor;
}