08m code not simulating when set to 08m2

jareid

New Member
Firstly congrats on the superb -M2 range of Picaxes, Especially the 08M2 which is now so capable and versatile.

I have been running some code in the real world in an 08M for several months now.

This code works and simulates perfectly with the latest version of PE (5.4.0)

However when the simulator is set to 08M+ the code is accepted but one line fails to compute.

I have attached the file, but the line that fails to execute correctly is:

if b2<b3 and pin2=1 then let pin2=0 let b3=b3-5min 30 endif;threshold min inc to 30 fm 20

Please let me know if this is a bug or an error on my part.

PS: sorry I have not yet had opportunity to test for real in an 08M2

Thanks
James
 

Attachments

eclectic

Moderator
Please describe how it
doesn't simulate.

Code:
;2jan11 usage so far no problems
;30dec10 installed in car
;29dec10 180/256bytes, cleaned code greatly
;29dec10 on time needs increase to 16secs, otherwise ok to date.
;28dec10 ver 10 installed in car to test 2nd ver this date
;27dec10 reduced time to 12seconds,changed intro flash sidelights 
;26dec10 ver 9 installed, includes sidelight tester amd exit delay
;2nd version using 08M version 2.0061x ;DEC 2010
;increased fogs threshold to 180 and off to sides plus 50
;changes made to reset variables on ignition off and to have a cumulative 
;desensitising with changes over a journey
;program for auto lights/fogs for car.
;pin1 = opto in
;pin2 = sidelights
;Pin3 = ignition
;Pin4 = interior lights
;pin0 = foglights
;b2 = light level hi=dark
;b3 = sidelights dynamic off
;b1 = fogs dynamic off
;b4 = for next loop register
;bit1= exit flag if high
;bit2= ign been on flag if high
;
;---------------------------Start and Ign off top loop-----------------------------------
start:;ign off routine
	low 0;fogs go off
	low 2;sidelights go off
	let b3=50	;const for lights off setting
	readadc 1,b2;read light level to b2
	if pin3=0 and pin4=1 and bit1=0 then timer;if ign off and intlt on and bit1=0 then timer

;---------------------------Ign on top loop---------------------------------------------	
main:	;ign on routine
	if pin4=0 then let bit1=0 endif; if intlt off then bit1=0 this is exit flag
	b1=60+b3;b1= threshold at which fogs go off, b3=threshold at which sidelights go off
	if pin3 = 0 then goto start; ign off reset line
	bit2=1;records the ign has been on, this is ign flag
	if b2<b1 then low 0 endif;foglights off threshold level
	
	;multiple samples of light level to ensure no BLIPS in light level throw the outcome
	;sampled over a 0.65 second period
	;the widened threshold points of 50 and 95 ensure good hysteresis

;-------------------------light sampling loop for sidelights------------------------------
	for b4 = 0 to 4;sample check routine
	readadc 1,b2;read light level into b2
	pause 130	
	if pin3 = 0 then goto start; ign off reset line
	if b2>50 and b2<95 then goto main; if light level in no mans land then no action
	next b4
	if b2<b3 and pin2 =1 then let pin2 =0 let b3=b3-5min 30 endif;threshold min inc to 30 fm 20
	if b2>95 and pin2 =0 then let pin2 =1 endif;lights on threshold
	
;--------------------------foglights on delay time to prevent flash-----------------------
	for b4 = 1 to 5 ; foglights check routine
	if b2>220 then high 0 : wait 1 endif;foglight threshold
	if pin3 = 0 then goto start;ign off reset line
	next b4
	if pin2=1 then wait 1 endif;slows down process when lights already on
	
	goto main
	
;----------------entry/exit routines below-------------------------------	

timer:;timer routine if light level is high then skip first part i.e no foglights
	;however the exit flag (bit1) is reset even if no illumination occurs

	if b2>199 then ret1;if light level low (more than 199) then goto fogson
	if bit2=1 or b2<50 then goto ret1;if bit2=0 and lt level dusk then flash sidelights else ret1
	
	;sidelights test routine - only if not exit routine (bit2=0) and b2>80 dusk 
	;but not higher than 199
	for b4 = 0 to 4
	high 2
	pause 300 ; sidelights test routine
	low 2
	pause 300
	if pin3 = 1 then goto ret; ign on reset line
	next b4
	
ret1:	; routine to filter, if not dark enough then ret(end routine) 
	;if bit2=1 then must be exit routine
	; so the fogs do not come on until the car is locked i.e int lights go off. 
	if b2<200 or pin3=1 then ret;level at which entry exit fogs activate;if ign on then leave timer
	if bit2=0 or pin4=0 then ret2; if ign flag 0 then skip this next routine
	goto ret1

ret2:	;foglights on for 15secs unless ign comes on then return
	high 0
	for b4=0 to 15
	wait 1
	if pin3 = 1 then goto ret; ign on reset line
	next b4

ret:	;exit routine which sets flags and turns lights off (by sending to start)
	let bit2=0;reset the ign been on flag
	let bit1=1;completed 20sec of fogs on (if dark) still set (exit) flag, 
	;this prevents repeated cycles if the in light is still on.
	goto start
e
 

jareid

New Member
if b2<b3 and pin2=1 then let pin2=0 let b3=b3-5min 30 endif;threshold min inc to 30 fm 20

this line does not execute
when b2 is lower than b3 and Pin2 is high (output)

The simulation just carries on running as though that line is not present.

If I delete the 'and pin2=1' section of the
code it works correctly - except for the missing element.

I have tried the 'pin c.2=1' too.


Hope this helps

Thanks for your quick response
James
 

hippy

Ex-Staff (retired)
if b2<b3 and pin2=1 then let pin2=0 let b3=b3-5min 30 endif;threshold min inc to 30 fm 20

this line does not execute
when b2 is lower than b3 and Pin2 is high (output)
Possibly because pin 2 is an output at that time ?

If that is the case then arguably it's a very accurate simulation as reading an output as an input is not guaranteed to always give a reliable result!

I didn't actually test fully as I couldn't work out the sequence required to get the code to meet the conditions.
 

jareid

New Member
The best way to simulate is to set pin3 high and put 100 in C.1 adc. Then pin 2 will go high.
If the adc value then goes below fifty it should turn off pin2.

It does on 08m in real life and simulation.

Reading an output pin when it is an output is normally possible if 'outpins' is used.
I have tried the if 'outpins=%00000100' instruction but this too does not work for the line mentioned, but it works elsewhere in the program (as does if pin2=1 even when an output)

Thanks anyway
James
 

jareid

New Member
Although as reported the code does not behave it did in the 08m simulation,
in the real world the code works correctly when programmed into an 08M2+

James
 
Top