Quadrature encoder and variables (SOLVED)
Moderator: Benj
-
- Posts: 161
- Joined: Sun Feb 25, 2007 10:56 am
- Location: bucharest, romania
- Has thanked: 90 times
- Been thanked: 34 times
- Contact:
Quadrature encoder and variables (SOLVED)
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 ...
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 ...
Last edited by bercioiu on Thu Dec 12, 2013 4:46 pm, edited 1 time in total.
-
- Posts: 161
- Joined: Sun Feb 25, 2007 10:56 am
- Location: bucharest, romania
- Has thanked: 90 times
- Been thanked: 34 times
- Contact:
Re: Quadrature encoder and variables
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...
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...
- Attachments
-
- ENCODER_SET_VARIABLE.fcf
- (24.01 KiB) Downloaded 414 times
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Quadrature encoder and variables
Hello,
I've had a look and can't see any problems with your code. Strange that (-4 / 4) is still resulting in -4?
I've had a look and can't see any problems with your code. Strange that (-4 / 4) is still resulting in -4?
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 161
- Joined: Sun Feb 25, 2007 10:56 am
- Location: bucharest, romania
- Has thanked: 90 times
- Been thanked: 34 times
- Contact:
Re: Quadrature encoder and variables
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
...

- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Quadrature encoder and variables
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?
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?
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 161
- Joined: Sun Feb 25, 2007 10:56 am
- Location: bucharest, romania
- Has thanked: 90 times
- Been thanked: 34 times
- Contact:
Re: Quadrature encoder and variables
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...
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...
-
- Posts: 161
- Joined: Sun Feb 25, 2007 10:56 am
- Location: bucharest, romania
- Has thanked: 90 times
- Been thanked: 34 times
- Contact:
Re: Quadrature encoder and variables
- EB006 E-blocks Multiprogrammer Board
- EB073 E-blocks Rotary Encoder Board
- EB005 E-blocks LCD Board
but the rezults are the same...
- Attachments
-
- encoder.JPG
- (135.55 KiB) Downloaded 2084 times
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Quadrature encoder and variables
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
From Decision macro.
Hope this helps
Martin
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
Code: Select all
Count > 0
Hope this helps
Martin
- Attachments
-
- Rotory Encoder 16f877A single steps.fcf
- (15.05 KiB) Downloaded 433 times
Martin
-
- Posts: 161
- Joined: Sun Feb 25, 2007 10:56 am
- Location: bucharest, romania
- Has thanked: 90 times
- Been thanked: 34 times
- Contact:
Re: Quadrature encoder and variables (SOLVED)
Thanks to Martin, I solved my probl.
Thank you very much Martin!
Thank you very much Martin!
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Quadrature encoder and variables
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
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
- Attachments
-
- Rotory Encoder 16f88 single steps.fcf
- (19.1 KiB) Downloaded 417 times
Martin
-
- Posts: 161
- Joined: Sun Feb 25, 2007 10:56 am
- Location: bucharest, romania
- Has thanked: 90 times
- Been thanked: 34 times
- Contact:
Re: Quadrature encoder and variables
Thanks but your last flowchart It is little bit complicated for me ...
Anyway, my flowchart will contain only a few variables. I`ll studie your last flowchart to understand what you did there! 
Thank you again! Have some happy winter holidays


Thank you again! Have some happy winter holidays
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Quadrature encoder and variables
No worries, I can help you understand it step by step if your interested.bercioiu wrote:Thanks but your last flowchart It is little bit complicated for me
If/when your ready to do that let me know.
Thanks, you tobercioiu wrote:Have some happy winter holidays

Martin
Martin