Richard, I think BASIC is cool and I would use it instead of C or ASM if I=20 could find a good BASIC compiler that was free. I'm following you as you=20 do this. I'm using hardware to display my readings and I'm only using=20 the PIC to latch in the reading and then to clear the display in=20 preparation for the next reading. Thanks, rich! On 7/19/2014 8:24 AM, Richard Pytelewski wrote: > Dwayne: > > Just finishing project with similar reqt's. Using the CCP in Capture mod= e, > and using TMR1, you can get excellent results. FWIW: use a good high fr= eq > crystal.... my measurements are in microseconds and anything but a crysta= l > will yield inconsistent results. > > I use ME Basic (OK, I know, BASIC is not cool) but here is my working cod= e > that may provide a start > > Detect: > T1CON =3D 0x05 ' TMR1 ON, 1:1 pre-scaler > CCP1CON =3D 0x05 ' CCP Capture mode, every risin= g edge > PIR1.5 =3D 0 ' Clear bit 5 > TMR1L =3D 0 ' Clear the TMR1L value > TMR1H =3D 0 ' Clear the TMR1H value > tim1 =3D 0 ' Reset variable > while PIR1.5 =3D 0 > nop > wend > if PIR1.5 =3D 1 then ' Capture occurred on rising ed= ge > TMR1L =3D 0 ' Clear the TMR1L value > TMR1H =3D 0 ' Clear the TMR1H value > CCP1CON =3D 0x04 ' CCP Capture mode, every falli= ng > edge > PIR1.5 =3D 0 ' Clear bit 5 (capture occurred= info) > end if > while PIR1.5 =3D 0 > nop > wend > if PIR1.5 =3D 1 then ' Capture occurred on rising = edge > tim1 =3D TMR1H<<8 + TMR1L ' Retain TMR1 value =3D ON time > CCP1CON =3D 0x05 ' CCP Capture mode, every risin= g edge > PIR1.5 =3D 0 ' Clear bit 2 (capture occurred= info) > end if > If tim1 <3700 then > TMR1L =3D 0 ' Clear the TMR1L value > TMR1H =3D 0 ' Clear the TMR1H value > tim1 =3D 0 ' Reset variable > goto Initialize_Detect > end if > > Rich > > --=20 http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .