Niemniej program pokazuje jak można użyć wejścia ICP do mierzenia jedncześnie długości impulsu masowego i plusowego co pozwala obliczyć wypełnienie
![Sarkazm ;)](./images/smilies/icon_e_wink.gif)
Program nie był przeze mnie bardziej testowany i może jakiś bug się tam ukrywa
![Duże szczęście, bardzo dobry humor :D](./images/smilies/icon_e_biggrin.gif)
Code: [Zaznacz cały] [Rozwiń/Zwiń]
- $regfile = "m32def.dat"
- $crystal = 16000000
- $hwstack = 64
- $swstack = 32
- $framesize = 128
- '***********************************************************
- '* *
- '* PROSTY MIERNIK CZĘSTOTLIWOŚCI, WYPEŁNIENIA I CZASÓW *
- '* *
- '* BARTek niveasoft *
- '***********************************************************
- Config Lcd = 20x4
- Config Lcdpin = Pin , Rs = Portb.4 , E = Portb.3 , Db4 = Portb.2 , Db5 = Porta.0 , Db6 = Porta.1 , Db7 = Porta.2
- Cursor Off , Noblink
- Cls
- Config Timer1 = Counter , Prescale = 64 , Capture_edge = Falling , Noise_cancel = 1 '262ms max
- Config Timer2 = Timer , Prescale = 1024 , Compare = Disconnect , Clear_timer = 1
- Enable Compare2 : On Compare2 Przerwanie_timer2 Nosave
- Compare2 = 155 '10ms @16MHz/1024
- Dim Miliseconds As Byte , 500ms As Byte , 1000ms As Byte
- Dim Mig As Byte , Helpb As Byte
- Dim New_tim As Word , Old_tim As Word , New_hi As Word , New_lo As Word , Period As Word
- Dim New_impuls As Byte , Countdown As Byte , Copy_hi As Word , Copy_lo As Word
- Dim Helpd As Dword , Freq As Dword , Time_hi As Dword , Time_lo As Dword , Duty As Dword
- Config Portd.6 = Input : Signal_in Alias Pind.6
- On Capture1 Capture_isr Nosave
- Enable Capture1
- Enable Interrupts
- Const Edge_fall = &B10000011
- Const Edge_rise = &B11000011
- Const Ticks = _xtal / 64 ' for 16MHz = 250 000
- Countdown = 1
- Do
- If New_impuls = 1 Then
- New_impuls = 0
- If Countdown = 0 Then Cls
- Countdown = 10
- End If
- If 500ms = 1 Then
- 500ms = 0
- Locate 1 , 16
- If Mig = 0 Then
- Mig = 1 : Lcd "*"
- Else
- Mig = 0 : Lcd " "
- End If
- If Countdown > 0 Then
- Decr Countdown
- If Countdown = 0 Then
- Locate 1 , 1 : Lcd "No signal..." ; Spc(4)
- Else
- Copy_hi = New_hi
- Copy_lo = New_lo
- Helpd = Copy_hi + Copy_lo 'for 1kHz = 250
- 'obliczanie wypelnienia
- Duty = Copy_hi : Duty = Duty * 100
- Duty = Duty / Helpd
- Locate 2 , 8 : Lcd "Duty=" ; Duty ; "% "
- 'oblicznie freq
- Shift Helpd , Left , 6 'for 1kHz = 16000
- Freq = _xtal / Helpd : Locate 2 , 1 : Lcd Freq ; "Hz "
- Shift Copy_hi , Left , 2
- Shift Copy_lo , Left , 2
- Locate 1 , 3 : Lcd Copy_hi ; "us/" ; Copy_lo ; "us"
- End If
- End If
- End If
- Loop
- End
- Capture_isr:
- $asm
- !PUSH R16
- !PUSH R17
- !PUSH R20
- !PUSH R21
- !PUSH R23
- !PUSH R24
- !PUSH R25
- !PUSH R26
- !PUSH R27
- !in R24, sreg
- !PUSH R24
- $end Asm
- If Signal_in = 0 Then
- New_hi = Capture1 - Old_tim
- Tccr1b = Edge_rise
- Else
- New_lo = Capture1 - Old_tim
- New_impuls = 1
- Tccr1b = Edge_fall
- End If
- Old_tim = Capture1
- ' Tuned with NoSave Tool 1.10
- $asm
- !POP R24
- !out sreg, r24
- !POP R27
- !POP R26
- !POP R25
- !POP R24
- !POP R23
- !POP R21
- !POP R20
- !POP R17
- !POP R16
- $end Asm
- Return
- Przerwanie_timer2:
- $asm
- !PUSH R16
- !PUSH R24
- !PUSH R26
- !PUSH R27
- !in R24, sreg
- !PUSH R24
- $end Asm
- If Miliseconds < 49 Then
- Incr Miliseconds
- Else
- Miliseconds = 0
- 500ms = 1
- End If
- ' Tuned with NoSave Tool 1.10
- $asm
- !POP R24
- !out sreg, r24
- !POP R27
- !POP R26
- !POP R24
- !POP R16
- $end Asm
- Return
Fotki miernika poniżej
![Duże szczęście, bardzo dobry humor :D](./images/smilies/icon_e_biggrin.gif)
![Obrazek](http://obrazki.elektroda.pl/6983466200_1500813200_thumb.jpg)
![Obrazek](http://obrazki.elektroda.pl/5451120200_1500813201_thumb.jpg)
![Obrazek](http://obrazki.elektroda.pl/6020982100_1500813202_thumb.jpg)
![Obrazek](http://obrazki.elektroda.pl/3389710000_1500813202_thumb.jpg)