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.
HallSensor.cpp
00001 #include "HallSensor.h" 00002 #define REF 23400.0 00003 #define MIN 60.0 00004 #define SEC_PERIOD (1.0 / (2.0 * REF / MIN )) 00005 00006 HallSensor::HallSensor (PinName a) : m_hallSensor (a,PullUp) 00007 { 00008 float fDummy_sec = 1000.0; 00009 m_hallSensor.rise (callback (this, &HallSensor::risingCallback)); 00010 m_period_sec = fDummy_sec; 00011 m_timer_sec.start (); 00012 } 00013 00014 float HallSensor::getSpeed_rps () 00015 { 00016 float fSpeed_rps; 00017 00018 if (m_timer_sec.read () > 0.1 || m_period_sec > 0.1) { 00019 fSpeed_rps = 0.0f; 00020 } else { 00021 fSpeed_rps = 2.0f*PI/m_period_sec; 00022 } 00023 return fSpeed_rps; 00024 } 00025 00026 void HallSensor::risingCallback() 00027 { 00028 if(m_timer_sec.read() > SEC_PERIOD) { 00029 m_period_sec = m_timer_sec.read(); 00030 m_timer_sec.reset(); 00031 } 00032 } 00033 00034 int HallSensor::getPinState () 00035 { 00036 return m_hallSensor; 00037 }
Generated on Wed Jul 27 2022 20:12:06 by
1.7.2