hello Dev Zone.
i need help.
now i'm try to make IR Line-tracer and detector
how ever, when my detecting object far then range,
"saadc" value change to Negative
I asume that it will goto 0, but change to "-" Velue
please check my code and help me
int NRF52Pin::initialiseSAADC() { static bool isConfig = false; if(!isConfig) { isConfig = true; // Configure the SAADC resolution. NRF_SAADC->RESOLUTION = SAADC_RESOLUTION_VAL_12bit << SAADC_RESOLUTION_VAL_Pos; // No automatic sampling, will trigger with TASKS_SAMPLE. NRF_SAADC->SAMPLERATE = SAADC_SAMPLERATE_MODE_Task << SAADC_SAMPLERATE_MODE_Pos; // Enable SAADC (would capture analog pins if they were used in CH[0].PSELP) NRF_SAADC->ENABLE = SAADC_ENABLE_ENABLE_Enabled << SAADC_ENABLE_ENABLE_Pos; // Calibrate the SAADC (only needs to be done once in a while) NRF_SAADC->TASKS_CALIBRATEOFFSET = 1; while (NRF_SAADC->EVENTS_CALIBRATEDONE == 0); NRF_SAADC->EVENTS_CALIBRATEDONE = 0; while (NRF_SAADC->STATUS == (SAADC_STATUS_STATUS_Busy <<SAADC_STATUS_STATUS_Pos)); } // Configure result to be put in RAM at the location of "result" variable. NRF_SAADC->RESULT.MAXCNT = 1; // adcSample -> int16_t adcSample NRF_SAADC->RESULT.PTR = (uint32_t)&adcSample; return DEVICE_OK; }
... ... // no existing channel found if (channel == -1) return DEVICE_NOT_SUPPORTED; else { initialiseSAADC(); } // Configure the SAADC channel with VDD as positive input, no negative input(single ended). NRF_SAADC->CH[0].PSELP = ((unsigned long)channel) << SAADC_CH_PSELP_PSELP_Pos; NRF_SAADC->CH[0].PSELN = SAADC_CH_PSELN_PSELN_NC << SAADC_CH_PSELN_PSELN_Pos; // Start the SAADC and wait for the started event. NRF_SAADC->TASKS_START = 1; while (NRF_SAADC->EVENTS_STARTED == 0); NRF_SAADC->EVENTS_STARTED = 0; // Do a SAADC sample, will put the result in the configured RAM buffer. NRF_SAADC->TASKS_SAMPLE = 1; while (NRF_SAADC->EVENTS_END == 0); NRF_SAADC->EVENTS_END = 0; return adcSample; } ... ...
Thanks,
Best Regards
Empe.