Reading a clocked input at the right time

matherp

Senior Member
Sorry the title isn't very clear but I will try and explain the problem.

I am using the picaxe to generate a 5Khz square wave using pwm. This is used to energise the primary, via a series tuned circuit, of a rotary variable differential transformer. This is a device for measuring angles. It works very simply by allowing the transformer's secondary coil to rotate relative to the primary so when they are at right angles the output is zero. When they are parallel the output is maximum and the output varies between the two. Because of the series tuned circuit on the primary the output is a sine wave and depending on the relative positions the output will be either in phase or out of phase with the input - I need to know this as it defines the quadrant. The problem is to detect whether the output is in phase or out of phase with the input. The magnitude of the output is read using a precision rectifier circuit, RC smoothing and the picaxe ADC.

The transformer output can be fed into a comparator to generate a VCC square wave and this connected to one of the picaxe input pins. The problem is that when I read the pin which I will want to do at about 50HZ I want to be sure that the pwm output is somewhere in the middle of the high part of the output waveform, then I know the input is valid.

My thinking at the moment is to use the pwm output separately into an RC circuit with a time constant of about 1/(5K * 4) seconds and use this delayed signal as the clock input to a 74HC74 latch with the comparator output as the data input to the latch. The output of the latch would then feed to the picaxe input and could be read safely at any time.

I think this works (comments welcome) but requires many extra components. The picaxe 20X2 and 28X2 have built in comparators, built in SR latch and it feels like hpwm should be able to create a staggered pair of clocks to both drive the output and clock the latch but I can't get my head around how to do this. Alternatively could I use the PWM output as an SPI clock input and the comparator as the SDI data? There must be a way of using all that lovely PIC hardware.

All ideas and suggestions welcome

best Regards

Peter
 

g6ejd

Senior Member
It looks like your already on the right track, as I recall you can use two 7474 latches cross coupled and fed with your clock and the phase to be measured, the result is a quadrant output indicator from the two data/Q outputs, the only problem is I don't recall how to cross couple the two d-type flip-flops. It is a form of digital phase-lock loop or the phase-comparator part thereof.
 
Last edited:

hippy

Technical Support
Staff member
Can't you generate the PWM, interrupt on the rising edge, pause, then read the input ?
 

matherp

Senior Member
Hippy

I don't think even at 64Mhz a picaxe is fast enough to allow the processing to take place within the 100us window while the pulse is high - the output has to be at 5KHZ to match the serial tuned circuit in the transformer

rgds

Peter
 

hippy

Technical Support
Staff member
It's not necessarily speed but accuracy and resolution. A 1100us delay for example from PWM going high will still allow a mid PWM reading, and PAUSEUS will allow very fine adjustment at 64MHz.

The following samples between the top line pulses. Probably needs some work doing but okay as a proof of concept ...

Code:
#Picaxe 20X2
#No_Data
#No_Table

SetFreq M64

PwmOut PWMDIV16, C.5, 199, 400 ' 5kHz

Gosub Interrupt_Enable:
Do:Loop

Interrupt:
  PauseUs 105
  PulsOut C.0, 1
  b0 = pinC.5
  PulsOut C.0, 1
Interrupt_Enable:
  Do:Loop While pinC.5=0
  SetInt %00000000, %00100000
  Return
 

Attachments

g6ejd

Senior Member
TPFD.gif

FYI - 2 x 7474 and 1 NAND gate gets you a digital PLL showing phase between the two signals.
 
Top