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.
Thanks Mike for the valuable suggestions.

The only thing I am concerned about is that in the datasheet it states that source impedance should be somewhere 2k-10k Ohms. If I connect a resistor across the cap will it have any affect on it??

Many many thanks Mike!

Vili

Ps: Mike-The schematic I have attached has the circuitry which you have suggested. I was wondering if I need to connect one end of the capacitor to ground or just leave it connected to the resistor [without the ground]?:confused:
 
Last edited:
You have to connect the ground or it will not work. As for input impedance, a little explanation of why it has to be low may help you understand. When you select the channel you want to convert a small capacitor (120pF) is connected to your signal. This capacitor has to charge up and the time it takes to charge is dependent on the resistance of your outside circuit. As you have a nice large capacitor outside the internal capacitor charges very quickly and so external resistance (in this case) is not a concern.

Mike.
 
Thanks a million Mike. That explains everything!

I am going to build the circuit now and will keep you posted about the progress.

Many many thanks Mike.

Vili
 
Hi,
The source impedance should be kept as low as possible. Check the datasheet under Electrical Characteristics, there's maximum recommended source impedance but no minimum. If it's too high, the acquisition time required is longer.
 
Hi,
Counter and Counter+1 are the general purpose registers used to count the time delay different between two signals.
As Pommie mentioned, each increment of counter indicates the delay difference of 10 us.
 
Hi,
Thanks for the reply. I am still confused about how to test whether the PIC is giving me the correct output or not? I mean is there any way to send the counter values to the LEDs and check the ans??

Many thanks in advance.

Vili
 
Hi,
Just take whatever in the counter and put it into say PORTB. Then you'll see what's the value in the counter.
 
Hi,
Why do you put 0xff into those registers (count) in the beginning? You can't show the value of two 8-bit registers on one 8-bit PORT. Maybe you can try two PORTs or use a button to switch between them.
 
How are you programming your chip? If you are using a PicKit2 or ICD2 then you can simply pause it and look at the contents of count. Alternatively, as suggested by bananasiong, you could toggle between the two values. If you feel ambitious then you could dump it to EEPROM and read it in your programmer.

From your earlier question, count should be defined as 2 bytes by doing,
Code:
	cblock
Count:2
	endc

Mike.
 
Dear Mike and bananasiong,
Thanks a million again for your kind replies.

I feel so bad asking all these stupid questions and also feel that I am getting on your nerves. I sincerely thank you for being so patient with me.

Why do you put 0xff into those registers (count) in the beginning?

The things which is making me confused is the use of "Count". I read Nigel's tutorial where he defined a Count register and placed 0xff values to it.
Here I am getting confused whether this Count and Count+1 will require the same settings or not?

That's the reason I used 0xff to both Count and Count+1.

Mike- as you have kindly suggested to use
Code:
cblock Count:2 endc
. I am right in assuming that Count will be a 16 bit register and hence we don't need another Count+1 register in the code any more?

Many thanks guys.

Vili

<Edit> Ps: Mike- I am using ICD2 for the programming. :)
 
Last edited:
You still need the count+1 part of the code as Pics can only access 1 byte at a time. If you are using ICD2 then you can set it up as a debugger and pause it to look at count. Use the watch window and add Count to it then set the properties to 16 bit and decimal.

Mike.
P.S. There are no stupid questions.
 
vili.chaudhary said:
The things which is making me confused is the use of "Count". I read Nigel's tutorial where he defined a Count register and placed 0xff values to it.
Here I am getting confused whether this Count and Count+1 will require the same settings or not?

The initial value is simply set to what you need it to be, in my case I wanted it to be 0xFF - so I used that value.

Really it depends what a variable is being used for - if it's a register which is NEVER read before it's written to, then you don't need to initialise it at all. Otherwise, your initial write to it initialises it - you shouldn't read any GPR unless it's been written to previously, when the PIC powers up they have undetermined contents.
 
Brilliant idea Mike. Cheers!

Mike- Will it be correct if I use two registers [8 bit each] as per in the code, Count and Count +1 rather than just defining Count:2?
It sounds less confusing to me [I apologise for that].


Many thanks again.

vili

Ps:
In your case, just clear the registers initially. Since you're going to count by incrementing them.
Thanks bananasiong, it finally went into my head! Many thanks for that!
 
vili.chaudhary said:
Mike- Will it be correct if I use two registers [8 bit each] as per in the code, Count and Count +1 rather than just defining Count:2?
It sounds less confusing to me [I apologise for that].

You can define them anyway that makes sense to you.
You may be more comfortable calling them CountLo and CountHi and defining them as,
Code:
	cblock
CountLo
CountHi
	endc

The important thing is that the location after count is not used by some other variable.

Mike.
 
Mike- I honestly don't have words to thank you for providing me this valuable guidance. [ and thanks to all of you guys for your kind replies].

I am just leaving for my department and I am going to try and use this code in a couple of hours. I am so exited about this:D .

Mike, I am going to use a signal generator [setting it to a squarewave output] and am planning to use a T-junction hence one signal will always be the reference and the other one will have some form of delay [using a cap and resistor]. I am going to display say CountHi on PORTC and CountLo on PORTD.
What value should I expect on these ports if I use say 90 deg phase difference signals??

Knowing that we have signals of 1ms period, and the maximum phase would be 360 deg. How exactly will the calculations work??

Many many thanks in advance.

Vili
 
As your signals are at 1kHz then the maximum phase difference would be 1mS - when signal 2 is lagging signal 1 by 359 degrees. As count gets incremented every 10uS then the maximum value would be 100. Whoops, maybe we should have done this calculation before as it is now clear that count+1 will always be zero. If you need better resolution then there are ways to achieve it, the easiest being to use a 20MHz crystal, the max value then would be 400.

Mike.
 
Thanks again Mike for the brilliant reply.

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??

For my specification, I can afford upto +or- 5 deg error :D .

many many thanks Mike!

Vili
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top