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.
Fork of autonomous Robot Android by
Hallsensor.h
00001 #ifndef HALLSENSOR_H 00002 #define HALLSENSOR_H 00003 00004 #include "mbed.h" 00005 00006 /** 00007 * @author Christian Burri 00008 * 00009 * @copyright Copyright (c) 2013 HSLU Pren Team #1 Cruising Crêpe 00010 * All rights reserved. 00011 * 00012 * @brief 00013 * 00014 * Interface to count the Hallsensor input from an EC-Motor. 00015 * 00016 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 00017 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00018 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00019 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00020 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 00021 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 00022 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00023 */ 00024 class Hallsensor 00025 { 00026 00027 private: 00028 00029 /** 00030 * @brief Update the pulse count. 00031 * Called on every rising/falling edge of Hall 1-3. 00032 * Reads the state of the channels and determines whether a pulse forward 00033 * or backward has occured, updating the count appropriately. 00034 */ 00035 void encode(void); 00036 00037 InterruptIn hall1_; 00038 InterruptIn hall2_; 00039 InterruptIn hall3_; 00040 00041 int prevState_; 00042 int currState_; 00043 00044 volatile int pulses_; 00045 00046 public: 00047 00048 /** 00049 * @brief Constructor of the class <code>Hallsensor</code>. 00050 * 00051 * Reads the current values on Hall1, Hall2 and Hall3 to determine the 00052 * initial state. 00053 * Attaches the encode function to the rise/fall interrupt edges of 00054 * Hall1, Hall2 and Hall3. 00055 * @param hall1 mbed pin for Hall1 input. 00056 * @param hall2 mbed pin for Hall2 input. 00057 * @param hall3 mbed pin for Hall3 input. 00058 */ 00059 Hallsensor(PinName hall1, PinName hall2, PinName hall3); 00060 00061 /** 00062 * @brief Reset the encoder. 00063 * Sets the pulses and revolutions count to zero. 00064 */ 00065 void reset(void); 00066 00067 /** 00068 * @brief Read the number of pulses recorded by the encoder. 00069 * @return Number of pulses which have occured, given in [count] 00070 */ 00071 int getPulses(void); 00072 00073 /** 00074 * @brief Read the number of revolutions recorded by the encoder. 00075 * @return Number of revolutions which have occured on the index channel. 00076 */ 00077 int getRevolutions(void); 00078 00079 }; 00080 00081 #endif
Generated on Tue Jul 12 2022 14:15:58 by
1.7.2
