PE simulate - ignoring pin change when pin assignment is through a variable

toolchimp

New Member
I think I have come across a bug with the programming editor simulation, or at the very least in my understanding!

I am planning on connecting 8 sensors to a 28x2, each with its own TX and RX pins. The 'sense' subroutine is the same for each and they are polled sequentially, so I am assigning the required input and output pins via variables. Once the 'start' command has been issued the sensor will hold the RX line low for a short period and I need to know when it is released. My aim is to do this with 'do...loop while' on the RX pin. If the pin in the simulator (PE 6.0.8.10) is high before starting, it comes straight out of the loop as expected but if the pin starts off low, the programming editor does not seem to recognise the change in state of the pin and stays in the loop indefintely.

This is the snippet in question:

Code:
#picaxe 28x2

symbol sensor_id = b50
symbol sensor_rx_pin = b51
symbol sensor_tx_pin = b52

symbol PINSENSOR0RX = pinB.0
symbol PINSENSOR1RX = pinB.1
symbol PINSENSOR2RX = pinB.2
symbol PINSENSOR3RX = pinB.3
symbol PINSENSOR4RX = pinB.4
symbol PINSENSOR5RX = pinB.5
symbol PINSENSOR6RX = pinB.6
symbol PINSENSOR7Rx = pinB.7

symbol PINSENSOR0TX = C.0
symbol PINSENSOR1TX = C.1
symbol PINSENSOR2TX = C.2
symbol PINSENSOR3TX = C.3
symbol PINSENSOR4TX = C.4
symbol PINSENSOR5TX = C.5
symbol PINSENSOR6TX = C.6
symbol PINSENSOR7Tx = C.7

init:
	sensor_id = 3
	gosub set_sensor_pin

main:
	high sensor_tx_pin
	pauseus 337				;337us low
	low sensor_tx_pin
	pauseus 356 			;356us high
	high sensor_tx_pin
	pauseus 278				;278us low
	low sensor_tx_pin
		
	do
	loop until sensor_rx_pin = 1 ;wait for sensor to release RX line
	goto main

set_sensor_pin:
	;assign sensor TX pin address to variable 'sensor_tx_address' and RX pin to variable 'sensor_rx_address'
	lookup sensor_id,(PINSENSOR0TX,PINSENSOR1TX,PINSENSOR2TX,PINSENSOR3TX,PINSENSOR4TX,PINSENSOR5TX,PINSENSOR6TX,PINSENSOR7TX),sensor_tx_pin
	lookup sensor_id,(PINSENSOR0RX,PINSENSOR1RX,PINSENSOR2RX,PINSENSOR3RX,PINSENSOR4RX,PINSENSOR5RX,PINSENSOR6RX,PINSENSOR7RX),sensor_rx_pin
	return
I tried just using the pin assignment directly and it works perfectly in the simulator:

Code:
main:
	do
	loop until pinB.3 = 1
goto main
can anyone shed any light on this?

Many thanks,

Paul
 

Technical

Technical Support
Staff member
Your lookup line puts the value of the pin *once, at the moment in time* into the variable b51 value.

It does not 'redirect' b51 to continuously read the input pin.
 

toolchimp

New Member
Hi Technical,

Thanks for the quick reply and the clarification on how the 'lookup' command works. I have reworked the code and it is now working successfully!

Code:
#picaxe 28x2

symbol sensor_id = b50
symbol sensor_rx_mask = b51
symbol sensor_tx_pin = b52

symbol MASKSENSOR0RX = %00000001
symbol MASKSENSOR1RX = %00000010
symbol MASKSENSOR2RX = %00000100
symbol MASKSENSOR3RX = %00001000
symbol MASKSENSOR4RX = %00010000
symbol MASKSENSOR5RX = %00100000
symbol MASKSENSOR6RX = %01000000
symbol MASKSENSOR7Rx = %10000000

symbol PINSENSOR0TX = C.0
symbol PINSENSOR1TX = C.1
symbol PINSENSOR2TX = C.2
symbol PINSENSOR3TX = C.3
symbol PINSENSOR4TX = C.4
symbol PINSENSOR5TX = C.5
symbol PINSENSOR6TX = C.6
symbol PINSENSOR7Tx = C.7

init:
	sensor_id = 3
	gosub set_sensor_tx_pin
	gosub set_sensor_rx_mask

main:
	high sensor_tx_pin
	pauseus 337				;337us low
	low sensor_tx_pin
	pauseus 356 			;356us high
	high sensor_tx_pin
	pauseus 278				;278us low
	low sensor_tx_pin
		
	do
	loop until pinsB = sensor_rx_mask ;wait for sensor to release RX line
	goto main

set_sensor_tx_pin:
	;assign sensor TX pin address to variable 'sensor_tx_address'
	lookup sensor_id,(PINSENSOR0TX,PINSENSOR1TX,PINSENSOR2TX,PINSENSOR3TX,PINSENSOR4TX,PINSENSOR5TX,PINSENSOR6TX,PINSENSOR7TX),sensor_tx_pin
	return

set_sensor_rx_mask:
	lookup sensor_id,(MASKSENSOR0RX,MASKSENSOR1RX,MASKSENSOR2RX,MASKSENSOR3RX,MASKSENSOR4RX,MASKSENSOR5RX,MASKSENSOR6RX,MASKSENSOR7RX),sensor_rx_mask
	return
 

hippy

Technical Support
Staff member
Bacuse all your TX and RX pins are on contiguous port pins, you can probably replace the LOOKUP commands. Untested ...

Code:
set_sensor_tx_pin:
  sensor_tx_pin = C.0 + sensor_id
  Return

set_sensor_rx_pin:
  sensor_rx_mask = 1 << sensor_id
  Return
 
Top