cancel
Showing results for 
Search instead for 
Did you mean: 

Encoder mode and rotary encoders as tuning knobs

turboscrew
Senior III
Posted on March 24, 2018 at 18:23

I understand that a timer (that supports encoder mode) can be used for keeping track of a rotary incremental encoder, but is there a good way of making the value saturating? So that when turned 'forward' the value increments to a given value and stops incrementing even if the knob is turned further, and the same way when turned 'backward' - the counter value saturates to zero.

#encoder-mode #rotary-encoder
1 ACCEPTED SOLUTION

Accepted Solutions
Posted on March 30, 2018 at 12:01

I know of no simple way of making the timer 'saturate', but you could do this easily in software when reading out the timer value, something along these lines:

global:

#define DIAL_VALUE_MIN 12

#define DIAL_VALUE_MAX 4253

uint16_t dialValue = DIAL_VALUE_MIN;

local:

uint16_t t;

static uint16_t oldt;

int32_t delta;

t = TIM3->CNT;

delta = (int32_t)(int16_t)(t - oldt);

delta += dialValue;

if (delta < DIAL_VALUE_MIN) delta = DIAL_VALUE_MIN;

else if (delta > DIAL_VALUE_MAX) delta = DIAL_VALUE_MAX;

dialValue = delta;

JW

View solution in original post

21 REPLIES 21
T J
Lead
Posted on March 24, 2018 at 21:29

Yes, you would need to enable the interrupts and test/block it manually.

the nature of rotary encoders is endless counting.

turboscrew
Senior III
Posted on March 24, 2018 at 22:00

OK, thanks. So there is no HW-setting. I think I'll then need to poll the counter value often enough so that the value doesn't change too much (maybe about +/- quarter of the full range to tell the difference between positive and negative change) and keep record of the value in SW adding/subtracting the read counter value - as long as the total is within the allowed range. I guess interrupts don't help me here, because when saturated, the counting needs to continue immediately if the knob is turned in the opposite direction.

(BTW, why does the site show stars in place of the word 'k n o b'?)

turboscrew
Senior III
Posted on March 24, 2018 at 22:32

Well, does anyone know a politically correct word to use instead?

(I'm a Finn, English is not my native language.)

Posted on March 24, 2018 at 22:11

turboscrew wrote:

(BTW, why does the site show stars in place of the word 'k n o b'?)

NSFW:

 

https://www.urbandictionary.com/define.php?term=knob

 

EDIT 

Ha ha - it even censored the web link!

turboscrew
Senior III
Posted on March 24, 2018 at 23:17

Hmm, I think I could get used to 'dial'...

Posted on March 24, 2018 at 22:42

spindle?

dial?

EDIT

And yet it allowed 'knobs' (plural) in the title

EDIT

  
Joerg Wagner
Senior III
Posted on March 25, 2018 at 00:02

Jog shuttle is used in tv production.

In this case it's a jog dial.

Posted on March 25, 2018 at 00:45

You chose the correct word - why 'k n o b' is censored is beyond me...bad software?

Posted on March 25, 2018 at 00:55

Because, in certain contexts, it is used as a rude word - see 

https://www.urbandictionary.com/define.php?term=knob

 

[NSFW]

Presumably, the censor is just using a simple dictionary lookup - with no context awareness.