Pause running time, General question

JPB33

Senior Member
I'm developing a process controller which is based around 7 looping timers triggered by two sensors with if statements etc. Program is 131 lines long, 231 bytes and uses an 20m2.

What I dont understand is that if I test the program and run a timer at 600 secs the actual time is 571.58 secs.

I thought it would be a longer time not shorter due to the processing delays within the rest of the program? Or am I just thinking wrong?

To check the accuracy of just one timer I extracted it and ran it separatly for 600 secs. This repeatedly came out 600.15 secs which I thought was pretty amazing!

Thanks

Peter
 

eggdweather

Senior Member
Need more information or code example. Are you using any commands that affect or stop time (SLEEP stops the timer for example). Some commands are so-called 'blocking' commands and can have an affect on other functions.
 

inglewoodpete

Senior Member
SerIn, SerOut, SerTxd and IRIn all have to stop internal interrupts to do their job. Other commands may do too.

Edit: I just noticed the difference between the title of the thread and the text in post #1. The title suggest the use of the Pause statement, while I get the impression from your post that you're using the PICAXE's internal 1-second timer. Posting your code will help us understand what is happening.
 
Last edited:

JPB33

Senior Member
I try not to use anything I dont understand and feel comfortable with so my program is pretty rock bottom by the standards of the forum. I didnt post it initially as I thought the answer to my question may have been due to my lack of experience.

I've put the actual times in for the delays I need to use but I've used lower numbers to speed simulation. Its always difficult to explain whats going on to others but on start up Holiday Mode runs continiously until the Outer Sensor goes high then it pumps inner to outer until the inner chamber is full, aerates and settles then pumps out and repeats the sequence. Its also got a couple of extra sequences in to ensure its not left too along without being areated. Im sure it will be improved/simplified but at present it works. I'm going to use led on outputs to follow the process as well as drive the air solenoids via a relay interface board.

My question is, on test the first timed period comes out shorter than 2 hrs? I thought it would be longer due to all the delay processing the rest of the program? If I use 7560 in the first counter I get a delay of 7201.96 seconds which is spot on.

Thanks

Code:
;JPB Balmoral SBR Controller 25-10-16, 26-10-16, 28-10-16, 30-10-16, 31-10-16

	do
	#Picaxe 20m2
	#No_Data	
	Disconnect    
	output B.0,B.1,B.2,B.3,B.4,B.5,B.6,B.7,C.0,C.1,C.2,C.3,C.4,C.5,C.7	
	input  C.1,C.0,C.6
							  '
	
	Symbol Inner_Sensor 	= pinC.0     'Goes high to activate 
	Symbol Outer_Sensor	= pinC.1	'Goes high to activate
	
	Symbol Aerate_Sol      		= B.1	  
	Symbol Pump_Outer_Sol 	= B.2	  
	Symbol Pump_Inner_Out_sol   = B.3   
	Symbol LED_Hol_Rest     	= B.4   
	Symbol LED_Aerate_Rest  	= B.5   
	Symbol Led_Spare_Count      = B.6   
	Symbol Air_Pump         	        = B.7   
	
	Symbol Aerate_Timer      = w0
	Symbol Rest_Timer        = w1
	Symbol Inner_Outer_timer = w2
	Symbol Spare_Count       = w3
	Symbol Xtra_Aerate	 = w4
	Symbol Spare_Counting    = w5
	Symbol Xtra_Counting     = w6
	
	pause 5000
Holiday_Mode:  '2hrs aerate  then 2 hrs settle, repeat infinitum until interuppted by high outer signal from Pin C.1

'Aerate
	do		
	high Aerate_sol, Air_pump 
	for Aerate_Timer  = 1 to 7200				'120 mins  timer
	if Outer_Sensor = 1 then				'sensor for outer tank, goes high when ready to pump to inner
	goto Outer_to_Inner
	endif		
	pause 1000							'Pause 1 second
	next Aerate_Timer 						
	Aerate_Timer  = 0 Spare_Count = 0			'Resets spare counter and others
	
'Aerate rest
	low Aerate_Sol, Air_Pump   				'Resets
	high LED_Hol_Rest						'Puts LED on to say whats happening as no other activity
	for Rest_Timer  = 1 to 7200				'120 mins timer 
	inc Xtra_Aerate						'Xtra Aerate Counting minutes of rest.
	pause 1000							'Pause 1 sec
	if Outer_Sensor = 1 then
	goto Outer_to_Inner
	endif								
	next Rest_Timer 
	Rest_Timer = 0 Xtra_Aerate = 0 low LED_Hol_Rest	'Resets
	loop
	
Outer_to_Inner:       						'Pumping inner to outer now timed

'Spare Count

	if Spare_count => 1 then 				'Spare count. Detects more than 1 outer to inner cycle and puts in extra timed aerate for 1 hr 
	high Aerate_sol, Air_pump high Led_Spare_Count 
	low LED_Hol_Rest	 					'Resets
	for Spare_Counting  = 1 to 3600			'60 mins timer timer						
	pause 1000							'Pause 1 sec)						
	next Spare_Counting
	Spare_Counting = 0
	endif

'Xtra Aerate

	if Xtra_Aerate => 6 then 				'Xtra Aerate. Detects more than 60min have passed on Aerate Rest and puts in extra timed aerate for 1 hr 
	high Aerate_sol, Air_pump high Led_Spare_Count 
	low LED_Hol_Rest						'Resets
	for Xtra_Counting  = 1 to 3600			'60 mins timer timer
	pause 1000							'Pause 1 second													
	next Xtra_Counting 
	Xtra_Aerate = 0						'Resets
	endif

'Pump inner to outer

	low Aerate_Sol, LED_Hol_Rest, Led_Spare_Count Aerate_Timer = 0 'Resets
	high Pump_Outer_Sol, Air_pump
	inc Spare_Count
	for Inner_Outer_timer = 1 to 3600			'60 mins timer to limit pumping time
	if Inner_Sensor = 1 then; 
	goto Aerate:	
	endif
	pause 1000							'Pause 1 second
	next Inner_Outer_timer                          'C.7 Sensor stops timer, inner tank full, goes to aerate
	low Pump_Outer_Sol Inner_Outer_timer = 0		'Resets
	goto Holiday_Mode						'No input from Sensor timer runs to end, back to Holiday_Mode
	
	
Aerate:	

'Aerate
	low Pump_Outer_Sol Inner_Outer_timer = 0		'Aerate 4 hrs settle for 2 hrs everything off then pump out
	for Aerate_Timer  = 1 to 14400			'240 mins timer
	high Aerate_Sol , Air_Pump
	pause 1000							'Pause 1 second
	next Aerate_Timer
	Aerate_timer = 0						'Resets
	
'Rest

	low Aerate_Sol , Air_Pump  Aerate_Timer = 0	'Resets
	high LED_Aerate_Rest					'Puts LED on to say whats happening as no other activity
	for Rest_Timer  = 1 to 7200				'wait 120 mins  in real time
	pause 1000							'Pause 1 second
	next Rest_Timer 
	Rest_Timer = 0 low LED_Aerate_Rest, Pump_Inner_Out_sol 'Resets
	
Pump_out:  	
									'Pump out until inner sensor  = 0
	high Pump_Inner_Out_sol, Air_Pump
	do
	loop until Inner_Sensor = 0
	low Pump_Inner_Out_sol, Air_Pump			'Resets
	loop
 

hippy

Technical Support
Staff member
In a perfect world "PAUSE 1000" would take exactly one second, that plus all the overhead should make a 7200 loop last more than two hours.

In practice a "PAUSE 1000" may be shorter or longer than one second, and even both depending where the command ends up within program memory, temperature and operating voltage.

The 'time' variable was introduced on the M2 to help resolve issues like this, and that would probably be what would be best to use here -

Code:
high Aerate_sol, Air_pump 
time =0
do
  if Outer_Sensor = 1 then
    goto Outer_to_Inner
  endif		
loop until time >= 7200
 

JPB33

Senior Member
Thanks for the information, it makes pause look a bit random so point taken about using time but need some guidance.

In this code after pinc.3 goes high it should give a 5 secs delay before C.2 goes high for 0.5 sec. In practice it sits looping so I put inc w2 in just to see whats happening. What am I doing wrong? Does time need enabling?

I initially thought an external 1hz timebase pulse would make an accurate way of controling my timers but I couldnt make that work either, any pointers on how to do this?

Thanks


Code:
start:
	enabletime
	do
	loop	until pinC.3 = 1
	time = 0		
	do
	inc w2
	loop until time >= 5
	high C.2
	pause 500
	low C.2
	return
 

hippy

Technical Support
Staff member
You can also add SERTXD commands to show what is happening, and they will also work in simulation ...

Code:
[b]#Picaxe 20M2
#Terminal 4800
Pause 2000
SerTxd( "Starting", CR, LF )[/b]
[b]SerTxd( "Waiting for pin C.3 to be high", CR, LF )[/b]
do
loop until pinC.3 = 1
[b]SerTxd( "Pin C.3 went high", CR, LF )[/b]
[b]SerTxd( "Starting 5 second delay", CR, LF )[/b]
time = 0		
do
[b]  SerTxd( #time, " " )[/b]
loop until time >= 5
[b]SerTxd( CR, LF, "5 seconds have elapsed", CR, LF )[/b]
[b]SerTxd( "High C.2", CR, LF )[/b]
high C.2
[b]SerTxd( "Wait half a second", CR, LF )[/b]
pause 500
[b]SerTxd( "Low C.2", CR, LF )[/b]
low C.2
[b]SerTxd( "Finished", CR, LF )[/b]
Under simulation there does need to be some command between a "DO" and "LOOP UNTIL time >" sequence because of the way the simulator determines elapsed time. Without any command it is calculating elapsed time but very slowly.
 

JPB33

Senior Member
Thanks Hippy for explaining time, thats also a very useful demo of seeing whats going on when simulating.

I've now got a version running from an external 1hz generator which will probably be a dedicated 8M2 as I want to try that idea out.
 
Top