simulates in VSM does not work in realtime

novolts

Senior Member
Hi all the following code runs in VSM

start:

if pinC.2=1 then goto blron
time=0
goto start

blron: ; boiler temperature control

do
readadc C.0,w2 ; 10k pot connected to pin C.0
w2=w2/25 ; 0 to 10 increments of 1

readtemp C.4,w3 ; DS18B20 connected to pin C.4
if w3<51 then ; setpoint 50oC
high b.4
endif

w4=w2+w3 ; readadc added to readtemp
w5=w4+1 ; 50oC to 60oC increments of 1

if w5>w4 then ; heater stays on until temperature is reached
high b.4
endif

if w5>60 then ; maximum temperatue 60oC
low b.4
endif

if time=20 then ; switches off after time delay
pause 100
low b.4
endif

if pinb.4=0 then ; goes to "start" after desired temperature is reached ;
goto start
endif

loop

However when I program the 14M2 the timing part of the code does not time out
The rest of the code works fine
If the temp reaches 50oC the led goes off if I increase the temp by using the pot the led goes off between 50oC and 60oC depending on what the pot is set to
I have attached the DSN file
any help would be appreciated
kind regards
novolts
 

Attachments

hippy

Senior Member
This is probably because simulation doesn't always reflect the hard reality of the physical universe.

I would guess the problem is in "IF time = 20 THEN". Should time be approaching 20, if a loop to READTEMP and the rest of the code takes just over a second, by the time it gets back to the IF time could have incremented to 21.

It is usually best to take a 'defensive' approach to programming; code that as "IF time >= 20 THEN".

Also ...

w5=w4+1
if w5>w4 then
high b.4
endif

w5 will always be greater than w4, B.4 will always be set high, even if cleared later.
 

novolts

Senior Member
Hippy
thank you for the prompt reply
"IF time >= 20 THEN".did not work
Back to the start for me to find another solution
regards
novolts
 

lbenson

Senior Member
If you remove this:

if pinb.4=0 then ; goes to "start" after desired temperature is reached ;
goto start
endif

and put "goto start" after each "low b.4", does that fix it? As I understand it, when you do "if pinb.4", that changes the pin from an output pin to an input pin, and may change the state of the pin depending on what you have attached to it--e.g., pullups or pulldowns--if the picaxe itself is no longer driving the pin state.
 

hippy

Senior Member
Also try putting some SERTXD commands in the program so you can see where program flow is going and what state the pins are in, what values variables have, when the code gets there.

Perhaps before even that, write a short test program which reads your inputs and reports those so you know those are behaving as expected.
 

novolts

Senior Member
thanks guys I really do appreciate all of the help
I will sit down next week and alter the code as advised
kind regards
novolts
 
Top