Quadrature encoder and variables (SOLVED)

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

Post Reply
bercioiu
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)

Post 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 ...
Last edited by bercioiu on Thu Dec 12, 2013 4:46 pm, edited 1 time in total.

bercioiu
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

Post 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...
Attachments
ENCODER_SET_VARIABLE.fcf
(24.01 KiB) Downloaded 390 times

User avatar
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

Post 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?

bercioiu
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

Post 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 :-( ...

User avatar
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

Post 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?

bercioiu
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

Post 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...

bercioiu
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

Post 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...
Attachments
encoder.JPG
(135.55 KiB) Downloaded 2084 times

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Quadrature encoder and variables

Post 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
Attachments
Rotory Encoder 16f877A single steps.fcf
(15.05 KiB) Downloaded 403 times
Martin

bercioiu
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)

Post by bercioiu »

Thanks to Martin, I solved my probl.
Thank you very much Martin!
ENCODER_SET_VARIABLE_Martin.fcf
(21.64 KiB) Downloaded 466 times

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Quadrature encoder and variables

Post 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
Attachments
Rotory Encoder 16f88 single steps.fcf
(19.1 KiB) Downloaded 387 times
Martin

bercioiu
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

Post 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

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Quadrature encoder and variables

Post 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
Martin

Post Reply