Home > other >  STM8L ADC sampling strange phenomenon
STM8L ADC sampling strange phenomenon

Time:10-18

Consult everybody, in the following program, I can only channel 1 normal collection, when only channel 2 can also be normal, but if use the channel 1 and channel 2 at the same time, the channel 1 and 2 show the numerical data for channel 2, channel 1 can't normal collection, where is the problem? Program the following


Uint8_t ADC_CH;
Uint16_t ADCdata1;
Uint16_t ADCdata2;

Uint16_t ADC_GetCh1 uint8_t (ch)
{uint16_t tmpreg=0;

ADC1_CR1_bit. ADON=1;//wake ADC
ADC1_SQR4_bit. CHSEL_S1=1;//set the channel 1 effective
//ADC_ITConfig (ADC1/* and */ADC_IT_EOC, ENABLE);//set the ADC sampling interrupt
ADC1_CR1_bit. START=1;//start conversion

While (ADC1_SR_bit. EOC==1);//wait for conversion end
Tmpreg=(uint16_t) (ADC1_DRH);
Tmpreg=(uint16_t) ((uint16_t) ((uint16_t) tmpreg & lt; <8) | ADC1_DRL);
ADC1_SR_bit. The EOC=0;//remove interrupt flag

ADC1_CR1_bit. ADON=0;//close the ADC
ADC1_SQR4_bit. CHSEL_S1=0;//remove the channel 1

Return tmpreg;
}


Uint16_t ADC_GetCh2 uint8_t (ch) {
Uint16_t tmpreg=0;

ADC1_CR1_bit. ADON=1;//wake ADC
ADC1_SQR4_bit. CHSEL_S2=1;//
//ADC_ITConfig (ADC1/* and */ADC_IT_EOC, ENABLE);//set the ADC sampling interrupt
ADC1_CR1_bit. START=1;//start conversion

While (ADC1_SR_bit. EOC==0);//wait for conversion end
Tmpreg=(uint16_t) (ADC1_DRH);
Tmpreg=(uint16_t) ((uint16_t) ((uint16_t) tmpreg & lt; <8) | ADC1_DRL);
ADC1_SR_bit. The EOC=0;//remove interrupt flag

ADC1_CR1_bit. ADON=0;//close the ADC ADC_Cmd (ADC1/* and */ENABLE);
ADC1_SQR4_bit. CHSEL_S2=0;//remove set channel 2

Return tmpreg;
}

Int main (void)
{under-16 adc1=234;
Under-16 adc2=587;


CLK_CKDIVR=0 x00;//internal clock to 1 points frequency=16 MHZ

OLED_AInit ();//OLED display initialization

CLK_PCKENR2_bit. PCKEN20=1;//open the ADC clock

PA_DDR_bit. DDR4=0;//set PA - & gt; 4 for the input
PA_CR1_bit. C14=0;//set to dangling inputs
PA_CR2_bit. C24=0;//set the interrupt disabling

PA_DDR_bit. DDR5=0;//set PA - & gt; 5 to enter
PA_CR1_bit. C15=0;//set to dangling inputs
PA_CR2_bit. C25=0;//set the interrupt disabling

ADC1_CR1_bit. RES=0;//set 12 resolution
ADC1_CR1_bit. CONT=0;//set to a single conversion mode
//ADC1_CR1_bit. CONT=1;//set to continuous conversion mode
ADC1_CR2_bit. PRESC=1;////ADC clock divider
2ADC1_CR2_bit. SMTP1=7;//

While (1)
{adc1=ADC_GetCh1 (1);//ADC1 sampling function
Adc2=ADC_GetCh2 (2);//ADC2 sampling function

OLED_ShowcADC1 (adc1);
OLED_ShowcADC2 (adc2);
}
return 0;
}

CodePudding user response:

Sample 1
According to 1
Sample 2
According to 2 try

CodePudding user response:

Sample 1
According to 1
Sample 2
Display 2 try just tried, no, may not be a time of the thing on the

CodePudding user response:

The building Lord, how much is your OLED display refresh time? Display refresh too fast will see only channel sampling values of 2,
You can change our order
OLED_ShowcADC2 (adc2);
OLED_ShowcADC1 (adc1);
And see if it is only show samples values for channel 1,
  • Related