Generate quadrature clock using P1?
porcupine
Posts: 80
I have been using the Prop for a few years but I still don't understand the counters. For some reason all the docs (like this one: http://www.parallax.com/downloads/an001-propeller-p8x23a-counters) and the explanations in the manual feel very terse to me, hard to comprehend.
I am trying to drive a clock for an HD6309E (Hitachi's version of the MC6809E, where E stands for external clock...) from a Prop. It has two clock inputs, which are to be quadrature clock, with a signal that looks something like this, say: http://www.techlib.com/schmartboard/quadclock.JPG
I can do this with bit twiddling individual pins, and I've done that in C and then in inline asm, but I don't think I'm going to be able to get the 4mhz clock I want this way.
It seems like the clock are made for this kind of thing, but I'm unclear how I would make this happen.
I am trying to drive a clock for an HD6309E (Hitachi's version of the MC6809E, where E stands for external clock...) from a Prop. It has two clock inputs, which are to be quadrature clock, with a signal that looks something like this, say: http://www.techlib.com/schmartboard/quadclock.JPG
I can do this with bit twiddling individual pins, and I've done that in C and then in inline asm, but I don't think I'm going to be able to get the 4mhz clock I want this way.
It seems like the clock are made for this kind of thing, but I'm unclear how I would make this happen.
Comments
Just start a counter to output 4MHz and then synchronize (or just count cycles) to quarter cycle and start another counter the same.
a cog have two counters, to simplify we only refer to counter who's registers ends in A, the second one is the same and have a B instead.
Select both to be NCO mode, that means when the counter is at 2147483648 and up to 4294967295 the pin will be asserted
e.g if last bit31 in PHSA is high=pin is high
Adding 1 to the PHSA counter and it would take 53.68 seconds for a complete toggle (called cycle or Hertz)
So something else have to be done and the solution is that you can tell how much to add to the counter at each Prop tick, a value you store at FRQA.
You want 4MHz and the Prop ticks are at 80Mhz, the math is 4294967296/80*4= 214748365 value to store in FRQA
As you can write and set the counters to a known value before you start them,so set PHSA to (4294967296 /4) and PHSB to 0 should give the two CLKs in the pic (A being the top)
At 80 MHz, there are 20 clock cycles per 4 MHz cycle, and 5 clock cycles per 1/4 4 MHz cycle, so ideally we would want to start the counters (set PHSx to #0) 5 clock cycles apart. An instruction takes 4 clock cycles, so we need to put PHSA one clock cycle ahead to get them synchronized, i.e., set PHSA to 214748365 (as per Tony's calculation above) and PHSB to 0 in the next instruction.
H
I've always thought of quadrature as just a 90° phase shift.
I think 50% duty cycle is kind of implied, but I don't think it is required for the signals to be quadrature.
Bean
50% duty cycle is mostly what is used but not required. As long as the signals overlap enough to meet the logic timing constraints they can be used to determine direction and speed/rpm.
Then again the use here might not be exact and rigid
Just thinking out loud.
H
I'm sure you're right. I'm also fairly sure the term started in the days when this was done with a magnet and two coils mounted at right angles to generate AC waveforms that were 90 degrees out of phase. Did a quick internet search but couldn't find any confirmation of that.
Two square waves 90 degrees out of phase (diagram 1) provides four times the positional precision of the pulses in diagram 2 and twice that of the square waves of diagram 3, although all three can be used for position and speed measurements.
Quad - comes from Latin, where it has the meaning "four, fourth."
rat - from the English word rotate (Edenic Word RATSah)
ure - Middle English, from Anglo-French, from Latin -ura means 'state of','act','process & rank'
So in thinking of a circle ( The rotational aspect ) with reference to Quad and rat, a circle divided into four equal quadrants would yield 90 Degree's per quadrant. Taking into account the entire word 'Quadrature' indicates that we can process the state of each quadrant within a circle. The two signals that are produced are the minimalistic requirements to obtain quadrant information being any two of the four quadrants that are adjacent to one another. In the analog realm the two output signals are sinusoidal in nature where in the digital realm the two output signals represent a 50% duty cycle square wave.
Note: For increased resolution per rotation, an encoder .... optical, magnetic, or mechanical may have several divisions per revolution but the TWO sensors providing a quadrature output will always be positioned 90 deg apart from one another in relation to the pitch of the number divisions per rotation you may have. (See resolver for other methods not using an encoder)