Program Won't Simulate Properly

AlbertZ

Senior Member
This is just a goofy little practice program that I am attempting to learn how to use 'outpins'. When I run it in the simulator (PICAXE editor 6.0.5.9) it steps through all the lines in the program, but it doesn't give me an indication on the graphic which pins are going high and low. It works if I use direct commands e.g. 'high B.1'.

Is this a glitch in the editor or am I missing something with the 'outpins' usage?

Code:
' ================= Cylon3v2.bas ==================

'	See if you can figure out how this version works.

' === Constants ===
	symbol abit = 100			' used to slow down

' === Variables ===
	symbol index = b0			' used in for/next loops
	symbol  LEDs = outpinsB			' used to vary lit LEDs	
	
' === Directives ===
	#com 4					' specify serial port
	#picaxe 18M2				' specify processor
	#terminal off			     ' disable terminal window

' ============== Begin Main Program ===============

do
	let outpinsB = %00000001			' light 1 on left
	pause abit					  ' slow down a bit
	let outpinsB = %00000011			' light 2 on left
	pause abit				  	' slow down a bit		
	LEDs = %00000111		  	' initialize LEDs 
	
	for index = 1 to 9			' for 9 "triplets"
		let outpinsB = LEDs				' light 3 (or 2 or 1)
		LEDs = LEDs * 2			   	' shift right     
	  pause abit						' slow down a bit
	next index
	wait 1
	
	let outpinsB = %10000000					' light 1 on right
	pause abit									' slow down a bit	
	let outpinsB = %11000000					' light 2 on right
	pause abit									' slow down a bit	
	LEDs = %11100000						' initialize LEDs 
	
	for index = 9 to 1 step -1	' for 9 "triplets"
		let outpinsB = LEDs						' light 3 (or 2 or 1)
		LEDs = LEDs / 2						' shift left
	  pause abit								' slow down a bit
	next index	
	wait 1	
loop
 

neiltechspec

Senior Member
You haven't set the pins as output

Put this before your do loop - let dirsB = %11111111

Try that (works in PE5.5).

Neil.
 

vttom

Senior Member
You have defined "symbol LEDs = outpinsB" and yet you're doing stuff like "let outpinsB = LEDs" which evaluates to "let outpinsB = outpinsB" which doesn't make any sense to me. What is your intended function here?
 

AlbertZ

Senior Member
You haven't set the pins as output

Put this before your do loop - let dirsB = %11111111

Try that (works in PE5.5).

Neil.
Thanks Neil!

I presume this has to do with the fact that the ports on the M2 series of processors swing both ways (input & output), thus you have to define their role in the program.

It does work in PE6.0

Al
 

AlbertZ

Senior Member
You have defined "symbol LEDs = outpinsB" and yet you're doing stuff like "let outpinsB = LEDs" which evaluates to "let outpinsB = outpinsB" which doesn't make any sense to me. What is your intended function here?
Tying myself up in knots it would seem. Remember, this program has no useful purpose other than teaching myself PICAXE basic, so it's not surprising that I started out intending to do one thing and ended up doing something else.

You're right, looking back it makes no sense to me either.

Thanks

Al
 

AlbertZ

Senior Member
You have defined "symbol LEDs = outpinsB" and yet you're doing stuff like "let outpinsB = LEDs" which evaluates to "let outpinsB = outpinsB" which doesn't make any sense to me. What is your intended function here?
OK, after I pondered this and stepped through the program I can see where I was going with this. I created a variable "LEDs" in order to facilitate the binary arithmetic. What I am trying to do in the "for...next" loop is light the LEDs in groups of 3, shifting them one place to the left or right depending on whether I am multiplying or dividing the variable "LEDs" by 2.

Al
 

AlbertZ

Senior Member
You have defined "symbol LEDs = outpinsB" and yet you're doing stuff like "let outpinsB = LEDs" which evaluates to "let outpinsB = outpinsB" which doesn't make any sense to me. What is your intended function here?
I deleted the statement "let outpinsB = LEDs" and the program runs the way I expected it to. Here is the revised code:
Code:
' ================= Cylon3v2.bas ==================

'	See if you can figure out how this version works.

' === Constants ===
	symbol abit = 100			' used to slow down

' === Variables ===
	symbol index = b0			' used in for/next loops
	symbol  LEDs = outpinsB			' used to vary lit LEDs	
	
' === Directives ===
	#com 4					' specify serial port
	#picaxe 18M2				' specify processor
	#terminal off			     ' disable terminal window

' ============== Begin Main Program ===============
let dirsB = %11111111
do
	let outpinsB = %00000001			' light 1 on left
	pause abit					  ' slow down a bit
	let outpinsB = %00000011			' light 2 on left
	pause abit				  	' slow down a bit		
	LEDs = %00000111		  		' initialize LEDs
	
	for index = 1 to 9			' for 9 "triplets"
		;let outpinsB = LEDs				' light 3 (or 2 or 1)
		LEDs = LEDs * 2			   	' shift right     
	  pause abit						' slow down a bit
	next index
	wait 1
	
	let outpinsB = %10000000					' light 1 on right
	pause abit									' slow down a bit	
	let outpinsB = %11000000					' light 2 on right
	pause abit									' slow down a bit	
	LEDs = %11100000						' initialize LEDs 
	
	for index = 9 to 1 step -1	' for 9 "triplets"
		;let outpinsB = LEDs						' light 3 (or 2 or 1)
		LEDs = LEDs / 2						' shift left
	  pause abit								' slow down a bit
	next index	
	wait 1	
loop
Another step in the learning process!

Thanks

Al
 

vttom

Senior Member
Alternatively, you could've assigned LEDs as a symbol for one of the built-in variables (eg. b0-b15), done all of your manipulations on that variable, and then copy it to the outputs pins with "let outpinsB = LEDs".
 

hippy

Ex-Staff (retired)
I presume this has to do with the fact that the ports on the M2 series of processors swing both ways (input & output), thus you have to define their role in the program.
That is correct as you have now found.

"High B.1" is the equivalent of "dirB.1=1" and "pinB.1=1", so it sets the pin as an output as part of the HIGH command.

Doing just a "pinB.1=1" has no observable effect as the pin remains an input unless something has previously made that pin an output.
 
Top