18M2 Time Issues

joely87

Member
Hi All,

I am trying to use the time variable on the 18M2. In a particular part of my program I am Sending the days, hours, minutes, seconds to a serial LCD. I am running the chip at 8MHz to make it serial LCD friendly however it seems to be halving the time. i.e when my LCD displays 0D:0H:8M:0S it has been 16 minutes on my watch.

I have tried to use the settimer t1s_8 command and get an error:
"Error: 'setuptimer' command not supported by this chip!"

I can not find any info about the 18M2 not supporting this command. Any Ideas??


Code:
Timeshift:
	if time > 59 then AddMinute
	if minutes > 59 then AddMinute
	if hours > 23 then AddDay
	return
	AddMinute:
		let time = 0
		let minutes = minutes + 1
		return
	AddHours:
		let minutes = 0
		let hours = hours + 1
		return
	AddDay:
		let hours = 0
		let days = days + 1
		return
''''' MISSING CODE""""""

	serout SERLCD,BAUD,(CMD,WIPE): pause sec
	serout SERLCD,BAUD,("Timer"): pause sec 
	serout SERLCD,BAUD,(CMD,192): pause sec 'curser to second line
	serout SERLCD,BAUD,(#Days,"D:",#Hours,"H:",#Minutes, "M:", #Time,"S"): pause sec10 
	return
Thanks again
 

inglewoodpete

Senior Member
Hi All,

I am trying to use the time variable on the 18M2. I have tried to use the settimer t1s_8 command and get an error:
"Error: 'setuptimer' command not supported by this chip!"

I can not find any info about the 18M2 not supporting this command. Any Ideas??
It is important to follow the command descriptions and availabilities as described in Manual 2 (Commands). The manual clearly indicates the SetTimer command is only available in the X1 and X2 series chips.
 

Technical

Technical Support
Staff member
Time is a predefined feature on the M2 series, and is different to timer (setuptimer command).

As time is predefined for 4MHz and 16MHz only, it will run twice as fast at 8MHz. However you can easily account for this in your program by using double the seconds required ie

if time > 118 then...

or

mytime = time / 2
if mytime > 59 then...
 
Last edited:

joely87

Member
Solved

Thanks technical & pete,

I solved by setting the frequency to 16MHz. Pete could you please direct me to a page number. I would not have posted without exhausting the manual or at least where I knew to look (pages 210, 211) the only mention of particular chips seems to be 20X2??

Cheers Joel.
 

westaust55

Moderator
could you please direct me to a page number. I would not have posted without exhausting the manual or at least where I knew to look (pages 210, 211) the only mention of particular chips seems to be 20X2??

Cheers Joel.
The SetTimer command is covered on page 216 in the PICAXE manual part 2 (V7.4 )
It is always necessary to look at the diagrams at the left side of each page to ascertain which PICAXE can use a given command. For the SetTimer comamnd this indicates only X1 and X2 parts use the command.

Where a command is used by several PICAXE chips eg 28X1 and 28X2, the X2 variable may have some added features/options and it is these options which are discussed further in the body of the manual text.

In case you have not read it, the 18M2 briefing/addenda available here:
http://www.rev-ed.co.uk/docs/picaxe18M2.pdf
also includes a brief description on the M2 "time" variable.

The commands DISABLETIME (p57) and ENABLETIME (p63) in PICAXE manual 2 are appropriate to the Time variable for the M2 part(s).


EDIT:
Maybe if Rev Ed were to add a paragraph/sentence under the usual sub-heading:
"Effect of Increased Clock Speed:"
that may also help clarify the situation for newcomers.
 
Last edited:

joely87

Member
Thanks WestAus,

I hadn't realised the symbols on the side. I have noticed them before but did not know what they meant.

Thank you.
 

Texy

Senior Member
I was also having a problem with the time appearing to be running slowly on an 18M2 project. setfreq is set to m16, so it should be counting correctly, however after a bit of code play it seems the readtemp and readtemp12 commands must temporarily halt the time count by approx 750mS, ie the amount of time taken to perform the readtime command. However my particular chip seems to take about 660mS. In order to correct for this delay, an extra word variable is needed to keep a count of how many temperature readings have taken place and that number is multiplied by 66/100 (in my case), ie

Code:
counter = 0
main_time:

Readtemp16 c.6, cur_temp                                 'read in result ds18b20
counter = counter + 1

temp_word = counter * 66 / 100 + time

gosub display_time

goto main_time
I,m note sure if this is mentioned in any manual and it is not mentioned in the picaxe18M2.pdf that I could see.
Rgds,

Texy
 
Last edited:

hippy

Ex-Staff (retired)
I don't know if it's specifically referenced but it falls under the catch-all of blocking commands which wait for an outcome and can't do anything else while waiting causing loss or delay of other events such as timer ticks, servo updates etc.

I haven't tested it but an alternative to doing the maths ( which will hit problems after 1000 or so seconds ) is to adjust 'time', accumulate the number of ms lost and then add them back on ...

Readtemp16 c.6, cur_temp
lostMilliseconds = lostMilliseconds + 660
If lostMilliseconds >= 1000 Then
time = time + 1
lostMilliseconds = lostMilliseconds - 1000
End If
 

Texy

Senior Member
Thanks Hippy - I forgot that once counter gets to a 1000, then multiplied by 66, it'll be over the word limit. I will give your code a try.

Texy

PS. where on the web is your 'lcd page' ??
 

Technical

Technical Support
Staff member
readtemp and readtemp12 commands must temporarily halt the time count by approx 750mS, ie the amount of time taken to perform the readtime command. However my particular chip seems to take about 660mS.
On M2 and X2 parts the temperature reading delay is how long the conversion actually takes (ie it is polled until complete) rather than just a standard fixed delay. So it can be anything 'up to' 750ms.
 
Top