Im trying to write a program to switch on four LEDs in response to HI/LO (5v) pulses from two optical sensors.Im at this point with it where Im just staring at it and I cant see whats wrong at all and I despratley need to ask for help with it.
The problem is when I power everything up all that hapens is the LED connected to RB0 comes on and it shouldnt and my optical sensors do nothing.In short it just dosent work and I cant understand why.Ive included the program that Ive writen and some pictures of the sensors and if somone could look at it and let me know what Ive done wrong I would be very greatfull.
The nuts and bolts is,it's intended ultimatley to fire four ignition coils sequentialy on an engine but for now four LEDs will do.
There are two infrared optical sensors.One has a single interuption per revolution and the other has four interuptions per revolution.This is achived with a segmented wheel runing through each sensor.As in the picture the four segment wheel is on the top and the single segment one is on the bottom of the same shaft.Ive included the scope readings from the sensors and you can see that when the sensor is interupted the voltage drops and goes low (0v).It can also be seen that the single segment sensor overlaps slightly the four and you can see it in the first part of the program also at Label "loop".The program has to see the signal from the lower single segment sensor first before it can enter the section to check the four segment section.
Its on the low (0v) from the sensors that I need my LEDs to come on.
Please,if anybody could read through this post and help me with where Im going wrong.
Its like a wall at the moment that I cant climb over,dig under,or go round.
Thanks very much everybody
All the best O.T.
PIC16F876
Compiler version = PICBASIC 1.45
SYMBOL ADCON1 = $9f
SYMBOL TRISA = $85
symbol TRISB = $86
symbol PortA = 5
symbol PortB = 6
Init: poke ADCON1, 7
POKE TRISA, %11111111
POKE TRISB, %00000000
loop: peek portA,B0
if Bit0 = 0 then chk1 ----------------------------------------------Lower single segment sensor
GOTO LOOP
chk1: peek portA,B1
if bit1 = 0 then fire1 ----------------------------------------------Upper four segment sensor
goto chk1
if bit1 = 0 then fire3
goto chk3
chk4: peek portA,B3
if Bit1 = 0 then fire4
goto chk4
chk2: peek portA,B4
IF BIT1 = 0 THEN fire2
goto chk2
fire1: poke PortB, %00000001
peek portA,B1
if Bit1 = 0 then fire1
poke PortB, %00000000
goto chk3
fire3: POKE pORTb, %00000010
peek portA,B2
if Bit1 = 0 then fire3
POKE PortB, %00000000
goto chk4
fire4: poke PortB, %00000100
peek portA,B3
if Bit1 = 0 then fire4
poke PortB, %00000000
goto chk2
fire2: poke PortB, %00001000
peek portA,B4
if Bit1 = 0 then fire2
poke PortB, %00000000
goto loop
end
Bookmarks