Why Programmation mode is different of Similation mode of my program?

Gaston Dezau

New Member
Hi,

My program works on Similation mode but it is not work correctly on Programmation mode.
When I tranfer the program to my PICAXE14M2, some lines of my program are not executed.
The problem carries when I insert a variable into the program
I installed PICASE SVM for real similation.
On this soft, the problem is same.
I use Programming Editor 5.5 version.
Other problem: some instructions of the editor(#picaxeM14, reset, setfreq ...) are not recognized by VSM.

Somebody can help me

My program:
-
Code:
;#picaxe14m2	
;setfreq m16	
setint %00000001,%00000011
;let b0=10 

mainprog:

	let w1=0
	low B.0
	low B.1
	low B.2
	low B.3
	if pinC.1=1 then goto  mainlt
	if pinC.2=1 then goto  lowlt
	if pinC.3=1 then goto  highlt
goto mainprog

mainlt:
	high B.0
	high B.1
	low B.2
	low B.3
	pause 8000
	low B.1 
	Do  
	w1=w1+1	 
	loop while pinC.2 =0 and pinC.3=0 and w1 <600
	pause 5000
	goto mainprog 

lowlt:
	high B.0
	low B.1
	high B.2
	low B.3
	pause 8000
	low B.2 
	Do 
 	w1=w1+1  
	loop while pinC.1 =0 ;and b0 <20
	pause 7000
	goto mainprog 
	
highlt:
	high B.0
	low B.1
	low B.2
	high B.3
	pause 8000
	low B.3 
	Do 
	w1=w1+1	
	loop while pinC.1 =0 ;and b0 <20
	pause 7000
	goto mainprog

interrupt:
	high B.0
	low B.1
	low B.2
	low B.3 
	if pinC.1 = 1 then interrupt 
	pause 4000 
	setint %00000001,%00000011 ;
	goto mainprog
 
Last edited by a moderator:

hippy

Ex-Staff (retired)
Welcome to the PICAXE forum.

Do you have a circuit diagram, or can you explain how your hardware is wired. It could be that some or all signals you expect to go low or high do the opposite with your real hardware. This would cause unexpected behaviour.

You terminate your interrupt routine with a GOTO. This needs to be a RETURN otherwise only the first interrupt will processed.
 

BESQUEUT

Senior Member
Welcome,...
Please, use
Code:
 and [ /CODE]
your code will be more readable.

It's not so evident cause lot of GOTO commands...
but :
if pinC.1=1 then
other test (if pinC.2... if pinC.3=1...) will never be executed...
 

Gaston Dezau

New Member
Sorry, this is my first program under Picaxe.
It runs correctly on similation mode but runs with some bugs on real mode.
Code:
;#picaxe14m2 
;setfreq m16 
setint %00000001,%00000011
;let b0=10 

mainprog:

let w1=0
low B.0
low B.1
low B.2
low B.3
if pinC.1=1 then goto mainlt
if pinC.2=1 then goto lowlt
if pinC.3=1 then goto highlt
goto mainprog

mainlt:
high B.0
high B.1
low B.2
low B.3
pause 8000
low B.1 
Do 
w1=w1+1 
loop while pinC.2 =0 and pinC.3=0 and w1 <600
pause 5000
goto mainprog 

lowlt:
high B.0
low B.1
high B.2
low B.3
pause 8000
low B.2 
Do 
w1=w1+1 
loop while pinC.1 =0 ;and b0 <20
pause 7000
goto mainprog 

highlt:
high B.0
low B.1
low B.2
high B.3
pause 8000
low B.3 
Do 
w1=w1+1 
loop while pinC.1 =0 ;and b0 <20
pause 7000
goto mainprog

interrupt:
high B.0
low B.1
low B.2
low B.3 
if pinC.1 = 1 then interrupt 
pause 4000 
setint %00000001,%00000011 ;
goto mainprog
 

The bear

Senior Member
Hi Gaston,
I can only do simple.
However, in the first four lines of your code, three are commented out.
Regards, Bear..
;#picaxe 14m2 (Space required before '14')
;setfreq m16
setint %00000001,%00000011
;let b0=10
Download circuit incorrect, see page 43 Getting Started
 
Last edited:

BESQUEUT

Senior Member
Your program with no change except indentation and return after interrupt:
Code:
;#picaxe14m2 
;setfreq m16 
setint %00000001,%00000011
;let b0=10 

mainprog:

	w1=0
	low B.0
	low B.1
	low B.2
	low B.3
	if pinC.1=1 then goto mainlt
	if pinC.2=1 then goto lowlt
	if pinC.3=1 then goto highlt
goto mainprog

mainlt:
	high B.0
	high B.1
	low B.2
	low B.3
	pause 8000
	low B.1 
	Do 
		w1=w1+1 
	loop while pinC.2 =0 and pinC.3=0 and w1 <600
	pause 5000
goto mainprog 

lowlt:
	high B.0
	low B.1
	high B.2
	low B.3
	pause 8000
	low B.2 
	Do 
		w1=w1+1 
	loop while pinC.1 =0 ;and b0 <20
	pause 7000
goto mainprog 

highlt:
	high B.0
	low B.1
	low B.2
	high B.3
	pause 8000
	low B.3 
	Do 
		w1=w1+1 
	loop while pinC.1 =0 ;and b0 <20
	pause 7000
goto mainprog

interrupt:
	high B.0
	low B.1
	low B.2
	low B.3 
	if pinC.1 = 1 then interrupt 
	pause 4000 
	setint %00000001,%00000011 ;
	return
if pinC.1=1 then
other test (if pinC.2... if pinC.3=1...) will never be executed...

Is this what you really want ?

Program without GOTO commands. This one does not do the same thing, but maybe you prefere :
Code:
;#picaxe14m2 
;setfreq m16 
setint %00000001,%00000011
;let b0=10 

do
	w1=0
	low B.0
	low B.1
	low B.2
	low B.3
	if pinC.1=1 then gosub MainLT
	if pinC.2=1 then gosub LowLT
	if pinC.3=1 then gosub HighLT
loop

mainlt:
	high B.0
	high B.1
	low B.2
	low B.3
	pause 8000
	low B.1 
	Do 
		inc w1
	loop while pinC.2 =0 and pinC.3=0 and w1 <600
	pause 5000
return 

LowLT:
	high B.0
	low B.1
	high B.2
	low B.3
	pause 8000
	low B.2 
	Do 
		inc w1
	loop while pinC.1 =0 ;and b0 <20
	pause 7000
return

HighLT:
	high B.0
	low B.1
	low B.2
	high B.3
	pause 8000
	low B.3 
	Do 
		inc w1
	loop while pinC.1 =0 ;and b0 <20
	pause 7000
return



interrupt:
	high B.0
	low B.1
	low B.2
	low B.3 
	if pinC.1 = 1 then interrupt 
	pause 4000 
	setint %00000001,%00000011 ;
	return
 

inglewoodpete

Senior Member
There are two main differences between simulation and a real circuit. The first is that the electronics must perform as expected. The second is timing.

It is difficult to see what you want the code to do when there are so few comments.

Some observations on your circuit diagram. The download circuit's resistors are connected incorrectly, which will affect programming of the chip. Also, what is the purpose of U5?
 

Gaston Dezau

New Member
Dear,
What resistors are connected incorrectly?
U5 is CMOS buffer inverser. When switch is closed, the input of opto goes high, the output goes low and the output of U5 goes high.
I'm trying to change some lines of my program.
 

BESQUEUT

Senior Member
Tested code ?
NO : only replaced the GOTO mainprog with a RETURN Statement (post #2 by Hippy)

I was only asking about the test structure and usage of GOTO command...

if pinC.1=1 then
other test (if pinC.2... if pinC.3=1...) will never be executed...
 

inglewoodpete

Senior Member
Dear,
What resistors are connected incorrectly?
U5 is CMOS buffer inverser. When switch is closed, the input of opto goes high, the output goes low and the output of U5 goes high.
I'm trying to change some lines of my program.
Compare your download circuit (R9/R10) with that in Manual 1: 'Getting Started'. Rxd on the download socket should connect to the junction of the two resistors.

Yes, I understand that U5 is an inverter. I don't think you need it in the circuit. You can connect the outputs of the opto isolators directly to input pins on the PICAXE and change your software to react to the opposite input condition.
 

hippy

Ex-Staff (retired)
Sorry, this is my first program under Picaxe.
It runs correctly on similation mode but runs with some bugs on real mode.
When first starting with real PICAXE hardware or any new PICAXE circuit, it is usually best to run a number of test programs to check that each hardware input and each output is working as expected, that inputs and outputs are low when they are meant to be low and high when meant to be high.

This will ensure that the hardware is as expected, has been wired correctly, should work as expected.

That is extra effort, may appear unnecessary when it simply confirms everything is as it should be, but over the long term it usually will prove beneficial. Those test will likely have to be done anyway if code does not work and it is not clear if the problem is with the hardware or the code or both.
 
Top