[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[avr-gcc-list] Re:[avr-gcc-list]AVR and external ADC
From: |
Marlin Unruh |
Subject: |
[avr-gcc-list] Re:[avr-gcc-list]AVR and external ADC |
Date: |
Mon, 20 May 2002 08:34:09 -0600 |
You could use a r/2r resistor network and pass its output thru an opamp voltage
follower. Then present the voltage to the
voltage comparator in the MCU. Do a search on Goggle with R/2R ladder and check
out the links. Its a cheap D/A convertor.
Then in your code do the higher/lower scheme. This will speed up the time it
takes to locate the unknown analog value. If
using 8 bit resolution, first apply 128 to the r/2r ladder if it is lower then
divide 128 in half and check if higher or
lower, etc. You should be able to find the value in eight or less samples.
Example: unknown analog = 125
128 (lower)
128-64= 64 (higher)
64+32= 96 (higher)
96+16= 112 (higher)
112+8= 120 (higher)
120+4= 124 (higher)
124+2= 126 (lower)
126-1= 125 (answer)
code example:
void get_unknown_analog(unsigned char result)
{
unsigned char v1, v2; // define variables
v1 = v2 = 128; // load vars
do {
v1 /= 2; // adjust v1 each time around
portx = v2; // value to place on the r/2r ladder
delay(x); // settle time
if(comparator_is_set) // test higher/lower condition
v2 -= v1; // if above trip point then sub v1 from v2
else
v2 += v1; // if below trip point then add v1 to v2
} while(v1);
return v2;
}
This is not perfect, but you get the idea.
Marlin Unruh
avr-gcc-list at http://avr1.org
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [avr-gcc-list] Re:[avr-gcc-list]AVR and external ADC,
Marlin Unruh <=