Hello, I wanted to do something but kinda got stuck on this problem. So I'm using an attiny85 and I'm using a simple 3-bit DAC to connect 3 buttons into one analog pin, but the ADC on the attiny85 is 10-bit and now I'm trying to figure out how to map this 10-bit value to the original 3-bit value. My current solution is to manually check each range one by one and return the number, but I feel like there should be a better way?
divide it by 128. That's 1024 (the ADC resolution) divided by 8 (the DAC resolution).
"map" two ranges that have a zero origin, is just scaling.
As you are detecting ranges, not values, you will have to add an offset to center the detection windows to 1/2 bit. e.g.
buttonSelection = (DACinputValue10bit + (1024 / 8) ) / 8;
For a confident answer on that, we should see a schematic of your DAC. You sound uninformed about what a DAC is, so it might not be a DAC. A 3 bit DAC would support 8 buttons not 3, and that is what my answer aims at solving.
Nevertheless, it is probably possible to use the division method to resolve inputs, if you provide details of the resistor network.
Usually, it's possible to apply a fixed voltage to a resistor network, using no DAC, and just connect the switches so they vary the resistor ratios, and thus the output voltage. So your description, or your design, is unusual.
I followed this diagram
Sorry, I was just guessing things, wasn't really sure what it was called, the website called it a digital to analog converter, and since I only have the 3 inputs (D0-D2) I called it 3 bits.
Can you explain that?
Is that 3-buttons that give you 3 different analog values? You're using analog when you REALLY WANT DIGITAL? I kinda' hate that!
I've never used the attiny85 but if the serial monitor works with it, just "print out" the values to see what you're getting.
If I guessED right and it's the 3-button trick, there will be some noise, instability, and uncertainty so instead of looking for an exact number, look for readings in range. But you only need 3 (actually 4) ranges (or maybe 8 for a combination of buttons at the same time) so 0-1023 is a lot to play with.
Thank you for the schematic. Now, please show how that is connected to the Arduino.
I have the "V Out" from the circuit connected to pin 7 on the attiny85.
But I have decided to just use if-else to just check if the analog input value is in the 8 possible range of values and just return the number. The noise/instability is not too bad so it is working fine so far.
I have an SPI display connected to the attiny so I was able to see the values without the serial monitor. This display is also why I'm using an analog input to use more buttons, it was just the first solution that I came up with and I don't have much electronic knowledge so it's what I decided to use.
Okay, I didn't phrase that very well in post #5. What I mean, is please post another schematic that is an actual schematic of your actual circuit, which includes the connections we all need to see. The verbal description in post #6 may or may not be complete enough, long experience on this forum has been that people consistently often can't see their own mistakes, and so don't communicate the things that are causing the problem.
A real schematic very often does communicate the problem because it is a literal, concise, and complete representation of the actual circuit.
Also, circuit noise or instability is strongly influenced by physical layout, so posting images of all your wiring and hardware is often helpful.
If you throw up your hands and accept a faulty circuit now, you will not learn how to avoid the same mistake(s) next time. That may or may not be important to you.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.