Помехи обусловлены алгоритмом фильтрации, пузырьковый алгоритм ,примененый вами ,ни как не годится для целей фильтрации
Алгоритм вычисления ЗИ ,судя по всему,тоже не совсем верный , погрешнотсь вашего алгоритма с моей катушкой составила 23 us. ниже прилагаю свой исходник , в нем значительно повышена стабильнось , с катушкой D=16 см на тоненькое золотое колечко чувство 17-18 см, печатка 20 см. Алгоритма расчета ЗИ пока нет , вводится в ручную методом проб и ошибок. У меня зи=80, rx=25 витков сечением 0.4 tx=27 витков такого же сечения d=16см .r15 и r17 не ставил
************************************************
This program was produced by the
CodeWizardAVR V1.25.3 Professional
Automatic Program Generator
© Copyright 1998-2007 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com
Project :
Version :
Date : 17.05.2009
Author : F4CG
Company : F4CG
Comments:
Chip type : ATtiny13
Clock frequency : 4,800000 MHz
Memory model : Tiny
External SRAM size : 0
Data Stack size : 16
*****************************************************/
#include <tiny13.h>
#include <delay.h>
#include <math.h>
#define ADC_VREF_TYPE 0x00
#define pulse 150
#define guardi 80
unsigned int z,z1,z3,sens=2;
unsigned char z2,i;
unsigned int ch[8];
// Timer 0 overflow interrupt service routine
interrupt [TIM0_OVF] void timer0_ovf_isr(void)
{
// Reinitialize Timer 0 value
//TCNT0=0x01;
TCNT0=(z2);
PORTB.1= !PINB.1;
// Place your code here
}
// Read the AD conversion result
unsigned int read_adc(unsigned char adc_input)
{
ADMUX=adc_input | (ADC_VREF_TYPE & 0xff);
// Start the AD conversion
ADCSRA|=0x40;
// Wait for the AD conversion to complete
while ((ADCSRA & 0x10)==0);
ADCSRA|=0x10;
return ADCW;
}
// Declare your global variables here
void main(void)
{
// Declare your local variables here
// Crystal Oscillator division factor: 1
#pragma optsize-
CLKPR=0x80;
CLKPR=0x00;
#ifdef _OPTIMIZE_SIZE_
#pragma optsize+
#endif
// Input/Output Ports initialization
// Port B initialization
// Func5=In Func4=In Func3=In Func2=Out Func1=Out Func0=In
// State5=T State4=P State3=T State2=0 State1=0 State0=T
PORTB=0x10;
DDRB=0x06;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: 75,000 kHz
// Mode: Normal top=FFh
// OC0A output: Disconnected
// OC0B output: Disconnected
TCCR0A=0x00;
TCCR0B=0x03;
TCNT0=0x01;
OCR0A=0x00;
OCR0B=0x00;
// External Interrupt(s) initialization
// INT0: Off
// Interrupt on any change on pins PCINT0-5: Off
GIMSK=0x00;
MCUCR=0x00;
// Timer/Counter 0 Interrupt(s) initialization
TIMSK0=0x00;
// Analog Comparator initialization
// Analog Comparator: Off
ACSR=0x80;
ADCSRB=0x00;
// ADC initialization
DIDR0=0x08;
ADMUX=ADC_VREF_TYPE & 0xff;
ADCSRA=0x83;
// Global enable interrupts
#asm("sei")
TIMSK0=0x02;
delay_ms(400);
TIMSK0=0x00;
PORTB.1=0;
PORTB.2=1; //start pulse
delay_us(pulse);
PORTB.2=0; //end pulse
delay_us(guardi); //guard int
z1=(1023-read_adc(3));
delay_ms(1000);
while (1)
{
TIMSK0=0x00;
PORTB.1=0;
PORTB.2=1; //start pulse
delay_us(pulse);
PORTB.2=0; //end pulse
delay_us(guardi); //guard int
z=(1023-read_adc(3));
//------------------------------filtr------------------------------------------
for (i=7;i>0;i--) {
ch[i]=ch[i-1]; //сдвигаем массив
}
ch[0]=z;
z3=0;
for (i=0;i<8;i++) {
z3=z3+ch[i]; //schitaem summu
}
z3=z3/8; //delim na 8
//------------------------------------------------------------------------------
z=z1-z3; // otnimaem iz z1
TIMSK0=0x00;
if (z>sens) {
z2=(z+180);
TIMSK0=0x02;
}
if (!PINB.4) {
delay_ms(1000);
z1=z3;}
delay_ms(16); //25
};
}