Scratchpad issues

buntay

Senior Member
Hello all, I have been through the manual and checked over my code but I cant find my error. The manual says that a word value uses 2 byte values....ie b0+b1=w0. so wouldn't b8+b9=w4 and b10+b11= w5?

here is what I am tryin to do. I have a 28x2 that is running code and I am using a 18m2 as a adjustable timer ( yes there are other ways but these are what I have on hand) looking at the code you can see how the timer works. Now, I using this timer in conjunction with a counter algorithm to gauge a "time to empty" loop.

well here is code and any help would be appreciated.
Code:
setfreq m16
'--------------------------------------------------------------------------
'variables used
'b0
'b1
'b2
'b3
'b4
'b5
'b6
'b7
'b8\
'b9/====W4
'b10\
'b11/===W5
'b12
'b13
'---------------------------------------------------------------------------


symbol stoker = b.0
symbol blower = b.1
symbol auger = b.2
symbol aux = b.3
symbol alarm = b.4
symbol lcd=b.5
symbol wifitx=b.6
symbol wifirx=b.7
symbol stokerpm = c.0
symbol blowerpm = c.1
symbol augerpm = c.2
symbol thermostat = pinc.3
symbol augprox =pinc.4
symbol reboot = pinc.5


pause 1000
serout lcd,T9600_16,("CL")  'Clears screen
pause 1000
serout lcd, T9600_16, ("STCR",20,4,128,192,148,212) 'sets screen for 20x4
pause 7000
serout lcd,T9600_16,("CS0") 'Turns Curser Off

Start:

low stoker
low blower
low auger
low aux
low alarm

w5=10000

serout lcd, T9600_16, ("CL","TT")
serout lcd, T9600_16, ("Begining System Tests",cr)
pause 5000
serout lcd, T9600_16, ("CL","TT")
pause 3000
serout lcd, T9600_16, ("Testing Stoker Motor",cr)
high stoker
pause 1000
count stokerpm,1000,b0
serout lcd, T9600_16, ("CL","TT")
if b0 > 5 then 
serout lcd, T9600_16, ("Stoker Motor Passed",cr)
else 
serout lcd, T9600_16, ("Stoker Failed",cr)
end if
low stoker
pause 1000
serout lcd, T9600_16, ("CL","TT")
pause 3000
serout lcd, T9600_16, ("Testing Blower Motor",cr)
high blower
pause 1000
count blowerpm,1000,b1
if b1 > 5 then 
serout lcd, T9600_16, ("Blower Motor Passed",cr)
else 
serout lcd, T9600_16, ("Blower Failed",cr)
end if
low blower
pause 3000
serout lcd, T9600_16, ("CL","TT")
pause 3000
serout lcd, T9600_16, ("Testing Bin Auger",cr)
high auger
pause 1000
count augerpm,1000,b2
if b2 > 5 then 
serout lcd, T9600_16, ("Bin Auger Passed",cr)
else 
serout lcd, T9600_16, ("Bin Auger Failed",cr)
end if
low auger
pause 3000
'if b0<5 then goto stokerdown
'if b1<5 then goto blowerdown
'if b2<5 then goto augerdown
'---------------------------------------------------------------------

serout lcd, T9600_16, ("CL","TT")
serout lcd, T9600_16, ("Box Temp",cr)
serout lcd, T9600_16, ("TP",0,1,"TT")
serout lcd, T9600_16, ("Incoming Temp",cr)



runsys:
b0=0
b1=0
b2=0
b3=0
b4=0
b5=0
b6=0
b7=0
'serin [1000],wifirx,T9600_16, b6
if b6= "a" then goto commands
if reboot =1 then reset
end if
readtemp a.0,b0
b12=b0 *9/5+32
if b12 <100 then 
serout lcd, T9600_16, ("TP",17,0,"TT ")
else 
serout lcd, T9600_16, ("TP",16,0,"TT ")
end if
serout lcd, T9600_16, (#b12,cr)
readtemp a.1,b1
b13=b1 *9/5+32
if b13 <100 then 
serout lcd, T9600_16, ("TP",17,1,"TT ")
else
serout lcd, T9600_16, ("TP",16,1,"TT ")
end if
serout lcd, T9600_16, (#b13,cr)
if thermostat = 1 then goto heat 
if thermostat = 0 then low stoker
if b0<90 then goto cooldown
if b0>90 and b0<218 then high blower 
if augprox = 1 then high auger
count augerpm,1000,b3
if b3<3 then goto augerdown
else low auger
end if
end if
end if
pause 3000


goto runsys


heat:
'serin [1000],wifirx,T9600_16, b6
if b6= "a" then goto commands
if b12>90 and b12<218 then high blower
end if
if b12>220 then low stoker goto overheat
else
high stoker
end if
overheat:
if augprox = 1 then high auger
else low auger
end if
if b12<90 then low blower
end if
'---------------------------------------------------------------
'count stokerpm,1000,b2
'if b2<5 then goto stokerdown
'count blowerpm,1000,b3
'if b3<5 then goto blowerdown
'---------------------------------------------------------------------------------------
if pinc.7=1 then high c.6:w4=w5 - 1 'uses a seperate picaxe as a timer to count down coal use
else low c.6                        'to gauge coal left in the bin
end if

if w4 <900 then serout lcd, T9600_16, ("TP",18,3,"TT ",cr)
end if
if w4 <800 then serout lcd, T9600_16, ("TP",17,3,"TT ",cr)
end if
if w4 <700 then serout lcd, T9600_16, ("TP",16,3,"TT ",cr)
end if
if w4 <600 then serout lcd, T9600_16, ("TP",15,3,"TT ",cr)
end if
if w4 <500 then serout lcd, T9600_16, ("TP",14,3,"TT ",cr)
end if
if w4 <400 then serout lcd, T9600_16, ("TP",13,3,"TT ",cr)
end if
if w4 <300 then serout lcd, T9600_16, ("TP",12,3,"TT ",cr)
end if
if w4 <200 then serout lcd, T9600_16, ("TP",11,3,"TT ",cr)
end if
if w4 <100 then serout lcd, T9600_16, ("TP",10,3,"TT ",cr)
end if
if w4 <50 then serout lcd, T9600_16, ("TP",9,3,"TT ",cr)
end if
if w4 <25 then serout lcd, T9600_16, ("TP",8,3,"TT ",cr)
end if
if w4 <12 then serout lcd, T9600_16, ("TP",10,3,"TT EMPTY",cr)
end if
'_______________________________________________________________________________________

serout lcd, T9600_16, ("TP",0,2,"TTCount down   ",#w4,cr)
w5=w4

goto runsys


cooldown:
'serin [1000],wifirx,T9600_16, b6
if b6= "a" then goto commands
b4=0
b5=0
readtemp a.0,b4
if b0<85 then low blower:goto done
end if
count blowerpm,1000,b5
if b4<5 then goto blowerdown
done:
goto runsys


stokerdown:
serout lcd, T9600_16, ("CL","TT")
pause 1500 
serout lcd, T9600_16, ("Furnace Off")
serout lcd, T9600_16, ("TP",0,1)
serout lcd, T9600_16, ("Stoker Error",cr)

stokerdown1:
'serin [1000],wifirx,T9600_16, b6
if b6= "a" then goto commands
high alarm 
low stoker 
low blower 
low auger

if reboot =1 then reset
end if
b6=0
low alarm
pause 1500
goto stokerdown1

blowerdown:
serout lcd, T9600_16, ("CL","TT")
pause 3000 
serout lcd, T9600_16, ("Furnace Off")
serout lcd, T9600_16, ("TP",0,1)
serout lcd, T9600_16, ("Blower Error",cr)

blowerdown1:
'serin [1000],wifirx,T9600_16, b6
if b6= "a" then goto commands
high alarm 
low stoker 
low blower 
low auger

if reboot =1 then reset
end if
b6=0
low alarm
pause 1500
goto blowerdown1

augerdown:
'serin [1000],wifirx,T9600_16, b6
if b6= "a" then goto commands
high alarm 
serout lcd, T9600_16, ("TP",0,3)
serout lcd, T9600_16, ("Auger Error",cr)
if reboot =1 then reset
end if
b6=0
goto runsys

commands:
serout wifitx,T9600_16,("B",cr,lf)

'serin wifirx,T9600_16, b7

if b7= "1" then goto stokercontrol
if b7= "2" then goto blowercontrol
if b7= "3" then goto augercontrol
if b7= "4" then goto temps
if b7= "5" then goto shutdown
if b7= "6" then goto continue
if b7= "7" then goto systemstatus
if b7= "8" then goto auxcontrol
if b7= "9" then reset
end if

stokercontrol:

b6=0
b7=0



blowercontrol:

b6=0
b7=0



augercontrol:

b6=0
b7=0



temps:

b6=0
b7=0



shutdown:
serout lcd, T9600_16, ("CL")
shutdown1:
b0=0
b1=0
high alarm
readtemp a.0,b0
readtemp a.1,b1

low alarm
low stoker
low blower
low auger
low aux
serout wifitx,T9600_16,(b0,b1,cr,lf)
serout lcd, T9600_16, ("TP",0,1)
serout lcd, T9600_16, ("Furnace Down",cr)
goto shutdown1



continue:
b6=0
b7=0
goto runsys


systemstatus:

b6=0
b7=0



auxcontrol:

b6=0
b7=0
 

Technical

Technical Support
Staff member
Your code is very unclear, what is the actual problem?

w4 is indeed made up of b8 (low byte) and b9 (high byte), ie w4 = (256 * b9) + b8
 

buntay

Senior Member
Your code is very unclear, what is the actual problem?

w4 is indeed made up of b8 (low byte) and b9 (high byte), ie w4 = (256 * b9) + b8

in my code you will find w5=10000
Code:
Start:

low stoker
low blower
low auger
low aux
low alarm

w5=10000
then under the "heat:" routine you will find
Code:
if pinc.7=1 then high c.6:w4=w5 - 1 'uses a separate picaxe as a timer to count down coal use
else low c.6                        'to gauge coal left in the bin
end if

if w4 <900 then serout lcd, T9600_16, ("TP",18,3,"TT ",cr)
end if
if w4 <800 then serout lcd, T9600_16, ("TP",17,3,"TT ",cr)
end if
if w4 <700 then serout lcd, T9600_16, ("TP",16,3,"TT ",cr)
end if
if w4 <600 then serout lcd, T9600_16, ("TP",15,3,"TT ",cr)
end if
if w4 <500 then serout lcd, T9600_16, ("TP",14,3,"TT ",cr)
end if
if w4 <400 then serout lcd, T9600_16, ("TP",13,3,"TT ",cr)
end if
if w4 <300 then serout lcd, T9600_16, ("TP",12,3,"TT ",cr)
end if
if w4 <200 then serout lcd, T9600_16, ("TP",11,3,"TT ",cr)
end if
if w4 <100 then serout lcd, T9600_16, ("TP",10,3,"TT ",cr)
end if
if w4 <50 then serout lcd, T9600_16, ("TP",9,3,"TT ",cr)
end if
if w4 <25 then serout lcd, T9600_16, ("TP",8,3,"TT ",cr)
end if
if w4 <12 then serout lcd, T9600_16, ("TP",10,3,"TT EMPTY",cr)
end if
'_______________________________________________________________________________________

serout lcd, T9600_16, ("TP",0,2,"TTCount down   ",#w4,cr)
w5=w4
goto runsys
here is what I am doing. I am using a high output from a separate 18m2 and when the 28X2 above sees that high on pin C.7 then it makes pin c.6 go high, telling the 18m2 that signal was received and start another timer cycle. the code on the 18m2 looks like this.

Code:
main:
high B.6
if pinB.7=1 then low c.6
pause 15000
end if
the 18m2 will be used as a timer(above), and a watchdog(later programming) for the 28X2.

at any rate if you copy and paste the entire code in post 1 and simulate it, in the simulated terminal window w5 will return a "0" and when you simulate the input on c.7 instead of w5 returning the value of 10000 like it was told too earlier it will return the maximum of 65000 something. So, the real problem is w5 was told to equal 10000 early in the program but it is never placed or is lost.

I have run the simple high, low com code on my ax91 board with a 20x2, an lcd, and an 18x, and it works as intended there when I use w4 and w5 to hold my variables

Hope this helps a bit :)
 

buntay

Senior Member
I could see that, however, w4 was told to equal w5 minus 1 before any call to w4 is made further down the line
 

srnet

Senior Member
Rather than someone else find the bug for you, why not take some steps to identify the bug ?

Put lines like this at various parts of the program, whenever w5 and w4 are used;

sertxd ("Step1 - W4",#w4,"W5,",#w5,CR,LF)

Do the values of w4 and w5 change in the way you expect\want ?
 

rossko57

Senior Member
I could see that, however, w4 was told to equal w5 minus 1 before any call to w4 is made further down the line
Only when c.7 is high
Before that , w4 is zero
Then w5 = w4 is executed
When c.7 does go high, you execute w4 = w5 - 1
0 - 1 = 65535 in unsigned words

Have you found the step function in the simulator?
 

buntay

Senior Member
Thanks rossko, that makes total sense why its doing what its doing. I must find this thing you call step....hahahaha.
 
Top