This is bugging me!

dpritt

New Member
I have a data logger built round a 18M2, which I have been trying to enhance by adding some code to allow me to set a start date and time via a serial connection.

I have developed the code which works as expected in the Program Editor, but when I blasted it to a chip it returns incorrect values. To try to locate the problem I have stripped the code back to the essential parts that set the values to be tested, and found that the problem is that these are scrambled on a real device, unlike the simulated program.

I must be doing something wrong, but I can not see what.

My test rig is a AXE091 Development Board, with a 18M2 inserted, a RTC and battery (time set correctly), Leg 16 is held high, and leg 18 is pulled high via a 10K, but taken low to trigger the Start Time routine.

The curent D&T is read from the RTC every second or so and sent to the terminal as part of the debugging, this works great. The Start time loaded is compared with this and once the current values exceed the values set the logging starts. I have removed this from the code while debugging.

The code follows, I would be grateful if someone could tell me what I am doing wrong.

Regards

Dave P

Code:
' Data Capture Unit
' Uses the Programming port for Terminal Access and to set log start time.
' Uses PicAxe 18M2
;
#picaxe 18m2

symbol Mem_i2c_addr = $A0		' Address of the i2c memory
symbol RTC 		= $D0		' Address of RTC 

symbol Day	 	= b0			' Stores current data from the RTC and used to send ASCII back to Terminal
symbol Date 		= b1			' Stores current data from the RTC and used to send ASCII back to Terminal
symbol Month		= b2			' Stores current data from the RTC and used to send ASCII back to Terminal
symbol Year		= b3			' Stores current data from the RTC and used to send ASCII back to Terminal
symbol Hours 		= b4			' Stores current data from the RTC and used to send ASCII back to Terminal
symbol Mins		= b5			' Stores current data from the RTC and used to send ASCII back to Terminal
symbol Secs 		= b6			' Stores current data from the RTC and used to send ASCII back to Terminal
symbol control 	= b7			' Stores current data from the RTC and used to send ASCII back to Terminal
symbol temp 		= b8			' Temporary store
symbol result 		= b9			' Temporary store
symbol value 		= b10		' Temporary store

symbol StartDate	= b11		' Capture start date and time
symbol StartMonth	= b12		' Capture start date and time
symbol StartYear	= b13		' Capture start date and time
symbol StartHours	= b14		' Capture start date and time
symbol StartMins	= b15		' Capture start date and time
symbol StartSecs	= b16		' Capture start date and time

symbol lsb 		= b17		' Temporary store
symbol msb 		= b18		' Temporary store
symbol ResultIndex 	= b19		' Temporary store

symbol EventCount 	= w10		' Number of readings taken
symbol EndCount     = w11		' No of readings to take

symbol SetClk 		= pinC.1		' Pin 18 - Pulled up to V+, take low to set Start Time
symbol Trigger 	= pinC.0		' Pin 17 - Pulled up to V+, take low to trigger a data recording

symbol Terminal 	= pinC.7		' Pin 16 - Pulled up to V+, If Low send output data raw via Wireless, if high send data as ASCII (for a terminal)
symbol Wireless	= pinC.2		' Pin 18 - Serial out to wireless module

sleep 2
							
init:

	disconnect						' Allow the programming port to be used for Terminal traffic to set the start time
	
Main:								' Main program starts here
	
	
	if SetClk = 0 then gosub SetStartTime	' If True go to set Set Start-Time routine   
	
	i2cslave %11010000, i2cslow, i2cbyte	' Initialise the RTC
	
	readi2c 0, (Secs,Mins,Hours,Day,Date,Month,Year,Control)	'Read the current data from the RTC
	

	
	'-----------------------------
	'Comparison and call to logging program goes here
	'-----------------------------
	
	if Terminal = 1 then gosub SendASCII	' Send the current date and time via Terminal
		
	if Terminal = 0 then gosub SendRaw		' Send Current date and time via Wireless link.
	
	sleep 1	
						
goto Main



SendASCII:						'This routine converts the BCD values and sends it to the Terminal as ASCII
	
		sertxd("  Date: ")
	let temp = date & %00110000 / 16
		sertxd(#temp)
	let temp = date & %00001111
		sertxd(#temp)
		
		sertxd("/")
	
	let temp = month & %00010000 / 16
		sertxd(#temp)
	let temp = month & %00001111
		sertxd(#temp)

		sertxd("/")

	let temp = year & %11110000 / 16
		sertxd(#temp)
	let temp = year & %00001111
		sertxd(#temp)
		
		sertxd(" Time: ")

	let temp = hours & %00110000 / 16
		sertxd(#temp)
	let temp = hours & %00001111
     		sertxd(#temp)
     		
     		sertxd(":")

	let temp = mins & %01110000 / 16
		sertxd(#temp)
	let temp = mins & %00001111
		sertxd(#temp)
		
		sertxd(":")

	let temp = secs & %01110000 / 16
		sertxd(#temp)
	let temp = secs & %00001111
		sertxd(#temp)
		
		sertxd(13,10)
return



SetStartTime:						'Load the start variables with the data

		
	sertxd("Enter the Logging Start Time using the prompts")
	sertxd(13,10)
	
	sertxd("Enter the Day >") 
	sertxd(13,10)
	serrxd Value
	gosub ConvertBytetoBCD
 	let StartDate = Result
	
	
	sertxd("Enter the Month >") 
	sertxd(13,10)
	serrxd Value
	gosub ConvertBytetoBCD
 	let StartMonth = Result
	
	
	sertxd("Enter the Year >") 
	sertxd(13,10)
	serrxd Value
	gosub ConvertBytetoBCD
 	let StartYear = Result
	

	sertxd("Enter the Hours >") 
	sertxd(13,10)
	serrxd Value
	gosub ConvertBytetoBCD
 	let StartHours = Result
	
	
	sertxd("Enter the Minutes >") 
	sertxd(13,10)
	serrxd Value
	gosub ConvertBytetoBCD
 	let StartMins = Result
	
	
	sertxd("Enter the Seconds >") 
	sertxd(13,10)
	serrxd Value
	gosub ConvertBytetoBCD
 	let StartSecs = Result
	
	
	'Code to enter the number of readings to take placed here..
	
	
								' Load the Start Variables into the TX Variables to read back.
	let Date = StartDate
	let Month = StartMonth
	let Year = StartYear
	let Hours = StartHours
	let Mins = StartMins
	let Secs = StartSecs
								' Read back the Start Variables
    	
  	sertxd("You have stored the following start time:")
  	sertxd(13,10)
  	
  	gosub SendASCII
  	
  	WaitKeyUp:
		if SetClk = 0 then WaitKeyUp	' Wait until the key is released to start
 	
Return
	
ConvertBytetoBCD:

	msb = 0
	lsb = 0
	
	do until Value < 10 			'count the most significant bits
		inc msb
		Value = Value - 10 
	loop 
	
	lsb = Value 					'least significant bits = remaining
	Result = msb * 16 + lsb 			'convert to bcd notation
	

return    

SendRaw:							'Sub-Routine to send data via Wireless Module      

		'Code removed while testing
		
Return     

TakeReading:						'Take Readings,store in EEPROM, then send using Terminal Flag

		'Code removed while testing

Return
 
Last edited:

John West

Senior Member
I'm not much help on this one, in particular because the code window is so wide I can't scroll through it and read it at the same time.

(Does someone on the site know of a fix for this? It makes code reading virtually impossible.)

At a guess, I'd suggest looking into device timing problems. Those may not show up in emulations.
 
Last edited:

Technical

Technical Support
Staff member
I'm not much help on this one, in particular because the code window is so wide I can't scroll through it and read it at the same time.

(Does someone on the site know of a fix for this? It makes code reading virtually impossible.)
Different browsers render in different ways, IE is probably the worst for this. If you have a scrollwheel mouse just click in the grey code area and scroll on the mouse.
 

Technical

Technical Support
Staff member
symbol Wireless = pinC.2 ' Pin 18 - Serial out to wireless module

On this type of definition you need
symbol Wireless = C.2 ' Pin 18 - Serial out to wireless module

Only if...then uses the pinC.2 variable, everything else needs the actual pin name instead.

Also
serrxd Value
Note this only receives a single character/byte - are you sending ascii or raw byte data?
 
Last edited:

Dippy

Moderator
IE or Firefox both the same. Poor old IE getting bad press again :)
It's not just this Forum.
If dpritt went and edited his great long comments then it may cure it.

It's something that should be considered when placing a post i.e. making it easier for others to read.
Can an autowrap type of thing be included by Webauthors in the box?
 

Dippy

Moderator
His is bigger than our's again. Totally awesome and cool.

I wonder how many people have got things as big as Andrew's?

If you could send me a signed photo I'd be your biggest fan. :rolleyes:
Sorry, second biggest fan to be correct.

I'm not sure everyone's parents can afford such good stuff as you have Andrew.

I bet you've got the biggest disk here too.
 

John West

Senior Member
Firefox is my browser. My video display is running 1024X768. That's the culprit, I'm sure. I'll try pushing the video resolution to see how small I can go and still read the text. Tnx.
 

hippy

Technical Support
Staff member
I'm not much help on this one, in particular because the code window is so wide I can't scroll through it and read it at the same time.

(Does someone on the site know of a fix for this? It makes code reading virtually impossible.)
Click a QUOTE reply, then copy and paste into Programming Editor or Notepad etc. That usually works for me. Cancel the reply.
 

dpritt

New Member
Sorry about the long rems, I write SQL code and I find I need to document my programs well so others can understand them in five years time, so I tend to do that everywhere.

It does look like a timing problem, but I am not sure how to fix it.
The RTC is read and decoded OK from the breadboard.

The problem is that while the correct values are being stored in the 'Start' variables when run on the simulator, they are not when run on the Breadboard.

If I poke BCD values directly into the variables and download the code to the chip it works, but I would like to make it easy for anyone to be able to set them from a terminal emulator program, this may end up being done over a remote link in the future.

When looking at code others have published on the Forum I tend to cut and paste it into the editor.

Oh, the screen on the PC I use for this is running at 1440 x 900.

Dave P
 

premelec

Senior Member
John, I'm using Firefox and it's way too wide on my screen too - but not all posts come out this way - it's intermittent and I've never figured out why it's happening or not... maybe Colorado weather... :) BTW it's not just the code that's wide - it's the text too that runs off rightward...
 
Last edited:

hippy

Technical Support
Staff member
The problem is that while the correct values are being stored in the 'Start' variables when run on the simulator, they are not when run on the Breadboard.

If I poke BCD values directly into the variables and download the code to the chip it works, but I would like to make it easy for anyone to be able to set them from a terminal emulator program, this may end up being done over a remote link in the future.
Has Technical's post #4 been lost in the discussion on code formatting ?

When it works in the simulator but not in the chip and it's something to do with SERRXD or SERIN it often turns out to be a data issue; binary / BCD being expected, sending ASCII and so on.

I haven't had time to study the code or see where the problem is but that's where I'd look.
 

John West

Senior Member
dpritt:

"Never apologize for writing good comments." - JW

As Hippy points out, pay close attention to Technical's posts. There's a reason his handle is "Technical." He's not just Rev. Ed. staff, he knows his stuff.
 

John West

Senior Member
John, I'm using Firefox and it's way too wide on my screen too - but not all posts come out this way - it's intermittent and I've never figured out why it's happening or not... maybe Colorado weather... :) BTW it's not just the code that's wide - it's the text too that runs off rightward...
Like me, you need to get a monitor with a better rez than 640X480. BTW, those round CRT's are no longer cutting edge. ;)
 

premelec

Senior Member
I wish...

John, I wish that was it - but for instance in this thread it's only the first post that goes far right - I suspect it's something the poster does in the first sentence - all the rest of the posts are correctly displayed and wrapped - I'm currently set at 1280 x 1024 on this display. It's been a problem intermittently for years on this forum display which otherwise is very excellent!

I'm trying to add a screenshot of the first two posts which shows the offset [reduced for file size]
 

Attachments

Last edited:

westaust55

Moderator
John, I wish that was it - but for instance in this thread it's only the first post that goes far right - I suspect it's something the poster does in the first sentence - all the rest of the posts are correctly displayed and wrapped - I'm currently set at 1280 x 1024 on this display. It's been a problem intermittently for years on this forum display which otherwise is very excellent!

I'm trying to add a screenshot of the first two posts which shows the offset [reduced for file size]
It is caused, as I believe hippy has already mentioned (without looking back), by having a long line in the program code window - usually due to long comments
in the case of post 1 the most offending line in terms of formatting is that starting:
"symbol Terminal = pinC.7 ' Pin 16 - Pulled up to V+, . . . . ."
 

premelec

Senior Member
Right you are - I think - somehow the code window doesn't wrap and expands the whole post - I've always tried to save myself typing by not making symbols very long and still clear in meaning. The post today about branching has one long line in the code which expands the whole window. This happens in XP directory windows where one long file name causes all the others to space out... If only all our troubles were this trivial!
 

John West

Senior Member
I try to put no more than a few words (of long code comments) on each line, allowing me to follow both the code and the comments without having to look back and forth.

Every little bit of convenience and clarity helps when it comes to writing code.
 

Dippy

Moderator
I tend to keep comments and code lines narrow enough so I can PRINT without unpredictable wrapping happening.
In that way you know where you are.

Users of any MikroElektronika IDEs will see a line in the Edit window showing width.
Users of Proton IDE have a Print Preview which is a handy guide.

Also, if I'm posting code, I will chop it down to fit.


Or maybe we can beg Rev-Ed's web authors to fix the width of the 'code' window and have auto-wrapping.
That's how they do it on Proton's and Microchip's Forum.
Makes life SO much easier for all those people who have screens and resolutions and many different sizes.
Rocket Science? I think not :rolleyes:
 

hippy

Technical Support
Staff member
Rocket science ... I wouldn't know; the forum software is standard off-the-shelf software produced by a third party.

I doubt there's any forum software which suits every taste and every circumstance, if it's not one thing that's not liked it will be another. The Proton and Microchip forums won't auto-resize for a 800x600 screen for me which makes use with some NetBooks and other internet devices difficult while other forums I've encountered don't shrink URL's so paste a long one and every single post goes to the width of that meaning lots of horizontal scrolling to read anything.

I don't know any forum software in widespread use which fully passes W3C validation; the first page of this thread threw up 7 errors, one random Microchip 12-post thread had 248 errors, a single Posting Guidelines post had 185 errors, a two-post Proton thread I looked at had only 2 errors but had the same behaviour I see with Code here ( could be my setup ).

I'm using marcos.placona's greasemonkey script with FF 2 and that sorts out code blocks how I like them. Re-reading a thread on code blocks and people reported different behaviours even with the same browser installed so there may well be more rocket science involved than it first appears.
 

papaof2

Senior Member
W3C validation is a lot of work, even for basic web pages. Did that for two sites several years ago as a freebie and haven't been back to either.

John
 

Dippy

Moderator
It's satisfying when you can find errors, though I haven't got a clue what you're on about. :)

I confess that I've never heard of W3C and frankly don't really care, sorry.
It reminds me of BBC's Moral Maze, where unless you can add "-ability" on the end of each word then you're classed second rate.;)

I use Microchip and Proton Forums on 3 different PCs, though all are bigger than 800x600 which was typical 20 years ago. Even a Samsung Netbook is bigger than that.
All three of my PCs show those Forums and their code windows properly.

In fairness, in 95% of cases I find this Forum perfect.
The autowrap works fine except for Code and the painful-width windows are rare.
But, there surely must be an Autowrap option for code windows?

Anyway, what the heck.
 

hippy

Technical Support
Staff member
W3C = World Wide Web Consortium

They are the body which defines HTML standards and related for both coders and browsers.

Any W3C compliant browser should display pages the same way as another if HTML is W3C compliant. If the HTML doesn't comply then the browser may get the rendering wrong or have to 'make guesses' how to best display a non-compliant web page. To ensure correct rendering, HTML should be fully compliant.
 
Top