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.
You can do this without using timers.

Here's some code to get you started. It assumes the signals are on Portb bits 0 and 1. Counter (16 bit) will end up with a value which is the time difference. It is in units of 10 cycles. If your processor is running at 1MHz (4MHz crystal) then the count is the number of 10uS periods.

Mike.
Code:
		clr	Count		;clear our 16 bit counter
		clr	Count+1
WaitSignal0	btfsc	PORTB,0		;wait for signal 1 to be low
		goto	WaitSignal0
WaitSignal1	btfss	PORTB,0		;wait for signal 1 to go high
		goto	WaitSignal1
		
TimeSignal0	btfss	PORTB,1		;is signal 2 low
		goto	WaitEdge	;yes, go wait for rising edge
		incf	Count,f		;no so count
		btfsc	STATUS,Z	;is there a carry
		incf	Count+1,f	;yes, inc high byte
		nop			;waste 1 cycle
		goto	$+1		;waste 2 cycles
		goto	TimeSignal0	;loop around - total time = 10 cycles

WaitEdge	btfsc	PORTB,1		;is signal 2 high
		goto	GotTime		;yes, so were done
		incf	Count,f		;as above
		btfsc	STATUS,Z
		incf	Count+1,f
		nop
		goto	$+1
		goto	WaitEdge

GotTime
 
Dear Mike,

Thank you so so much again. You always save me :)

I will read the counter part from the datasheet and will compile your suggested code. I will keep you posted on how it's going.

Many many thanks again Mike.

Vili.

Ps: You Rock!!
 
Hi,
Can you show your schematic? 1 V across the diode will drop become 0.3 V. Half wave filtering the 0.3 V will become almost nothing IMO.
 
Hi,
Thanks for your replies.

Can you show your schematic? 1 V across the diode will drop become 0.3 V. Half wave filtering the 0.3 V will become almost nothing IMO.

I am using a germanium diode which has a drop of .3 V and the voltage of my signal before rectification is 1.3. Thus 1V pk signal to the PIC.


For potentiometer at 1V how many leds you can see on PORTC?

I am getting the value 51 in binary on the LEDs [using a potentiometer] but am getting 255 [i.e. 5V] when I apply the same pk 1V signal which is rectified and converted to DC. I am all confused about this.

Many thanks
 
Hi Mike,

Can you measure the voltage on the pic pin.

The voltage on each PORTC pin is 4.85V

Mike- Do you suggest this code will work on the DC coming out from my circuitry?:confused:

Many many thanks in advance.

vili
 
Ps : Attached with this post is the schematic of the circuit board. Its on page 23 [Figure A-2].


Many thanks.

Vili
 

Attachments

  • PICDEM_2_Plus_Board_Users_Guide.pdf
    627.2 KB · Views: 457
What is the voltage on the pin with the signal connected? This should be the voltage across your capacitor. If this isn't 1V then we need to see the circuit between your AC signal and the pin.

Mike.
 
Dear Mike,

I have attached a schematic of my AC to DC circuitry. I measured the voltage across the capacitor using a oscilloscope. The voltage measured was 1V.

Many thanks
 

Attachments

  • Circuit.jpg
    Circuit.jpg
    21.5 KB · Views: 222
This makes no sense. If you put a variable voltage on the pin it works correctly but if you put a fixed 1V on the pin it reads as though 5V is on it.:confused:

Mike.
 
Gayan Soyza said:
DId you try taking samples once in a while as I said before.

Yes I did. I increased the delay to 2 seconds and the LEDs started flashing this time. Its basically the same situation.

Ps: Yes Mike it is frustrating :( !
 
Hi all,

Mike- I figured out the problem. There was something wrong in the oscilloscope's reading [Finally my lab technician has fixed it :)].

The code seems to be working fine. When I increase the amplitude of the signal, the corresponding values at PORTC appear to be correct. The only weird thing is that when I increase the input magnitude from 1 to 5 V, sometimes the values are totally wrong. I am assuming that it has something to do with the capacitor and its charging and discharging properties :confused: .

In my circuit, one end of the capacitor is connected to ground and the other end to the PIC [RA0]. Could you please advise if I need some changes in the AC to DC circuitry to overcome this last problem?

Many many thanks in advance.

Vili
 
Your 100uF capacitor is rather large. It may be taking time to charge from your signal. Try changing it for a 1uF. Once charged your capacitor need someway to discharge, try putting a 100k resistor across it. This will allow fast charging and slow discharge. You could also try 0.1uF and 1M but this may be too low for the Pic.

Mike.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top