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.
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:
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:
And the data output just repeats 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