I needed an RCTIME-like routine to use with a QTR line detector. the standard PICAXE lib does not provide one. as the application in hand did care much about to the micro-sec timing but rather a time span, I had reached the following code. as I am working on a 20X2 device, this is where I have tested and verified things. I hope the following code is self explanatory.
Code:
; *******************************
; ******* RCTIME Routine *******
; *******************************
; Filename: QTR V2.bas
; Date: 14/04/2010
; File Version: 2
; Written by: Amr Younis
; Function:
; Last Revision: RCTIME
; Target PICAXE: 20x2
; *******************************
#picaxe 20x2
#freq m8
#no_table
#no_data
hintsetup %00000100 'setup hw interrupts
setintflags %00000100, %00000100 'setup interrupt flags
settimer 65505 'setup timer at 32 usec
do
high c.1 'start charging RC circuit
pause 1 'wait sometime to finish charging
input c.1 'toggle c.1 to input to start discharging the RC circuit
timer = 0 'reset timer var to 0
pause 10 'let the interrup finish and circuits are back to normal
loop
interrupt:
if pinb.1 <> 0 then interrupt 'wait for a complete discharge, based on a TTL value
w0 = timer 'capture rctime value
toggle c.0 'inverse c.0, for demo purposes if you have a scope
pause 10 'give c.0 some time
flags = %00000000 'reset flags
setintflags %00000100, %00000100 'reinitiate interrupts
return