Revision 314
Updated BOM and rangefinder to use new analog. Entering alpha testing phase.
branches/analog/trunk/code/projects/libdragonfly/analog.c | ||
---|---|---|
164 | 164 |
/** |
165 | 165 |
* Reads a ten bit number from the specified port. |
166 | 166 |
* analog_init must be called before using this function. |
167 |
* |
|
167 | 168 |
* |
168 | 169 |
* @param which the analog port to read from. Typically |
169 | 170 |
* a constant, one of AN0 - AN7. |
... | ... | |
174 | 175 |
**/ |
175 | 176 |
unsigned int analog10(int which) |
176 | 177 |
{ |
178 |
int adc_h; |
|
179 |
int adc_l; |
|
180 |
|
|
177 | 181 |
// Let any previous conversion finish |
178 | 182 |
while (ADCSRA & _BV(ADSC)); |
179 | 183 |
|
... | ... | |
190 | 194 |
// Wait for the conversion to finish |
191 | 195 |
while (ADCSRA & _BV(ADSC)); |
192 | 196 |
|
193 |
return ((ADCH << 2) | (ADCL >> 6)); |
|
197 |
adc_l = ADCL; |
|
198 |
adc_h = ADCH; |
|
199 |
|
|
200 |
return ((adc_h << 2) | (adc_l >> 6)); |
|
194 | 201 |
} |
195 | 202 |
|
196 | 203 |
/** |
... | ... | |
208 | 215 |
return analog_get8(WHEEL_PORT); |
209 | 216 |
} |
210 | 217 |
|
211 |
/**@}**/ //end defgroup |
|
212 | 218 |
|
219 |
/** |
|
220 |
* Sets the value of the external analog mux. Values are read |
|
221 |
* on AN7 physical port. (AN8 - AN15 are "virtual" ports). |
|
222 |
* |
|
223 |
* @param which which analog mux port (0-7) which corresponds |
|
224 |
* to AN8-AN15. |
|
225 |
* |
|
226 |
* @bug FIX THIS IN THE NEXT BOARD REVISION: |
|
227 |
* ADDR2 ADDR1 ADDR0 |
|
228 |
* G2.G4.G3 set mux to port 0-7 via vinary selection |
|
229 |
* math would be much cleaner if it was G4.G3.G2 |
|
230 |
* |
|
231 |
* @see analog_init |
|
232 |
**/ |
|
213 | 233 |
void set_adc_mux(int which) |
214 |
{ |
|
215 |
// FIX THIS IN NEXT REVISION |
|
216 |
// ADDR2 ADDR1 ADDR0 |
|
217 |
// G2.G4.G3 set mux to port 0-7 via binary selection |
|
218 |
// math would be much cleaner if it was G4.G3.G2 |
|
219 |
|
|
234 |
{ |
|
220 | 235 |
// mask so only proper bits are possible. |
221 | 236 |
PORTG = (PORTG & 0xE3) | ((which & 0x03) << 3) | (which & 0x04); |
222 | 237 |
} |
238 |
|
|
239 |
/**@}**/ //end defgroup |
|
240 |
|
|
223 | 241 |
|
224 | 242 |
ISR(ADC_vect) { |
225 | 243 |
static volatile int adc_prev_loop_running = 0; |
branches/analog/trunk/code/projects/libdragonfly/analog.h | ||
---|---|---|
96 | 96 |
|
97 | 97 |
#define ADMUX_OPT 0x60 |
98 | 98 |
|
99 |
/** @brief Struct to hold the value of a particular analog port */ |
|
99 | 100 |
typedef struct { |
100 | 101 |
uint8_t adc8; |
101 | 102 |
uint16_t adc10; |
102 | 103 |
} adc_t; |
103 | 104 |
|
104 |
//extern adc_t an_val[10]; |
|
105 | 105 |
|
106 |
/** @brief Initialize analog ports. **/ |
|
106 |
/** @brief Initialize analog ports. Will start running a loop |
|
107 |
if start_conversion is ADC_START.**/ |
|
107 | 108 |
void analog_init(int start_conversion); |
109 |
/** @brief starts the analog loop. Doesn't do anything if the loop is already running. **/ |
|
108 | 110 |
void analog_start_loop(void); |
111 |
/** @brief Stops the analog loop. Doesn't do anything if the loop is already stopped. **/ |
|
109 | 112 |
void analog_stop_loop(void); |
110 |
/** @brief Read an 8-bit number from an analog port. **/ |
|
113 |
/** @brief Read an 8-bit number from an analog port. Loop must be stopped for this to work. **/
|
|
111 | 114 |
unsigned int analog8(int which); |
112 |
/** @brief Read a 10-bit number from an analog port. **/ |
|
115 |
/** @brief Read a 10-bit number from an analog port. Loop must be stopped for this to work. **/
|
|
113 | 116 |
unsigned int analog10(int which); |
114 | 117 |
/** @brief Read the position of the wheel. **/ |
115 | 118 |
int wheel(void); |
119 |
/** @brief Returns an 8-bit analog value from the look up table. Use this instead of analog8. **/ |
|
116 | 120 |
unsigned int analog_get8(int which); |
121 |
/** @brief Returns an 10-bit analog value from the look up table. Use this instead of analog10. **/ |
|
117 | 122 |
unsigned int analog_get10(int which); |
118 | 123 |
|
119 | 124 |
|
branches/analog/trunk/code/projects/libdragonfly/bom.c | ||
---|---|---|
113 | 113 |
int a, i, j, h; |
114 | 114 |
h = 255; |
115 | 115 |
|
116 |
//Turn off the loop so that we can actually use analog8 correctly |
|
117 |
analog_stop_loop(); |
|
118 |
|
|
119 |
//Iterate through through each LED |
|
116 | 120 |
for (j = 0; j < 16; j++) |
117 | 121 |
{ |
118 | 122 |
i = lookup[j]; |
... | ... | |
146 | 150 |
} |
147 | 151 |
|
148 | 152 |
} |
153 |
|
|
154 |
//Restart loop now that we are done using analog8 |
|
155 |
analog_start_loop(); |
|
149 | 156 |
|
150 | 157 |
//threshold on the bom analog value. |
151 | 158 |
//defined in bom.h |
branches/analog/trunk/code/projects/libdragonfly/rangefinder.c | ||
---|---|---|
132 | 132 |
* @see range_init |
133 | 133 |
**/ |
134 | 134 |
int range_read_distance (int range_id) { |
135 |
return linearize_distance(analog8(range_id)); |
|
135 |
return linearize_distance(analog_get8(range_id));
|
|
136 | 136 |
} |
137 | 137 |
|
138 | 138 |
/** @} **/ //end defgroup |
Also available in: Unified diff