Hallo
Mal aus der Hüfte geschossen: adcLSL wird durch das Tasksystem mit dem Helligkeitswert geladen:
Code:
/**
* This functions checks all ADC channels sequentially in the Background!
* It can save a lot of time, if the ADC channels are checked like this, because
* each A/D conversion takes some time. With this function you don't need to
* wait until the A/D conversion is finished and you can do other things in the
* meanwhile.
* If you use this function (this is also the case if you use task_RP6System
* because it calls this function), you can NOT use readADC anymore!
*
* Instead you can use the seven global variables you see above to
* get the ADC values!
*/
void task_ADC(void)
{
static uint8_t current_adc_channel = 0;
if(!(ADCSRA & (1<<ADSC))) {
// ADCSRA |= (1<<ADIF);
switch(current_adc_channel) {
case 0: adcBat = ADC; startADC(ADC_MCURRENT_L); break;
case 1: adcMotorCurrentLeft = ADC; startADC(ADC_MCURRENT_R); break;
case 2: adcMotorCurrentRight = ADC; startADC(ADC_LS_L); break;
case 3: adcLSL = ADC; startADC(ADC_LS_R); break;
case 4: adcLSR = ADC; startADC(ADC_ADC0); break;
case 5: adc0 = ADC; startADC(ADC_ADC1); break;
case 6: adc1 = ADC; startADC(ADC_BAT); break;
}
if(current_adc_channel == 6)
current_adc_channel = 0;
else
current_adc_channel++;
}
}
Wenn du das Tasksystem vorerst nicht verwenden möchtest, dann kannst du die Werte auch mit readADC() ermitteln:
Code:
/*****************************************************************************/
// ADC:
/**
* Read ADC channel (10 bit -> result is an integer from 0 to 1023).
* The channels (ADC_BAT etc.) are defined in the RP6RobotBase.h file!
*
* This is a blocking function, which means it waits until the conversion
* is complete. There is a more complicated alternative that frequently
* checks all channels (s. below).
*
* This function returns 0 if the ADC is buisy! This has been done to
* prevents problems when the automatical function is used.
* You should usually NOT use this function if you use the automatic one!
*
* Example:
*
* uint16_t uBat = readADC(ADC_BAT);
* if(uBat < 600)
* writeString("WARNING: BAT IS LOW!\n");
*
*/
uint16_t readADC(uint8_t channel)
{
if((ADCSRA & (1<<ADSC))) return 0; // check if ADC is buisy...
ADMUX = (1<<REFS0) | (0<<REFS1) | (channel<<MUX0);
ADCSRA = (0<<ADIE) | (1<<ADSC) | (1<<ADEN) | (1<<ADPS2) | (1<<ADPS1) | (1<<ADIF);
while ((ADCSRA & (1<<ADSC)));
ADCSRA |= (1<<ADIF);
return ADC;
}
(Beide Funktionen sind aus RP6RobotBaseLib.c)
Die Kanäle werden in RP6RobotBase.h definiert:
Code:
#define ADC_BAT 7
#define ADC_MCURRENT_L 6
#define ADC_MCURRENT_R 5
#define ADC_LS_L 3
#define ADC_LS_R 2
#define ADC_ADC1 1
#define ADC_ADC0 0
Gruß
mic
Lesezeichen