Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

input and save input

Status
Not open for further replies.
Like this
Screenshot from 2017-11-30 17-18-57.png
 
I simulated all on one output but the voltage output varied by as little as .2 volts. Wanting to avoid marginal errors for indicating which switch was depressed so I found using the posted schematic worked well.
voltage output goes from 4.17, 4.00, 3.75, 3.33, 2.5.
 
When I posted Burts Schematic was not included. Will take another look at your circuit Burt.
 
I think this is what Burt was suggesting? I just may go with one ADC input. Am wondering WHY the simulation shows 2.54volts with no switches closed?
BURTS SUGGSTIOON.JPG
 
Your input is floating, unless you have a weak pull down or pull up attached to it..
 
This is a bit easier to understand. Add as many 1k resistors and switches as needed. Add the 100k resistor and 0.1uF cap to ground to avoid noise pickup.

Calculate the expected range for each step using the voltage divider equation, using minimum and maximum values based on 1% resistor tolerances. Make your life easy by using 1024 as the input voltage; that way the steps are the ADC values you will read.
BP20wpg_d.jpg
 
Hey Jon why not pick the adc up 2 buttons up like mr deb did just joking lol.
Microchip shows 16 of them reading just like your post I no 10 works fine I get nice reading using a map function.

What i posted is there is 400 mV between each point on the ladder easy to read
 
I planned on using the divide by 1024. 5 ? 1024 = .0048828
Plan to breadboard and using an LCD for testing, write code to display what each button affects the output. Not sure if it can display the LOW and HIGH of the actual voltage after it is divided by 1024. Maybe going off the grid with this idea?? My hope is if I can get an in-between voltage before it transgresses to the next bswitch thus hopefully all the boards I assemble and program will act the same.
an actual circuit is IMO better than just doing the math. No guessing but just hard facts on the actual output.
Hopefully I explained this right.
After i extract the voltage of each button press I plan to use a CASE SELECT
Thanks for the tip on using the capacitor. As for the floating input?? not sure if I need to worry about it since it is an ADC input but the 100K resistor basically ties the port input to LOW or GRD.
 
You will get a reading between 0 and 1024. If you have ten switches then each switch will read 1024/10 above zero. So add 51 (1024/20) and divide by 102 (1024/10) and you will have 0 for no switch pressed and 1 to 10 for the switches. It is really basic maths.

Mike.
 
I mentioned before, I am terrible with math but fascinated with it.
Where did the 51 come from 1024/10 I assume says the calculator. Then the 1024 / 20 Why 20?
I am lost with the math, sorry but.
1024/10 = 102.4
1024/20=51.2
After reading Pommies post I am not lost but confused?? Why divide by 102, and 20.
 
With integer maths 1024/10 = 102 and 1024/20 = 51.

You add 51 (1024/20) to place the value in the middle of the range. So no key=51, key 1 = 153, key 2 = 254 etc.

Say key 3 is pressed then the reading from the adc will to three tenths of 1024 = 312 - however it may vary 10 or 20 each way. Adding 51 will make it 363, doing 363 (integer) divided by ten is 3, the number of the switch pressed.

Note, a different number of keys requires different numbers.

Mike.
 
MrDEB,

You truly go to great lengths to avoid actually understanding how anything actually works. You must put forth considerable effort to avoid having any knowledge rub off on you, no matter how many times it's explained.

As for the floating input?? not sure if I need to worry about it since it is an ADC input

Why worry about a floating input? You are depending an an ADC reading to tell you what switch is read. When you tested it above, it was reading mid scale with no switch pressed because it's floating. That will wander around depending on electrical noise, humidity and the phase of the moon, so how will you know what's noise and what's a button press?

I planned on using the divide by 1024. 5 ? 1024 = .0048828

Aside from your error in math, why would you convert ADC readings into "volts"? You don't actually know what voltage a reading of 1023 means since you don't have a voltage reference. What you know is that ratio of the reading to the full scale value. A reading of 1023 means it's the same voltage as the supply voltage. Is it 5? 4.5? 3? Who cares. The steps from the switches will be the ratio from full scale, no matter what full scale is. Of course you haven't considered that if you convert some value to 2.345 volts, in integer math, that equals 2. You'll get only 4 or 5 steps using integer math...and 12 more pages in the forum trying to explain why.

actual circuit is IMO better than just doing the math. No guessing but just hard facts on the actual output.

No. Sorry. Your opinion is worth ZERO in this case. If you do this, you will have data for that exact set of resistors under those exact conditions. You mentioned using 1% resistors. The values of these resistors will vary by +/- 1%. No two resistor ladders made with 1% resistors will be the same. But it's easy to find the band each switch can be in. Use the voltage divider equation. Calculate the bound with all the resistors on the top of the voltage divider at the max value and all the resistors on the bottom at their minimum value. Then to the reverse to calculate the other bound. If your resistors are truly 1% tolerance, the ADC values MUST be within those bounds.


I'll bet I can design a circuit board to do this task, send the files to China, have the boards back, assembled and programmed before this forum thread reaches a conclusion.
 
Burt, you missed off the 100k tie down resistor to the input pin.

Mike.
I was just showing the voltages
I only added the buttons to show that the voltages came out the switch at that value.

If I was making it it be like Jon post #128
 
Last edited:
MrDEB,
I'll bet I can design a circuit board to do this task, send the files to China, have the boards back, assembled and programmed before this forum thread reaches a conclusion.
I for one will NOT be taking that bet.

Mike.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top