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.

**UPDATE/CHANGED**Reading analogue value of A/D convertor with PIC 16F877A. Need Help

Status
Not open for further replies.
vili.chaudhary said:
So am I right in assuming that we have a resolution of 3.6 deg per count?
Hence for every 1 count the error will be 3.6 deg??

Correct, as long as you are running your pic at 4MHz.

Mike.
 
Dear Mike,
I'm indebted to you for all these valuable suggestions. I am off to the lab to perform this test :D. I will definitely keep you posted on how I perform!

Many many many thanks MIKE :) .

Vili
 
Dear Mike,

I tried using the code with two TTL 4V squarewave inputs with ZERO phase difference and I was expecting ZERO on the output but the output values are very confusing.:(

I am displaying CountHo value on PORTC and CountLo value on PORTD.
The values I am getting are:
PORTC Pin 0-7 : 2.35 V
PORTD pin 0-3 :2.35 , pin 4,5 : 0V and pin 6,7 : 0-2.3 V


Many thanks.
Vili
 
Last edited:
A phase difference of zero is also a phase difference of 360° and the way the code works, it will return 360°.

You have a couple of things wrong with the code. The counter needs to be zeroed at the start of the main loop. You have CountHi and CountLo switched around. The reason your seeing strange values is because they are rapidly changing from 1 to 0 and your meter is averaging them.
Code:
Main
[COLOR="Blue"]	clrf	CountLo
	clrf	CountHi[/COLOR]
WaitSignal0
	btfsc	PORTA,0		;wait for signal 1 to be low
	goto	WaitSignal0
WaitSignal1  
	btfss	PORTA,0		;wait for signal 1 to go high
	goto	WaitSignal1
		
TimeSignal0	
	btfss	PORTA,1		;is signal 2 low
	goto	WaitEdge	;yes, go wait for rising edge
	incf	Count[COLOR="blue"]Lo[/COLOR],f	;no so count
	btfsc	STATUS,Z	;is there a carry
	incf	Count[COLOR="blue"]Hi[/COLOR],f	;yes, inc high byte
	nop			;waste 1 cycle
	goto	$+1		;waste 2 cycles
	goto	TimeSignal0	;loop arnd - total time = 10 cycles

WaitEdge
	btfsc	PORTA,1		;is signal 2 high
	goto	GotTime		;yes, so were done
	incf	Count[COLOR="blue"]Lo[/COLOR],f	;as above
	btfsc	STATUS,Z
	incf	Count[COLOR="blue"]Hi[/COLOR],f
	nop
	goto	$+1
	goto	WaitEdge

GotTime
	movf	CountHi,W
	movwf	PORTC
	movf	CountLo,W
	movwf	PORTD
	goto	Main

The CountLo/Hi being swapped would not effect the working of the code. It's just a little confusing.

Mike.
 
Hi Pommie,
He has the registers cleared in his code ;)

Hi Vili,
Do you have any current limiting resistors with the LEDs? That weird voltage reading maybe is because of the voltage drop across the LED.
 
Mikeeeeee !!!!!!:D It finally worked.

I am so grateful for all your advice.

I got 100 in binary at the output which means a 360 deg phase.

The only thing I am stuck with is on how to introduce a delay using a cap and resistor? I have tried using the different values but it doesn't give any delay!

I am so so thankful for all your help Mike.

Many thanks.

Ps: Thanks bananasiong for bringing the LEDs resistor values into my knowledge. i am using 470 ohm resistors across LEDs.
 
Hi,
For the delay, maybe you can try this (I haven't tried before):
a simple RC low pass filter, and the phase shift is atan of the ratio of the input frequency to the cut off frequency.
Since your input frequency is 1 kHz, maybe you can try a low pass filter with the cut off frequency of 500 Hz, then the phase shift will be 63.43 degree.

*EDITED calculation.
 
Last edited:
Congratulations.

If you use something like a 5k resistor and a 1uF capacitor you should get a delay of a few mS but your amplitude will roughly half. If you increase the capacitance then the delay will increase but your amplitude will further decrease. With a 10uF capacitor your phase shift will be nearly 90° but your amplitude will be a tenth of the incoming signal. You could also invert the signal to get a 180° phase shift.

If your wondering where I got these figures, it was using switchercad available free from Linear Technology.

Mike.
 
Hi Mike,

I have just tried using a 1uF cap and a 4.7k ohm resistor but I am always getting the same values at the output LEDs [360 deg]

[My setting is: source--> 1uF cap in series--> and then 4.7kOhm resistor at the load]

As soon as I am replacing the 1uF cap with 1nF, the LEDs start blinking in a random pattern. I don't know how to introduce a delay now. It’s giving me either 360 deg or random values whenever I am trying to change the cap. :(

I am very much struggling now.

Please help!

Many thanks.
Vili
 
You should have the resistor from your signal to the pic pin and the capacitor from pic to ground.

Mike.
 
Status
Not open for further replies.

Latest threads

Back
Top