Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

LOGIC in a Micro-controller

Status
Not open for further replies.

shom_show

New Member
I am facing a problem regarding the implementation of LOGIC in a Micro-controller. It is as follows -

Suppose I have two ports name PORT1 and PORT2. Now the ports status will change by the following way:-


PORT1 PORT2 COMMENT

5 V or Logic1 5 V or Logic1 Initial condition

0 V or Logic0 5 V or Logic1 Timer Start

0 V or Logic0 0 V or Logic0 Timer Stop

Now the time gap between timer start and timer stop will be in nano-second range. I want to display this time delay on a display device. This will be done one time. It will

not be done in a continuous manner. If need another experiment will perform manually by pressing power on/off switch or pressing reset button. Please find the logic

diagram in the attachment. Please send me your valuable suggestion (any device that makes it easy to attain the objective) at the earliest.

Thanking You.
 
Last edited by a moderator:
the time gap between timer start and timer stop will be in nano-second range. I want to display this time delay on a display device.
That's a heck of a jump from the '1ms to 10 sec' in your original post!
What micro are you hoping to use to measure such brief periods?
 
That's a heck of a jump from the '1ms to 10 sec' in your original post!
What micro are you hoping to use to measure such brief periods?
You are replying to a high-jacked post. ;)
 
You want to trigger on a negative going transition to start a timer and trigger on the next negative going transition to stop the timer. With a good high end frequency counter this is not a problem. However, I do not know of any PIC that is capable of accurately measuring 1 nano second. Doesn't mean it doesn't exist, just I do not know of one. You are looking at 1 GHz.

Ron
 
You are replying to a high-jacked post.
Oh, yes. Silly me!

New Thread Created.
Moderation
E
 
Last edited by a moderator:
As Realoadron stated you will need a very high frequency counter to measure in the ns range. A 1GHz counter will give 1ns resolution. You use one signal to start the counter and the other signal to stop the counter. You can then read the counter value to determine the difference in ns.

Of course 1Gz counters are not trivial to make. The require careful layout on a multilayer PCB using very high speed logic, possibly with stripline traces. And, of course you need a 1GHz digital clock source.
 
I think I'd do this mostly in the analogue domain. At the start of the timed period start charging a cap at constant charge current. At the end of the period stop the charging. Measure the cap voltage (proportional to the period) at leisure using an A/D converter. No need for ultra-fast counters/clocks.
 
I think I'd do this mostly in the analogue domain. At the start of the timed period start charging a cap at constant charge current. At the end of the period stop the charging. Measure the cap voltage (proportional to the period) at leisure using an A/D converter. No need for ultra-fast counters/clocks.

Not a bad idea. Use the pulse to charge a 100pF cap via a low resistor, a voltage follower using a Pico input op-amp (TLC271) and measure the voltage direct. Use a decent FET (pico amps off drain current) to the ground the cap after measuring. You may still need a very high speed buffer (NE5539 is fast but there maybe better now).

If you are using a micro, then you don't need a constant current generator. Just calculate using the RC charge of a cap. V(t)=Vpulse * (1 - e^t/RC). You need to re-arrange to get 't'. Even if you cannot get decent components, you can characterise what you do have.
 
I think I'd do this mostly in the analogue domain. At the start of the timed period start charging a cap at constant charge current. At the end of the period stop the charging. Measure the cap voltage (proportional to the period) at leisure using an A/D converter. No need for ultra-fast counters/clocks.

The CTMU module in some PIC controllers have this function with a current source so the voltage rise is linear. http://ww1.microchip.com/downloads/en/DeviceDoc/70635A.pdf

A touch controller demo with a PIC18F46K22.
https://www.flickr.com/photos/nsaspook/sets/72157628477730187/show/
 
Last edited:
CTMU time ns measurement in a fiber-optic cable system tester.

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

Time measurement ISR code.
Code:
#pragma interrupt high_handler				// the TIMER is first in the sequence, then the CTMU and finally the ADC to read the data
void high_handler (void)
{
	static	unsigned char	show_raw=DISPLAY_RAW, BASELINE=FALSE;		// baseline calibration timer delay
	static	unsigned int	i=0,delay_meas=0,delay_cal=0;				// CTMU cap charge voltages

        if ( INTCONbits.TMR0IF) {							// check timer0, setup CTMU for charging
			CTMUCONHbits.EDGEN=0;							// edges are blocked
			LEDR=1;											// light link xmit is connected to LEDR (active low)										// 
			CTMUCONHbits.CTMUEN = 1; 						// Enable the CTMU
			CTMUCONHbits.IDISSEN = 0; 						// end drain of touch circuit
			CTMUCONL = CTMU_REGL;							// reset CTMU flags
			CTMUCONHbits.EDGSEQEN=1;						// edge 1 then 2 for interrupt
			TIME_CHARGE=TRUE;								// set charging flag
			CTMU_WORKING=TRUE;								// set working flag, doing 
       		WriteTimer0 (TIMERCHARGE_BASE_X10);				// set timer to charge rate time
			CTMUCONHbits.EDGEN=1;							// edges are not blocked
			LEDR = 0; 										// Begin charging the touch circuit (xmit led on)
        		INTCONbits.TMR0IF = 0; 							// clear TIMER interrupt flag
		}

		if (PIR3bits.CTMUIF) {								// the current source has been on and then turned off by the edge detect inputs
			CTMUCONHbits.EDGEN=0;							// edges are blocked
			LEDR=1;											// xmit is off
			TIME_CHARGE=FALSE;								// clear charging flag
			CTMU_WORKING=TRUE;								// set working flag, doing touch ADC conversion
			// configure ADC for next reading
			ADCON0bits.GO=1; 								// and begin A/D conv, will set adc int flag when done.
			PIR3bits.CTMUIF=0;								// clear CTMU interrupt flag
		}

		if (PIR1bits.ADIF) {								// check ADC irq
			if (!BASELINE) {
				delay_cal=ADRES;							// baseline voltage
				if (++i > BASE_WAIT) {
					BASELINE=TRUE;
					LEDB=1;									// calibration complete LED
				}
			} else {										// get current measurement
				if (ADRES>delay_cal) {						// only show longer delays
					delay_meas=ADRES-delay_cal;				// find the diff from the 1M cable 5ns baseline measurement
				}
				C.raw=ADRES;								// load the C structure with delay data
				C.base=delay_cal;
				C.result=delay_meas;
				CTMU_ADC_UPDATED=TRUE;						// New data set is in C structure, set to FALSE in main program flow
				if (!show_raw) {		
					LATC=~delay_meas; 
					LATD=~delay_meas;
				}
			}
			if (show_raw) {
				LATC=~ADRES;
				LATD=~ADRES;
			};
			CTMU_WORKING=FALSE;									// clear working flag, ok to read timer3 counter.
			LEDR = 1; 											// Set xmit off
			// config CTMU for next reading
			CTMUCONHbits.IDISSEN = 1; 							// drain charge on the circuit
       		WriteTimer0 ( TIMERDISCHARGE );						// set timer to discharge rate
			PIR1bits.ADIF = 0; 									// clear ADC int flag
		}
}
 
Last edited:
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top