cancel
Showing results for 
Search instead for 
Did you mean: 

How to overcome adc fluctuation.

MAnsa.1
Associate II

Hiii guys, i am using stm8s003f3.i configure it according to datasheet and it work almost fine,but problem is, it is generating random voltage when there is no input is connected and because of this input fluctuation getting unwanted output.how to make this adc value zero if there are no input connected,please help. here is my ADC initialization and ADC read code.....

void ADC__Initialization (void)
{
    ADC1->CR1_BitFields.ADON  = 1;                        // Turn ON the ADC
    ADC1->CR2_BitFields.ALIGN = 1;                        // ADC data is right aligned
		ADC1->CR3 |= 0x00; //Disabling buffer
		ADC1->TDRH                = 0xFF;                     // Disable High Schmitt Trigger
    ADC1->TDRL                = 0xFF;                     // Disable Low  Schmitt Trigger
}
float ADC__ReadChannel (uint8_t channel)		
{
    uint16_t  val;
	 
 
    ADC1->CSR_BitFields.CH   = channel;                   // Select the desired ADC channel
		ADC1->CR1 |= (1<<1);  // Continuous conversion Mode.
		ADC1->CR1_BitFields.ADON = 1;                         // Turn ON the ADC
    do {
        _asm("nop");
        _asm("nop");
        _asm("nop");
    } while (ADC1->CSR_BitFields.EOC == 0);               // Wait till conversion has completed
    val                      = (uint16_t)ADC1->DRH << 8;  // Move DRH:DRL into 16-bit return value
    val                     |= (uint16_t)ADC1->DRL;
    val                     &= 0x03FF;
    ADC1->CSR_BitFields.EOC  = 0;                         // Clear the end of conversion (EOC) flag
    return (val);
}

Thanks!!!!

6 REPLIES 6
Uwe Bonnes
Principal II

Only a voltage source with low enough input impedance can give stable values. A floating input has high input impedance. So pull down the floating input with low enough resistance according to datasheet the and you will read stable values around 0 V

Bro i dont understand what u said,can you please explain in detail how i will get stable 0v at ADC channel???

Make a short between the ADC input and ground and test again. If still not stable look for other errors. Datasheet, reference manual ADC section and application notes around ADC can help you.

i check the voltage at ADC pin at 0V the adc value was correct that mean hardware part is perfectly fine.i guess some issue is in software.so can u help me to rectify this problem.

Thanks!!!

The Voltmeter works as a pull down, mostly 10 MOhm.

n i pass different input value all the voltage look like fine.thats why i am sure the actual problem is in software.