Sign in

username:

password:



Not a member?

Search piclist



Search tips

Subscribe to piclist



piclist by Keywords

12F675 | 16F628 | 16F84 | 16f877 | 16F877A | 16F88 | 18F458 | ADC | AVR | Bootloader | CAN | CCS | CRC | EAGLE | EEPROM | ICD | ICSP | IDE | JDM | LED | Macros | Microchip | MPLAB | PCB-CAD | PIC10F | Pic12f675 | PIC16F84 | PIC16F84A | PIC16F877 | PIC18 | PIC18F452 | PicBasic | PICC | PICSTART | PWM | RS-485 | RS232 | SMT | SPI | UART | USART | USB | Wireless | Wisp628 | Xilinx


Ads

Discussion Groups

See Also

DSPFPGAElectronics

Discussion Groups | Piclist | Selecting resistor values for 3 pb switches on one ADC input pin


Advertise Here

A discussion group for the PICMicro microcontroller. Also called the Microchip PIC, this list is dedicated to the use and abuse of this fine, simple, microcontroller. Close to topic posts are welcome, ie. general electronics.

Selecting resistor values for 3 pb switches on one ADC input pin - ransom peek - Mar 4 13:13:00 2004

Selecting resistor values for 3 pb switches on one ADC input pin

Am trying to read three pushbutton switches with one ADC (16F688) input pin, using voltage divider method, and need help choosing resistor values .  There is a Microchip app note showing use of comparator to read multiple switches (capacitor charge timing), but this seems more complicated from a software standpoint.


                                      R1

                     -------------/\/\/\/\/\-------- +3V (VCC)    

                    |

                    |

                    |

                    |                  R2                                    R3

ADC I/O ----------------------/\/\/\/\/\------------------------------/\/\/\/\/\-------

                    |                                  |                                    |

                    |                                  |                                    |

                     \                                  \                                    \

          SW1     \                      SW2     \                      SW3       \

                    |                                  |                                    |

                    |                                  |                                    |

                 GND                            GND                              GND



The Microchip 16F688 data sheet advises that for the ADC, the maximum recommended impedance for analog sources is 10K ohms.

One (non Microchip) design note recommends that the divider network slices the range into equal sized bins, as follows

:

   BIN SIZE = 2 raised to the # bits in the ADC  /  # keys scanned.

   First choose pull up (R1) resistor value.  Then use formula for the other resistors:

                            10

   So BIN SIZE =  2   /  3 =  1024 / 3  =  341 ohms.

Trade off, I think is lower power usage with higher resistance values, faster conversion speed for lower values.  For my application, will poll the ADC to read one of three pushbuttons (not simultaneous on).

Need minimum power usage, but not sure if the conversion speed makes any difference

So, my best guess is to choose resistors as follows:

    R1 (pullup)  8.2K ohm

    R2  360 ohm  (common value close to 341 ohms)

    R3  360 ohm

So the three possible voltage into the ADC would be:

SW1   0 volts

SW2   [360/(8200+360)] * 3 volts = 0.042 volts                                            

SW3   [720/(8200+720)] * 3 volts = 0.081 volts

                                          

Is this enough differential for reliability and simplified coding?  Shouldnt I try for more differential by increasing R2 and R3, and reducing R1 to keep it all within the 10K ohm limit.  Is the 10k ohm ADC impedance limitation calculated from the ADC pin to VCC (thru R1) or Ground (thru the other resistors)?

I need some help!

One more thing one example I found on the internet shows this kind of design with a 1 nf (nanofarad I assume) cap between the ADC pin and ground.  Other examples do not show this.  Is this important?

Ransom Peek






(You need to be a member of piclist -- send a blank email to piclist-subscribe@yahoogroups.com )


Re: Selecting resistor values for 3 pb switches on one ADC input pin - Chad Russel - Mar 4 19:46:00 2004

Hint: 341 is bits, not ohms. :)

Chad

=====
My software has no bugs. Only undocumented features.

__________________________________



______________________________
Stellaris® MCU Family: New Parts, New Package, New Price.


(You need to be a member of piclist -- send a blank email to piclist-subscribe@yahoogroups.com )

Re: Selecting resistor values for 3 pb switches on one ADC input pin - Chad Russel - Mar 4 21:42:00 2004

Ok. This method will detect one of three switches, but not multiple
presses. That is a little more complicated and requires 9 bins instead
of 3.

Easier for me to look at voltage ratios. With no switches pressed the
input will be VCC and with SW1 pressed the input will be zero volts.
Easy so far? Now the next trick is to evenly divide the two remaining
switches. To make life easy set R1 to 10K, then the input impedance
will always be less than 10K. (I can show you the math to nail that at
10K max if you want.)

Next consider SW3 because that will be both resistors in series and the
next highest voltage which we would like to be 2/3 * Vcc. Make R2 + R3
= RA. Then RA/(R1 + RA) = 2/3 > RA = 20K.

If SW2 is pressed we want a voltage of 1/3 * Vcc > R2/(R1 + R2) = 1/3 >
R2 = R1/2 > R1 = 5K.

R1 + R2 = RA so R2 = 15K.

Check my math.
Chad

--- ransom peek <> wrote:
> Am trying to read three pushbutton switches with one ADC (16F688)
> input
> pin, using voltage divider method, and need help choosing resistor
> values . There is a Microchip app note showing use of comparator to
> read multiple switches (capacitor charge timing), but this seems more
> complicated from a software standpoint. > R1
> -------------/\/\/\/\/\-------- +3V (VCC)
> |
> |
> |
> | R2
> R3
> ADC I/O
>
----------------------/\/\/\/\/\------------------------------/\/\/\/\/\
> -------
> | |
> |
> | |
> |
> \ \
> \
> SW1 \ SW2 \
> SW3 \
> | |
> |
> | |
> |
> GND GND
> GND >
> The Microchip 16F688 data sheet advises that for the ADC, the
> "maximum
> recommended impedance for analog sources is 10K ohms".
>
> One (non - Microchip) design note recommends that the divider network
> slices the range into equal sized "bins", as follows
> :
> BIN SIZE = 2 raised to the # bits in the ADC / # keys scanned.
>
> First choose pull up (R1) resistor value. Then use formula for
> the
> other resistors:
>
> 10
> So BIN SIZE = 2 / 3 = 1024 / 3 = 341 ohms.
>
> Trade off, I think is lower power usage with higher resistance
> values,
> faster conversion speed for lower values. For my application, will
> poll
> the ADC to read one of three pushbuttons (not simultaneous on).
>
> Need minimum power usage, but not sure if the conversion speed makes
> any
> difference
> So, my best guess is to choose resistors as follows:
>
> R1 (pullup) 8.2K ohm
> R2 360 ohm (common value close to 341 ohms)
> R3 360 ohm
>
> So the three possible voltage into the ADC would be:
>
> SW1 0 volts
> SW2 [360/(8200+360)] * 3 volts = 0.042 volts
>
> SW3 [720/(8200+720)] * 3 volts = 0.081 volts
>
> Is this enough differential for reliability and simplified coding?
> Shouldn't I try for more differential by increasing R2 and R3, and
> reducing R1 to keep it all within the 10K ohm limit. Is the 10k ohm
> ADC
> impedance limitation calculated from the ADC pin to VCC (thru R1) or
> Ground (thru the other resistors)?
>
> I need some help!
>
> One more thing - one example I found on the internet shows this kind
> of
> design with a 1 nf (nanofarad I assume) cap between the ADC pin and
> ground. Other examples do not show this. Is this important?
>
> Ransom Peek

=====
My software has no bugs. Only undocumented features.

__________________________________






(You need to be a member of piclist -- send a blank email to piclist-subscribe@yahoogroups.com )

Re: Selecting resistor values for 3 pb switches on one ADC input pin - Dave Mucha - Mar 5 9:08:00 2004

I'm not sure it is this complicated.

Since you listed ADC as your inputs, we'll start there.

The ADC is 10 bit or 1024 discrete steps, change your math if your
ADC is different.

Using a pair of resistors as a voltage divider will yield some value
between 0 and 1024 bits. A pair if same value resistors will yield
512. This is bits input in the uC, but 2.5 volts on the input pin.

If you were looking at one switch, (same sized resistors) you could
look for anything above 256. That would offer a window for the pull
down(up?) resistor to keep the ADC at zero, and the switch to deliver
2.5 volts or 512 bits. Having the threshold at 511 to see 512 would
be a pretty poor choice as any variation in resistances would
possibly alter the actual range. splitting the difference and
looking to see if it is more than half way or less than half way
offers a pretty large window. ie: with half voltage and half ADC
input and half bits in the micro, your threshold to verify the switch
was pressed would be one quarter the range, or mid point between the
signal value and your non-signal value.

Assume 3 switches, all equally rated, say all at 10k ohm, plus the
pulldown(up?) at 10k also. Each would offer 512 when pressed, but 2
pressed at the same time would offer different numbers and 3 pressed
at the same time would also yield a different number. The problem
is you would not know which switch was pressed. Only that one, two
or three switch were pressed.

Select each switch to have a different resistance and then make sure
the added values would wind up being different voltages.

Then, select the mid point between those calculated values as the
toggle point in software.

a 1k, a 3k and a 5k will each offer a different voltage and the 1k
and 3k will yield 4k. So you would have 3 distinct ranges.
to keep the math simple, think 5k as the pull down, and each switch
offers a different input to the ADC.

IMPORTANT => ADD debounce.
a cap would offer a voltage value after the switch is pressed, but
voltage decay would have the voltage passing thru each voltage
range. would make for some odd readings. A SECOND APPROACH

Another input method would be to use an RC to generate pulses that
can be read on an input pin NOT and ADC input.

You can detect switches on an ADC channel or from a RC input as
pulses. That changes the calculations for selection, but not overall
concept.

A CAP is REQUIRES as it is integral to the RC pulse generator that
creates the pulses.

Since it too will degrade and the value will cross other inputs,
consider the time constant and use that in your debounce software. A THIRD APPROACH

When using more than 3 switches, look to a serial input chip that
would see 8 inputs and report via serial back to your uC the status.
Those can be daisy changed for lots and lots and lots of switches.

And for those, you can poll them continuously, or connect it so that
any switch will alert your uC to poll because a switch was pressed. Dave

ps: please feel free to comment on the best approach.





(You need to be a member of piclist -- send a blank email to piclist-subscribe@yahoogroups.com )

16f877 - peter hadge - Mar 5 23:12:00 2004

hi all,
 
if i want to control 8 relays by the 16F877, could i connect these relayes directly to 8 output from the PIC without using any kind of buffers or any other components?
thanx






(You need to be a member of piclist -- send a blank email to piclist-subscribe@yahoogroups.com )

RE: 16f877 - Carlos Marcano - Mar 5 23:43:00 2004

You shouldnt. Better use transistors to drive the relays.
 
Regards,
 
*Carlos*
-----Mensaje original-----
De: peter hadge [mailto:p...@yahoo.com]
Enviado el: Sábado, 06 de Marzo de 2004 12:12 a.m.
Para: p...@yahoogroups.com
Asunto: [piclist] 16f877

hi all,
 
if i want to control 8 relays by the 16F877, could i connect these relayes directly to 8 output from the PIC without using any kind of buffers or any other components?
thanx






(You need to be a member of piclist -- send a blank email to piclist-subscribe@yahoogroups.com )

Re: 16f877 - Chad Russel - Mar 5 23:43:00 2004

Depends on the relay drive requirements. Are they higher or lower than
the PIC is capable of driving. Most likely higher. --- peter hadge <> wrote:
> hi all,
>
> if i want to control 8 relays by the 16F877, could i connect these
> relayes directly to 8 output from the PIC without using any kind of
> buffers or any other components?
> thanx >
>
> ---------------------------------
>
=====
My software has no bugs. Only undocumented features.

__________________________________





(You need to be a member of piclist -- send a blank email to piclist-subscribe@yahoogroups.com )

Re: 16f877 - Phil - Mar 6 2:21:00 2004

Your 5V relay coils are likely to pull 80-100 mA. way too much for
the PIC. check this page out.
<http://ourworld.compuserve.com/homepages/Bill_Bowden/r_ctrl.htm> its
a good summary of how to drive relays. If you are using 5V relays,
you can use option B which doesn't require a resistor. I'm using
2n2222s to drive several 5V relays in my latest project. Dont forget
the diode for each coil as it keeps the smoke in.

By the way, you might also want to look at solid state relays. They
are bit more expensive but dont require the clamping diode or drive
transistor so its less space, a much cleaner layout and a far longer
life cycle. Inexpensive relays are often only spec'd for 100K
operations - cycle 100 times a day and it will last only 3 years.

--- In , peter hadge <pt2263@y...> wrote:
> hi all,
>
> if i want to control 8 relays by the 16F877, could i connect these
relayes directly to 8 output from the PIC without using any kind of
buffers or any other components?
> thanx >
>
> ---------------------------------
>


______________________________
Stellaris® MCU Family: New Parts, New Package, New Price.


(You need to be a member of piclist -- send a blank email to piclist-subscribe@yahoogroups.com )

RE: Selecting resistor values for 3 pb switches on one ADC input pin - ransom peek - Mar 6 11:11:00 2004

Thank you Chad! I will use the 10K, 5K and 20K ohms values as you
advise. You advise that with the pull up resistor at 10k ohms, then the
input impedance will always be less than 10k. Is the input impedance
measured between I/O pin and ground or VCC? Could you kindly show how
the math works for this?

Ransom Peek

-----Original Message-----
From: Chad Russel [mailto:]
Sent: Thursday, March 04, 2004 7:42 PM
To:
Subject: Re: [piclist] Selecting resistor values for 3 pb switches on
one ADC input pin

Ok. This method will detect one of three switches, but not multiple
presses. That is a little more complicated and requires 9 bins instead
of 3.

Easier for me to look at voltage ratios. With no switches pressed the
input will be VCC and with SW1 pressed the input will be zero volts.
Easy so far? Now the next trick is to evenly divide the two remaining
switches. To make life easy set R1 to 10K, then the input impedance
will always be less than 10K. (I can show you the math to nail that at
10K max if you want.)

Next consider SW3 because that will be both resistors in series and the
next highest voltage which we would like to be 2/3 * Vcc. Make R2 + R3
= RA. Then RA/(R1 + RA) = 2/3 > RA = 20K.

If SW2 is pressed we want a voltage of 1/3 * Vcc > R2/(R1 + R2) = 1/3 >
R2 = R1/2 > R1 = 5K.

R1 + R2 = RA so R2 = 15K.

Check my math.
Chad

--- ransom peek <> wrote:
> Am trying to read three pushbutton switches with one ADC (16F688)
> input
> pin, using voltage divider method, and need help choosing resistor
> values . There is a Microchip app note showing use of comparator to
> read multiple switches (capacitor charge timing), but this seems more
> complicated from a software standpoint. > R1
> -------------/\/\/\/\/\-------- +3V (VCC)
> |
> |
> |
> | R2
> R3
> ADC I/O
>
----------------------/\/\/\/\/\------------------------------/\/\/\/\/\
> -------
> | |
> |
> | |
> |
> \ \
> \
> SW1 \ SW2 \
> SW3 \
> | |
> |
> | |
> |
> GND GND
> GND >
> The Microchip 16F688 data sheet advises that for the ADC, the
> "maximum
> recommended impedance for analog sources is 10K ohms".
>
> One (non - Microchip) design note recommends that the divider network
> slices the range into equal sized "bins", as follows
> :
> BIN SIZE = 2 raised to the # bits in the ADC / # keys scanned.
>
> First choose pull up (R1) resistor value. Then use formula for
> the
> other resistors:
>
> 10
> So BIN SIZE = 2 / 3 = 1024 / 3 = 341 ohms.
>
> Trade off, I think is lower power usage with higher resistance
> values,
> faster conversion speed for lower values. For my application, will
> poll
> the ADC to read one of three pushbuttons (not simultaneous on).
>
> Need minimum power usage, but not sure if the conversion speed makes
> any
> difference
> So, my best guess is to choose resistors as follows:
>
> R1 (pullup) 8.2K ohm
> R2 360 ohm (common value close to 341 ohms)
> R3 360 ohm
>
> So the three possible voltage into the ADC would be:
>
> SW1 0 volts
> SW2 [360/(8200+360)] * 3 volts = 0.042 volts
>
> SW3 [720/(8200+720)] * 3 volts = 0.081 volts
>
> Is this enough differential for reliability and simplified coding?
> Shouldn't I try for more differential by increasing R2 and R3, and
> reducing R1 to keep it all within the 10K ohm limit. Is the 10k ohm
> ADC
> impedance limitation calculated from the ADC pin to VCC (thru R1) or
> Ground (thru the other resistors)?
>
> I need some help!
>
> One more thing - one example I found on the internet shows this kind
> of
> design with a 1 nf (nanofarad I assume) cap between the ADC pin and
> ground. Other examples do not show this. Is this important?
>
> Ransom Peek

=====
My software has no bugs. Only undocumented features.

__________________________________ to unsubscribe, go to http://www.yahoogroups.com and follow the
instructions
Yahoo! Groups Links



______________________________
Stellaris® MCU Family: New Parts, New Package, New Price.


(You need to be a member of piclist -- send a blank email to piclist-subscribe@yahoogroups.com )

RE: Selecting resistor values for 3 pb switches on one ADC input pin - Chad Russel - Mar 6 13:12:00 2004

Input impedance is the resistance the input pin sees. Since VCC and
ground are both zero ohms then to either or both. 10K to vcc and 10 K
to ground = output impedance of 5K. Any leakage current has to flow
through the output impedance. The leakage current developes a voltage
which equals an error component. The lower the resistance the lower
the error. The 10K maximum number is just a good rule for the +/- 1.0
ua leakage current which = +/- 10 millivolt error.

Chad

--- ransom peek <> wrote:
> Thank you Chad! I will use the 10K, 5K and 20K ohms values as you
> advise. You advise that with the pull up resistor at 10k ohms, then
> the
> input impedance will always be less than 10k. Is the input impedance
> measured between I/O pin and ground or VCC? Could you kindly show
> how
> the math works for this?
>
> Ransom Peek
>
> -----Original Message-----
> From: Chad Russel [mailto:]
> Sent: Thursday, March 04, 2004 7:42 PM
> To:
> Subject: Re: [piclist] Selecting resistor values for 3 pb switches on
> one ADC input pin
>
> Ok. This method will detect one of three switches, but not multiple
> presses. That is a little more complicated and requires 9 bins
> instead
> of 3.
>
> Easier for me to look at voltage ratios. With no switches pressed
> the
> input will be VCC and with SW1 pressed the input will be zero volts.
> Easy so far? Now the next trick is to evenly divide the two
> remaining
> switches. To make life easy set R1 to 10K, then the input impedance
> will always be less than 10K. (I can show you the math to nail that
> at
> 10K max if you want.)
>
> Next consider SW3 because that will be both resistors in series and
> the
> next highest voltage which we would like to be 2/3 * Vcc. Make R2 +
> R3
> = RA. Then RA/(R1 + RA) = 2/3 > RA = 20K.
>
> If SW2 is pressed we want a voltage of 1/3 * Vcc > R2/(R1 + R2) = 1/3
> >
> R2 = R1/2 > R1 = 5K.
>
> R1 + R2 = RA so R2 = 15K.
>
> Check my math.
> Chad
>
> --- ransom peek <> wrote:
> > Am trying to read three pushbutton switches with one ADC (16F688)
> > input
> > pin, using voltage divider method, and need help choosing resistor
> > values . There is a Microchip app note showing use of comparator
> to
> > read multiple switches (capacitor charge timing), but this seems
> more
> > complicated from a software standpoint.
> >
> >
> > R1
> > -------------/\/\/\/\/\-------- +3V (VCC)
> > |
> > |
> > |
> > | R2
> > R3
> > ADC I/O
> >
>
----------------------/\/\/\/\/\------------------------------/\/\/\/\/\
> > -------
> > | |
> > |
> > | |
> > |
> > \ \
> > \
> > SW1 \ SW2 \
> > SW3 \
> > | |
> > |
> > | |
> > |
> > GND GND
> > GND
> >
> >
> >
> > The Microchip 16F688 data sheet advises that for the ADC, the
> > "maximum
> > recommended impedance for analog sources is 10K ohms".
> >
> > One (non - Microchip) design note recommends that the divider
> network
> > slices the range into equal sized "bins", as follows
> > :
> > BIN SIZE = 2 raised to the # bits in the ADC / # keys scanned.
> >
> > First choose pull up (R1) resistor value. Then use formula for
> > the
> > other resistors:
> >
> > 10
> > So BIN SIZE = 2 / 3 = 1024 / 3 = 341 ohms.
> >
> > Trade off, I think is lower power usage with higher resistance
> > values,
> > faster conversion speed for lower values. For my application, will
> > poll
> > the ADC to read one of three pushbuttons (not simultaneous on).
> >
> > Need minimum power usage, but not sure if the conversion speed
> makes
> > any
> > difference
> > So, my best guess is to choose resistors as follows:
> >
> > R1 (pullup) 8.2K ohm
> > R2 360 ohm (common value close to 341 ohms)
> > R3 360 ohm
> >
> > So the three possible voltage into the ADC would be:
> >
> > SW1 0 volts
> > SW2 [360/(8200+360)] * 3 volts = 0.042 volts
> >
> > SW3 [720/(8200+720)] * 3 volts = 0.081 volts
> >
> > Is this enough differential for reliability and simplified coding?
> > Shouldn't I try for more differential by increasing R2 and R3, and
> > reducing R1 to keep it all within the 10K ohm limit. Is the 10k
> ohm
> > ADC
> > impedance limitation calculated from the ADC pin to VCC (thru R1)
> or
> > Ground (thru the other resistors)?
> >
> > I need some help!
> >
> > One more thing - one example I found on the internet shows this
> kind
> > of
> > design with a 1 nf (nanofarad I assume) cap between the ADC pin and
> > ground. Other examples do not show this. Is this important?
> >
> > Ransom Peek
> >
> >
> >
> >
> > =====
> My software has no bugs. Only undocumented features.
>
> __________________________________ > to unsubscribe, go to http://www.yahoogroups.com and follow the
> instructions
> Yahoo! Groups Links

=====
My software has no bugs. Only undocumented features.

__________________________________






(You need to be a member of piclist -- send a blank email to piclist-subscribe@yahoogroups.com )

RE: Selecting resistor values for 3 pb switches on one ADC input pin - ransom peek - Mar 6 15:25:00 2004

Now I get it - very clear! Thank you!

Ransom -----Original Message-----
From: Chad Russel [mailto:]
Sent: Saturday, March 06, 2004 11:12 AM
To:
Subject: RE: [piclist] Selecting resistor values for 3 pb switches on
one ADC input pin

Input impedance is the resistance the input pin sees. Since VCC and
ground are both zero ohms then to either or both. 10K to vcc and 10 K
to ground = output impedance of 5K. Any leakage current has to flow
through the output impedance. The leakage current developes a voltage
which equals an error component. The lower the resistance the lower
the error. The 10K maximum number is just a good rule for the +/- 1.0
ua leakage current which = +/- 10 millivolt error.

Chad

--- ransom peek <> wrote:
> Thank you Chad! I will use the 10K, 5K and 20K ohms values as you
> advise. You advise that with the pull up resistor at 10k ohms, then
> the
> input impedance will always be less than 10k. Is the input impedance
> measured between I/O pin and ground or VCC? Could you kindly show
> how
> the math works for this?
>
> Ransom Peek
>
> -----Original Message-----
> From: Chad Russel [mailto:]
> Sent: Thursday, March 04, 2004 7:42 PM
> To:
> Subject: Re: [piclist] Selecting resistor values for 3 pb switches on
> one ADC input pin
>
> Ok. This method will detect one of three switches, but not multiple
> presses. That is a little more complicated and requires 9 bins
> instead
> of 3.
>
> Easier for me to look at voltage ratios. With no switches pressed
> the
> input will be VCC and with SW1 pressed the input will be zero volts.
> Easy so far? Now the next trick is to evenly divide the two
> remaining
> switches. To make life easy set R1 to 10K, then the input impedance
> will always be less than 10K. (I can show you the math to nail that
> at
> 10K max if you want.)
>
> Next consider SW3 because that will be both resistors in series and
> the
> next highest voltage which we would like to be 2/3 * Vcc. Make R2 +
> R3
> = RA. Then RA/(R1 + RA) = 2/3 > RA = 20K.
>
> If SW2 is pressed we want a voltage of 1/3 * Vcc > R2/(R1 + R2) = 1/3
> >
> R2 = R1/2 > R1 = 5K.
>
> R1 + R2 = RA so R2 = 15K.
>
> Check my math.
> Chad
>
> --- ransom peek <> wrote:
> > Am trying to read three pushbutton switches with one ADC (16F688)
> > input
> > pin, using voltage divider method, and need help choosing resistor
> > values . There is a Microchip app note showing use of comparator
> to
> > read multiple switches (capacitor charge timing), but this seems
> more
> > complicated from a software standpoint.
> >
> >
> > R1
> > -------------/\/\/\/\/\-------- +3V (VCC)
> > |
> > |
> > |
> > | R2
> > R3
> > ADC I/O
> >
>
----------------------/\/\/\/\/\------------------------------/\/\/\/\/\
> > -------
> > | |
> > |
> > | |
> > |
> > \ \
> > \
> > SW1 \ SW2 \
> > SW3 \
> > | |
> > |
> > | |
> > |
> > GND GND
> > GND
> >
> >
> >
> > The Microchip 16F688 data sheet advises that for the ADC, the
> > "maximum
> > recommended impedance for analog sources is 10K ohms".
> >
> > One (non - Microchip) design note recommends that the divider
> network
> > slices the range into equal sized "bins", as follows
> > :
> > BIN SIZE = 2 raised to the # bits in the ADC / # keys scanned.
> >
> > First choose pull up (R1) resistor value. Then use formula for
> > the
> > other resistors:
> >
> > 10
> > So BIN SIZE = 2 / 3 = 1024 / 3 = 341 ohms.
> >
> > Trade off, I think is lower power usage with higher resistance
> > values,
> > faster conversion speed for lower values. For my application, will
> > poll
> > the ADC to read one of three pushbuttons (not simultaneous on).
> >
> > Need minimum power usage, but not sure if the conversion speed
> makes
> > any
> > difference
> > So, my best guess is to choose resistors as follows:
> >
> > R1 (pullup) 8.2K ohm
> > R2 360 ohm (common value close to 341 ohms)
> > R3 360 ohm
> >
> > So the three possible voltage into the ADC would be:
> >
> > SW1 0 volts
> > SW2 [360/(8200+360)] * 3 volts = 0.042 volts
> >
> > SW3 [720/(8200+720)] * 3 volts = 0.081 volts
> >
> > Is this enough differential for reliability and simplified coding?
> > Shouldn't I try for more differential by increasing R2 and R3, and
> > reducing R1 to keep it all within the 10K ohm limit. Is the 10k
> ohm
> > ADC
> > impedance limitation calculated from the ADC pin to VCC (thru R1)
> or
> > Ground (thru the other resistors)?
> >
> > I need some help!
> >
> > One more thing - one example I found on the internet shows this
> kind
> > of
> > design with a 1 nf (nanofarad I assume) cap between the ADC pin and
> > ground. Other examples do not show this. Is this important?
> >
> > Ransom Peek
> >
> >
> >
> >
> > =====
> My software has no bugs. Only undocumented features.
>
> __________________________________ > to unsubscribe, go to http://www.yahoogroups.com and follow the
> instructions
> Yahoo! Groups Links

=====
My software has no bugs. Only undocumented features.

__________________________________
to unsubscribe, go to http://www.yahoogroups.com and follow the
instructions
Yahoo! Groups Links




(You need to be a member of piclist -- send a blank email to piclist-subscribe@yahoogroups.com )

RE: Re: Selecting resistor values for 3 pb switches on one ADC input pin - ransom peek - Mar 6 15:25:00 2004

Thanks Dave.  The explanation about how the ADC breaks the incoming voltage value down is especially helpful for me.  I am going to go with the ADC mode, three switches, a 10k ohm pull up, and, consistent with Chad’s suggestion, a 5k ohm and a 20k ohm resistor, dividing the voltage into thirds (one switch has no resistor).  I will not need to read more than one switch at a time.

 

 

Ransom.

 

 

-----Original Message-----
From: Dave Mucha [mailto:d...@juno.com]
Sent:
Friday, March 05, 2004 7:08 AM
To: p...@yahoogroups.com
Subject: [piclist] Re: Selecting resistor values for 3 pb switches on one ADC input pin

 

I'm not sure it is this complicated.

Since you listed ADC as your inputs, we'll start there.

The ADC is 10 bit or 1024 discrete steps, change your math if your
ADC is different.

Using a pair of resistors as a voltage divider will yield some value
between 0 and 1024 bits.   A pair if same value resistors will yield
512.  This is bits input in the uC, but 2.5 volts on the input pin.

If you were looking at one switch, (same sized resistors) you could
look for anything above 256.  That would offer a window for the pull
down(up?) resistor to keep the ADC at zero, and the switch to deliver
2.5 volts or 512 bits.  Having the threshold at 511 to see 512 would
be a pretty poor choice as any variation in resistances would
possibly alter the actual range.  splitting the difference and
looking to see if it is more than half way or less than half way
offers a pretty large window.  ie: with half voltage and half ADC
input and half bits in the micro, your threshold to verify the switch
was pressed would be one quarter the range, or mid point between the
signal value and your non-signal value.

Assume 3 switches, all equally rated, say all at 10k ohm, plus the
pulldown(up?) at 10k also.  Each would offer 512 when pressed, but 2
pressed at the same time would offer different numbers and 3 pressed
at the same time would also yield a different number.   The problem
is you would not know which switch was pressed.  Only that one, two
or three switch were pressed.

Select each switch to have a different resistance and then make sure
the added values would wind up being different voltages.

Then, select the mid point between those calculated values as the
toggle point in software. 

a 1k, a 3k and a 5k will each offer a different voltage and the 1k
and 3k will yield 4k.  So you would have 3 distinct ranges.
to keep the math simple, think 5k as the pull down, and each switch
offers a different input to the ADC. 

IMPORTANT => ADD debounce.
a cap would offer a voltage value after the switch is pressed, but
voltage decay would have the voltage passing thru each voltage
range.  would make for some odd readings. A SECOND APPROACH

Another input method would be to use an RC to generate pulses that
can be read on an input pin NOT and ADC input. 

You can detect switches on an ADC channel or from a RC input as
pulses. That changes the calculations for selection, but not overall
concept.

A CAP is REQUIRES as it is integral to the RC pulse generator that
creates the pulses.

Since it too will degrade and the value will cross other inputs,
consider the time constant and use that in your debounce software. A THIRD APPROACH

When using more than 3 switches, look to a serial input chip that
would see 8 inputs and report via serial back to your uC the status. 
Those can be daisy changed for lots and lots and lots of switches.

And for those, you can poll them continuously, or connect it so that
any switch will alert your uC to poll because a switch was pressed. Dave

ps: please feel free to comment on the best approach.


to unsubscribe, go to http://www.yahoogroups.com and follow the instructions






(You need to be a member of piclist -- send a blank email to piclist-subscribe@yahoogroups.com )

Re: Selecting resistor values for 3 pb switches on one ADC input pin - Dave Mucha - Mar 6 22:09:00 2004

--- In , "ransom peek" <ransom.peek@c...>
wrote:
> Thanks Dave. The explanation about how the ADC breaks the incoming
> voltage value down is especially helpful for me. I am going to go
with
> the ADC mode, three switches, a 10k ohm pull up, and, consistent
with
> Chad's suggestion, a 5k ohm and a 20k ohm resistor, dividing the
voltage
> into thirds (one switch has no resistor). I will not need to read
more
> than one switch at a time. I believe that you will only need to read one switch at a time, but
since the audience for the group may want a little more I tend to
point out some alternatives.

ramble mode is ON.......

Also, When designing a project, I look at the bare minimum, then the
useful features, then the really cool features and then the maximum
possible bunch of c&@p that I can stuff into the darn thing.

Obviously the bare minimum is attainable with common sense, the next
level of features are things to add if convenient, but the max is
always in the back of my mind. I have been known to add silly
features at each opportunity and leaving room for them makes sense.
At least to me. :)

Currently we are working on a data logger. A memory chip, a PIC
packaged into a nice case. The idea is to offer people a way to add
portable data logging to their applications. Since it is self
contained and can work on 4 AA batteries for a couple weeks I figured
why not add a couple different power jacks.

Chances are we will not use them, but also some user might want the
opportunity.

Also, since our goal was for 32 data points and the enclosure has
some space, I'm hoping that we can find room for a small applications
board so the end user can add their circuit directly into our
enclosure.

We are nearing release for the kits and are looking to make some
changes, but the basic unit is done.

We reached the Bare Bones phase so that is a DONE.

We reached the add a few nifty features stage so that means we are
really done for all intent of the original goal.

I expect that some users will want things that will get added in as
standard features as the product moves in it's life.

Just thought you might like to see the thoughts behind the idea how
one person looks at a project.

Dave

ramble mode is OFF


______________________________
Stellaris® MCU Family: New Parts, New Package, New Price.


(You need to be a member of piclist -- send a blank email to piclist-subscribe@yahoogroups.com )