Multiple Switches with one analogue input
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Multiple Switches with one analogue input
Has any one had success with there own values for R1, R2, R3, R4 & R5.
I would assume binary weighted would be best, but LSB can’t be too high.
Best values would produce a difference of at least 200mV with all permutations.
I can mange 200mV with most but with one permutation there is only a difference of 50mV.
I am looking to have more than one switch closed at a time.
I would assume binary weighted would be best, but LSB can’t be too high.
Best values would produce a difference of at least 200mV with all permutations.
I can mange 200mV with most but with one permutation there is only a difference of 50mV.
I am looking to have more than one switch closed at a time.
Martin
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Multiple Switches with one analogue input
Hello
If you are creating a DAC then you will be better of using the R/2R approach.
Resistors normally have a 5% tolerance which means that more then 5% of your analogue end voltage will be inaccurate which will completely illiminate the least significant bit and maybe even the next bit too.
Resistors in a pack will still have 5% tolerance but within the pack they will all be almost identical so the tolerance problem is removed. This is why the R/2R DAC is so great. For the 2R resistors simply use two of your single R resistors.
http://www.avr-asm-tutorial.net/avr_en/AVR_DAC.html
If you are creating a DAC then you will be better of using the R/2R approach.
Resistors normally have a 5% tolerance which means that more then 5% of your analogue end voltage will be inaccurate which will completely illiminate the least significant bit and maybe even the next bit too.
Resistors in a pack will still have 5% tolerance but within the pack they will all be almost identical so the tolerance problem is removed. This is why the R/2R DAC is so great. For the 2R resistors simply use two of your single R resistors.
http://www.avr-asm-tutorial.net/avr_en/AVR_DAC.html
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Multiple Switches with one analogue input
Thanks Ben. I Did think of R2R fist, but ruled it out since I am using a SPST dip switch. Don't R2R need a SPDTswitch i.e switch to either o/p or short resistor to ground? Refering to the link you posted: If you think about it, bits o/p from a Microcontroller will be either at +5V or GND when using as DAC.
If I am wrong and R2R can use SPST, then I will defiantly use that method!
If I am wrong and R2R can use SPST, then I will defiantly use that method!
Martin
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Multiple Switches with one analogue input
Hello
I think you can get away with using SPST switches with the R/2R system.
Simply connect each switch to +V and then connect the other side of the switch to the bitx as shown on the weblink In my previous post.
I think you can get away with using SPST switches with the R/2R system.
Simply connect each switch to +V and then connect the other side of the switch to the bitx as shown on the weblink In my previous post.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Multiple Switches with one analogue input
Thinking about this I may have been wrong. Let me know how you get on.
Otherwise it may be worth getting low tolerance resistors to eliminate the previous error you were getting. Alternativly you could use multiples of the same resistor value to avoid the tolerance issue.
Otherwise it may be worth getting low tolerance resistors to eliminate the previous error you were getting. Alternativly you could use multiples of the same resistor value to avoid the tolerance issue.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Multiple Switches with one analogue input
Code: Select all
msb lsb Voltage
0 0 0 0 0
0 0 0 1 0.493
0 0 1 0 0.704
0 0 1 1 0.925
0 1 0 0 0.986
0 1 0 1 1.234
0 1 1 0 1.312
0 1 1 1 1.441
1 0 0 0 1.455
1 0 0 1 1.767
1 0 1 0 1.877
1 0 1 1 2.025
1 1 0 0 2.016 < Problem
1 1 0 1 2.187
1 1 1 0 2.23
1 1 1 1 2.321
R=10k 2R=20k
It nearly works! Have highlighted where the problem one is.
Going back to previous method, just trying to work out which resistors are best values. I know best is R 2R 4R 8R 16R etc. but is the initial R value which would make not make R too large. Finally its what value to make R5? If too low will have more significant effect on 16R.
Martin
- Steve
- Matrix Staff
- Posts: 3433
- Joined: Tue Jan 03, 2006 3:59 pm
- Has thanked: 114 times
- Been thanked: 422 times
Re: Multiple Switches with one analogue input
I've had a look at this and the best I can come up with is a minimum difference of 70mV. To do this, I used the resistors as follows:
R1 = 2k2
R2 = 4k7
R3 = 10k
R4 = 22k
R5 = 1k
Things can be drastically improved if the network of resistors is powered off 10V instead of 5V. Using the same resistor values, the minimum difference becomes 140mV.
A spreadsheet is attached. I hope I got the math(s) right!
R1 = 2k2
R2 = 4k7
R3 = 10k
R4 = 22k
R5 = 1k
Things can be drastically improved if the network of resistors is powered off 10V instead of 5V. Using the same resistor values, the minimum difference becomes 140mV.
A spreadsheet is attached. I hope I got the math(s) right!
- Attachments
-
- multiple switches to ADC.xls
- (18.5 KiB) Downloaded 309 times
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Multiple Switches with one analogue input
Thank you to both of you for your replies. I appreciate it.
Especially thanks to Steve for taking the time to produce a useful spreadsheet.
I will go the 10V supply route, since alreay have a 10V supply to drive 2 EC motors.
Especially thanks to Steve for taking the time to produce a useful spreadsheet.
I will go the 10V supply route, since alreay have a 10V supply to drive 2 EC motors.
Martin
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Multiple Switches with one analogue input
I have just completed a test on real hardware. Measured actual resistor values, and entered them into spreadsheet.
Steve your maths is spot on! I have attached results for anyone to view.
Steve your maths is spot on! I have attached results for anyone to view.
- Attachments
-
- multiple switches to ADC(1).xls
- (19 KiB) Downloaded 317 times
Martin