18m2 memory read/write problem

cravenhaven

Senior Member
I was making a simple little datalogger for another project by using an 18m2 in a chi035 project board to read 3 ADC channels, save them to memory and then print them out to the terminal. For reasons beyond me, I cannot get this to work correctly. If I read the ADC channels and immediately output the data to serial, then all works as expected. If I save the ADC readings to memory and then squirt them out to the serial port I seem to get all sorts of weird inconsistent readings.

I made up a simple routine to write a sequence of data to memory and then read it out through the serial port but I still have problems and cant understand whats going on.
It all seems to work in the simulator but not in real life. I am considering that I may have an older model 18m2 but I still dont know why that would cause a problem.

Code:
#PICAXE 18m2
setfreq m32
SYMBOL	data0=w7
SYMBOL	ctrl0=w8
SYMBOL	power=w9
SYMBOL	ch1loc=w0
SYMBOL	ch2loc=w1
SYMBOL	ch3loc=w2
SYMBOL	index=b6

SYMBOL	beginram = 30

ch1loc=beginram
ch2loc=ch1loc+2
ch3loc=ch2loc+2
 
main:
	GOSUB collectdata
end 


collectdata:
	DO
		index=0
		DO
			READADC10   C.0,data0 
			READADC10   C.1,ctrl0
			READADC10   C.2,power
			data0=1
			ctrl0=2
			power=3
			POKE ch1loc,WORD data0
			POKE ch2loc,WORD ctrl0
			POKE ch3loc,WORD power
			ch1loc=ch1loc+6
		 	ch2loc=ch2loc+6	
		 	ch3loc=ch3loc+6	
		LOOP UNTIL ch3loc >= 500
		GOSUB senddata
	LOOP UNTIL index >0
RETURN	

senddata:
	ch1loc=beginram
	ch2loc=ch1loc+2
	ch3loc=ch2loc+2
	setfreq m4
	DO
		PEEK ch1loc,WORD data0
		PEEK ch2loc,WORD ctrl0
		PEEK ch3loc,WORD power
		SERTXD("power ",TAB,#power,TAB," D0 ",TAB,#data0,TAB," C0 ",TAB,#ctrl0,CR,LF)
		ch1loc=ch1loc+6
	 	ch2loc=ch2loc+6	
	 	ch3loc=ch3loc+6	
		
	LOOP UNTIL ch3loc >= 500
	ch1loc=beginram
	ch2loc=ch1loc+2
	ch3loc=ch2loc+2
	index=0
RETURN

I tried the change in speed to see if it would have any effect on the output, but there was no significant differences.

The data I get out is like this:

power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 252 D0 1 C0 3
power 0 D0 260 C0 262
power 0 D0 3 C0 0
power 0 D0 3 C0 0
power 0 D0 3 C0 0
power 1 D0 3 C0 0
power 1 D0 3 C0 0
power 1 D0 3 C0 0
power 1 D0 3 C0 0
power 1 D0 3 C0 0
power 1 D0 3 C0 0
power 1 D0 3 C0 0
power 1 D0 3 C0 0
power 1 D0 3 C0 0
power 1 D0 3 C0 0
power 1 D0 3 C0 0
power 1 D0 3 C0 0
power 1 D0 3 C0 0
power 1 D0 3 C0 0
power 1 D0 3 C0 0
power 1 D0 3 C0 0
power 1 D0 3 C0 0
power 1 D0 3 C0 0
power 1 D0 3 C0 0
power 1 D0 3 C0 0
power 1 D0 3 C0 0
power 1 D0 3 C0 0
power 1 D0 3 C0 0
power 1 D0 3 C0 0
power 1 D0 3 C0 0
power 1 D0 3 C0 0
power 1 D0 3 C0 0
power 1 D0 3 C0 0
power 1 D0 3 C0 0
power 1 D0 3 C0 0
power 1 D0 3 C0 0
power 1 D0 3 C0 0
power 1 D0 3 C0 0
power 1 D0 3 C0 0
power 1 D0 3 C0 0
power 1 D0 3 C0 0
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 0 D0 1 C0 3
power 252 D0 1 C0 3
power 0 D0 260 C0 262
power 0 D0 3 C0 0
power 0 D0 3 C0 0
power 0 D0 3 C0 0
And the data output just repeats like this.
 

hippy

Senior Member
You are writing to RAM, from address 0 onwards. That will corrupt the variables you are using which are also held in / share that RAM.
 

cravenhaven

Senior Member
Could it be that the older model of 18M2 you have doesn't have 512 bytes of RAM, only 256 ?
Thanks Hippy,
Is there any way to find out exactly what chip I've got?
I'll try some more tests tomorrow (cause its nearly midnight here ATM).
 

hippy

Senior Member
Clicking "Check PICAXE type connected" in the "Workspace Explorer" panel of PE6 will report the chip type and firmware version.
 

cravenhaven

Senior Member
Problem solved thanks Hippy. It seems that my 18m2 has only 256bytes of ram, maybe the simulator and online doco needs to take account of the older chips that are around.

My 18m2 is v2.A according to the probe by PE6.
 
Top