void vTaskADC(void *parameters){ int i; for(i = 0;i < 16; i++){ devices[i].port = -1; } initADC(); vSemaphoreCreateBinary(adcSemaphore); ADCinitialized = 1; while(devices[0].port == -1){ vTaskDelay(10); } while(1){ ADCStart(&devices[currDevice]); currDevice++; if(currDevice >= 16 || devices[currDevice].port == -1){ currDevice = 0; } xSemaphoreTake(adcSemaphore,portMAX_DELAY); } }
void ADCSetReference(uint8_t reference) { CLEARPINS(ADMUX, ADC_REF_MASK); SETPINS(ADMUX, (reference & ADC_REF_MASK)); // First read after changing reference is probably garbage ADCStart(); // Wait for the AD conversion to complete while (!ADCDone()); ADCFinish(); }
uint8_t ReadADC(uint8_t channel) { ADCSetChannel(channel); // Set ADC channel select bits ADCSetAdjust(ADC_LEFTADJUST); // Set left/right adjust bit ADCStart(); // Wait for the AD conversion to complete while (!ADCDone()); ADCFinish(); return ADCH; }