Modyfikacja programu Bascom do pomiaru szerokości impulsu

To forum jest dla wszystkich pasjonatów wiecznie młodych mikrokontrolerów '51. Wymiana doświadczeń i pomoc dla początkujących w pisaniu programów zarówno w C, Asemblerze jak i BASCOM. Zapraszam znawców tematu, aby pomogli wszystkim początkującym!
ODPOWIEDZ
Brodowski
-
Posty: 1
Rejestracja: 21 lip 2007, 23:50
Lokalizacja: Warszawa

Modyfikacja programu Bascom do pomiaru szerokości impulsu

Post autor: Brodowski » 21 lip 2007, 23:57

Czy ktoś mógłby pomóc w napisaniu podprogramu służącemu pomiaru szerokości/wypełnienia badanego impulsu do już istniejącego który wskazuje jego częstotliwosć?

Kod: Zaznacz cały

$regfile = "89c2051.dat" 
$crystal = 24000000 

' define variables used 
Dim A As Byte 
Dim C As Long , D As Long 
Dim Count As Word 
Dim T0ic As Long 
Dim Delayword As Word 


' Initialize variables 
Count = 0 
T0ic = 0 
D = 0 

' initialize ports 
P1 = 0 
P3 = 255 

' configure lcd display 
Config Lcd = 16 * 2 
Config Lcdpin = Pin , Db4 = P1.4 , Db5 = P1.5 , Db6 = P1.6 , Db7 = P1.7 , E = P1.3 , Rs = P1.2 
Cls 
 'clear the LCD display 
Lcd " EFY Freq Meter " 

' define timer0 
Config Timer0 = Counter , Gate = Internal , Mode = 1 
'Timer0 = counter : timer0 operates as a counter 
'Gate = Internal : no external gate control 
'Mode = 1 : 16-bit counter 

' set t0 internal interrupt 
On Timer0 Timer_0_overflow_int 
' interrupt will be generated on every 65536 count 
Priority Set Timer0 
Enable Interrupts 
Enable Timer0 


Counter0 = 0 
'clear counter 
Start Counter0 
'enable the counter to count 

Do 
'set up a 1 sec accurate DO NOTHING loop 
Enable Interrupts 
'wait 1 as per BASCOM-51 is not accurate 

For Delayword = 1 To 45440 
Next Delayword 

Disable Interrupts 
C = Counter0 
'get counter value 
D = T0ic * 65536 

Lowerline 
C = C + D 
T0ic = 0 
Lcd "  " 
Lowerline 
' show the frequency 
Lcd "f=" ; C ; " Hz" 
Waitms 255 
Waitms 255 

C = 0 

Counter0 = 0 
Start Counter0 
're-start it because it was stopped by accessing the COUNTER 
Loop 



' timer0 int subroutine 
Timer_0_overflow_int: 
Rem timer0 overflow ( 65535 ) interrupt comes here 
' increment the variable 
Incr T0ic 
Return 
End 
Załączniki
an35-schematic.jpg
schemat

ODPOWIEDZ