BASCOM

Kalkulator do obliczeń tłumika rezystorowego typu T


Tłumiki rezystorowe używamy w sytuacji konieczności tłumienia poziomu napięć zmiennych oraz, gdy potrzebujemy zachować stałą rezystancję wejściową lub wyjściową.
Kalkulator pozwala w sposób błyskawiczny uzyskać dane wartości rezystorów wchodzących w skład tłumika.

'Tlumik1.bas

'Projektowanie tłumika rezystorowego typu T.

'Patrz schemat Tlumik1.png

'Pamięć zajęta w 71%.

'Opracował Henryk Wydmuch

'Sposób działania:

'dołącz klawiaturę komputerową do Portb.2 i Portb.1,

'przyciśnij przycisk P1 (Portd.7), trzymaj, wpisz na klawiaturze tłumienie filtru (od 1 do 40dB),

'przyciśnij P2 (Portd.6), trzymaj, wpisz na klawiaturze oporność wejściową (wyjściową) tłumika,

'teraz odczytaj wynik obliczeń naciskając F1 (na klawiaturze).

'Na wyświetlaczu Lcd zobaczysz wartości: R1, R2,(patrz schemat).

 

 $regfile = "m8def.dat"                                     'Dyrektywy dla kompilatora.

 $crystal = 4000000                                         'Zastosujemy generator wewnętrzny 4MHz (bez kwarcu).

Config Lcd = 16 * 2                                         'Konfigurujemy Lcd.

Config Lcdpin = Pin , Db4 = Portc.3 , Db5 = Portc.2 , Db6 = Portc.1 , Db7 = Portc.0 , E = Portc.4 , Rs = Portc.5

                                       'LCD dłączony do Port 2, 3, 4, 6, 1, 0.

Config Keyboard = Pinb.2 , Data = Pinb.1 , Keydata = Keydata       'Keyboard=klawiatura, podłączona do Pinb.2 i 1.

 

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

 Config Pind.7 = Input                                      'Konfiguracje Portów.

 Config Pind.6 = Input                                      '

 Config Pind.2 = Output                                     '

 Config Pind.3 = Output                                     '

 Config Pind.4 = Output                                     '

 Set Portd.7                                                '

 Set Portd.6                                                '

 Set Portd.2                                                '

 Set Portd.3                                                '

 Set Portd.4                                                '

 

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

 Dim A1 As Single                                           'Deklaracje zmiennych.

 Dim A4 As Single                                           '

 Dim Rwe As Word                                            '

 Dim R1 As Word                                             '

 Dim R2 As Word                                             '

 Dim Kodklaw As Byte                                        '

 Dim Zapis As String * 4                                    '

 Dim Zet As String * 4                                      '

 Dim Decyb As Word                                          '

 Dim Licz As Byte                                           '

 Dim B1 As String * 4                                       '

 Dim B2 As String * 4                                       '

 Dim B3 As String * 4                                       '

 Dim B4 As String * 4                                       '

 Dim Con As Byte                                            '

 Dim C1 As String * 4                                       '

 Dim C2 As String * 4                                       '

 

 Deflcdchar 0 , 32 , 16 , 20 , 24 , 16 , 16 , 30 , 32       'Narysowano ł. (Rysujemy tutaj: Ctrl+L i LCD Designer).

 Deflcdchar 1 , 32 , 32 , 28 , 2 , 30 , 18 , 30 , 1         'Narysowano ą.

 Deflcdchar 2 , 1 , 2 , 15 , 8 , 6 , 1 , 15 , 32            'Narysowano ś.

 Deflcdchar 3 , 2 , 4 , 30 , 18 , 16 , 16 , 30 , 32         'Narysowano ć.

 Deflcdchar 4 , 32 , 32 , 30 , 18 , 30 , 16 , 30 , 4        'Narysowano ę.

 

 Cls                                                        '

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

 Do                                                         'Pętla.

  Kodklaw = Getatkbd()                                      '

 

'''''''''''''''''''''''''''''''''''''''''''''''

 If Kodklaw > 58 And Kodklaw < 127 Then                     'Jeśli przyciśniemy jakąś literę...

 Home                                                       'Czyść Lcd.

 Lcd Chr(kodklaw)                                           'Pokaż ten znak.

 Lowerline                                                  '

 Lcd "B" ; Chr(0) ; Chr(1) ; "d klawiatury!"                'POkaż komunikat.

 End If                                                     '                                                   '

 

',,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

 If Kodklaw > 31 And Kodklaw < 48 Then                      'Jeśli przyciśniemy jakiś znak na klawiaturze...

 Home                                                       'Czyść Lcd.

 Lcd Chr(kodklaw)                                           'Pokaż ten znak.

 Lowerline                                                  '

 Lcd "B" ; Chr(0) ; Chr(1) ; "d klawiatury!"                'POkaż komunikat.

 End If                                                     '                                                 '

 

'--------P1-przycisk--dB-------------------------------

 If Pind.7 = 0 Then                                         'Przyciśnij P1 i wpisz tłumienie w dB (od 1 do 40).

 Reset Portd.3                                              'Zaświeć Led.

 If Kodklaw > 47 And Kodklaw < 58 Then                      'Jeśli wybrano klawisz cyfry na klawiaturze...

 Incr Con                                                   'Po naciśnięciu klawisza klawiatury, powiększaj zmienną.

 Home                                                       '

 Lowerline                                                  '

 

 Select Case Con                                            'Przeglądaj zmienną Con.

 Case 1:                                                    'Pierwszy klawisz(jedna cyfra).

 C1 = Chr(kodklaw)                                          'Zamień ASCI i wpisz do C1.

 Zapis = C1                                                 'Zmienna Zapis zawiera liczbę decybeli (wpisane tłumienie z klawiatury).

 Decyb = Val(zapis)                                         'Zawartość zmiennej Zapis zostaje zamieniona na liczbę.

 Writeeeprom Decyb , 1                                      'Liczba zostaje zapisana do Eprom.

 Lcd Decyb ; " dB    "                                      'Pokaż tę liczbę.

 Case 2:                                                    'Drugi klawisz(druga cyfra).

 C2 = Chr(kodklaw)                                          '

 Zapis = C1 + C2                                            'Zmienna Zapis zawiera liczbę decybeli (wpisane tłumienie z klawiatury).

 Decyb = Val(zapis)                                         '

 Writeeeprom Decyb , 1                                      'Liczba zostaje zapisana do Eprom.

 Lcd Decyb ; " dB    "                                      'Pokaż tę liczbę.

   If Decyb > 40 Then                                       'Jeśli wpiszemy liczbę większą od 40...

    Locate 1 , 1                                            '

    Lcd "Tylko do 40dB!   "                                 'Komunikat.

   End If                                                   '

 Case 3:                                                    '

 Lcd "Tylko do 40 dB!   "                                   '

 Decyb = 0                                                  '

 End Select                                                 '

 

 End If                                                     'Koniec warunku.

 End If                                                     '

'---------------------------------------

  If Pind.7 = 1 Then                                        'P1 nie wciśnięty.

  If Kodklaw > 47 And Kodklaw < 58 Then                     'Jeśli nacisnęliśmy cyfrę, ale brak przycisku P1...

 Home                                                       'Czyść Lcd.

 Lcd Chr(kodklaw) ; " Brak przycisku" ;                     '

 Lowerline                                                  '

 Lcd "B" ; Chr(0) ; Chr(1) ; "d klawiatury!"                'POkaż komunikat.

 End If                                                     '                                                  '

 End If                                                     '

 

'.........P2 przycisk, Rwe-Rwy.................................

 If Pind.6 = 0 Then                                         'Przyciśnij P2 i wpisz oporność wejściową i wyjściową tłumika.

 If Kodklaw > 47 And Kodklaw < 58 Then                      'Jeśli wybrano klawisz klawiatury od 0 do 9...

 Reset Portd.2                                              'Zaświeć Led.

 Cls                                                        '

 Home                                                       '

 Incr Licz                                                  'Po naciśnięciu klawisza klawiatury, powiększaj zmienną.

 

 Select Case Licz                                           'Przeglądaj zmienną Licz.

 Case 1 : B1 = Chr(kodklaw)                                 'Pierwszy klawisz wpisz do B1.

 Zet = B1                                                   'Zmienna Z = B1(B1 czyli numer ASCI).

 Rwe = Val(zet)                                             'Odczytaj ASCI i zamień na cyfrę. Wpisz ją do Rwe.

 Writeeeprom Rwe , 5                                        'Cyfrę zapisz do Eprom, adres 5.

 Lcd "Rwe " ; Rwe ; "     " ;                               'Pokaż cyfrę.

 Case 2 : B2 = Chr(kodklaw)                                 '

 Zet = B1 + B2                                              '

 Rwe = Val(zet)                                             '

 Writeeeprom Rwe , 5                                        '

 Lcd "Rwe " ; Rwe ; "     " ;                               '

 Case 3 : B3 = Chr(kodklaw)                                 '

 Zet = B1 + B2 + B3                                         '

 Rwe = Val(zet)                                             '

 Writeeeprom Rwe , 5                                        '

 Lcd "Rwe " ; Rwe ; "     " ;                               '

 Case 4 : B4 = Chr(kodklaw)                                 '

 Zet = B1 + B2 + B3 + B4                                    '

 Rwe = Val(zet)                                             '

 Writeeeprom Rwe , 5                                        '

 Lcd "Rwe " ; Rwe ; "     " ;                               '

 Rwe = 0                                                    '

 Case 5 :                                                   '

 Lcd "Tylko 4 cyfry!     "                                  '

 End Select                                                 '

 

 End If                                                     '

 End If                                                     '

 

 '.........Delette.......................................

  If Kodklaw = 127 Then                                     'Kasowanie Eprom (Delette).

  Decyb = 0                                                 '

  Rwe = 0                                                   '

  Writeeeprom Decyb , 1                                     'Zapis zera.

  Writeeeprom Rwe , 5                                       'Zapis zera.

 End If                                                     '

'.......................................................

 

'----Odczyt wyniku--------------------------------------

 If Kodklaw = 5 Then                                        'Przyciśnięcie F1, odczyt wyniku.

 Cls                                                        'Czyść Lcd.

 Readeeprom Decyb , 1                                       'Odczyt wprowadzonego z klawiatury tłumienia w dB.

 Readeeprom Rwe , 5                                         'Odczyt wprowadzonej z klawiatury oporności wej/wyj.

 Toggle Portd.4                                             'Zaświeć Led.

 

 Select Case Decyb                                          'Przeglądaj zmienną Decyb

 Case 1 : A1 = 0.0575                                       'Jeśli tłumienie ma mieć 1dB...

 A4 = 8.688                                                 '

 Gosub Pokaz                                                '

 Decyb = 0                                                  '

 Rwe = 0                                                    '

 

 Case 2 : A1 = 0.115                                        'Jeśli tłumienie ma mieć 2dB...

 A4 = 4.304                                                 '

 Gosub Pokaz                                                '

 Decyb = 0                                                  '

 Rwe = 0                                                    '

 

 Case 3 : A1 = 0.171                                        'Jeśli tłumienie ma mieć 3dB...

 A4 = 2.836                                                 '

 Gosub Pokaz                                                '

 Decyb = 0                                                  '

 Rwe = 0                                                    '

 

 Case 4 : A1 = 0.226                                        'Jeśli tłumienie ma mieć 4dB...

 A4 = 2.086                                                 '

 Gosub Pokaz                                                '

 Decyb = 0                                                  '

 Rwe = 0                                                    '

 

 Case 5 : A1 = 0.280                                        'Jeśli tłumienie ma mieć 5dB...

 A4 = 1.645                                                 '

 Gosub Pokaz                                                '

 Decyb = 0                                                  '

 Rwe = 0                                                    '

 

 Case 6 : A1 = 0.332                                        'Jeśli tłumienie ma mieć 6dB...

 A4 = 1.339                                                 '

 Gosub Pokaz                                                '

 Decyb = 0                                                  '

 Rwe = 0                                                    '

 

 Case 7 : A1 = 0.383                                        'Jeśli tłumienie ma mieć 7dB...

 A4 = 1.116                                                 '

 Gosub Pokaz                                                '

 Decyb = 0                                                  '

 Rwe = 0                                                    '

 

 Case 8 : A1 = 0.430                                        'Jeśli tłumienie ma mieć 8dB...

 A4 = 0.947                                                 '

 Gosub Pokaz                                                '

 Decyb = 0                                                  '

 Rwe = 0                                                    '

 

 Case 9 : A1 = 0.476                                        'Jeśli tłumienie ma mieć 9dB...

 A4 = 0.811                                                 '

 Gosub Pokaz                                                '

 Decyb = 0                                                  '

 Rwe = 0                                                    '

 

 Case 10 : A1 = 0.519                                       'Jeśli tłumienie ma mieć 10dB...

 A4 = 0.703                                                 '

 Gosub Pokaz                                                '

 Decyb = 0                                                  '

 Rwe = 0                                                    '

 

 Case 11 : A1 = 0.560                                       'Jeśli tłumienie ma mieć 11dB...

 A4 = 0.612                                                 '

 Gosub Pokaz                                                '

 Decyb = 0                                                  '

 Rwe = 0                                                    '

 

 Case 12 : A1 = 0.598                                       'Jeśli tłumienie ma mieć 12dB...

 A4 = 0.536                                                 '

 Gosub Pokaz                                                '

 Decyb = 0                                                  '

 Rwe = 0                                                    '

 

 Case 13 : A1 = 0.634                                       'Jeśli tłumienie ma mieć 13dB...

 A4 = 0.471                                                 '

 Gosub Pokaz                                                '

 Decyb = 0                                                  '

 Rwe = 0                                                    '

 

 Case 14 : A1 = 0.667                                       'Jeśli tłumienie ma mieć 14dB...

 A4 = 0.416                                                 '

 Gosub Pokaz                                                '

 Decyb = 0                                                  '

 Rwe = 0                                                    '

 

 Case 15 : A1 = 0.698                                       'Jeśli tłumienie ma mieć 15dB...

 A4 = 0.367                                                 '

 Gosub Pokaz                                                '

 Decyb = 0                                                  '

 Rwe = 0                                                    '

 

 Case 16 : A1 = 0.726                                       'Jeśli tłumienie ma mieć 16dB...

 A4 = 0.325                                                 '

 Gosub Pokaz                                                '

 Decyb = 0                                                  '

 Rwe = 0                                                    '

 

 Case 17 : A1 = 0.753                                       'Jeśli tłumienie ma mieć 17dB...

 A4 = 0.288                                                 '

 Gosub Pokaz                                                '

 Decyb = 0                                                  '

 Rwe = 0                                                    '

 

 Case 18 : A1 = 0.777                                       'Jeśli tłumienie ma mieć 18dB...

 A4 = 0.256                                                 '

 Gosub Pokaz                                                '

 Decyb = 0                                                  '

 Rwe = 0                                                    '

 

 Case 19 : A1 = 0.798                                       'Jeśli tłumienie ma mieć 19dB...

 A4 = 0.227                                                 '

 Gosub Pokaz                                                '

 Decyb = 0                                                  '

 Rwe = 0                                                    '

 

 Case 20 : A1 = 0.818                                       'Jeśli tłumienie ma mieć 20dB...

 A4 = 0.202                                                 '

 Gosub Pokaz                                                '

 Decyb = 0                                                  '

 Rwe = 0                                                    '

 

 Case 21 : A1 = 0.836                                       'Jeśli tłumienie ma mieć 21dB...

 A4 = 0.180                                                 '

 Gosub Pokaz                                                '

 Decyb = 0                                                  '

 Rwe = 0                                                    '

 

 Case 22 : A1 = 0.853                                       'Jeśli tłumienie ma mieć 22dB...

 A4 = 0.160                                                 '

 Gosub Pokaz                                                '

 Decyb = 0                                                  '

 Rwe = 0                                                    '

 

 Case 23 : A1 = 0.868                                       'Jeśli tłumienie ma mieć 23dB...

 A4 = 0.142                                                 '

 Gosub Pokaz                                                '

 Decyb = 0                                                  '

 Rwe = 0                                                    '

 

 Case 24 : A1 = 0.881                                       'Jeśli tłumienie ma mieć 24dB...

 A4 = 0.127                                                 '

 Gosub Pokaz                                                '

 Decyb = 0                                                  '

 Rwe = 0                                                    '

 

 Case 25 : A1 = 0.894                                       'Jeśli tłumienie ma mieć 25dB...

 A4 = 0.113                                                 '

 Gosub Pokaz                                                '

 Decyb = 0                                                  '

 Rwe = 0                                                    '

 

 Case 26 : A1 = 0.905                                       'Jeśli tłumienie ma mieć 26dB...

 A4 = 0.101                                                 '

 Gosub Pokaz                                                '

 Decyb = 0                                                  '

 Rwe = 0                                                    '

 

 Case 27 : A1 = 0.915                                       'Jeśli tłumienie ma mieć 27dB...

 A4 = 0.0895                                                '

 Gosub Pokaz                                                '

 Decyb = 0                                                  '

 Rwe = 0                                                    '

 

 Case 28 : A1 = 0.924                                       'Jeśli tłumienie ma mieć 28dB...

 A4 = 0.0800                                                '

 Gosub Pokaz                                                '

 Decyb = 0                                                  '

 Rwe = 0                                                    '

 

 Case 29 : A1 = 0.928                                       'Jeśli tłumienie ma mieć 29dB...

 A4 = 0.0710                                                '

 Gosub Pokaz                                                '

 Decyb = 0                                                  '

 Rwe = 0                                                    '

 

 Case 30 : A1 = 0.939                                       'Jeśli tłumienie ma mieć 30dB...

 A4 = 0.0654                                                '

 Gosub Pokaz                                                '

 Decyb = 0                                                  '

 Rwe = 0                                                    '

 

 Case 31 : A1 = 0.945                                       'Jeśli tłumienie ma mieć 31dB...

 A4 = 0.0564                                                '

 Gosub Pokaz                                                '

 Decyb = 0                                                  '

 Rwe = 0                                                    '

 

 Case 32 : A1 = 0.950                                       'Jeśli tłumienie ma mieć 32dB...

 A4 = 0.0503                                                '

 Gosub Pokaz                                                '

 Decyb = 0                                                  '

 Rwe = 0                                                    '

 

 Case 33 : A1 = 0.955                                       'Jeśli tłumienie ma mieć 33dB...

 A4 = 0.0448                                                '

 Gosub Pokaz                                                '

 Decyb = 0                                                  '

 Rwe = 0                                                    '

 

 Case 34 : A1 = 0.960                                       'Jeśli tłumienie ma mieć 34dB...

 A4 = 0.0399                                                '

 Gosub Pokaz                                                '

 Decyb = 0                                                  '

 Rwe = 0                                                    '

 

 Case 35 : A1 = 0.965                                       'Jeśli tłumienie ma mieć 35dB...

 A4 = 0.0358                                                '

 Gosub Pokaz                                                '

 Decyb = 0                                                  '

 Rwe = 0                                                    '

 

 Case 36 : A1 = 0.969                                       'Jeśli tłumienie ma mieć 36dB...

 A4 = 0.0306                                                '

 Gosub Pokaz                                                '

 Decyb = 0                                                  '

 Rwe = 0                                                    '

 

 Case 37 : A1 = 0.973                                       'Jeśli tłumienie ma mieć 37dB...

 A4 = 0.0282                                                '

 Gosub Pokaz                                                '

 Decyb = 0                                                  '

 Rwe = 0                                                    '

 

 Case 38 : A1 = 0.976                                       'Jeśli tłumienie ma mieć 38dB...

 A4 = 0.0252                                                '

 Gosub Pokaz                                                '

 Decyb = 0                                                  '

 Rwe = 0                                                    '

 

 Case 39 : A1 = 0.978                                       'Jeśli tłumienie ma mieć 39dB...

 A4 = 0.0225                                                '

 Gosub Pokaz                                                '

 Decyb = 0                                                  '

 Rwe = 0                                                    '

 

 Case 40 : A1 = 0.980                                       'Jeśli tłumienie ma mieć 40dB...

 A4 = 0.0200                                                '

 Gosub Pokaz                                                '

 Decyb = 0                                                  '

 Rwe = 0                                                    '

 

 End Select                                                 '

 End If                                                     '

 

 Loop                                                       'Powtarzaj pętlę.

 End                                                        'Koniec tej pętli.

'----------------------------------------------------

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

 Pokaz:                                                     'Podprogram wyliczenia R1 i R2

 R1 = A1 * Rwe                                              'Mnożenie.

 R2 = A4 * Rwe                                              'Mnożenie.

 Lcd "R1=" ; R1 ; "  R2=" ; R2 ;                            'Pokaż wynik R1 R2.

 Lowerline                                                  '

 Lcd "dB" ; Decyb ; " Rwe/wy" ; Rwe ;                       'Przy takich założeniach.

 Return                                                     'Wracaj do pętli.

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

 

  'Tablica numerów przycisków klawiatury AT w kodzie ASCI:

Keydata:                                                    'Podprogram tablicy.

     'Małe litery

   Data 0 , 5 , 0 , 3 , 4 , 5 , 6 , &H07 , 5 , 5 , 5 , &H0B , &H0C , 0,       ''''''''''''A

   Data 63 , 63 , 63 , 63 , 63 , 63 , 63 , 113 , 49 , 63 , 63 , 63 , 122,       ''''''''''B

   Data 115 , 97 , 119 , 50 , 63 , 63 , 99 , 120 , 100 , 101 , 52 ,       ''''''''''''''''C

   Data 51 , 63 , 63 , 32 , 118 , 102 , 116 , 114 , 53 , 63 , 63 , 110 ,       '''''''''''D

   Data 98 , 104 , 103 , 121 , 54 , 63 , 63 , 63 , 109 , 106 , 117 , 55 ,       ''''''''''E

   Data 56 , 63 , 63 , 44 , 107 , 105 , 111 , 48 , 57 , 63 , 63 , 46 , 47 ,       ''''''''F

   Data 108 , 59 , 112 , 95 , 63 , 63 , 63 , 63 , 63 , 63 , 61 , 63 , 63 , 63 ,       ''''G

   Data 63 , 13 , 63 , 63 , 124 , 63 , 63 , 63 , 63 , 63 , 63 , 63 , 63 , 63 , 63,       'H

   Data 63 , 49 , 63 , 52 , 55 , 63 , 63 , 63 , 48 , 127 , 50 , 53 , 54 , 56,       ''''''I

   Data 1 , 63 , 5 , 43 , 51 , 45 , 42 , 57 , 63 , 63       ''''''''''''''''''''''''''''''J

 

    'Duże litery

  Data 0 , 0 , 0 , 5 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0,       ''''''''''K

  Data 0 , 0 , 0 , 0 , 0 , 0 , 81 , 33 , 03 , 0 , 0 , 90 , 83 , 65,       ''''''''L

  Data 87 , 64 , 0 , 0 , 67 , 88 , 68 , 69 , 36 , 35 , 0 , 0 , 0 , 86,       '''''M

  Data 70 , 84 , 82 , 37 , 0 , 0 , 78 , 66 , 72 , 71 , 89 , 94 , 0,       ''''''''N

  Data 0 , 0 , 77 , 74 , 85 , 38 , 42 , 0 , 0 , 60 , 75 , 73 , 79,       '''''''''O

  Data 41 , 40 , 0 , 0 , 62 , 63 , 76 , 58 , 80 , 0 , 0 , 0 , 0 , 0,       '''''''P

  Data 0 , 123 , 43 , 0 , 0 , 0 , 0 , 0 , 125 , 0 , 0 , 0 , 0 , 0 , 0,       '''''Q

  Data 0 , 0 , 0 , 0 , 0 , 0 , 49 , 49 , 0 , 52 , 55 , 0 , 0 , 0 , 48,       '''''R

  Data 44 , 50 , 53 , 54 , 56 , 0 , 0 , 0 , 43 , 51 , 45 , 42 , 57 , 0 , 0       'S

'---------------------------------------------------------------------------