Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

ADC1 fluctuation

Status
Not open for further replies.

DANXIA

Junior Member level 2
Joined
Oct 20, 2020
Messages
20
Helped
0
Reputation
0
Reaction score
0
Trophy points
11
Activity points
169
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!!!!!
 
Last edited by a moderator:

If you input is floating then because it is hi-z input it will pick up noise, coupled and
possibly induced.

If you are not using it can you either stop it or just do a test on a flag to ignore inputs ?

As an aside there are processors out there that can terminate internally the input to
ground or chips Vdd, and /or stop the converter and power it down.

Alternatively you can use a GPIO pin configed as open drain, connect that pin to ADC input
pin, and turn it on (logic 0 to pin output register) to ground the ADC input pin.....then when
operating ADC write a "1" to that pin register, turning off the open drain pin, lifting the ground
on the ADC input pin. When you turn on ADC, turn off the open drain pin, allow for some settling
time for the adc sampler to acquire the input and "settle".....Only use this method if ADC source
to measure is not low Z itself, otherwise you will draw a lot of current from that source wasting
power, possibly violating pin current limits which affect internal buss supply voltage levels and
possibly chip operation.



Regards, Dana.
 
Last edited:

Hi,

Or simply connect a (relatively high ohmic) resistor to GND.

Klaus
 
Terminating ADC input with a R has considerations. Example 5 V logic,
coupled thru 10 pF of stray, will present the ADC with significant noise.
Depending on when ADC closes its sampling, and its own charge storage,
will reflect in possible noise of concern. You would have to play with this
and also consider ADC source signal loading.

1612396649939.png


Regards, Dana.
 

An open-drain I/O, or a tristate I/O with a choice
between 0 and Z states would work as an internal
input shunt.

For purposes of test, what's wrong with a shorting
connector / cap? Or on a PCB of your own design
a 3-post standard jumper header than can be
put to input or ground, close-in to the ADC input
pin?

If there's a large "antenna" left attached that will
give any such mitigation, a harder time to make
"dead quiet" (i.e. less than 1/2 LSB noise amplitude).
 

Hi,

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
 

Hi,

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
Hii
can you please explain your last paragraph?my only aim is to read adc value 512 if there is no input is connected.
 

Hi,

In post#1 you want zero, now you want 512.
can you please explain your last paragraph?my only aim is to read adc value 512 if there is no input is connected.
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
 

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
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.
can you please elaborate more about set jumper n all..
 

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
 

Hi,
can you please elaborate more about set jumper n all..
I've tried it twice already. It seems I'm not good with this. Maybe anyone else could do this for me. Thanks.

Klaus
 

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
Hi,
my VDD is 5v.so i mapped it 0-2.5-5=1000-0-(-1000).
but i am facing two issue...
1. ADC channel generating continuous some randome value
2.step size error.
this error can be minimize by oversampling.but i dont understand how to get stable adc value??????????????
 

A couple of questions (some confusion)-

1) How do you know an input is not connected to anything, electrically ?
In other words do you need to detect its connected and when its not
connected/floating ? Stated another way how do you insure that a reading
is of a connected input ?

2) What input Z can you live with to ADC. Asking because as mentioned
earlier if input has a R attached to it such that input never floats then the
ADC output will be full scale for R to Vdd, 0 or - scale for R connected to
ground.

3) Why cant you use code, a flag, to ignore ADC output when not in use ? Is
that because you have no means of knowing if it is unconnected versus
connected ?

The ST processor is limited in what can be done with its front end to ADC.
There are processors out there that can control an inputs connection and
termination internally. But that means you must know when to connect,
when to terminate, eg. some criteria for that operation.


Regards, Dana.
 

Hi,

please show as a schematic of your used circuitry, as you still have not clarified if there is a DC bias voltage applied. Further, we would see how your analog reference voltage is created and especially how it is applied to its corresponding MCU pin (filtering, ferrite beat, etc.).

Have you ever tried to directly attach e.g. an AA battery which has a nominal voltag of 1.5 V, to the input of your ADC. With the battery you should get a really stable reading. Further, you can perform a statistical evaluation by means of the mean value and standard deviation, which also can be used to calculate the SNR. With those values you are able to clarify how good your ADC is able to perform.

BR
 

For future reference this is an approach using a single chip and user
controlled routing to/from internal components and pins. A component
in this chips nomenclature is an onchip resource. A catalog of components
attached. Resources used/left for other tasks shown in right hand window.

Note could have been done with the SAR onchip as well, also the onchip mux and
A/D's, SAR and DelSig, could be done in differential mode if so desired.

Basically set up for 8 channels, could be more if needed. The top two channels
are onchip reference V's of ground and Vdd to force A/D to its extreme input
values when selected by mux under software control. Note MUX could have been
HW controlled if so desired, like using an onchip state machine (LUT) with DMA to
control whole process in HW.

1612614502035.png



Regards, Dana.
--- Updated ---

Note, depending on family, this has ARM core(s) in it.

Regards, Dana.
 

Attachments

  • Component List (2).pdf
    183 KB · Views: 76
Last edited:

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!!!!!


Simplily connect a (relatively high ohmic) resistor to GND.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top