Using time

JPB33

Senior Member
Which is the most accurate command to use for a time delay so its not affected by the other tasks running? I've previously used pause and wait but never managed to get time to work for me. Set at 6 secs for now I want to achieve 30mins and this is part of a two part parallel task program. Thanks

Code:
main:
do
	loop	until pinC.3 = 0   
	do
	loop	until pinC.3 = 1
	wait 6
	high C.2
	pause 500
	low C.2
	goto main
 

hippy

Ex-Staff (retired)
Using an on-chip timer would be most accurate but I suspect long PAUSE commands using units of 100ms* would probably be most accurate. So thirty "PAUSE 60000" commands should give pretty close to 30 minutes. Accuracy would ultimately depend on what the other task(s) were doing.

* I cannot remember what unit of time PAUSE suspends for in a multi-tasking program, but I believe it is multiples of 20ms. Use PAUSE times in multiple of 100ms and that is very probably an integer multiple of whatever it actually is.
 

Hemi345

Senior Member
Maybe I misunderstood, but are you wanting something using the elasped time counter variable on an M2 series?
Code:
start0:
	
	goto start0	'loop

start1:
	do
	loop	until pinC.3 = 1
	time = 0		'reset time to zero
	do
	loop until time >= 1800	'loop for ~30 minutes
	high C.2
	pause 500
	low C.2
	goto start1	'loop
 

JPB33

Senior Member
Thanks for the info. I didnt think it was that simple to use after looking at the example got really confused!
 
Top