PSL
 
Yes, you have come up with the same method I used on a Scenix programmer which also has to measure edge widths. You can improve the use of the timer a little by using
disabling TMR0 using OPTION_REG, now CLRF TMR0 at the top and then enabling it using OPTION_REG at the beginning of your timing cycle. Now read it at the end of the cycle to avoid the need to use your temporary variable "Edge".
 
As you may have gathered writing to TMR0 whilst it is running causes 3 cycle delay according to the data sheet - in practice my experiments seemed to show more than 3 cycles (is there a bug in the data sheet here ?))
 
Robin Abbott - robin.abbott@fored.co.uk
 
**************************************************************************
*
* Forest Electronic Developments
* http://www.fored.co.uk
*
**************************************************************************
----- Original Message -----
From: PSL
To: PICLIST@MITVMA.MIT.EDU
Sent: 20 October 1999 18:41
Subject: period capture...

Hi people
got a question here hope you can help me out..
 
I am trying to measure a pulse train of 50 KHZ at 50% duty cycle without the icap funtion from the chip.
Is the following code capable? and to what extend??
 
language suite : microchip
prescaler <1:1>
TMR0 is program cycle triggered
edge2- edge1=period
 
LOOP1     BTFSC     PORTD,0     ;to ensure that the 
          GOTO      LOOP1       ;high state is capture
LOOP2     BTFSS     PORTD,0     ;after an edge  
          GOTO      LOOP2
          MOVF      TMR0,W
          MOVWF     EDGE1
LOOP3     BTFSC     PORTD,0
          GOTO      LOOP3
          MOVF      TMR0,W
          MOVWF     EDGE2
If i am not wrong error max 4 cycles 
2 at loop2 (at worse case)
2 at loop3 (at worse case)
Therefore the min period that can capture is
period = 10 cycles assuming 50% duty cycle
 
Any if any one have any better way of doing
this task please kindly mail it to me.
I am still very new to this .THANKS
 
regards
PSL