Library for manual Encoders as used in user interfaces. Very simple, reduced and rock solid encoder library. Counts full pulses only. Inherent debouncing through state machine. Running on a regular timer IRQ. No IRQ jamming through bouncing. Immune to false edges giving unwanted counts when moving partial steps. Not depending on PinDetect or anything else. May be enhanced by adding acceleration and push button debouncing in the future.

Library for manual Encoders as used in user interfaces. Very simple, reduced and rock solid. Counts full pulses/steps only. Inherent debouncing through state machine. No time dependency for debouncing. Very tight code running in a regular timer IRQ. No IRQ jamming through bouncing edges. Immune to false edges giving unwanted counts when moving partial steps back and forth. Not depending on PinDetect or any other debouncing library. May be enhanced in the near future by adding acceleration and push button debouncing.

Committer:
eduardoG26
Date:
Wed Mar 18 16:41:59 2015 +0000
Revision:
6:c2af98aa7d2b
Parent:
5:70534b19d8bf
Child:
8:3086ea6466d1
State Machine enhanced for more stability with high resolution bouncing encoders

Who changed what in which revision?

UserRevisionLine numberNew contents of line
eduardoG26 2:603b47d3755e 1 // Encoder lib for user interfaces
eduardoG26 2:603b47d3755e 2 // Use this file for configuring the pins, timings etc.
eduardoG26 2:603b47d3755e 3 /*
eduardoG26 2:603b47d3755e 4 The MIT License (MIT)
eduardoG26 2:603b47d3755e 5
eduardoG26 2:603b47d3755e 6 Copyright (c) 2014 calima engineering
eduardoG26 2:603b47d3755e 7
eduardoG26 2:603b47d3755e 8 Permission is hereby granted, free of charge, to any person obtaining a copy
eduardoG26 2:603b47d3755e 9 of this software and associated documentation files (the "Software"), to deal
eduardoG26 2:603b47d3755e 10 in the Software without restriction, including without limitation the rights
eduardoG26 2:603b47d3755e 11 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
eduardoG26 2:603b47d3755e 12 copies of the Software, and to permit persons to whom the Software is
eduardoG26 2:603b47d3755e 13 furnished to do so, subject to the following conditions:
eduardoG26 2:603b47d3755e 14
eduardoG26 2:603b47d3755e 15 The above copyright notice and this permission notice shall be included in
eduardoG26 2:603b47d3755e 16 all copies or substantial portions of the Software.
eduardoG26 2:603b47d3755e 17
eduardoG26 2:603b47d3755e 18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
eduardoG26 2:603b47d3755e 19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
eduardoG26 2:603b47d3755e 20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
eduardoG26 2:603b47d3755e 21 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
eduardoG26 2:603b47d3755e 22 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
eduardoG26 2:603b47d3755e 23 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
eduardoG26 2:603b47d3755e 24 THE SOFTWARE.
eduardoG26 2:603b47d3755e 25 */
eduardoG26 2:603b47d3755e 26
eduardoG26 2:603b47d3755e 27 #ifndef ENCODER_CONFIG_H_
eduardoG26 2:603b47d3755e 28 #define ENCODER_CONFIG_H_
eduardoG26 2:603b47d3755e 29
eduardoG26 6:c2af98aa7d2b 30 #include "project.h"
eduardoG26 6:c2af98aa7d2b 31
eduardoG26 2:603b47d3755e 32 // Chose encoder pins
eduardoG26 4:ee384561bfa4 33 // First tested with Nucleo STM32F302
eduardoG26 2:603b47d3755e 34 #define ENCODER_PIN_A D6
eduardoG26 2:603b47d3755e 35 #define ENCODER_PIN_B D7
eduardoG26 5:70534b19d8bf 36 #define ENCODER_PIN_PB D5
eduardoG26 2:603b47d3755e 37
eduardoG26 2:603b47d3755e 38 // Sample every ... microseconds, default
eduardoG26 2:603b47d3755e 39 // 250µs is a good value for cheap 24 ppr encoders (ALPS EC12E24...) with strong bouncing.
eduardoG26 2:603b47d3755e 40 // 1000µs is a good value for quality 24 ppr encoders (ALPS EC12E24...) with low bouncing.
eduardoG26 4:ee384561bfa4 41 // 250µs is a good value for fast 24+ ppr encoders (Sparkfun, Some Bourns types, ...).
eduardoG26 6:c2af98aa7d2b 42 #define ENCODER_SAMPLE_PERIOD_US (125)
eduardoG26 2:603b47d3755e 43
eduardoG26 5:70534b19d8bf 44 // Pushbutton debouncing in milliseconds
eduardoG26 6:c2af98aa7d2b 45 #define ENCODER_PB_DEBOUNCE_MS (125uL)
eduardoG26 5:70534b19d8bf 46
eduardoG26 2:603b47d3755e 47
eduardoG26 2:603b47d3755e 48 #endif // ENCODER_CONFIG_H_