Jak zmierzyć czas impulsu występującego na danym pinie? Impuls ujemny czyli n.p. p3.0=0 ?
Do you prefer the English version of the page elektroda?
No, thank you Send me over therePULSEIN var , PINX , PIN , STATE
do
if px.x=0 then
start timerx
exit do
loop
do
if px.x=1 then
stop timerx
exit do
loop
hunterhouse wrote:
...
ja bym ci proponował zrobić tak ustawic timer w tryb timera i tak dobrać preskaler aby napewno nienastąpiło przepełnienie.
...
w AVR jest taka możliwość aby timer sam liczył czas impulsu wejściowego. ale jak sprawa wygląda w '51 to nie wiem.
Quote:Input Capture Unit
The Timer/Counter incorporates an input capture unit that can capture external events
and give them a time-stamp indicating time of occurrence. The external signal indicating
an event, or multiple events, can be applied via the ICP1 pin or alternatively, via the
analog-comparator unit. The time-stamps can then be used to calculate frequency, dutycycle,
and other features of the signal applied. Alternatively the time-stamps can be
used for creating a log of the events.
$crystal = 12000000
$regfile = "89c2051.dat"
Dim T1ov As Byte , Cnt1 As Word
Config Timer1 = Timer , Mode = 1 , Gate = Internal
On Timer1 T1_int Nosave
Enable Timer1
Enable Interrupts
Impuls Alias P3.0
Counter1 = 0
Do
While Impuls = 1 : Wend 'czekamy dopuki P3.0=1
T1ov = 0
Start Timer1
While Impuls = 0 : Wend 'czekamy dopuki P3.0=0
Stop Timer1
Cnt1 = Counter1
Counter1 = 0
'Tu sobie obliczamy jaki to czas uplynąl
'T1ov * 65536 + Cnt1 = zliczone cykle maszynowe przez T1
'Dla kwarcu 12MHz czas trwania "0" na P3.0 <= ~1.6 s ,
'bo jeśli dluższu to T1ov się przepelni i wyjdzie kicha ;)
Loop
T1_int:
Incr T1ov 'ilość przepelnień T1
Return