Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Resistor values of voltage divider (dip switch)

Status
Not open for further replies.

crnewton

Newbie
Newbie level 3
Joined
Mar 3, 2022
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
38
I have an 8 pin dip switch, and I want to connect it to my ADC so I can connect other peripherals to my DI.
I want to use all the 256 codes.

With the help of this topic I figured out how this is possible, but I'm not sure if my schematics are correct, and if this would work with these resistors.
The math works out, but I feel like my resistor values are too low, and I've read that they should be of the power of 2 of the previous one.
I hope someone an look over it and tell me what I'm doing wrong.
My components:
  • STM32F446RE
  • - 12bit - ADC
  • - max ADC input voltage = 3.3V
  • - min_adc_step_voltage = 0.008056 V
  • 8 pin dip switch
  • R1 - R8 = resistor for each dip (r_top)
  • R9 = resistor bottom voltage devider (r_bottom)

Here is what I came up with:
Schematic_KL-HV_V3_2022-03-02.png



1646302639398.png

(The V_out is below 3.3V, and each combination differs with more than the 'min_adc_step_voltage'.)

Do I also have to look at the current?

Formulas used:
v_out = v_in * (r_bottom/(r_bottom+r_top));
power_dissipation_mw = (pow(v_in, 2) / (r_bottom + r_top)) * 1000 ;
 
Last edited:

Unclear what you want to achieve.
- Close 1 out of 8 switches to input 8 or 9 different codes
- Use arbitrary switch combinations to signal up to 2^8 codes

For the first purpose, resistors can be dimensioned to achieve more or less aquidistant voltage levels.
The second pupose can't be achieved with this circuit
 

Hi,

Why? ... is my first question.
If it is for learning, then do it.
If it is for a serious design, then don´t do it.

Please use Excel to calculate all possible 256 values.
Then decide how you can calculate back which switches are ON and OFF. I´d say it is impossible, because some combinations are not to differ.

What´s the value when 2k is ON --> 2.475V
and when 3k AND 6k is ON --> 2.475V
--> how do you want to differ them?

Klaus
 

Unclear what you want to achieve.
- Close 1 out of 8 switches to input 8 or 9 different codes
- Use arbitrary switch combinations to signal up to 2^8 codes

For the first purpose, resistors can be dimensioned to achieve more or less aquidistant voltage levels.
The second pupose can't be achieved with this circuit
The second purpose, use the dip switch to get 2^8 codes.

why can this not be achieved? each resistor must be the power of
Hi,

Why? ... is my first question.
If it is for learning, then do it.
If it is for a serious design, then don´t do it.

Please use Excel to calculate all possible 256 values.
Then decide how you can calculate back which switches are ON and OFF. I´d say it is impossible, because some combinations are not to differ.

What´s the value when 2k is ON --> 2.475V
and when 3k AND 6k is ON --> 2.475V
--> how do you want to differ them?

Klaus
It is for a serious design.
You say 'don't do it' , you mean don't do it this way, or not at all? if so why not?

Ah I see my mistake, I will calculate all values., will this be solvable when I use for every resistor an power of 2 of the previous resistor?
 

The best approach for 2^8 codes would be R-2R ladder, unfortunately it needs DT instead of ST switches.

2^n weighted resistors and ST switches can work with additional operational amplifier as I-V converter but not in a voltage divider circuit as shown in post #1. You'll realize if you calculate achieved voltage values yourself.
 

Hi
You say 'don't do it' , you mean don't do it this way, or not at all? if so why not?
Your approach is to read in 8 switches.
8 switches (digital) -->analog (with noise and errors) --> ADC (with noise and errors) --> calls for problems

Nowadays a avoid dip switches and replace it with memory. (eeprom for example)
But for sure sometimes switches give a benefit.
If so I`d rather use an I2C bus extender like PCF8574 (there are many others: 8bit, 16 bit, SPI ...)
It just uses 2 microcontoller pins. One IC instead of 9 resistors. No problems. No need to decode.

Other options are: multiplexing, or 8 microcontroller pins (= simplest) ...

Klaus
 


Thank you all!
My usecase is a dip switch to configure the RS485 address.
I didn't think of an I2C bus extender, that seems like an easier solution, I will look into that.
 

You could could use your 8 pin dip switch to control inputs to an 8 bit buffer, such as a 74HC244A, and use the buffer outputs to drive an R-2R DtoA ladder. This would allow the single pole dip swiches to generate the High and Low logic levels for the ladder.
 

Although single-pole switches are less than ideal for the R2R network (per post #5)...
Nevertheless by adding resistors to ground, you can obtain reasonable DAC results. Linearity is not perfect.

Simulation showing principle of operation. One analog switch is closed in the 4-bit ladder. The other 3 switches are open.

R2R ladder 4-bit single-pole switches 2k resis to gnd.png
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top