Quadrature output

Hi can anybody help me out with the problem below.

i am supposed to create standard quadrature o/p (2 or 3 oututs, A B and RM) from PWM or outputcompare pins of a dsPIC 30F3010 or dsPIC 30f3011 The preferred frequency could be in the range of 1Mhz or a bit lesser. The timing parameters for these outputs will be obtained to 2 Inputcapture modules in the dsPIC from the outside analogue world. Can we create this output at good resolution (around 0.1um resolution) when the linear change is around 1m/s? dsPIC is running at 30Mhz Fcy

Many thanks

Reply to
Spider_mce
Loading thread data ...

I don't know the dsPIC, but if it is any help, I did the same thing on a IsoPod(TM) DSP56F805. Here are my notes from the program:

( Quadrature Generator ( The idea here is to take a variable containing a desired Pulses Per ( Second and generate a quadrature output that produces those ( counts. ( ( I originally tried to do this with PWM, but it was hard to get the 90 ( degree phasing to work out. Then I did it with individual port lines. ( While not at 90 degrees, at least I generated workably overlaping ( Phase A and B signals. ( ( The idea seemed to be to do the generation with two timers, each ( timing out and toggling an output in the middle of the other timers ( time span. Seems fine for a steady state after the thing was rolling. ( But for a dynamic changing of two timers in synchronization while ( still running..., the idea got murky.

( Then I came up with the idea: one timer that times out four times as ( often. get to the timer each time before it times out ( change the output mode to toggle a different pin. ( but you don't get to assign output pins, so that wouldn't work. ( While interrupts could be used at time out to do a software toggle ( of pins the latency would determine how accurately the phases ( changed.however, this wouldn't be fine enough for a "perfect" ( wave.

( Instead, using four timers could create perfect form waves, to 25ns ( anyway One timer is needed to do prescaling to bring the ( quadrature down to reasonable rates, say milliseconds. Then ( another timer is set to count how many of these ticks pass per ( phase. Two other timers count this output. These two timers ( have repetitive counts to 2, and are set off by one count. ( They toggle their outputs each time out.

( USE ( 0 PRESCALER ! ( 0 COUNTER ! ( GIVES 2.5 MHz OUTPUT ( DECIMAL ( 40000 1- PRESCALER ! ( 50000 1- COUNTER ! ( GIVES .0012 Hz OUTPUT

So I was successful in making any quadrature output rate I wanted from

2.5MHz down to hundreds of seconds per cycle.

HTH's with some ideas at least.

Reply to
Randy M. Dumse

Thanks Randy, It was really helpful.I have now succesfully (using dsPIc30f2010)generated 2 signals A and B from 2 output compares at 1MHZ which are 90 degress phase shifted to each other.I was also able to generate these 2 signals A and B at different phases.But now i am facing a different problem .I know that these quad signals are used to produce information about postion,direction and velocity.But i want to know how to make these quad signals to gives us the inofrmation abt postion,direction and velocity.can anybody help me out Many Thanks Regards Sandeep

Reply to
Sandeep

You don't have a hardware way of decoding quadrature signals? This is surprising. The dsPIC doesn't have a built in quadrature counter?

On the IsoPod(TM) DSP there are two built in quadrature counters. Then any common group pair of the 14 timers can also be set to count quadrature.

If you don't have hardware counting on the chip, reading quadrature at

1MHz and above will be difficult.

Basically, to decode quadrature, you build a little state machine. Later I'll describe the states and the transitions of the signal pair, but first I'll just mention you could make a quadrature encoder by placing two half disks on a shaft, and running each disk through a photo interrupter. The half disks should be 90 degrees rotated from each other if the photo interrupters are side by side. Alternatively, you could use one disk and two photo interrupters mounted 90 degrees to each other.

Sitting that way, the edge of the half disk would be in one encoder at a time. The other encoder would be completely in the middle of the part of the disk that was opaque, or completel in the middle of the part of the disk that was transparent. So while one photo interrupter might be changing, the other was solidly one way of the other.

The idea with quadrature to measure rotation is that only one phase will be changing at one time. So you can tell very well direction and speed.

Look at this sequence below. What does it mean?

00000001001010101101110111101111110111111111111

If you have a single signal, you can't tell if the shaft is jittering or actually turning. Maybe you look at this and think, well the shaft started out slow and speed up and then slowed down again.

But if you have a second signal, you can tell for sure whats going on. If the second signal looks like this.

A 00000001001010101101110111101111110111111111111 B 11111111111111111111111111111111111111111111111

Oh! with quadrature you can say, well, clearly that's just a transition point on the A phase, and the shaft really isn't moving much at all. A did make a single solid transition from 0 to 1, so we can see a little movement.

If following the above we see

A 11111111111111111111111111111111111111111111111

B 11111101111010101101110111101111110111111111111

Now we can see there is some noise on B, but no actual transition in the end. Later

A 11111111111111111111111111111111111111111111111

B 11110111101110110111011110111111000101100000000

There we see B make it past the transition point and settle to a zero, so we continue to see slow rotation in the same direction.

Notice when quadrature is done right, one phase is stable, while the other phase is changing, so noise on the edge of the change does not cause a false count. This is why quadrature is so useful for counting position reliably.

Now let me show a simpler situation of fast rotation with no noise.

000011110000111100001111000011110000111100001111 110000111100001111000011110000111100001111000011

Here's what it looks like going the opposite way.

000011110000111100001111000011110000111100001111 001111000011110000111100001111000011110000111100

Now let me extract only the state changes in a cycle going the first direction

0011 and repeat 1001

and the other

0011 and repeat 0110

So the state pairs proceed

0,1 > 0,0 > 1,0 > 11 ...

or

0,0 > 0,1 > 11 > 1,0 ...

0.0 > 1,1 and 1,1 > 0,0 is prohibited by mechanical construction..

So let's say your sitting with both phases (A,B) at zero. Since only one phase can change at a time, you either go to 0,1 or 1,0. By which one, you know which direction the shaft is turning.

So quadrature gives direction, but the order the phases transition, and eliminates false readings where you don't know which direction a pulse goes. Step and direction isn't as secure when the direction changes, and counts are often misinterpreted, so absolute positiion is lost.

Now, if you take a snapshot of how many counts you have at some time, and another snapshot a fixed time later, you know velocity. So c2 - c1 is the count difference, t2 - t1 is the time interval. So c2 - c1 / t2 - t1 is the velocity. This comparing of counts at time intervals is called differencing and is the basis of the calculus principle "taking a derivative. Do the same thing again to the velocity, and you will have acceleration. v2 - v1 / t2 - t1 is acceleration.

So there. From quadrature count, given a known period, you can get position, and by change in position to time, velocity, and by change of velocity, acceleration. You can know a great deal about the motion from following quadrature over time.

I hope that helps, and I didn't just explain the obvious, but it seemed to be what you were asking, how quadrature gave position velocity and direction on only two wires.

Reply to
Randy M. Dumse

thanks a lot randy

Reply to
Sandeep

PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.