Skip to main content
turboscrew
Senior III
March 24, 2018
Solved

Encoder mode and rotary encoders as tuning knobs

  • March 24, 2018
  • 9 replies
  • 3911 views
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
This topic has been closed for replies.
Best answer by waclawek.jan
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

9 replies

T J
Senior III
March 24, 2018
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
March 24, 2018
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'?)

Andrew Neil
Super User
March 24, 2018
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!

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
turboscrew
Senior III
March 24, 2018
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.)

Andrew Neil
Super User
March 24, 2018
Posted on March 24, 2018 at 22:42

spindle?

dial?

EDIT

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

EDIT

  
A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
turboscrew
Senior III
March 24, 2018
Posted on March 24, 2018 at 23:17

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

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

Jog shuttle is used in tv production.

In this case it's a jog dial.

turboscrew
Senior III
March 25, 2018
Posted on March 25, 2018 at 16:06

So, no better ideas to share?

T J
Senior III
March 25, 2018
Posted on March 25, 2018 at 17:07

N o b ? or Dial as suggested by

Wagner.Joerg

I have 3 installed on my new board, so a nice name would be good.

I am thinking left hand usage,

Spacial Dials

Coordinate adjuster

Colour Mixer, is my preference.

T J
Senior III
March 25, 2018
Posted on March 25, 2018 at 19:36

how about Morning Glory..?

Its an affliction of the soul, a cross we all have to bear.

turboscrew
Senior III
March 25, 2018
Posted on March 25, 2018 at 20:57

I meant ideas of handling the encoder... :D

AvaTar
Senior III
March 29, 2018
Posted on March 29, 2018 at 12:21

Having had plenty of exposure to the english language (neither my native one), I never came across k-n-o-b in THIS particular context.

Perhaps I never consorted with the 'proper' circles.

But back to the topic.

There are so-called 'electronic potentiometers', with digital interfacing.

Perhaps such devices fulfill your requirements.

turboscrew
Senior III
March 30, 2018
Posted on March 30, 2018 at 01:09

Mad magazine made at least 'door knob' familiar to me. :)

I have, unfortunately, no decision power there. The encoder is already selected.

waclawek.jan
waclawek.janBest answer
Super User
March 30, 2018
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

turboscrew
Senior III
March 31, 2018
Posted on March 31, 2018 at 11:07

Thanks for confirmation. That's the way I was planning to do it too.