RCTIME Equivalent on 20X2

ayounis

New Member
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
 

BeanieBots

Moderator
I have no idea how the QTR line detector detector works but as you have been using RCTIME to measure it, I suspect it is analogue.
PICAXE chips can read analogue voltages directly with no need to resort to charging/discharging RC time constants.
Using ReadADC would be a much quicker/easier/more accurate solution if my assumption is correct about the sensor.

So, why do you want to emulate RCTIME besides that being the way the previous micro did it?
 

ayounis

New Member
thanks for your comment... I think you are confusing between reading voltage and time. the former will be done through ADC as you absolutely mentioned but the later will still need a time-based mechanism to measure, as I am advising.
 

BeanieBots

Moderator
My sincere appologies.
I thought this was still under question.
[moved back to finished projects]
 
Last edited:
Top