Clock speed impact on TIME

pmolsen

Senior Member
The manual says the following under DISABLETIME and ENABLETIME

Effect of increased clock speed:
The time function will work correctly at 4MHz or 16 MHz.
At 2MHz or 8MHz the interval will be 2s
At 16MHz the interval will be 0.5s

It first says it works correctly at 16MHz then says the interval will be 0.5s. Is that a mis-print?
What about 32MHz?
 

matchbox

Senior Member
Has anyone else also noticed that if the "time" function is used in conjuction with more than a 1sec pause time in the program loop, it locks up the 'time' variable and it will not count.
It took me a while to work out what was happening. But in the end the only way i could resolve the issue was to use little or no pause intervals in the program. I tried it with many different programs using 08M2's and the out come was the same.
Does anyone know why this is? Or is there a way to over come this that i have missed?
 

hippy

Technical Support
Staff member
Has anyone else also noticed that if the "time" function is used in conjuction with more than a 1sec pause time in the program loop, it locks up the 'time' variable and it will not count.
It seems to work for me with a 5 second pause in place. Perhaps post your code which demonstrates it not incrementing.

Code:
#Picaxe 08M2
#Terminal 4800
Do
  Pause 5000
  SerTxd( #time, " " )
Loop
 

matchbox

Senior Member
This is one of the codes i used. Even the sub command pause effects the time variable. But if i remove the pauses it works perfectly.


Code:
volt:
     readadc 4,b0                                            
     if b0<=179 then goto volt                               
                                              
temp:
     readtemp 1,b3                                          
     if b3<=1 then goto volt                                 
     
PS:
     do
     if time=10 then let time=0 goto volt endif              
     if pinc.3=1 then pause 100 goto pumptimer endif         
     loop 
     
pumptimer:
     do
     if time=10 then let b7=1 time=0 endif
     pause 500
     if pinc.3=1 then pause 100 high c.0,c.2 b8=0 endif      
     if pinc.3=0 then pause 100 inc b8 gosub pumpoff endif   
     if b8=>8 then let b8=0 low c.0 b7=0 goto PS endif       
     loop until b7=24                                        
     let b8=0 b7=0                                          
     low c.2                                                
     
water_cutoff:    
     pause 6000                                              
     high c.2                                                
     do
     if time=10 then let b7=1 time=0 endif
     pause 500
     if pinc.3=1 then pause 100 high c.0,c.2 b9=0 endif     
     if pinc.3=0 then pause 100 inc b9 gosub pumpoff endif   
     if b9=>8 then let b9=0 low c.0 b7=0 goto PS endif       
     loop until b7=6                                                                        
     let b9=0 b7=0
     low c.2 pause 700 low c.0                              
     end
         
pumpoff:
     pause 800                                              
     low c.2                                                 
     return
 

hippy

Technical Support
Staff member
This is one of the codes i used. Even the sub command pause effects the time variable. But if i remove the pauses it works perfectly.
How do you know the 'time' variable is locking up and not counting ? Have you actually proven that is the case or just surmised it is because your code is not doing what you expected with the pauses in place ?

Your code seems to do things which relate to periods of ten seconds, but it tests for only when 'time=10'; if 'time' was 9, you do something, and when you check 'time' again, what happens if it is now 11 ?

Let's say you are in "pumptimer:", the 'time' is 9 and just about to become 10, you pause 500, if pinC.3=0 you pause 100, then gosub pumpoff which pauses 800, so a total pause of 1400. When you next read 'time' it will be 11.

Your 'time' comparisons should probably be "time >= 10".

It's the same when saying "I'll go home at 17:00". If you look at your watch and it shows 17:01 you don't stay all night :)
 

matchbox

Senior Member
I get your meaning Hippy. I have changed this peice of code around many times. I did have the >= inserted into the code before and in this version that i cut and pasted, i didn't have it. I also tried it just from the time variable and not by storing lots of 10 into a variable, with no luck either.
The main reason i assume the 'time variable' is locking up is due to what is seen on the debug output. When ever i drop the combine pause intervals below 1second; the time function counts close to perfectly on the debug output and in real life, using a stop watch.
 
Top