Reputation: 39
Can somebody help to explain why my code or setup not updating the ADC values of a 10K-potentiometer please?
I use MPLAB XPRESS PIC16F18877 board and MPLAB MCC to generate the code. The voltage result only gets updated once after resetting the board.
main.c
#include "mcc_generated_files/mcc.h"
void display_result(float v);
void main(void) {
adc_result_t convResult = 0;
float v = 0;
// initialize the device
SYSTEM_Initialize();
ADCC_StartConversion(POT);
while (1) {
// Convert ADC values
while (!ADCC_IsConversionDone());
convResult = ADCC_GetConversionResult();
v = convResult * 3.3 / 1023;
// send the value to display
display_result(v);
}
}
void display_result(float v) {
if (v > 1.65) {
LED_SetHigh();
} else {
LED_SetLow();
}
}
Upvotes: 1
Views: 236
Reputation: 39
This question is solved by calling
ADCC_StartConversion(POT);
in the while(1) loop.
Upvotes: 2