dtusllitg
Newbie
Hi everyone,
I'm trying to read and convert analog values of a 10K-potentiometer into voltages (0V to 3V3) with PIC16F18877. To see the result, an LED toggling method is used to detect if the voltage is greater or less than 1.65V. I use MPLAB v5.5, XC8 to generate code with its MCC library, shown below. Please see a few beginner questions after code.
main.c
Questions:
1) Why isn't the converted voltage value updated unless the MCU being reset?
2) Why does an ADC implementation in PIC need a timer? I see some tutorials using a timer and some don't use it. I try both and get the same result, the voltage value never gets updated unless the MCU is reset.
3) In the MCC window, there is an option to enable ADC interrupt, is it necessary to enable it?
Thanks -- Dan
I'm trying to read and convert analog values of a 10K-potentiometer into voltages (0V to 3V3) with PIC16F18877. To see the result, an LED toggling method is used to detect if the voltage is greater or less than 1.65V. I use MPLAB v5.5, XC8 to generate code with its MCC library, shown below. Please see a few beginner questions after code.
main.c
C:
#include "mcc_generated_files/mcc.h"
void display_volt(float);
/*
Main application
*/
void main(void)
{
adc_result_t convResult = 0;
float v = 0;
// initialize the device
SYSTEM_Initialize();
ADCC_StartConversion(POT);
while (1)
{
while(!ADCC_IsConversionDone()); // check the ADC conversion
convResult = ADCC_GetConversionResult(); // get ADC value
v = (convResult * 3.3)/1023; // get voltage value
display_volt(v); // send the value to display
}
}
void display_volt(float v){
while (v >1.65){
LED_SetHigh();
}
LED_SetLow();
}
/**
End of File
*/
Questions:
1) Why isn't the converted voltage value updated unless the MCU being reset?
2) Why does an ADC implementation in PIC need a timer? I see some tutorials using a timer and some don't use it. I try both and get the same result, the voltage value never gets updated unless the MCU is reset.
3) In the MCC window, there is an option to enable ADC interrupt, is it necessary to enable it?
Thanks -- Dan