turn left or turn right of an wheel?

Moderator: Benj

Post Reply
ardiles
Posts: 23
Joined: Tue Jun 24, 2014 11:38 am
Has thanked: 7 times
Been thanked: 1 time
Contact:

turn left or turn right of an wheel?

Post by ardiles »

i want to detect an turn of a shaft with two optical sensors?

i want implement Gray code, how can i implement that in flowcode?

senzor optic1/2 » optical sensors slot/slit/indenture like this:
Attachments
schema simplificata.png
electrical wiring....simplified
(55.62 KiB) Downloaded 2780 times
example  position of optical sensors
example position of optical sensors
vedere in sectiune a axului si a senzorilor..jpg (23.67 KiB) Viewed 12415 times
optical sensors slot/slit/indenture
optical sensors slot/slit/indenture
senzor optic - exemplu.jpg (5.81 KiB) Viewed 12415 times
Last edited by ardiles on Tue Jun 24, 2014 12:26 pm, edited 1 time in total.

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: turn left or turn right of an wheel?

Post by Benj »

Hello,

The quadrature encoder component should work well with the outputs from the optical sensors to give you a reliable position count.

There are examples available using the component with a timer (polling) or with a port change interrupt (specific pins). The latter is probably less prone to error long term if you are free to use any pin on the microcontroller.

ardiles
Posts: 23
Joined: Tue Jun 24, 2014 11:38 am
Has thanked: 7 times
Been thanked: 1 time
Contact:

Re: turn left or turn right of an wheel?

Post by ardiles »

i was adviced to wse interrupt by port: 16f684 have IOC onny portA...i use RA4 & RA5(please see the schematic wire)
Attachments
vedere axiala.png
axial view, and position sensor...
(10.29 KiB) Downloaded 8264 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: turn left or turn right of an wheel?

Post by Benj »

Hello,

Yes that looks spot on.

Here is a v5 example file you can use (Example2), just configure the pin connections of the encoder component and the interrupt icon for your specific microcontroller and interrupt input.

http://www.matrixmultimedia.com/resourc ... php?id=652

The example has two encoders and a GLCD but you can just rip these bits out the code.

Using the free version of Flowcode 6 here is the same example but this time you can simulate the encoder input.
ESketch.fcfx
(9.44 KiB) Downloaded 328 times

ardiles
Posts: 23
Joined: Tue Jun 24, 2014 11:38 am
Has thanked: 7 times
Been thanked: 1 time
Contact:

Re: turn left or turn right of an wheel?

Post by ardiles »

how can i simulate/modify value of encoder connected to portA, on RA4 & RA5, becouse when i play the simulation, the encoder putted on the panel, it disappears?

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: turn left or turn right of an wheel?

Post by Benj »

Hello,

In v5 the encoders do not simulate so you have to use the hardware if you want to see it in action. For v6 the encoder components simulate which is why I posted the v5 and v6 examples.

ardiles
Posts: 23
Joined: Tue Jun 24, 2014 11:38 am
Has thanked: 7 times
Been thanked: 1 time
Contact:

Re: turn left or turn right of an wheel?

Post by ardiles »

Benj wrote:so you have to use the hardware if you want to see it in action.
i understand this...
but,
can i use 2 optical sensors to succesfully replace an real encoder? see schemathic!
how teeths must have my disc from wheel?

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: turn left or turn right of an wheel?

Post by Benj »

Hello,
can i use 2 optical sensors to succesfully replace an real encoder? see schemathic!
Yes your schematic looks fine, use the two signals from the optical sensors to drive the encoder component pins.
how teeths must have my disc from wheel?
Well it's up to you how much resolution you require in your application. i.e. how many counts you want to detect per single rotation of the wheel. I would start with a low count like you showed in your diagram, once this is working you can increase the resolution if needed. Both optical sensors will have to fit inside a single segment on the wheel to allow the grey code type operation to drive the encoder counter correctly.

i.e. we need to see these signals for the component to work.

A goes high
B goes high
A goes low
B goes low

This will not work

A goes high
A goes low
B goes high
B goes low

ardiles
Posts: 23
Joined: Tue Jun 24, 2014 11:38 am
Has thanked: 7 times
Been thanked: 1 time
Contact:

Re: turn left or turn right of an wheel?

Post by ardiles »

thanks!
so, i must modify lenght of teeth like this:
a lenght of a cog(tooth)(implicit the pause between cogs(teeth)) = width of twoo sensors?
is correct? :D
Attachments
lenght of teeth = lenghth of sensor.png
lenght of a cog = lenght of two nearest sensors
(9.17 KiB) Downloaded 8224 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: turn left or turn right of an wheel?

Post by Benj »

Hello,
so, i must modify lenght of teeth like this:
a lenght of a cog(tooth)(implicit the pause between cogs(teeth)) = width of twoo sensors?
is correct?
Yes that should give you the best result.

Let us know how your getting on.

ardiles
Posts: 23
Joined: Tue Jun 24, 2014 11:38 am
Has thanked: 7 times
Been thanked: 1 time
Contact:

Re: turn left or turn right of an wheel?

Post by ardiles »

i downloaded flowcode V6(too complex as V5), and i modified example 1(microcontroller, inputs and outputs)...
works, but in last moments, the encoder working on negative front... or turn right, or turn left, the encoder encrements only negative front...
any ideea?

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: turn left or turn right of an wheel?

Post by medelec35 »

Hi ardiles,
This is what I would do.
Use port interrupt on change (IOC) for S2 only,
As soon as S2 has changed state i.e from logic 0 to logic 1 or from logic 1 to logic 0 then immediately check state of S1.
This must be done within the interrupt service routine macro (ISR).
If the state of S1 is the same as S2, e.g both at logic one or both at logic0, then the encoder is moving counter clockwise.
If the state of S1 is not the same as S2, then the encoder is moving clockwise.
In theory it should work so long as each segment is wider than the width of the two sensors.
So be best to allow a bit of an overlap.

It can be looked at:
IF S2 = S1:
Yes: Direction = counter clockwise
No: Direction = clockwise,
You can also get timer 1 interrupt to count a variable every second.
Reset timer1, count the pulses until timer 1 variable = 1.
Then since 1 second has lapsed RPM = count total/number of segments*60
If you are going to try what I have suggested then if your suck, then post your flowchart and I will see if I can get it working for you.

Martin
Martin

ardiles
Posts: 23
Joined: Tue Jun 24, 2014 11:38 am
Has thanked: 7 times
Been thanked: 1 time
Contact:

Re: turn left or turn right of an wheel?

Post by ardiles »

good day!
here is an .fcfx file, modified by me yesterday from "Example 1"
that file meet example of schematic wire posted by me "Tue Jun 24, 2014 2:14 pm"
Attachments
cornering lights - cu 16F684.fcfx
(9.24 KiB) Downloaded 261 times

ardiles
Posts: 23
Joined: Tue Jun 24, 2014 11:38 am
Has thanked: 7 times
Been thanked: 1 time
Contact:

Re: turn left or turn right of an wheel?

Post by ardiles »

good day dear friends!
i build hardware of this encoder...BUT:
why it not recognize two directions? it recongnize only one direction...only left; in simullation works fine but hardare no.
when i turn left, it set 1 RC0 (an LED)...if i am tuning left 10rotations, my led from RC0 is on while turn right the 10rotations... from this situation, i understand: my microcontroler recongnize twoo directions ! but when i turning right, not turn on RC1 but recognize my turning(if i turn right 5 rotations, when i turn left 5+1 rotations, turning on opposide led...)...

ardiles
Posts: 23
Joined: Tue Jun 24, 2014 11:38 am
Has thanked: 7 times
Been thanked: 1 time
Contact:

Re: turn left or turn right of an wheel?

Post by ardiles »

i find the problem!
an transistor was broken, but was new...
so, my encoder turning on an led, if i turn left and turn another led when i turn opposide direction.
working good!
but: for my application does not fit becouse this "turning transducer", have Hysteresis error...
i developed ideea with potentiometer sensor, from here:
http://www.matrixtsl.com/mmforums/viewt ... 49&t=15027

Post Reply