1

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();
    }
}

1 Answer 1

2

This question is solved by calling

ADCC_StartConversion(POT);

in the while(1) loop.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.