More than one issue with that piece of code. For one, you're running at 64MHz so it's probably going to wrap around X variable quite quickly giving you weird results. I'd try something like this:
Code:
Th VAR WORD
Tl VAR WORD
PWIN VAR PORTB.0
Main:
GOSUB Measure
LCDOUT $FE, $01, "High: ", DEC Th
LCDOUT $FE, $C0, "Low: ", DEC Tl
GOTO Main
Measure:
Th = 0
Tl = 0
WHILE !PWIN : WEND ' Wait for rising edge
WHILE PWIN ' Measure high pulse width
Th = Th + 1
PAUSEUS 999
WEND
WHILE !PWIN ' Measure low pulse width
Tl = Tl + 1
PAUSEUS 999
WEND
RETURN
Once you have that working, displaying pulsewidth values matching what you see on the scope you can A) increase resolution (if needed) and/or B) calculate PPMs or percentage or whatever you want to display. Small steps...
Bookmarks