Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

[SOLVED] Angle measurement using MOC7811

Status
Not open for further replies.

Anantha Krishna

Member level 1
Joined
Feb 10, 2011
Messages
41
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,642
Hi All,

I am using MOC7811 to detect the angle of a wheel. I have attached a small wheel with 90 slotted cuts, which cuts the connection between receiver and the transmitter of MOC7811, and by detecting the edges, I can measure the angle.
I am using two optos adjacent to each other, through which I will able to measure 360 degrees.[i.e. each opto will give two edges for each slot. The small wheel contains 90 slots. So each opto gives 180 deg. Totally 360 deg].

Please see the attached image of the MOC7811 circuit that I am using.

Detecting the angle in single direction is easy. I am not able to figure out how to measure angle in both +ve and -ve directions. i.e. The indicator should show +ve angle in clockwise and -ve angle in anticlockwise directions.

Please someone help to solve this problem.

Thank you.
MOC7811 Circuit.jpg
 

IanP

Advanced Member level 5
Joined
Oct 5, 2004
Messages
7,942
Helped
2,308
Reputation
4,618
Reaction score
531
Trophy points
1,393
Location
West Coast
Activity points
66,459
If you re-design the encoder to have two sets of LED/phototransistor pairs, those pairs aligned such that their square-wave output signals are 90o out of phase with each other, you’ll have what is known as a quadrature output encoder ..
A phase detection circuit may be made from a D-type flip-flop, to distinguish a clockwise pulse sequence from a counter-clockwise pulse sequence ..
See attached picture ..

:wink:
IanP
 

Attachments

  • Like
Reactions: DrWhoF

    V

    points: 2
    Helpful Answer Positive Rating

    DrWhoF

    points: 2
    Helpful Answer Positive Rating

Anantha Krishna

Member level 1
Joined
Feb 10, 2011
Messages
41
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,642
Thank you.

But I am using a microcontroller to detect the angle, not flip flop or counters.

Could you explain how to achieve 360 deg bidirectional angle measurement using C, if we implement both D flip flop and up/down counter in C programming?
 

JayantD

Member level 3
Joined
Nov 2, 2010
Messages
58
Helped
9
Reputation
18
Reaction score
9
Trophy points
1,288
Location
Pune, India
Activity points
1,548
First of all, to sense direction, you need quadrature outputs from your sensing arrangement. This is what IanP has suggested. From what you have described, it is not clear whether you are getting phase shifted outputs. A photograph of your sensor mounting arrangement will be helpful..Refer Austria microsystems AS5035 datasheet.
When you get quadrature outputs, using the D flipflop as suggested by IanP, Q output will be logic high for one direction, logic low for the other.
 

Anantha Krishna

Member level 1
Joined
Feb 10, 2011
Messages
41
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,642
Hi,

I have ensured that the sensor arrangement results in quadrature outputs.

If we see the image attached by IanP, Q is updated at the rising edge of the Clk. But since the outputs are quadrature, whenever the clk is high the D will be low. So we will get only one state output at Q. So the counter updates in the single direction, not both. This what I observed while implementing this arrangement in my program.

Please correct me if I am wrong and give a solution.
 

FvM

Super Moderator
Staff member
Joined
Jan 22, 2008
Messages
47,489
Helped
14,048
Reputation
28,351
Reaction score
12,706
Trophy points
1,393
Location
Bochum, Germany
Activity points
276,162
You can easily count four events per period by combining the present and the previous state of both detectors.

Code:
A=detA;
B=detB;
deltaA = A ^ prevA;
deltaB = B ^ prevB;
if (deltaA || deltaB) // any change
{
  if (deltaA && deltaB) 
  {
    // overrun
  }
  else if (A ^ prevB) 
  {
    // count up
  }
  else
  {
    // count down
  }
}
prevA = A;
prevB = B;
 

FvM

Super Moderator
Staff member
Joined
Jan 22, 2008
Messages
47,489
Helped
14,048
Reputation
28,351
Reaction score
12,706
Trophy points
1,393
Location
Bochum, Germany
Activity points
276,162
Perhaps your circuit can not deliver 50% duty cycle ??
I didn't hear yet a clear statement about deviation from an ideal quadrature signal. The OP wants 4 counts per quadrature cycle, which is a reasonable requirement. The previously suggested D-FF circuit can't provide it, and it also tends to produce false counts with bouncing inputs or incremental back and forth rotations, that can occur in some applications. Decoding the quadrature signal like a gray counter gives exact count results in all situations.
 

IanP

Advanced Member level 5
Joined
Oct 5, 2004
Messages
7,942
Helped
2,308
Reputation
4,618
Reaction score
531
Trophy points
1,393
Location
West Coast
Activity points
66,459
...D-FF circuit can't provide it, and it also tends to produce false counts with bouncing inputs or incremental back and forth rotations, that can occur in some applications...
D-FF does not count anything, it's purely used to indicate direction ..
:wink:
 
  • Like
Reactions: DrWhoF

    DrWhoF

    points: 2
    Helpful Answer Positive Rating

Anantha Krishna

Member level 1
Joined
Feb 10, 2011
Messages
41
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,642
@FvM - I have already tried similar code. It works fine for upcounting. But down counting will not work properly. Further, this type of coding doesn't actual counts if the change in pulses is too fast, even if are deteting the edges in interrupt mode. This is what I have observed.

@JayntD and IanP - the images are indeed self explanatory. But could you please help to realize this in programming instead of using D flip flop? i.e how to identify which one is leading and which is lagging?
 

JayantD

Member level 3
Joined
Nov 2, 2010
Messages
58
Helped
9
Reputation
18
Reaction score
9
Trophy points
1,288
Location
Pune, India
Activity points
1,548
it would be easier to implement a D flip flop. State machines would be helpful in writing code.
BTW, what is the maximum frequency of your signals ?
 

Anantha Krishna

Member level 1
Joined
Feb 10, 2011
Messages
41
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,642
Thank you all.

It is working fine with a pull up resistor of 5.1k at the output.
 

FvM

Super Moderator
Staff member
Joined
Jan 22, 2008
Messages
47,489
Helped
14,048
Reputation
28,351
Reaction score
12,706
Trophy points
1,393
Location
Bochum, Germany
Activity points
276,162
I have already tried similar code. It works fine for upcounting. But down counting will not work properly. Further, this type of coding doesn't actual counts if the change in pulses is too fast, even if are deteting the edges in interrupt mode. This is what I have observed.
I think, your intentions are unclear. To refer to your previous statement:
But I am using a microcontroller to detect the angle, not flip flop or counters.
Could you explain how to achieve 360 deg bidirectional angle measurement using C, if we implement both D flip flop and up/down counter in C programming?
There's no such thing as a D-FF in C. Furthermore you would need FFs acting on both edges to implement the requested 360 steps counter in hardware.

The problem is, that a processor solution relies on the processor speed - or needs dedicated quadrature decoder hardware.

Also your observations are unclear. Overrun with too fast input pulses is one thing, not counting correctly another one. Your processor solution should at least count correctly on slow rotation. If it doesn't, either the code or the quadrature signals are wrong.

You previously gave the impression, that you don't know how to write the respective C-code. Now you tell, you already have tried it. You may want to tell more clearly, what you're missing exactly.

My code should mainly give an example. There are different ways to implement a software quadrature decoder with maximum speed. You didn't tell yet about count frequencies or processor speed, so we don't know, if a processor solution can work at all.

D-FF does not count anything, it's purely used to indicate direction ..
The problem is, that the direction information is only updated on the rising edge of one channel. I'm sure, you can figure out yourself, why the said solution produces false counts with "unsuitable" decoder moves.

P.S.:
It is working fine with a pull up resistor of 5.1k at the output
Surprizing.... But good news anyway.
 

JayantD

Member level 3
Joined
Nov 2, 2010
Messages
58
Helped
9
Reputation
18
Reaction score
9
Trophy points
1,288
Location
Pune, India
Activity points
1,548
This seems a good opportunity to introduce a sticky template about specifications that must be included along with a query..
I haven't looked, it might already be there.. don't pounce on me! :wink:

Comments please, Moderators!
 

Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top