Urządzenie niby proste a jest problem. Przetwornik 4-20mA.
Jeżeli na wejściu ADC Atmegi jest napięcie 2,425V to na wyświetlaczu ma się wyświetlić wartość 450, a jeżeli na ADC Atmegi jest napięcie 0,809V to na wyświetlaczu ma się wyświetlić wartość 600. Nawet jak uśredniłem wynik ( ze 100 pomiarów ) to ostatnia cyfra skacze np. przy wartości 550 cały czas skacze 549, 550, 551 i tak w kółko. Bez uśredniania wyniku przy wartości ustawionej 550 na LCD pokazują się wyniki w zakresie od 539 do 563.
Schemat w załączniku poniżej. Bardzo proszę o podpowiedź jak to ugryźć. W normalnej sytuacji ta skacząca wartość nie miała by znaczenia ale w tym przypadku jest to bardzo ważne. Podłączając miernik pod piny, wartość napięcia jest stała, tzn. nie skacze, a wynik na LCD tak.
- $regfile = "m8def.dat"
- $crystal = 8000000
- '----- KONFIGURACJA WYŚWIETLACZA -----------------------------------------------
- Config Lcd = 16 * 2
- Config Lcdpin = Pin , Db4 = Portd.3 , Db5 = Portd.2 , Db6 = Portd.1 , Db7 = Portd.0 , E = Portd.4 , Rs = Portd.5
- Cursor Off , Noblink
- Cls
- '----- KONFIGURACJA PORTÓW WEJŚCIA I WYJŚCIA / SCL i SDA / 1 WIRE / ALIASY -----
- Config Portb.0 = Output : Reset Portb.0 : Dodaj Alias Portb.0
- Config Portb.1 = Output : Reset Portb.1 : Disp Alias Portb.1
- Config Portb.2 = Output : Reset Portb.2
- Config Pinb.3 = Input : Set Portb.3 : Dn Alias Pinb.3
- Config Pinb.4 = Input : Set Portb.4 : Up Alias Pinb.4
- Config Pinb.5 = Input : Set Portb.5 : Menu Alias Pinb.5
- Config Portc.0 = Output : Reset Portc.0
- Config Portc.1 = Output : Reset Portc.1
- Config Portc.3 = Output : Reset Portc.3
- Config Portc.4 = Output : Reset Portc.4
- Config Portc.5 = Output : Reset Portc.5
- Config Portd.6 = Output : Set Portd.6 : Buzer Alias Portd.6
- Config Portd.7 = Output : Reset Portd.7 : Odejmij Alias Portd.7
- '----- KONFIGURACJA ADC --------------------------------------------------------
- Config Adc = Single , Prescaler = 128 , Reference = Internal
- Start Adc
- 'Config ADC = Single | Free
- 'Prescaler = Auto | 2| 4| 8 | 16 | 32 | 64 | 128
- 'Reference = Off | Avcc | Internal
- '----- KONFIGURACJA TIMERÓW I PRZERWAŃ -----------------------------------------
- Config Timer0 = Timer , Prescale = 256
- On Timer0 Generator_01s
- Enable Timer0
- Enable Interrupts
- '----- DEKLARACJA STAŁYCH I ZMIENNYCH ------------------------------------------
- Dim Impuls As Byte , Licznik As Byte
- Dim Suma_pary As Single , Krok As Word
- Dim Para As Word , Para_1 As Word , Para_2 As Word , Para_3 As Single , Para_4 As Word , Para_5 As Word
- '----- STARTOWY ODCZYT EEPROM --------------------------------------------------
- '----- WARTOŚCI ZMIENNYCH USTALANE PRZY STARCIE --------------------------------
- Licznik = 0
- '----- PĘTLA GŁÓWNA ------------------------------------------------------------
- Disp = 1
- Buzer = 0 : Waitms 500 : Buzer = 1
- Do
- If Licznik = 8 Then
- Gosub Pomiar_ciśnienia
- Locate 1 , 5 : Lcd "PARA " ; Para
- Locate 2 , 13 : Lcd Para_2 ; " "
- Licznik = 0
- End If
- Loop
- '*************************************
- Pomiar_ciśnienia:
- Suma_pary = 0
- For Krok = 1 To 100
- Para_1 = Getadc(2)
- Suma_pary = Suma_pary + Para_1
- Next Krok
- Para_2 = Suma_pary / 100
- Para_3 = Para_2 / 4.86
- Para_4 = Para_3
- Para = 656 - Para_4
- Return
- '*************************************
- Odejmowanie:
- Return
- '*************************************
- Dodawanie:
- Return
- '*************************************
- Przygotuj_odejmowanie:
- Return
- '*************************************
- Przygotuj_dodawanie:
- Return
- '*************************************
- '*************************************
- Generator_01s:
- Load Timer0 = 250
- Incr Impuls
- If Impuls = 12 Then '12*8ms=96ms
- Impuls = 0
- Incr Licznik
- End If
- Return
- '*************************************