Page 1 of 1
turn left or turn right of an wheel?
Posted: Tue Jun 24, 2014 12:14 pm
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:
Re: turn left or turn right of an wheel?
Posted: Tue Jun 24, 2014 12:25 pm
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.
Re: turn left or turn right of an wheel?
Posted: Tue Jun 24, 2014 12:33 pm
by ardiles
i was adviced to wse interrupt by port: 16f684 have IOC onny portA...i use RA4 & RA5(please see the schematic wire)
Re: turn left or turn right of an wheel?
Posted: Tue Jun 24, 2014 2:01 pm
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.
https://www.matrixtsl.com/resources/get ... 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.
Re: turn left or turn right of an wheel?
Posted: Wed Jun 25, 2014 6:43 am
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?
Re: turn left or turn right of an wheel?
Posted: Wed Jun 25, 2014 9:20 am
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.
Re: turn left or turn right of an wheel?
Posted: Wed Jun 25, 2014 9:57 am
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?
Re: turn left or turn right of an wheel?
Posted: Wed Jun 25, 2014 11:24 am
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
Re: turn left or turn right of an wheel?
Posted: Thu Jun 26, 2014 8:01 am
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?

Re: turn left or turn right of an wheel?
Posted: Thu Jun 26, 2014 9:17 am
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.
Re: turn left or turn right of an wheel?
Posted: Thu Jun 26, 2014 11:45 am
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?
Re: turn left or turn right of an wheel?
Posted: Thu Jun 26, 2014 2:32 pm
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
Re: turn left or turn right of an wheel?
Posted: Fri Jun 27, 2014 5:17 am
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"
Re: turn left or turn right of an wheel?
Posted: Fri Jul 04, 2014 11:09 am
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...)...
Re: turn left or turn right of an wheel?
Posted: Tue Jul 08, 2014 9:58 am
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