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);
}
HiiHi,
There's a general rule not to leave any inputs floating.
How do (other) voltmeters work?
It's the nature of floating inputs to get undetermined voltage.
It's the nature of ADCs that LSB(s) may to toggle, even if the input is shorted. .... due to noise and quantisation.
Even if the input is shorted an ADC may show a "non zero" output due to offset.
Thus: If a "non automatic" solution is acceptable (like manually setting a jumper), then use a microcontroller input for this and let the software make a "perfect zero". Free from noise and offset.
Klaus
So there is the option to set a jumper. Then wire it to a port input. And when the port pin has the desired state you "force" the ADC value to 512 (or whatever you want). No need to do a conversion in this case.can you please explain your last paragraph?my only aim is to read adc value 512 if there is no input is connected.
Actually i am measureing a voltage in both range positive as well as negaive.so,0-511 i will get negatibe value and 513-1000i get positive value.mean at 512 i will get 0v.Hi,
In post#1 you want zero, now you want 512.
So there is the option to set a jumper. Then wire it to a port input. And when the port pin has the desired state you "force" the ADC value to 512 (or whatever you want). No need to do a conversion in this case.
Klaus
I've tried it twice already. It seems I'm not good with this. Maybe anyone else could do this for me. Thanks.can you please elaborate more about set jumper n all..
Hi,Hi,
I'm curious how you circuitry looks like. The MCU has a single supply e.g. VDD = 3.3 V & VSS = 0 V (GND). If there is no adequate biasing voltage applied (e.g. 3.3 V / 2; assuming your analog reference voltage is 3.3 V as well) at the input of your ADC you are trying to measure a negative voltage, which its out of range of your ADC. Have a look at the datasheet [1] at page 18, which mentions the following: " Input voltage range: 0 to VDDA".
[1] https://www.st.com/en/microcontrollers-microprocessors/stm8s003f3.html
BR
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.....
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!!!!!
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?