Hi, student new to pic here. I've written a simple piece of code that reads the value of a potentiometer using ADC and generates a PWM output to dim an LED.
The code above works and the led dims as the pot is turned. My question is regarding the " >>10 " piece of code in where the ADC result is set into 'adcResult' Without it the led turned on or off randomly as the pot was turned and after adding ">>10" (Instruction guide I followed added this bit shift and didn't explain why properly), the LED began to dim with the pot and work correctly. How does bit shifting to the right 10 bits make the LED dim gradually? What's happening here?
Using: PIC16F18446 (LPC Curiosity board standard PIC)
Using: MPLABx 5.40
C:
void main(void)
{
// initialize the device
SYSTEM_Initialize();
PWM_IN1_Enable();
while (1)
{
adcResult = ADCC_GetSingleConversion(POT) >> 10 ;
//adcResult = map(adcResult,0,1023,511,1023);
PWM6_LoadDutyValue(adcResult);
}
}
Using: PIC16F18446 (LPC Curiosity board standard PIC)
Using: MPLABx 5.40