Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Thread Tools Display Modes
Old 10th August 2007, 01:55 PM   (permalink)
Default

Oh, I was simply pointing out that you were correct and my 22K resistor was way over the limit! I realize that it will vary from PIC to PIC, but at least I have learned and know to check the datasheet in the future. I'm happy -- the day is young and I've already learned something new today!

I'm going to go change it and see what kind of results I get.
Kyle-s4h is offline   Reply With Quote
Old 10th August 2007, 01:59 PM   (permalink)
Default

Quote:
Originally Posted by Kyle-s4h
@Nigel -- page 114 of the 16f87X datasheet;



Thank you -- I will change the resistor (actually, I'll change it a couple of times... ie. 12K, 10K, 2K, 1K, just to see the results).
The 10k ohms limit is required to meet the pin leakage specification.
The equivalent resistance 'seen' by the analog input should be as low as possible. You can change the external resistor, but not those inside the lock. The solution is to use an op amp, wired as a voltage follower, to feed the A/D converter.
eng1 is offline   Reply With Quote
Old 10th August 2007, 02:13 PM   (permalink)
Default

Quote:
Originally Posted by eng1
The 10k ohms limit is required to meet the pin leakage specification.
The equivalent resistance 'seen' by the analog input should be as low as possible. You can change the external resistor, but not those inside the lock. The solution is to use an op amp, wired as a voltage follower, to feed the A/D converter.
Interesting -- I did a quick read on op-amps -- they'll definitely require more reading than I have time for right now!

A question would be -- is that really needed though? If I put a 1K resistor in place of the 22K, with my top resistance reading from the keypad of 7.53K, that would still keep my under the total 10K limit (8.53K), no?

So, without knowing a whole lot about op amps, it seems to me that replacing the 1K resistor with an op amp would only save me 1K of resistance (seeing as I cannot change the resistors in the keypad). Am I confused?
Kyle-s4h is offline   Reply With Quote
Old 10th August 2007, 02:19 PM   (permalink)
Default

Quote:
Originally Posted by kyle-s4h
The thing that I have noticed that is strange is the fact that I am only using the ADRESH byte for my calculations. I just got up and have not looked at the datasheet or midrange manual regarding A/D Conversion, but I was under the impression that the high byte should only contain the first 2 LSB, with the upper 6 clear. Nigels tutorial even masks the upper 6 bits to make sure they are clear. Anyway, what I am seeing is a consistent LOW byte (either C0/00 or 80/40) and a HIGH byte that is unique (but using more than the first two bits).
While reading the datasheet on A/D Conversion, I also noted a "left" and "right" justification for the A/D results -- the default is left justified, which is what I am using. This, to me, makes the above statement make sense -- if I am understanding this correctly.

When set to left justify, I am using ALL bits of the HIGH byte, and only the 2 MSB of the LOW byte -- correct? That would explain why I only get two readings from the LOW byte (C0 & 80) and all readings for the HIGH byte are different (as posted above).
Kyle-s4h is offline   Reply With Quote
Old 10th August 2007, 02:28 PM   (permalink)
Default

Quote:
Originally Posted by Kyle-s4h
A question would be -- is that really needed though? If I put a 1K resistor in place of the 22K, with my top resistance reading from the keypad of 7.53K, that would still keep my under the total 10K limit (8.53K), no?
The limit for proper operation of the A/D converter is about 2k ohms, as mentioned. Anything lower is better. The op amp provides a low output impedance, in the order of hundreds of ohms.


Quote:
Originally Posted by Kyle-s4h
So, without knowing a whole lot about op amps, it seems to me that replacing the 1K resistor with an op amp would only save me 1K of resistance (seeing as I cannot change the resistors in the keypad). Am I confused?
Not exactly a replacement. You can still use the external resistor, if required, but it shouldn't be too high or the maximum voltage that appears at the ADC input is far less than 5 V.
eng1 is offline   Reply With Quote
Old 10th August 2007, 02:32 PM   (permalink)
Default

Quote:
Originally Posted by Kyle-s4h
I'm going to go change it and see what kind of results I get.
Sorry but wrong again
First calculate what you can expect then change it.

I suppose the values you posted earlier are kOhm.
Then I suggest using 8.2 kOhm serie resistor and like eng1 already suggested a opamp with a gain of 2.
Serie resistor & lock resistors feed from 5V same as Vref of the PIC

That way you get the following results:

Key Voltage ADC bits Hex
# 0 0.000 000 0000
# 1 0.604 123 007B
# 2 1.050 215 00D7
# 3 1.495 306 0132
# 4 1.976 404 0194
# 5 2.472 506 01FA
# 6 2.997 613 0265
# 7 3.564 729 02D9
# 8 4.130 845 034D
# 9 4.787 980 03D4

Like you see no tricky "either C0/00 or 80/40" stuff (what I call weird hex data) only streight forward data from 0000 to almost 0400 (1024)

If you get other readings than these with this setup your PIC code is wrong

You're welcome.

Last edited by mcs51mc; 10th August 2007 at 02:41 PM.
mcs51mc is offline   Reply With Quote
Old 10th August 2007, 02:39 PM   (permalink)
Default

Quote:
Originally Posted by Kyle-s4h
Interesting -- I did a quick read on op-amps -- they'll definitely require more reading than I have time for right now!
Off topic and with many
Typical sales man talk.
Sell a "bad" product now and an upgrade later on.
That's twice $$$$$$
mcs51mc is offline   Reply With Quote
Old 10th August 2007, 02:40 PM   (permalink)
Default

You are correct about the left justification of the ADC result. This is user configurable but after PIC reset, it defaults to left justify on the 16F873.

You should make provisions for your key value comparison routine because you have not taken into account the two LSBs. So a value of 0x05 in ADRESH could means 0XC0 or 0x00 in the ADRESL register. If you test for equality of 0x05 for a particular key, then by some drifts later the value of ADRESL increased or decreased by one bit, your ADRESH will increment/decrement, becoming 0x06 or 0x04. Your routine will then fail to return the correct key value.
__________________
L.Chung
eblc1388 is offline   Reply With Quote
Old 10th August 2007, 02:48 PM   (permalink)
Default

Quote:
Originally Posted by eng1
The limit for proper operation of the A/D converter is about 2k ohms, as mentioned. Anything lower is better. The op amp provides a low output impedance, in the order of hundreds of ohms.
Man, I really don't want to sound stupid here... but is this 2K limit for "proper operation" just something "you have to know", or am I not following you? I mean, the datasheet for the 16F87X says the limit is 10K (as I stated above).

Page 114 of the datasheet (Figure 11-2) shows an analog input model -- Ric shows a resistor of 1K or less between the sampling switch and the input pin (I am not actually using it BETWEEN, I have it wired as a pull up)... and it also shows a 5pF cap between the input pin and Vss. That would work, and probably better. I have a 0.1 cap on the power rail near the ADC input, but not actually on it. The whole point to the resistor was simply to provide protection against a direct short on initialization -- the cap would do that. It would provide a constant power supply to the ADC input and protect against a direct short, no?
Kyle-s4h is offline   Reply With Quote
Old 10th August 2007, 02:50 PM   (permalink)
Default

Quote:
Originally Posted by mcs51mc
Off topic and with many
Typical sales man talk.
Sell a "bad" product now and an upgrade later on.
That's twice $$$$$$

LOL! Not what I was thinking! I am a service tech and pride myself on having a callback rate of as near to zero as one could hope for. I like to do the job once -- and correctly at that!

I only meant "at this particular minute" -- I usually print stuff like this out and put it beside my La-Z-boy for later perusal!

Last edited by Kyle-s4h; 10th August 2007 at 02:58 PM.
Kyle-s4h is offline   Reply With Quote
Old 10th August 2007, 02:53 PM   (permalink)
Default

Quote:
Originally Posted by eblc1388
You are correct about the left justification of the ADC result. This is user configurable but after PIC reset, it defaults to left justify on the 16F873.

You should make provisions for your key value comparison routine because you have not taken into account the two LSBs. So a value of 0x05 in ADRESH could means 0XC0 or 0x00 in the ADRESL register. If you test for equality of 0x05 for a particular key, then by some drifts later the value of ADRESL increased or decreased by one bit, your ADRESH will increment/decrement, becoming 0x06 or 0x04. Your routine will then fail to return the correct key value.
Awesome, thanks!

I have taken into account the "drift" (I think I mentioned it above) -- I am going to finish up the routine this morning (well, that was the plan before we started the 22K resistor talk! ) and will post it later. Basically, it grabs the key ADC value from a LUT and then subtracts 2 and sets the "low range", then it adds 4 and sets the "high range", giving me -2 and +2 ( 4 number range) to compare against.

Button one, for example is dec 5 -- so my range would be 3-7... button two is dec 10 and would be 8-12, etc. I think that should take care of any noise issues.

Last edited by Kyle-s4h; 10th August 2007 at 02:56 PM.
Kyle-s4h is offline   Reply With Quote
Old 10th August 2007, 03:06 PM   (permalink)
Default

Quote:
Originally Posted by Kyle-s4h
Page 114 of the datasheet (Figure 11-2) shows an analog input model -- Ric shows a resistor of 1K or less between the sampling switch and the input pin (I am not actually using it BETWEEN, I have it wired as a pull up)... and it also shows a 5pF cap between the input pin and Vss. That would work, and probably better. I have a 0.1 cap on the power rail near the ADC input, but not actually on it. The whole point to the resistor was simply to provide protection against a direct short on initialization -- the cap would do that. It would provide a constant power supply to the ADC input and protect against a direct short, no?
Reading this and looking at that picture I think you are wrong in the way that all that is on the right side of the ANx pin is INSIDE the PIC so don't worry about that, you have it.

Your application is on the left side of the ANx pin thus only VA and Rs in that picture.

The circuit represented in the dotted line is different for every design.
Yours is a 8k2 resisitor in serie with your key pad between +5V and GND. The connection between the 8k2 and the key pad is also connected to the PIC ADC pin preferably with an opamp with a gain of 2 in between .
mcs51mc is offline   Reply With Quote
Old 10th August 2007, 03:30 PM   (permalink)
Default

Ah! I understand you -- thanks!

I found out on my own that it doesn't work by creating a direct short! (It's not too bad with the Inchworm+ and Unicorn USB upgrade though... it simply creates an unknown USB device on any short... delete the device, do a reboot and you're good to go!)

I am going to do some reading on op amps later today and will probably go that route as it has been suggested by the pros! For now, I'm going to go stick a 1K in and see what changes -- if for nothing else than to understand what the different resistor values do to the ADC.

I have learned SO MUCH this morning -- thank you to all who have replied!
Kyle-s4h is offline   Reply With Quote
Old 10th August 2007, 04:19 PM   (permalink)
Default

Quote:
Originally Posted by Kyle-s4h
Basically, it grabs the key ADC value from a LUT and then subtracts 2 and sets the "low range", then it adds 4 and sets the "high range", giving me -2 and +2 ( 4 number range) to compare against.
I'm a lazy guy and all these calculation is too much "work" for me or the PIC.

I would just use the ADRESH result as an index to a lookup table which give me "5" for ADRESH=4,5 or 6.

I think a +1 margin each side of the intended value is adequate and sufficient but certainly there is no harm going for a +2 margin.
__________________
L.Chung
eblc1388 is offline   Reply With Quote
Old 10th August 2007, 04:27 PM   (permalink)
Default

Hmmm... never thought of it that way -- but unless I am not quite understanding what you are saying, my LUT would be huge. Using the posted values above, I would need 66 indices as my largest number is 65 ,plus one on the high side.

Compounding that would be the fact that I just went down to a 1K resistor, which provides bigger steps, but also a bigger range (0 - 226). This would mean I would need 227 indices?
Kyle-s4h is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Latest
Analog Meter windozeuser General Electronics Chat 19 3rd October 2007 02:44 PM
A/D, value for Vref on PICs for best accuracy. Odin Micro Controllers 12 19th June 2007 03:04 AM
help on A/D conversion on pic18F2620 lionman Micro Controllers 0 15th May 2007 03:28 PM
A/D problem Merkur Micro Controllers 8 3rd February 2007 10:35 AM
Specifications Applied Caltech General Electronics Chat 1 25th December 2003 05:00 PM



All times are GMT. The time now is 10:09 AM.


Electronic Circuits  |  Electronics Wiki
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.