CTMU for time measurement calibration

Thread Starter

Tera-Scale

Joined Jan 1, 2011
164
Hi,
I have been experimenting a lot with the PIC24F16KA102 for measuring accurately a period at nanosecond resolution.

I managed to get current calibration up an d running with very good values. I used the 55µA mode with 30K 0.1% resistance to produce 70% of full scale 2.5V as suggested in the application note.

Now I am trying to do capacitance calibration. I am starting from the smallest value of time to give to the A/D internal cap to charge and gradually increase the time and plot a graph. At first there seems to be a cap charging graph but at times, the value is totally distorted and totally goes out of the way. When I simulate it with proteus I get good values all the way. With MPLAB SIM the 5 transients for the A/D cap to charge up to approx. 1.65V, the stop watch showed 184µs. The code is below and the schematic is attached. The CTMUI is infact the voltage across the resistance not the current.
LCD 4-bit PIC24.png

Did anyone try something like and can give me some tips? Or even maybe there is a particular pic that is preferred when it comes to time measurement with the ctmu. (if it is possible to eliminate these factors)
 
Last edited:

nsaspook

Joined Aug 27, 2009
13,306
I've looked at the app note code but I'm not sure what result you're looking for as the time delay for a few pF of internal and stray capacitance will be small (62us for 70% of vdd at 15pF).

I have some simple demo code for PIC18 CTMU time measurements. It's the base code for a fiber-optic cable checker that looks for changes in fiber (ns scale) delays as a sign of signal loss. I don't bother with internal calibration but use a standard 1M plastic cable as the quality standard on startup.

Links to some videos of the CTMU response to ns delays caused by poor connections or bad cables. The floor model will have a PIC18F25K22.

http://www.flickr.com//photos/nsaspook/sets/72157629114207524/show/
 

Attachments

Thread Starter

Tera-Scale

Joined Jan 1, 2011
164
thanks a lot for the example, I will look into and it will be a lot of help for me.

Two questions about the CTMU:

I saw that the current source was disabled by an external input in CED1 or CED2. I also need to start the current source from an external input is this possible? I will be measuring a frequency so I will start current source on rising edge and stop it on falling edge for example.

My period may be long so I need to use ctmu in the first clock cycle, and then use it again in the last clock cyle. Then add the time of the ctmu in the first and subtract the last. How do you think is the best way to takle it ?
 

nsaspook

Joined Aug 27, 2009
13,306
thanks a lot for the example, I will look into and it will be a lot of help for me.

Two questions about the CTMU:

I saw that the current source was disabled by an external input in CED1 or CED2. I also need to start the current source from an external input is this possible? I will be measuring a frequency so I will start current source on rising edge and stop it on falling edge for example.

My period may be long so I need to use ctmu in the first clock cycle, and then use it again in the last clock cycle. Then add the time of the ctmu in the first and subtract the last. How do you think is the best way to tackle it ?
The current source was started and stopped by the external inputs as the program just switches a port low to start the measurement process. The CTED1 input pin is also connected (PCB jumper) to the port output pin that drives the link transmitter. The link receiver data output (HIGH with no signal) is connected to CED2. Both inputs are normally high so the current source is off (CTED1 is HIGH and CTED2 is HIGH), when the output port drops low to turn-on the transmitter led the current source starts (CTED1 is LOW and CTED2 is HIGH). The signal travels from the link transmitter led, into the link cable, into the link receiver driving the CTED2 input LOW causing the current source to stop (CTED1 and CTED2 are LOW) and trigger a CTMU interrupt (1 to 2 sequence bit is also set) to measure the voltage on the pin that was charged from the current source during the time the CTED inputs were mismatched.

The baseline delay with a 1M cable (about 5ns from the cable) is about 50ns total (slow transceivers). I have longer 5M cables to calibrate the ADC voltage change (time per ADC step at ~1mV per step using the 1.024v internal reference) from the baseline cable.

Ch1 is CED1, Ch2 is CED2.


I'm not sure about your clock cycle question.
 

Attachments

Last edited:

nsaspook

Joined Aug 27, 2009
13,306
A quick take on your problem:

To measure the signal start/stop edge with the next clock edge might need some external glue to make it work. (uC selected normal/invert XOR signal to CTED1, gated AND clock pulses to CTED2) If the clock is stable and we know it's time period is regular then we need to convert the clock rising and falling edges to edge detect pulses. The clock edges need to be gated by the CTED1 signal so they only change on the CTED2 input when the signal is active or (if inverted) inactive. The glue gate delays can be accounted for in the program.

The timer/ctmu interrupt ISR code can read the ADC result from the first CTMU measurement and setup the gates for the second measurement trigger. I hope this gives you some ideas and whatever this is for is worth the effort.
 

Attachments

Last edited:

nsaspook

Joined Aug 27, 2009
13,306
What is it you need to measure exactly to calculate? Is it the frequency of the clock (time between rising edge to rising edge)
 

Avalanche

Joined Mar 21, 2012
7
What is it you need to measure exactly to calculate? Is it the frequency of the clock (time between rising edge to rising edge)
Sorry to hijack this thread. But I'm in the same boat as the OP and want to measure the just about the same thing that is the time of Fin except that in my case Fin would not be a single pulse but a frequency so I would need to measure the time between consecutive rising edges of Fin.

But I have no Idea how to generate the edge signals to the CTMU. I was hoping to trigger the edge signals using the internal modules rather than external edge signals that would save the glue logic if possible.

The chip that I'm using supports (apart from the CTED1 and CTED2 pins)
Edge1 input source from --> OC1 or Timer1 module
Edge2 input source from --> CMP1 or OC1 or IC1 module

TIA
 

Thread Starter

Tera-Scale

Joined Jan 1, 2011
164
Oh sry for the delay but I was confused because at the same time there was another person on another forum and I was helping him.

What frequency do you want to measure.. range etc.. ? You can use just CTED1 for measuring Time period T. It depends what do you want to measure exactly?
 

Avalanche

Joined Mar 21, 2012
7
Oh sry for the delay but I was confused because at the same time there was another person on another forum and I was helping him.

What frequency do you want to measure.. range etc.. ? You can use just CTED1 for measuring Time period T. It depends what do you want to measure exactly?
frequency to be measured is 5khz to 10khz range.
Yes I need to measure the period so how to generate the required start stop on CTED1 and CTED2.
You say that I can only use CTED1, do you mean that I can just short CTED1 and CTED2 and connect the Fin to those pins?
 

Avalanche

Joined Mar 21, 2012
7
Oh sry for the delay but I was confused because at the same time there was another person on another forum and I was helping him.

What frequency do you want to measure.. range etc.. ? You can use just CTED1 for measuring Time period T. It depends what do you want to measure exactly?
Tera-Scaaaaaaaaaaaaaaale!!!!
 

Avalanche

Joined Mar 21, 2012
7
Have read this app note by microchip?

http://ww1.microchip.com/downloads/en/DeviceDoc/70661B.pdf

If I were you I would have a look at the forum rules. Nonone would help with your attitude ;).
Thanks for the document. I had read it earlier may be I need to revisit it. It might give me some clues. :)
And as for me acting kiddish I'm sorry for that kind of behavior. Maybe I have to climb my own mountain :p

I appreciate your replies.
Million Thanks.
 

Thread Starter

Tera-Scale

Joined Jan 1, 2011
164
It's oki. Yes sometimes you need to climb your own mountain to learn.
Have you start experimenting yet with the chip? Have you started some simple debugging with MPLAB to get familiar?

First get the calibration parts to work.(current and capacitance). In the app note codes, it disables the CTMU. Do not disable it in the setup function. Instead of CTMUCON = 0x1090 , just put CTMUCON = 0x0090
 

Avalanche

Joined Mar 21, 2012
7
It's oki. Yes sometimes you need to climb your own mountain to learn.
Have you start experimenting yet with the chip? Have you started some simple debugging with MPLAB to get familiar?

First get the calibration parts to work.(current and capacitance). In the app note codes, it disables the CTMU. Do not disable it in the setup function. Instead of CTMUCON = 0x1090 , just put CTMUCON = 0x0090
Hello TeraScale,
During calibration is it mandatory to place the calibration resistor on AN2 or can I use any other channel?
I have already used up AN2 in my circuit.

Regards,
A
 

Thread Starter

Tera-Scale

Joined Jan 1, 2011
164
You can use any analog channel an0, an1 , 4, 8.. etc. Just be sure to configure the correct channel selection in the setup by AD1CHS.

The current calibration has to be on a seperate analog channel then the capacitance calibration! .. and you will need to call two different setup functions.
 
Top