Well, I had to deal with a couple of issues before getting back to the heart of the matter. One of my breadboards developed a short and had to be replaced. I guess that is better than a breadboard in your shorts. Also I had to ditch the XINO shield which developed an intermittent and was a pain in the butt to attach wires to.
First I made the software changes everyone suggested – here is the revised code:
Code:
'=======================PinewoodDerby.bas===========================
'===constants===
'===variables===
Symbol Q_3 = B.0 ; rename input B.0 ‘Q_3’
Symbol Q_1 = B.1 ; rename input B.1 ‘Q_1’
Symbol SW_1 = B.2 ; rename input B.2 ‘SW_1’
Symbol Q_2 = B.3 ; rename input B.3 ‘Q_2’
Symbol Ln_2 = C.0 ; rename output C.0 ‘Ln_2’
Symbol Ln_1 = C.1 ; rename output C.1 ‘Ln_1’
Symbol Ln_3 = C.2 ; rename output C.2 ‘Ln_3’
'===directives===
'#com3 'specify serial port
#picaxe 18M2 'specify processor
#no_data 'save download time
'#terminal of 'disable terminal window
'=======================begin main program===========================
setfreq M32 'run program at max speed
let dirsC=%11111111 'all outputs
let dirsB=%11110000 'change bits 7,6,5, & 4 to 'outputs
pwmout pwmdiv64, B.6, 124, 250 'produces a 1 kHz square wave
'output on pin B.6
init: b2 = 0 ; reset targetbyte
; before the loop
; input B.2, active high, jump to ‘pushed’ label when = 1
myloop: button SW_1,1,200,100,b2,1,pushed
b0 = pinsB & %00001011 ;mask off bits 0, 1 & 3
if bit1 = 1 then LOW C.1 ;IR beam broken on Lane 1
endif
if bit3 = 1 then LOW C.0 ;IR beam broken on Lane 2
endif
if bit0 = 1 then LOW C.2 ;IR beam broken on Lane 3
endif
goto myloop
pushed: high C.0: high C.1: high C.2 ; output on
;outpinsC = outpinsC | %00000111
sertxd ("START RACE") ; send push message
goto myloop
Since I’m not using them in the breadboard configuration, I ran B.0 and B.3 to ground through a couple of 10k resistors. I also had to re-wire the phototransistor to the appropriate pins (3 & 4) on U2 hex inverter.
I powered the board up and nothing happened until I tripped the limit switch, then it immediately started counting. Eureka!
Now for the acid test; I broke the IR beam expecting the count to stop -- and it did not. Whiskey Tango Foxtrot!
Definitely getting a Hi/Lo signal from the Schmidt trigger every time the beam is interrupted. B.1 stays Lo until the beam is interrupted, and goes Hi whenever I break the beam. The phototransistor is doing exactly what it is supposed to do, however C.2 is staying Hi all the time. The 18M2 should be driving C.2 Lo whenever B.1 goes Hi.
C.2 is the control signal which opens and closes the CD4066 gate allowing pulses to go to the display. I did ground pins 5, 12 & 13 of the CD4066.
When the beam is broken, C.2 should go Lo and stay there until the 18M2 is reset, even after the car passes by the beam. We don’t want the display to start counting again after the car has passed by. This brings up another issue. We made no provision for resetting the system.
My thought was to use the N.C. contact of the limit switch. The race starts by closing the limit switch and pulling Pin 1 of the 74LS14 Lo.
Now the limit switch stays closed for the entire duration of the race. It only opens up again when the starting gate is positioned for the next race. The N.C. contact could be wired to one of the unused input pins on the 18M2. This pin would stay Hi until the race started when it would go Lo and stay there for the entire race. When the starting gate was positioned for the next race, the pin would go high again, thus resetting the system.
So that begs three questions:
1. Can anyone suggest an issue with the code that is preventing C.2 from going Lo?
2. Is there a possibility of a wiring error that I am somehow overlooking?
3. Can anyone suggest a snippet of code that would implement a reset function?
Thanks
Al