Page 1 of 1

PaulStoffregen / Encoder/ Encoder requires interrupt pins, but this board does not have any

Posted: Mon Jul 27, 2020 11:34 am
by GreenBrainArc
Hello, first of all sorry for my bad English
I have the following problem:
I would like to control the LCDML with a rotary encoder.
Unfortunately I am missing in interrupt_pins.h
the definition for the STM32F103C
Can someone help me there?

Re: PaulStoffregen / Encoder/ Encoder requires interrupt pins, but this board does not have any

Posted: Tue Jul 28, 2020 1:12 am
by Ollie
The STM32F103C has 16 EXTI lines that can be programmed to trigger interrupts from the GPIO pins. That is not the proper method in case there is no electronic RC filtering of the signals. In practice, it is very difficult to have the proper values for the RC filtering.

A better method is to use software filtering. For example, you can have a timer to generate an interrupt on every 125 us to read the all the rotary encoder input values. In that routine, you can detect if a new value has been unchanged for 500 us. If less than that, the value is part of the normal contact bouncing and should be ignored. This has very low CPU loading and detects the real changes very fast. The interrupt routine can do at the same time the normal A and B channel processing.

Re: PaulStoffregen / Encoder/ Encoder requires interrupt pins, but this board does not have any

Posted: Wed Jul 29, 2020 4:47 pm
by dannyf
you may find it helpful that a small capacitor is much simpler and more robust a solution here.

If you have to go down the software path, i would rely on 1) a solution based on a state machine - it is much more resistant to switch bounces; and 2) see if you can slow down the read. For example, once a change of state has been detected, read the pin sometime later.

something like this:
Pin change ISR:
set a flag;
disable pin change interrupt;

in the main code:
if (pin change flag is set) time stamp a variable
if (pin change flag is set and enough time has passed) {
read the pin;
clear the pin change flag;
re-enable pin change interrupt;
}
unless you are dealing with really fast fingers, a few ms is good enough.