Searching \ for '[PIC]:Success with 16f628 conversion - ADC Update' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/ios.htm?key=adc
Search entire site for: 'Success with 16f628 conversion - ADC Update'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]:Success with 16f628 conversion - ADC Update '
2003\02\02@074251 by michael brown

picon face
On Saturday 01 February 2003 07:58 am, you wrote:

> I am attempting to read the value of a pot. using the 628's
> comparator and a TMR0 loop to sample the voltage at an R/C junction
> and compare that to the voltage at the wiper of the pot.  The
> comparator output is then fed to the R/C time constant thru the R and
> also "added" to a counter.  This, AIUI, PWM's the R/C creating a
> matching voltage accross the capacitor.  Every 256 loops, the counter
> is copied and cleared. Hopefully, this all results in a feedback loop
> that works to give me an 8 bit value representing the wiper position
> of the pot.  ;-)   If all goes well, I should have that working
> today.

Some quick details:  TMR0 is generating 2560 ints/sec.  I am using 256 itterations of the loop to come up with one pseudo AD conversion, therefore ten samples second.

Well, I got it all working now, more or less.  It seems to work pretty well until the pot is positioned near the extremes (supply rails).  The voltage generated on the cap deviates from the voltage on the pot wiper.  I don't understand why this is happening.  The voltage on the cap is stable, but it doesn't exactly match the voltage coming from the pot.  It can be off by as much as 300mV.  How can this be?  Does the comparator have funny characteristics when one input (this case the -) is near Vdd or ground?  It's as if the comparator actually thinks that 4.7V on the + input is the same as 4.99V on the -.

I'm using the mode with just one comparator enabled (101)  The datasheet says that when the + input is less than the - input, the comparator output will be low, but I seem to be getting a high output from the comparator when at the above listed conditions.  I'm fairly sure that the code is working correctly as it perfectly tracks the pot voltage until you push to the extremes.  If you get the comparator logic backwards, it doesn't even remotely work.  ;-D  When I turn the pot away from the extremes the system immediately begins tracking correctly again.  Could the problem be due to trying to charge a cap to extremely low or high values?  Should I just put extra resistors "around" the pot to keep the voltage in a more narrow range?

I played around with the R/C components some, and found that they seem to be able to be varied quite a bit and still work.  Anything from a 1K to 47K resistor with a 1uF to 22uF cap.  Larger values give a smoother voltage (less ripple) on the cap, but make the system slow to respond and it tends to overshoot the correct value for a second or so.  But then I'm sure that many of you guys already knew that.  ;-)

michael

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2003\02\02@082310 by Roman Black

flavicon
face
michael brown wrote:
>
> On Saturday 01 February 2003 07:58 am, you wrote:
>
> > I am attempting to read the value of a pot. using the 628's
> > comparator and a TMR0 loop to sample the voltage at an R/C junction
> > and compare that to the voltage at the wiper of the pot.

> Well, I got it all working now, more or less.  It seems to work pretty
> well until the pot is positioned near the extremes (supply rails).  The
> voltage generated on the cap deviates from the voltage on the pot
> wiper.  I don't understand why this is happening.  The voltage on the
> cap is stable, but it doesn't exactly match the voltage coming from the
> pot.  It can be off by as much as 300mV.


The PIC output PWM etc cannot go to the rail voltages.
There is about 0.3v to 0.8v sat, depedning on current,
so a PIC pin "low" will be about 0.3v.

Try adding a resistor above and below the pot, so
the pot wiper voltage varies from 0.5v to 4.5v full
scale, then compensate in software. :o)
-Roman

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2003\02\02@111359 by michael brown

picon face
On Sunday 02 February 2003 07:14 am, you wrote:
{Quote hidden}

I put the resistors in and it's now acting much more cooperatively.  ;-)  The pot is 10K so I used 2.0K  resistors to push the pot about .6V away from the rails.  I determined this value thru experimenting with 1K - 2K resistors.  (you should see my resistor collection, that I bought surplus.  I didn't know they even manufactured some of these values ;-)

Of course my readings are not from 0 to 255 anymore.  :-(  But they are more consistent and very repeatable.  I have to smooth the numbers out anyway still, so I will deal with scaling the reading in software while I do the rest.  BTW, it "appears" that the comparator is not comfortable with inputs coming within about .3V of the supply rails.  
Question:  Is the comparator really the problem, or is it that I'm trying to regulate (PWM) the voltage on the capacitor too close to the supply limits?  BTW, I'm not using any hardware PWM, it's all done in software using TMR0 interrupts to regularly (every 400us) look at the comparator output and toggle charge/discharge line to the cap/resistor.  Would it make any improvement on the higher voltage regulation to sample more often?

The datasheet makes an ambiguous reference about coming within .6V "either way" of the supply lines.  They are specifically mentioning internal protection diodes, so I would have /assumed/ that they meant exceeding the supply limits and not just approaching them, but that's not generally a good thing to do.  ;-)

Thanks for the input, this has really been an educational experience that didn't involve an inordinate amount of pain.  ;-)  I had always assumed that *basic* PID control would be much harder to implement.  Of course I understand that *real world* PID control would/can be much more difficult especially with large, slow reacting systems.  For example if you were checking paint color consistancy by analyzing sample photographs of painted walls, you prolly wouldn't want to make instantaneous large adjustments in your color mixing based on one sample.  ;-D

michael

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2003\02\02@182857 by

flavicon
face
Think of an external op-amp as comparator.

I you'd like to run it from a single 5V supply,
and expecting input levels "rail-to-rail", you
have to use an op-amp of the "rail-to-rail" variant
where that specific capability is documented.

Nowhere in the PIC docs does it say that the internal
op-amp is of the "rail-to-rail" type, so I wouldn't
expect it to be either...

Jan-Erik Söderholm.


michael brown wrote :
> BTW, it "appears" that the comparator is not
> comfortable with inputs coming within about .3V
> of the supply rails.  
--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2003\02\02@183800 by Spehro Pefhany

picon face
At 12:24 AM 2/3/2003 +0100, you wrote:

>Nowhere in the PIC docs does it say that the internal
>op-amp is of the "rail-to-rail" type, so I wouldn't
>expect it to be either...

Eh? The capability is quite clearly indicated in the electrical
specifications as parameter D301.

Best regards,

Spehro Pefhany --"it's the network..."            "The Journey is the reward"
spam_OUTspeffTakeThisOuTspaminterlog.com             Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog  Info for designers:  http://www.speff.com

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2003\02\02@185435 by

flavicon
face
Param D301 says "Input common mode voltage = 0 to VDD-1.5",
does that qualify as "rail-to-rail"  ?

If so, I'm sorry, I'v missunderstod that term.

(It also says in a note "These parameters are characterized but
not tested.")

Jan-Erik Söderholm.

Spehro Pefhany wrote :

>>Nowhere in the PIC docs does it say that the internal
>>op-amp is of the "rail-to-rail" type, so I wouldn't
>>expect it to be either...
>
>Eh? The capability is quite clearly indicated in the electrical
>specifications as parameter D301.
>
>Best regards,

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2003\02\02@190301 by Spehro Pefhany

picon face
At 12:48 AM 2/3/2003 +0100, you wrote:
>Param D301 says "Input common mode voltage = 0 to VDD-1.5",
>does that qualify as "rail-to-rail"  ?
>
>If so, I'm sorry, I'v missunderstod that term.

No, it means that it *should* work to the lower rail (like
a "single supply" comparator/op-amp), but possibly won't work
above Vdd -1.5V on the inputs. It does
NOT say what happens when you go outside this CM range- the
comparator may not work correctly at all, though usually
comparators work properly when at least one input is within
the CM range (ignoring substrate current phase reversal on
bipolar comparators such as the LM393 when inputs go below 0).

>(It also says in a note "These parameters are characterized but
>not tested.")

Yes, it does, so it might be prudent to allow a bit more safety
margin, and not to try to work right up to the edges of the 0...Vdd-1.5V
common mode range.

Best regards,

Spehro Pefhany --"it's the network..."            "The Journey is the reward"
.....speffKILLspamspam@spam@interlog.com             Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog  Info for designers:  http://www.speff.com

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2003\02\02@191742 by michael brown

picon face
On Sunday 02 February 2003 05:36 pm, you wrote:
> At 12:24 AM 2/3/2003 +0100, you wrote:
> >Nowhere in the PIC docs does it say that the internal
> >op-amp is of the "rail-to-rail" type, so I wouldn't
> >expect it to be either...
>
> Eh? The capability is quite clearly indicated in the electrical
> specifications as parameter D301.

Why do you suppose I'm having trouble using it near the rails.  Once I get within about .4V of Vcc (or is it Vdd?...whatever....the positive supply ;-) my comparator contolled PWM charger runs all the way up to 5V with the comparator (apparently) not seeing that the voltage is getting too high.  Same thing when you drop below about .3V above ground.  The PWM simply drops all the way to zero volts.  Between those extremes, the PWM developed voltage tracks the wiper voltage with great precision.
I'm wondering if I'm experiencing trouble because I'm testing the comparator too infrequently (2500hz).  Do you have any tips on this?  Right now, I'm using a 4k7 (4.7k) resistor and a 1uF cap for my low pass filter to the comparator input.  I really don't have much of a clue on matching my R/C time constant to the sampling rate.  I can say that putting 2k resistors on outer pot terminals makes it work fine since I'm not coming close to the rails.  If I was having some kind of latch-up issue, could it begin working again by just lowering the voltage on the input, or would I have to power cycle to un-freeze it?

michael brown

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2003\02\02@192409 by michael brown
picon face
On Sunday 02 February 2003 06:01 pm, you wrote:
> At 12:48 AM 2/3/2003 +0100, you wrote:
> >Param D301 says "Input common mode voltage = 0 to VDD-1.5",
> >does that qualify as "rail-to-rail"  ?
> >
> >If so, I'm sorry, I'v missunderstod that term.
>
> No, it means that it *should* work to the lower rail (like
> a "single supply" comparator/op-amp), but possibly won't work
> above Vdd -1.5V on the inputs. It does

Hmm....it doesn't like things below 300mV.

> NOT say what happens when you go outside this CM range- the
> comparator may not work correctly at all, though usually
> comparators work properly when at least one input is within
> the CM range (ignoring substrate current phase reversal on
> bipolar comparators such as the LM393 when inputs go below 0).
>
> >(It also says in a note "These parameters are characterized but
> >not tested.")

They should try it sometime, they might be surprised.  ;-)

> Yes, it does, so it might be prudent to allow a bit more safety
> margin, and not to try to work right up to the edges of the
> 0...Vdd-1.5V common mode range.

Hmm again....I think I will use a bigger resistor on the + side of the pot.  Even though it's working fairly well right now (good enough for the application), the high side is still consistantly a little off (about 30mV max) though it is still tracking it.  Most of the tracking range is accurate to about 1mV.

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2003\02\02@195114 by Olin Lathrop

face picon face
> Param D301 says "Input common mode voltage = 0 to VDD-1.5",
> does that qualify as "rail-to-rail"  ?

No, it means the inputs work down to the negative rail, but not up to the
positive rail.


*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2003\02\02@221942 by Roman Black

flavicon
face
michael brown wrote:

> > No, it means that it *should* work to the lower rail (like
> > a "single supply" comparator/op-amp), but possibly won't work
> > above Vdd -1.5V on the inputs. It does
>
> Hmm....it doesn't like things below 300mV.


I did post an answer yesterday, the problem is NOT the
comparator, it's the fact that you are doing successive
approximation using a PIC OUTPUT pin! The output pin
is not capable of going rail to rail, there is a sat
voltage loss of 0.3v to 0.8v or so depending on current
and which PIC and which type of output, TTL or ST.
-Roman

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2003\02\02@222405 by Spehro Pefhany

picon face
At 02:04 PM 2/3/2003 +1100, you wrote:


>I did post an answer yesterday, the problem is NOT the
>comparator, it's the fact that you are doing successive
>approximation using a PIC OUTPUT pin! The output pin
>is not capable of going rail to rail, there is a sat
>voltage loss of 0.3v to 0.8v or so depending on current
>and which PIC and which type of output, TTL or ST.

I don't know his circuit, but the outputs of a PIC should swing to within
a few millivolts of either rail if not loaded- and there's no such thing
as a ST output.

Best regards,

Spehro Pefhany --"it's the network..."            "The Journey is the reward"
speffspamKILLspaminterlog.com             Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog  Info for designers:  http://www.speff.com

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2003\02\02@225924 by Roman Black

flavicon
face
Spehro Pefhany wrote:
>
> At 02:04 PM 2/3/2003 +1100, you wrote:
>
> >I did post an answer yesterday, the problem is NOT the
> >comparator, it's the fact that you are doing successive
> >approximation using a PIC OUTPUT pin! The output pin
> >is not capable of going rail to rail, there is a sat
> >voltage loss of 0.3v to 0.8v or so depending on current
> >and which PIC and which type of output, TTL or ST.
>
> I don't know his circuit, but the outputs of a PIC should swing to within
> a few millivolts of either rail if not loaded- and there's no such thing
> as a ST output.


Sorry, that should have been TTL or CMOS. :o)
A PIC output set to low will go close to 0v, IF
there is something to pull it down, but not if it
is held by a cap etc. There is no mechanism to sink
current to drain the cap, unless you include the
cap leakage. Likewise at the high end the PIC can
only source current to *around* 4.5v or so, these
specs are clearly described in the datasheet.
-Roman

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2003\02\02@233933 by Spehro Pefhany

picon face
At 02:49 PM 2/3/2003 +1100, you wrote:


>Sorry, that should have been TTL or CMOS. :o)
>A PIC output set to low will go close to 0v, IF
>there is something to pull it down, but not if it
>is held by a cap etc. There is no mechanism to sink
>current to drain the cap, unless you include the
>cap leakage. Likewise at the high end the PIC can
>only source current to *around* 4.5v or so, these
>specs are clearly described in the datasheet.

Not true, Roman. The outputs look like a low-value resistor to Vdd or Vss,
with a tiny bit of leakage from the opposing MOSFET. Of course if there
is a lot of current flowing through the Vdd or Vss pin, there may be some
offset, but we're talking tens of mV at worst.

See, for example, the curves in the 16F87x datasheet.

Best regards,

Spehro Pefhany --"it's the network..."            "The Journey is the reward"
.....speffKILLspamspam.....interlog.com             Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog  Info for designers:  http://www.speff.com

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2003\02\03@020050 by Roman Black

flavicon
face
My apologies, I just looked up the graph and you are
correct; at minute currents the PIC output pins will
approach 0v and 5v. Since I always drive outputs at
least a few mA I was used to the sat voltage gap.
:o)
-Roman



Spehro Pefhany wrote:
{Quote hidden}

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.

2003\02\03@055854 by michael brown

picon face
On Sunday 02 February 2003 09:22 pm, you wrote:
> At 02:04 PM 2/3/2003 +1100, you wrote:
> >I did post an answer yesterday, the problem is NOT the
> >comparator, it's the fact that you are doing successive
> >approximation using a PIC OUTPUT pin! The output pin
> >is not capable of going rail to rail, there is a sat
> >voltage loss of 0.3v to 0.8v or so depending on current
> >and which PIC and which type of output, TTL or ST.
>
> I don't know his circuit, but the outputs of a PIC should swing to
> within a few millivolts of either rail if not loaded- and there's no
> such thing as a ST output.

I believe that Roman is misunderstanding my problem.  I'm not having trouble with the output voltage of the PIC, that's working as expected.  At the bottom of this message is an ascii-art schematic, use a fixed width font to view.

I have RA3 (output) connected thru a 4.7K resistor to a 1uF cap.  One comparator input is connected to the junction of the resistor and the cap, to monitor the DC charge present.  There is no further load on that part of the circuit.  
RA3 is used to charge/discharge the cap based upon feedback from the comparator.  RA3 has no trouble pushing the cap voltage to very near 5 volts, nor does it have any problem lowering the cap voltage to almost zero.  IOW, I'm not having any trouble getting rail to rail voltages out of the pic pin for charging the cap thru the resistor.

The other comparator input is connected to a pot wiper.  When the pot wiper's voltage is below 300mV, the comparator seems to percieve that as being less than the other input which is almost 0V.  This causes my program to stop charging the cap completely, by not turning on RA3 at all, even though the comparator output should be a 1.  It's as if the comparator can't handle the inputs being driven near the rail voltages.  
If the pot wiper is above about 4.5 volts, the opposite problem occurs.  The cap voltage suddenly increases to 5V as my program (which simply copies the comparator output to RA3 starts writing nothing but ones to the pin, apparently never seeing the fact that RA2 is now < RA1.  The datasheet does say that I should keep the input below 3.5V (Vdd - 1.5V), but it also says that I should be able to go to the lower rail.

If I were using a revision A chip, would it be marked with an actual letter 'A'?  The chip I'm using is not so marked.

Here is some ugly ascii art of the schematic.  Obviously it has been simplified for my convenience, but it shows all the components of the feedback loop.

+5V     |-------------
|       V            |            16F628
|____/\/\/\/\___     |         __________________
               |    |___RA2__| Comp +   Comp - |___RA1___
      10K      V             |                 |        |
              Gnd     __RA3__| Charge Pin      |        |
                      |      |                 |        |
                      |      |_________________|        |
                      |                                 |
                      |                _________________|
                      |                |
                      |____/\/\/\/\____|___|(______
                                                  |
                             4.7K         1uF     V
                                                 Gnd

Thanks for any advice you may have.

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.

2003\02\03@061818 by Jinx

face picon face
> The other comparator input is connected to a pot wiper

Is the pot > 10k and greater than the recommended source
impedance ? Have you tried a 4k7 ? Maybe there's a little
crosstalk between RA2 and RA3 as RA3 switches

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.

2003\02\03@084036 by Spehro Pefhany

picon face
At 05:50 PM 2/3/2003 +1100, you wrote:
>My apologies, I just looked up the graph and you are
>correct; at minute currents the PIC output pins will
>approach 0v and 5v. Since I always drive outputs at
>least a few mA I was used to the sat voltage gap.

No problem. It's a common characteristic of all CMOS outputs. The nice
thing is that you can get a fairly precise DC voltage with just a passive
filter on a PIC's PWM output pin. Even better if you buffer it with a
cheap CMOS inverter running off a separate reference supply.

Best regards,

Spehro Pefhany --"it's the network..."            "The Journey is the reward"
EraseMEspeffspam_OUTspamTakeThisOuTinterlog.com             Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog  Info for designers:  http://www.speff.com

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.

2003\02\03@153259 by Peter L. Peres

picon face
On Sun, 2 Feb 2003, Spehro Pefhany wrote:

*>I don't know his circuit, but the outputs of a PIC should swing to within
*>a few millivolts of either rail if not loaded- and there's no such thing
*>as a ST output.

They do, to within better than 5mV when measured with a high Z dvm. To be
able to rely on this keep the Iout under 100uA. This is easy (50k circuit
impedance at 5V). But check before using this info.

Peter

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.

More... (looser matching)
- Last day of these posts
- In 2003 , 2004 only
- Today
- New search...