Home > other >  STM8S003F3 ADC problem
STM8S003F3 ADC problem

Time:09-20

Ask: I use PD2 (AIN3) sampling, the mouth I received GND, but to run the program, the sampling data to the constantly changing, is not 0. Using this chip for the first time, don't know what's the matter, please before to give directions, thank!
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Void init_adc (void)
{
//PD2
PD_DDR_DDR2=0;//PD2: input
PD_CR1_C12=0;
PD_CR2_C22=0;//FLOATING WIHTOUT INTERRUPT



ADC_CSR=0 x03;//EOCIE=0
//Channel: AIN3

ADC_TDRL |=0 x08;//AIN3: DISABLE Schmitt trigger

ADC_CR1=0 x00;//fADC=fMASTER/2
//CONT=1
//ADON=0

ADC_CR2=0 x00;//the ALIGN=0
//SCAN=0

ADC_CR3=0 x00;//DBUF=1

AdcFlag=0;

}

Void enable_adc (void)
{
Unsigned char I=0;
ADC_CR1 |=0 x01;
Delay_us (200);
for(i=0; i<10; I++)
{
ADC_CR1 |=0 x01;
while(! (ADC_CSR & amp; 0 x80));
AdcData [I]=ADC_DRH;
ADC_CR1 & amp;=0 x7f;
};

CodePudding user response:

Due to outside interference, the power supply noise, sampling the data change is normal, can through hardware and software to reduce influence,

CodePudding user response:

reference 1st floor xuyaqi029 response:
due to outside interference, power supply, such as noise data sampling to constantly change is normal, can through hardware and software to reduce influence,


Is, but near the theoretical value fluctuation data according to the truth, I fixed a sampling mouth level 0 V or 1.2 V, sampling to the value of the completely wrong, so strange,

Thank you for your reply.

CodePudding user response:

If sampling to value completely wrong, it may be there is a problem in your program,

CodePudding user response:

reference xuyaqi029 reply: 3/f
if sampling to the value of the completely wrong, that may be there is a problem in your program,


Is, so I send out the sampling program, don't feel where there are problems, EOC flag are normal production, would you please help to see what went wrong,

Feeling of STM to get too complicated, I used before EMC, SONIX, NYQUEST chips and so on Taiwan, are not so complicated, after the set up values conform to the theoretical value,

CodePudding user response:

reference 4 floor Lin Ningning response:
Quote: reference xuyaqi029 reply: 3/f

If sampling to value completely wrong, it may be there is a problem in your program,


Is, so I send out the sampling program, don't feel where there are problems, EOC flag are normal production, would you please help to see what went wrong,

Feeling of STM to get too complicated, I used before EMC, SONIX, NYQUEST chips and so on Taiwan, are not so complicated, after the set up values conform to the theoretical value,


I'm sorry, I don't have STM8S003F3, unable to help,

CodePudding user response:

Found the problem reasons, is not a problem of software code, is the OPTION BYTE AFR2 need set 1, otherwise the function to realize, when doing PWM output to refer to it,
  • Related