Project

General

Profile

Revision 437

Added by Kevin Woo almost 14 years ago

Cleaned up analog.c code. Recompiled library. Mostly commenting and
documentation fixes. No changes made to actual code.

View differences:

analog.c
56 56
 * Initializes the ADC.
57 57
 * Call analog_init before reading from the analog ports.
58 58
 *
59
 * @see analog8, analog10
59
 * @see analog8, analog10, analog_get8, analog_get10
60 60
 **/
61 61
void analog_init(int start_conversion)
62 62
{
......
110 110
	}
111 111
}
112 112

  
113
/**
114
 * Returns the 10-bit analog conversion of which from
115
 * the lookup table. If the requested port is the BOM_PORT
116
 * you will get an automatic 0 since the BOM_PORT is not
117
 * read in the loop and not stored. If you need that port
118
 * you should use the functions in bom.c. There is an analog_get10
119
 * function which for instant lookups but should be avoided.
120
 *
121
 * @param which the port that you want to read
122
 *
123
 * @bug may cause a seg fault if which is a larger value
124
 * than exists in an_val table. Not sure if we should fix
125
 * this or not since it would add overhead.
126
 *
127
 * @return 10-bit analog value for the which port requested
128
 *
129
 * @see analog8, analog_get8, analog_get10
130
 **/
113 131
unsigned int analog10(int which) {
114 132
	if (which == BOM_PORT) {
115 133
		return 0;
......
118 136
	}
119 137
}
120 138

  
139

  
140
/**
141
 * Starts the analog update loop. Will continue to run
142
 * until analog_stop_loop is called.
143
 *
144
 * @see analog_stop_loop
145
 **/
121 146
void analog_start_loop(void) {
122 147
	//Start the conversion
123 148
	ADCSRA |= _BV(ADSC);
124 149
	adc_loop_running = 0x1;
125 150
}
126 151

  
127
//will stop after current conversion finishes
152
/**
153
 * Stops the analog update loop. If there is a current
154
 * read, it will finish up and be stored before the loop
155
 * is interrupted. No further updates will be made until
156
 * the loop is started again.
157
 *
158
 * @see analog_start_loop
159
 **/
128 160
void analog_stop_loop(void) {
129 161
	//Stop the conversion
130 162
	adc_loop_running = 0x0;
......
240 272

  
241 273

  
242 274
ISR(ADC_vect) {
243
	static volatile int adc_prev_loop_running = 0;
244

  
275
	static volatile int adc_prev_loop_running = 0; 
245 276
	int adc_h = 0;
246 277
	int adc_l = 0;
247 278

  
248
	//usb_putc('p');
249
	//usb_puti(adc_current_port);
250
	//usb_putc('r');
251
	//usb_puti(adc_loop_running);
252
	//usb_puts("\n\r");
253

  
254 279
	//Store the value only if this read isn't for the BOM
255 280
	if (ADMUX != BOM_PORT) {
256 281
		adc_l = ADCL;
......
258 283
	
259 284
		an_val[adc_current_port - 1].adc10 = (adc_h << 2) | (adc_l >> 6);
260 285
		an_val[adc_current_port - 1].adc8 = adc_h;
261
		//usb_puti(an_val[adc_current_port - 1].adc10);
262
		//usb_puts("\n\r");
263
		//usb_puti(an_val[adc_current_port - 1].adc8);
264
		//usb_puti(ADCH);
265
		//usb_puts("\n\r");
266 286
	}
267 287
	
268 288
	//Save the result only if we just turned off the loop
......
293 313
	}
294 314

  
295 315
	//Initiate next conversion only if we are running a loop
296
	if (!adc_loop_running)
316
	if (!adc_loop_running) {
297 317
		return;
298

  
299
	ADCSRA |= _BV(ADSC);
300
	
301
	//if (ADCSRA & _BV(ADSC))
302
	//	usb_putc('s');
318
    } else {
319
    	ADCSRA |= _BV(ADSC);
320
	}
303 321
		
304 322
	return;
305 323
}

Also available in: Unified diff