Page 1 of 1

Quadrature encoder and variables (SOLVED)

Posted: Fri Nov 29, 2013 9:22 pm
by bercioiu
Hi guys! I need your help again.
I'm working on a new project where I have to change some variables in a menu. All settings I want to do with an encoder. I have a problem that I can not pass. How do I upload a variable to an encoder counter?
If I use "variable_1=ReadCounter" and increment counter to 10, next time when I need to set the variable and load "variable_1" in counter, how can I do that? How can I make counter=10?
I do not know if I made ​​myself clear ...

Re: Quadrature encoder and variables

Posted: Sat Nov 30, 2013 9:23 am
by bercioiu
I think I found a way to do this, is a little bit complicated but I see that it works.
Now I have a little problem, I want to increment / decrement a variable by one at one "click" of the encoder, not with 4. I have divide the counter by 4 before to ad it to the variable. If I turn encoder to the right (for increment), all seems to be ok, the variable is incremented by 1 (one) but if I turn the encoder to the left (decrement), the variable is decremented by 4 betwen 2 "clicks", my "divide by 4" is ignored...

Re: Quadrature encoder and variables

Posted: Thu Dec 05, 2013 10:28 am
by Benj
Hello,

I've had a look and can't see any problems with your code. Strange that (-4 / 4) is still resulting in -4?

Re: Quadrature encoder and variables

Posted: Thu Dec 05, 2013 11:21 am
by bercioiu
Yes, very strange indeed... I tried to divide by 2 and the result is the same... I mean that it increase with 2 units between 2 clicks (on cw) but it decrease with 4 units between 2 click (on ccw). I give up :-( ...

Re: Quadrature encoder and variables

Posted: Thu Dec 05, 2013 11:33 am
by Benj
Hello,

I wonder if it's because your using a signed int to store the encoder count but then assigning to a byte variable. What happens if you change VAR1 to also be a signed int variable?

Re: Quadrature encoder and variables

Posted: Thu Dec 05, 2013 1:42 pm
by bercioiu
Thank you for your support!
I tried before and nothing change with the ccw sense... just I had negative variable below zero but the same step of 4 between 2 clicks...

Re: Quadrature encoder and variables

Posted: Thu Dec 05, 2013 2:15 pm
by bercioiu
ENCODER_SET_VARIABLE_1.fcf
(23.35 KiB) Downloaded 481 times
I changed the connections for the components to use your`s HW:

- EB006 E-blocks Multiprogrammer Board
- EB073 E-blocks Rotary Encoder Board
- EB005 E-blocks LCD Board

but the rezults are the same...

Re: Quadrature encoder and variables

Posted: Sat Dec 07, 2013 12:24 pm
by medelec35
Hi, Would you like to try My basic encoder Flowchart.
I modified my original version just so it counts up/down one step at a time.

I created it for 16F877A so before changing target you will need to change LCD from port D to port B
Count Variable will only count down to 0 so if you want negative numbers, just remove calculation

Code: Select all

Count = Count - 1
Update_LCD = 1
From

Code: Select all

Count > 0
Decision macro.

Hope this helps


Martin

Re: Quadrature encoder and variables (SOLVED)

Posted: Sat Dec 07, 2013 2:00 pm
by bercioiu
Thanks to Martin, I solved my probl.
Thank you very much Martin!
ENCODER_SET_VARIABLE_Martin.fcf
(21.64 KiB) Downloaded 465 times

Re: Quadrature encoder and variables

Posted: Sat Dec 07, 2013 2:31 pm
by medelec35
Hi bercioiu,
Your welcome.
Glad you have got your flowchart working, and thanks for sharing it with us :)

Attached is a flowchart that should do what you set out to do but will also allow you to add up to 256 different Values (252 more than your original version) and make flowchart more efficient.

So in stead of 4 independent values:
Variable0 =x0
Variable1 =x1
Variable2 =x2
Variable3 =x3

You can have
Variable0 =x0
Variable1 =x1
Variable2 =x2
Variable3 =x3
Variable4 =x4
Variable5 =x5
....
....
Variable255 =x255

There is not much to change to do implement that.

Also if when turning encoder counter clockwise, instead of variable going 1,0,255.254 etc
Flowchart can be easily modified to go 1,0,0,0 etc
i.e stay on 0 until turned clockwise.

Martin

Re: Quadrature encoder and variables

Posted: Sat Dec 07, 2013 4:22 pm
by bercioiu
Thanks but your last flowchart It is little bit complicated for me ... :lol: Anyway, my flowchart will contain only a few variables. I`ll studie your last flowchart to understand what you did there! :oops:
Thank you again! Have some happy winter holidays

Re: Quadrature encoder and variables

Posted: Sat Dec 07, 2013 4:31 pm
by medelec35
bercioiu wrote:Thanks but your last flowchart It is little bit complicated for me
No worries, I can help you understand it step by step if your interested.
If/when your ready to do that let me know.
bercioiu wrote:Have some happy winter holidays
Thanks, you to :)

Martin