Page 1 of 1

Rotory Encoder and PIC

Posted: Tue Jun 28, 2011 5:24 pm
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

Re: Rotory Encoder and PIC

Posted: Tue Jun 28, 2011 6:37 pm
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

Re: Rotory Encoder and PIC

Posted: Wed Jun 29, 2011 9:23 am
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.

Re: Rotory Encoder and PIC

Posted: Thu Jun 30, 2011 8:07 am
by Dan81
Hello Indana

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

Daniel

Re: Rotory Encoder and PIC

Posted: Thu Jun 30, 2011 1:39 pm
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

Re: Rotory Encoder and PIC

Posted: Thu Jun 30, 2011 2:40 pm
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

Re: Rotory Encoder and PIC

Posted: Sat Jul 02, 2011 4:15 pm
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

Re: Rotory Encoder and PIC

Posted: Sat Jul 02, 2011 8:48 pm
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

Re: Rotory Encoder and PIC

Posted: Sun Jul 03, 2011 8:24 am
by Dan81
Hello Indana

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

Which hardware are you using ?

Daniel

Re: Rotory Encoder and PIC

Posted: Sun Jul 03, 2011 10:11 pm
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

Re: Rotory Encoder and PIC

Posted: Sun Jul 03, 2011 10:18 pm
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?

Re: Rotory Encoder and PIC

Posted: Sun Jul 03, 2011 11:54 pm
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

Re: Rotory Encoder and PIC

Posted: Mon Jul 04, 2011 7:41 am
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

Re: Rotory Encoder and PIC

Posted: Mon Jul 04, 2011 9:00 am
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.

Re: Rotory Encoder and PIC

Posted: Mon Jul 04, 2011 9:44 am
by Dan81
Hello Indana

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

Daniel

Re: Rotory Encoder and PIC

Posted: Mon Jul 04, 2011 12:42 pm
by nmindana
Hi Daniel,

I am using EB006 board.

BR

Indana

Re: Rotory Encoder and PIC

Posted: Mon Jul 04, 2011 12:52 pm
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

Re: Rotory Encoder and PIC

Posted: Mon Jul 04, 2011 10:24 pm
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

Re: Rotory Encoder and PIC

Posted: Mon Jul 04, 2011 11:00 pm
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

Re: Rotory Encoder and PIC

Posted: Sun Sep 25, 2011 9:47 am
by benp
I did that encoder reading 2 years ago:
test codeur.fcf
(7.5 KiB) Downloaded 270 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?

Re: Rotory Encoder and PIC

Posted: Sun Sep 25, 2011 11:12 am
by nmindana
Hi Good Job,

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

Indana

Re: Rotory Encoder and PIC

Posted: Sun Sep 25, 2011 1:15 pm
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.

Re: Rotory Encoder and PIC

Posted: Sun Sep 25, 2011 7:38 pm
by nmindana
Hi Martin,

Excellent article. Very well explained and tested.

Thanks very much. :)

Re: Rotory Encoder and PIC

Posted: Sun Sep 25, 2011 9:48 pm
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