18M2 delay time

davidwf

Senior Member
What are the units in this command
symbol motor_max_time=15000

I presumed they were in milliseconds and I ask because the delay is considerably longer than 15 seconds - in fact it's around 55 sec!

thanks
 
Last edited:

AllyCat

Senior Member
Hi,

AFAIK that is not a pre-defined (system) constant or variable, so the units will be whatever the program-writer has chosen them to be. In any case, it could be affected by any SETFREQ command, so we need a link to the program using it.

Cheers, Alan.
 

davidwf

Senior Member
I have used setfreq mdefault at the beginning and am using this to step it

high b.0
for run_time = 0 to motor_max_time
readadc c.0, motor_current
next motor_run_time
low b.0

return
 

AllyCat

Senior Member
Hi,

PICaxe Basic delay times are not officially documented (partly because they are not absolutely constant, e.g. between chips) but from my spreadsheet, a FOR .. NEXT loop executes in about 1.5 ms per pass and a READADC in about 0.75 ms. So I would estimate the "units" of motor_..._time in that program to be about 2.25 ms.

But two issues: the FOR xxx and NEXT xxx variables have not been defined to be the same (the variable in the NEXT is optional and may be ignored), and nothing is being done with the variable "motor_current". Any additional processing of that variable will change the loop period and thus the "units".

ADDED: Typically one would put a PAUSE 8 (ms) in the loop and then the "units" would be approximately tens of ms. If additional instructions were included in the loop then the PAUSE value would need to be reduced accordingly. With M2s, an alternative structure could give a reasonably absolute value directly in seconds, e.g :
Code:
symbol motor_max_time = 10      ; Period in seconds
time = 0           ; Reset the (automatic) system variable
do
   READADC .....       ; etc.
loop until time => motor_max_time
Cheers, Alan.
 
Last edited:

davidwf

Senior Member
my apologies.... I tried to truncate the text to the minimum and it is wrong.....

This is the actual code used - and I think it is correct....sorry about that!

lounge_curtain_motor:

' sertxd ("lounge curtain motor","","","",""," [433]", cr,lf)
high b.0 ' pic pin 6 hi - start curtain motor
pause 1000 ' 1 sec stabilise before enabling motor load current trip
for motor_run_time = 0 to motor_max_time ' loop for time period (safeguard only to stop motor after max motor run time (15 sec) - motor will normally current trip)
readadc c.0, motor_current_trip ' pic pin 17 / c.0 - motor current trip
if motor_current_trip >=100 then
low b.0, b.3 ' motor exceeded current limit so turn it off
' pause 500 ' wait 1/2 sec before sertxd - only for debugging (ratchet) otherwise error on sertxd report
' sertxd ("motor stop (normal)","","","",""," [441]", cr,lf)
exit ' ********************************************************
endif ' ***** important.... "exit & endif" in this order ! *****
next motor_run_time ' safeguard only to stop motor after max motor run time (10 sec) - motor will normally current trip)
low b.0 ' pic pin 6 lo - stop curtain motor
low b.3 ' pic pin 9 lo - release c/o relay
return
 

davidwf

Senior Member
..... by trial and error I found a setting of 3000 gives about 12 sec....which I cannot correlate with your math...
 

inglewoodpete

Senior Member
@davidwf: You can improve the readability of your code by pasting the structured code into the "code" window, accessed from the forum's editor tool bar.

Code:
lounge_curtain_motor:

   ' sertxd ("lounge curtain motor","","","",""," [433]", cr,lf)
   high b.0   ' pic pin 6 hi - start curtain motor
   pause 1000 ' 1 sec stabilise before enabling motor load current trip
   for motor_run_time = 0 to motor_max_time ' loop for time period (safeguard only to stop motor after max motor run time (15 sec) - motor will normally current trip)
      readadc c.0, motor_current_trip ' pic pin 17 / c.0 - motor current trip
      if motor_current_trip >=100 then
         low b.0, b.3 ' motor exceeded current limit so turn it off
              ' pause 500 ' wait 1/2 sec before sertxd - only for debugging (ratchet) otherwise error on sertxd report
              ' sertxd ("motor stop (normal)","","","",""," [441]", cr,lf)
         exit ' ********************************************************
      endif   ' ***** important.... "exit & endif" in this order ! *****
   next motor_run_time ' safeguard only to stop motor after max motor run time (10 sec) - motor will normally current trip)
   low b.0    ' pic pin 6 lo - stop curtain motor
   low b.3    ' pic pin 9 lo - release c/o relay
   return
 

Attachments

AllyCat

Senior Member
Hi,

The additional IF motor_current_trip >=100 then : <Not True> : ENDIF takes around 1.25 ms to execute, so the total loop period could be around 3.5 ms. Not too far from the 4 ms you have measured *. As I said above, the figures are not even formally specified, let alone "guaranteed". ;)

Cheers, Alan.

* PS: And did your 12 seconds measurement include the PAUSE 1000 initial 1 second delay before the loop runs?
PPS: And I see in the Original Post (#1) that you measured the loop time as 55 / 15 = 3.6 ms. ;)
 
Last edited:

hippy

Technical Support
Staff member
for motor_run_time = 0 to motor_max_time ' loop for time period (safeguard only to stop motor after max motor run time (15 sec) - motor will normally current trip)
next motor_run_time ' safeguard only to stop motor after max motor run time (10 sec) - motor will normally current trip)
I would presume 'Symbol motor_max_time = 15000' was intended to set a time period for that FOR-NEXT loop of 15 seconds, 15000ms, and the second "10 sec" reference was a discrepancy with the first "15 sec".

It is likely a classic case of initial code design and intent not matching exactly with implementation or documentation. 15000 was chosen, found to work, and the code was then used as it was with no attention paid to any discrepancies.
 
Top