Rotory Encoder and PIC

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
nmindana
Posts: 82
Joined: Thu Nov 18, 2010 5:00 pm
Has thanked: 52 times
Been thanked: 5 times
Contact:

Rotory Encoder and PIC

Post by nmindana »

Hi every one / Martin,

I am trying to use Enocoder (Incremental), farell order code: 1520813, to input numbers on the LCD.
I am new to encoders, these are similar to car radio rational switches, where you can rotate and select the options on the menu. As there is no component in flowcode, I have used two switches to mimic the two input pins from the enocoder.

Please help, as the attached programme doesn't work.

regards

Indana

What I know:

I am told incremental encoders have two outputs which are out phase with each other at 90 degrees.
In order to determine direction of rotation. Gray coding is used.



Two useful links:

http://www.tufts.edu/programs/mma/emid/ ... ncoder.pdf

http://www.parallax.com/dl/docs/cols/nv ... ol/nv8.pdf
Attachments
rotory enocder and numbers.fcf
(10.5 KiB) Downloaded 376 times

User avatar
JohnCrow
Valued Contributor
Valued Contributor
Posts: 1367
Joined: Wed Sep 19, 2007 1:21 pm
Location: Lincolnshire
Has thanked: 364 times
Been thanked: 716 times
Contact:

Re: Rotory Encoder and PIC

Post by JohnCrow »

Hi
Rotary encoders is something I want to have a look at myself in the near future,
Sorry but I don't know anymore than you at the moment.

Have you looked at this post maybe something useful to you here

http://www.matrixmultimedia.com/mmforum ... der#p21037
1 in 10 people understand binary, the other one doesn't !

User avatar
Steve
Matrix Staff
Posts: 3418
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times
Contact:

Re: Rotory Encoder and PIC

Post by Steve »

Strangely enough, we have just signed-off work on a rotational encoder E-block. We hope to have this product for sale in the next 2 months.

We'll also work on a Flowcode component, but this is likely to be limited to Flowcode V5. However, I'm sure that functions in C code will be made available.

User avatar
Dan81
Valued Contributor
Valued Contributor
Posts: 268
Joined: Sun Jan 15, 2006 4:07 pm
Location: Albi France
Been thanked: 60 times
Contact:

Re: Rotory Encoder and PIC

Post by Dan81 »

Hello Indana

You can do something like this.
An other way is to use interrupt (RB0 or PortChange)

Daniel
Attachments
rotory encoder v2.fcf
OK in simulation
Not hard tested
(9 KiB) Downloaded 417 times

nmindana
Posts: 82
Joined: Thu Nov 18, 2010 5:00 pm
Has thanked: 52 times
Been thanked: 5 times
Contact:

Re: Rotory Encoder and PIC

Post by nmindana »

Thanks Daniel,

Will try it out and let you know if it worked, but the Rotory encoder would need two input pins as they are at 90 degrees with
each other at any one time. RB0 is a single input, PORTB change is a good one. :)

Thanks for your help.

Regards

Indana

User avatar
Dan81
Valued Contributor
Valued Contributor
Posts: 268
Joined: Sun Jan 15, 2006 4:07 pm
Location: Albi France
Been thanked: 60 times
Contact:

Re: Rotory Encoder and PIC

Post by Dan81 »

Hello Indana

If you use RB0 int , just connect one of the output of the encoder to RB0 and the other one anywhere.

If you use PortB Change , you will have to search which pin have changed and the sign of the edge .
With a 16F887 you can reduce the number of pins of the interrupt.

Daniel

nmindana
Posts: 82
Joined: Thu Nov 18, 2010 5:00 pm
Has thanked: 52 times
Been thanked: 5 times
Contact:

Re: Rotory Encoder and PIC

Post by nmindana »

Hi Daniel,

Your prog althoug working on simulation, is not working well with the hardware, you are right, may be it will work with an interrupt as you have suggested!.

thanks any way :)

Regards

Indana

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

Re: Rotory Encoder and PIC

Post by medelec35 »

:idea: I've had an idea, but don't know if it will work or not. :?:
I know it wont work in flowcode simulator because the simulator can't simulate T0CKI pin. The simulator behaves as though clock source is selected.
All you need to do is connect RA4 to 1 I/P of encoder, and the other 90 deg I/P connect to RA0 .Its the RA0 pin that's determining direction.
Count is increased or decreased on every rising edge. To change count on falling edge, then alter within timer0 properties to: High-to-low transition.
I decided to try using T0CKI (a part of timer 0 interrupt) instead of port B for the interrupt.
Only because the LCD is connected to port B.
If the count direction is opposite to what your after, just double click Rotation_Direction and select 'Swap Yes and No'.
There is no switch de-bounce within Flowchart posted. If not using a LPF then you can decrease value of tmr0 (within Encoder_Detect macro) to increase de-bounce. If set too low the de-bounce will be too high, so will not detect properly.
E.g currently tmr0=+255
This means a count of 1 every time pin A4 goes from low to high.
If you change 255 to 252 then there will be a count of 1 when A4 goes from low to high for 3rd time. (255-253 = 3)

Regards
Martin
Attachments
rotory encoder v2 Modified.fcf
(9 KiB) Downloaded 365 times
Martin

User avatar
Dan81
Valued Contributor
Valued Contributor
Posts: 268
Joined: Sun Jan 15, 2006 4:07 pm
Location: Albi France
Been thanked: 60 times
Contact:

Re: Rotory Encoder and PIC

Post by Dan81 »

Hello Indana

Can you tell what my program is doing or not doing.

Which hardware are you using ?

Daniel

nmindana
Posts: 82
Joined: Thu Nov 18, 2010 5:00 pm
Has thanked: 52 times
Been thanked: 5 times
Contact:

Re: Rotory Encoder and PIC

Post by nmindana »

Hi Daniel,

I am 16f88, with the encoder used RB6/RB7 pins.
Both clockwise and AC produce the same result, ie, incrementing!. Bizzare?. :?

Let me know if I am doing something wrong?.

Thanks

regards

Indana

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

Re: Rotory Encoder and PIC

Post by medelec35 »

nmindana wrote: I am 16f88, with the encoder used RB6/RB7 pins.
Both clockwise and AC produce the same result, ie, incrementing!. Bizzare?. :?

Let me know if I am doing something wrong?.

Thanks

regards

Indana
With the one I posted you need to use RA4. But the RA0 can be changed.
I could change to the B6 and B7 pins if you like?
Martin

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

Re: Rotory Encoder and PIC

Post by medelec35 »

Here is a slightly different version using ports RB6 and RB7 as promised.
I have not used an encoder before, so can't guarantee it will work, but you never know :wink:
This version is not using timer0 T0CKI but instead using portB interrupt, so should simulate in Flowcode as well.
Just for testing purposes I have changed Days into and integer. Since starting from 0 if counting down you will see a negative number.

Regards

Martin
Attachments
rotory encoder v2 Modified1.fcf
(9 KiB) Downloaded 305 times
Martin

jgu1
Posts: 1333
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1135 times
Been thanked: 299 times
Contact:

Re: Rotory Encoder and PIC

Post by jgu1 »

Hi!

I made a small project for a Ham radio with a rotary encoder. Maybe you can use something from here. It works in real world.

Regard

jgu1
Attachments
Storno11.fcf
(22.7 KiB) Downloaded 306 times

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

Re: Rotory Encoder and PIC

Post by medelec35 »

After looking at the datasheet for the encoder (again :P)
I have altered Flowchart so this version should work, whereas I don’t think the one on my post above post will work that well.
Attachments
rotory encoder v2 Modified2.fcf
(10 KiB) Downloaded 277 times
Martin

User avatar
Dan81
Valued Contributor
Valued Contributor
Posts: 268
Joined: Sun Jan 15, 2006 4:07 pm
Location: Albi France
Been thanked: 60 times
Contact:

Re: Rotory Encoder and PIC

Post by Dan81 »

Hello Indana

Which hardware are you using : Matrix board HP488 , EB006 ?

Daniel

nmindana
Posts: 82
Joined: Thu Nov 18, 2010 5:00 pm
Has thanked: 52 times
Been thanked: 5 times
Contact:

Re: Rotory Encoder and PIC

Post by nmindana »

Hi Daniel,

I am using EB006 board.

BR

Indana

nmindana
Posts: 82
Joined: Thu Nov 18, 2010 5:00 pm
Has thanked: 52 times
Been thanked: 5 times
Contact:

Re: Rotory Encoder and PIC

Post by nmindana »

Hi everyone,

I am pleased to say I found the cure. I worked it out based on the Grey coding. . This is a system of binary counting in which adjacent codes differ in only one position.

The encoder I am using is a quadrate mechanical type, it has 24 indents, going through 360 degree rotation.



Gray Coding
Sector Contact 1 Contact 2 Contact 3 Angle
1 off off off 0° to 45°
2 off off ON 45° to 90°
3 off ON ON 90° to 135°
4 off ON off 135° to 180°
5 ON ON off 180° to 225°
6 ON ON ON 225° to 270°
7 ON off ON 270° to 315°
8 ON off off 315° to 360°

The attached works well, it is set to reset to "0" after 180 days.
"WoW", Can't believe it, I surprised myself. Thanks for all your support, especially Martin.

Now I can input numbers, how to I input alphabets ?.


Regards

Indana
Attachments
rotory using nterrupts working.fcf
(11 KiB) Downloaded 315 times

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

Re: Rotory Encoder and PIC

Post by medelec35 »

Well done Indana!
Glad you found your own solution. It just proves how well your getting to know Flowcode.
nmindana wrote:how to I input alphabets ?.


Regards

Indana
I have modified your Flowchart to count up in the alphabet instead of numbers.

Regards

Martin
Attachments
rotory using nterrupts working V2.fcf
(11 KiB) Downloaded 303 times
Martin

nmindana
Posts: 82
Joined: Thu Nov 18, 2010 5:00 pm
Has thanked: 52 times
Been thanked: 5 times
Contact:

Re: Rotory Encoder and PIC

Post by nmindana »

Thanks Martin,

Din't think that it would be so simple. :)
Number to ASCI, looks I need to learn basic fundamentals.

regards.

Indana

benp
Posts: 155
Joined: Sat Mar 28, 2009 5:44 pm
Location: LYON FRANCE
Has thanked: 3 times
Been thanked: 41 times
Contact:

Re: Rotory Encoder and PIC

Post by benp »

I did that encoder reading 2 years ago:
test codeur.fcf
(7.5 KiB) Downloaded 268 times
That one is very simple: only 6 flowcode instructions in interrupt. 7 instructions in main for display.
Maybe it is possible to do shorter with RotaryEncoder.pdf XOR method (link in the first post).

It works in real world on a manual encoder. If this can help.
For simulation, press 1 and 0 on the computer keyboard.
To increase the counter:
press 0, 0 and 1,1,nothing and repeat...

I don't know if it can work on a motor encoder because it must be high speed.
I want to perform test in the future.
Steve, will your component count with hardware or software?
Regards
INSA 1er cycle GCP projects with or without eblocks:
http://www.youtube.com/user/INSAgcp

nmindana
Posts: 82
Joined: Thu Nov 18, 2010 5:00 pm
Has thanked: 52 times
Been thanked: 5 times
Contact:

Re: Rotory Encoder and PIC

Post by nmindana »

Hi Good Job,

wow !.
Programme looks sleek, have you tested on hard ware? :D

Indana

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

Re: Rotory Encoder and PIC

Post by medelec35 »

Hi Indana,
Have you seen this thread:
http://www.matrixmultimedia.com/mmforum ... =26&t=8773

It may be of interest since It has flowcharts of encoders that have been tested with hardware before being posted.

Martin.
Martin

nmindana
Posts: 82
Joined: Thu Nov 18, 2010 5:00 pm
Has thanked: 52 times
Been thanked: 5 times
Contact:

Re: Rotory Encoder and PIC

Post by nmindana »

Hi Martin,

Excellent article. Very well explained and tested.

Thanks very much. :)

benp
Posts: 155
Joined: Sat Mar 28, 2009 5:44 pm
Location: LYON FRANCE
Has thanked: 3 times
Been thanked: 41 times
Contact:

Re: Rotory Encoder and PIC

Post by benp »

The last program what tested on hardware with an optical encoder. It works at 500 pulses/s.
There is no need to debounce because it is an optical encoder.
On the thread:
http://www.matrixmultimedia.com/mmforum ... =26&t=8773
It is a mechanical encoder so you need a debounce.

Here is a new program with the xor method:
test codeur-XOR.fcf
(7.5 KiB) Downloaded 302 times
Only 4 instruction in the interrupt.
Not tested yet. I want to test 30000 pulse/s.

Indiana, that one won't work on your encoder because it is mechanical. You need to add a 5ms delay in the interrupt so it should work.
There is no rollover protection. Add one if necessary.

Medelec, your "Rotory Encoder V1 with a 5ms delay .fcf" is alpha style (1/2) in http://www.matrixmultimedia.com/mmforum ... =26&t=8773?
The "test codeur-XOR.fcf" is panasonic style (1)
The "test codeur.fcf" is 1/4
Regards
INSA 1er cycle GCP projects with or without eblocks:
http://www.youtube.com/user/INSAgcp

Post Reply