DANXIA
Junior Member level 2
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.....
Thanks!!!!!
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!!!!!
Last edited by a moderator: