0
我有一個ADC中斷,我想對通道(ADCBUF0)進行8次採樣,然後取樣本的平均值。我的代碼利用標誌跳出if語句。代碼編譯和我的變量在別處被初始化。有人能告訴我爲什麼我沒有收到SpeedADC的價值?在ADC中斷中使用位移和陣列的平均值
///////Global////////////
int SpeedADCcount=0;
/////////////////////////
SpeedADCflag=1;
if(SpeedADCflag==1) //The following is meant to take a an average of the incoming ADC voltages
{
SpeedADCcount++;
for(i = SpeedADCcount; i < 16; i++)
{
while(!ADCON1bits.SAMP); //Sample Done?
ADCON1bits.SAMP=0; //Start Converting
while(!ADCON1bits.DONE); //Conversion Done? Should be on next Tcy cycle
SpeedADCarray[i] = ADCBUF0;
SpeedADCflag=0;
}
}
if(SpeedADCcount==15)
{
SpeedADC=SpeedADCarray[i]>>4;
SpeedADCcount=0;
// Re-enable the motor if it was turned off previous
if((SpeedADC>246) && Flags.RunMotor==0){RunMotor();}
/*Go through another stage of "filtering" for any analog input voltage below 1.25volts
你在哪裏計算平均值? –
我假設平均值將被定義爲SpeedADC = SpeedADCarray [i] >> SpeedADCcount – Stumpyhuck29
這是將* 1 *的樣本除以2^SpeedADCcount(其中^爲「of the power of」)。 –