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
ActuatorsSensor/Hallsensor.h@39:a4fd6206da89, 2013-06-10 (annotated)
- Committer:
- chrigelburri
- Date:
- Mon Jun 10 14:40:37 2013 +0000
- Revision:
- 39:a4fd6206da89
- Parent:
- 38:d76e488e725f
V1.0
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| chrigelburri | 3:92ba0254af87 | 1 | #ifndef HALLSENSOR_H |
| chrigelburri | 3:92ba0254af87 | 2 | #define HALLSENSOR_H |
| chrigelburri | 3:92ba0254af87 | 3 | |
| chrigelburri | 3:92ba0254af87 | 4 | #include "mbed.h" |
| chrigelburri | 3:92ba0254af87 | 5 | |
| chrigelburri | 3:92ba0254af87 | 6 | /** |
| chrigelburri | 3:92ba0254af87 | 7 | * @author Christian Burri |
| chrigelburri | 3:92ba0254af87 | 8 | * |
| chrigelburri | 38:d76e488e725f | 9 | * @copyright Copyright (c) 2013 HSLU Pren Team #1 Cruising Crêpe |
| chrigelburri | 3:92ba0254af87 | 10 | * All rights reserved. |
| chrigelburri | 3:92ba0254af87 | 11 | * |
| chrigelburri | 11:775ebb69d5e1 | 12 | * @brief |
| chrigelburri | 3:92ba0254af87 | 13 | * |
| chrigelburri | 15:cb1337567ad4 | 14 | * Interface to count the Hallsensor input from an EC-Motor. |
| chrigelburri | 6:48eeb41188dd | 15 | * |
| chrigelburri | 38:d76e488e725f | 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
| chrigelburri | 38:d76e488e725f | 17 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| chrigelburri | 38:d76e488e725f | 18 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| chrigelburri | 38:d76e488e725f | 19 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| chrigelburri | 38:d76e488e725f | 20 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| chrigelburri | 38:d76e488e725f | 21 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| chrigelburri | 38:d76e488e725f | 22 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| chrigelburri | 3:92ba0254af87 | 23 | */ |
| chrigelburri | 3:92ba0254af87 | 24 | class Hallsensor |
| chrigelburri | 3:92ba0254af87 | 25 | { |
| chrigelburri | 3:92ba0254af87 | 26 | |
| chrigelburri | 6:48eeb41188dd | 27 | private: |
| chrigelburri | 6:48eeb41188dd | 28 | |
| chrigelburri | 6:48eeb41188dd | 29 | /** |
| chrigelburri | 11:775ebb69d5e1 | 30 | * @brief Update the pulse count. |
| chrigelburri | 6:48eeb41188dd | 31 | * Called on every rising/falling edge of Hall 1-3. |
| chrigelburri | 6:48eeb41188dd | 32 | * Reads the state of the channels and determines whether a pulse forward |
| chrigelburri | 6:48eeb41188dd | 33 | * or backward has occured, updating the count appropriately. |
| chrigelburri | 6:48eeb41188dd | 34 | */ |
| chrigelburri | 6:48eeb41188dd | 35 | void encode(void); |
| chrigelburri | 6:48eeb41188dd | 36 | |
| chrigelburri | 6:48eeb41188dd | 37 | InterruptIn hall1_; |
| chrigelburri | 6:48eeb41188dd | 38 | InterruptIn hall2_; |
| chrigelburri | 6:48eeb41188dd | 39 | InterruptIn hall3_; |
| chrigelburri | 6:48eeb41188dd | 40 | |
| chrigelburri | 6:48eeb41188dd | 41 | int prevState_; |
| chrigelburri | 6:48eeb41188dd | 42 | int currState_; |
| chrigelburri | 6:48eeb41188dd | 43 | |
| chrigelburri | 6:48eeb41188dd | 44 | volatile int pulses_; |
| chrigelburri | 6:48eeb41188dd | 45 | |
| chrigelburri | 3:92ba0254af87 | 46 | public: |
| chrigelburri | 3:92ba0254af87 | 47 | |
| chrigelburri | 3:92ba0254af87 | 48 | /** |
| chrigelburri | 11:775ebb69d5e1 | 49 | * @brief Constructor of the class <code>Hallsensor</code>. |
| chrigelburri | 3:92ba0254af87 | 50 | * |
| chrigelburri | 15:cb1337567ad4 | 51 | * Reads the current values on Hall1, Hall2 and Hall3 to determine the |
| chrigelburri | 3:92ba0254af87 | 52 | * initial state. |
| chrigelburri | 3:92ba0254af87 | 53 | * Attaches the encode function to the rise/fall interrupt edges of |
| chrigelburri | 3:92ba0254af87 | 54 | * Hall1, Hall2 and Hall3. |
| chrigelburri | 3:92ba0254af87 | 55 | * @param hall1 mbed pin for Hall1 input. |
| chrigelburri | 3:92ba0254af87 | 56 | * @param hall2 mbed pin for Hall2 input. |
| chrigelburri | 3:92ba0254af87 | 57 | * @param hall3 mbed pin for Hall3 input. |
| chrigelburri | 3:92ba0254af87 | 58 | */ |
| chrigelburri | 3:92ba0254af87 | 59 | Hallsensor(PinName hall1, PinName hall2, PinName hall3); |
| chrigelburri | 3:92ba0254af87 | 60 | |
| chrigelburri | 3:92ba0254af87 | 61 | /** |
| chrigelburri | 11:775ebb69d5e1 | 62 | * @brief Reset the encoder. |
| chrigelburri | 3:92ba0254af87 | 63 | * Sets the pulses and revolutions count to zero. |
| chrigelburri | 3:92ba0254af87 | 64 | */ |
| chrigelburri | 3:92ba0254af87 | 65 | void reset(void); |
| chrigelburri | 3:92ba0254af87 | 66 | |
| chrigelburri | 3:92ba0254af87 | 67 | /** |
| chrigelburri | 11:775ebb69d5e1 | 68 | * @brief Read the number of pulses recorded by the encoder. |
| chrigelburri | 3:92ba0254af87 | 69 | * @return Number of pulses which have occured, given in [count] |
| chrigelburri | 3:92ba0254af87 | 70 | */ |
| chrigelburri | 3:92ba0254af87 | 71 | int getPulses(void); |
| chrigelburri | 3:92ba0254af87 | 72 | |
| chrigelburri | 3:92ba0254af87 | 73 | /** |
| chrigelburri | 11:775ebb69d5e1 | 74 | * @brief Read the number of revolutions recorded by the encoder. |
| chrigelburri | 3:92ba0254af87 | 75 | * @return Number of revolutions which have occured on the index channel. |
| chrigelburri | 3:92ba0254af87 | 76 | */ |
| chrigelburri | 3:92ba0254af87 | 77 | int getRevolutions(void); |
| chrigelburri | 3:92ba0254af87 | 78 | |
| chrigelburri | 3:92ba0254af87 | 79 | }; |
| chrigelburri | 3:92ba0254af87 | 80 | |
| chrigelburri | 12:235e318a414f | 81 | #endif |
