Could I please ask for some help on my code


Results 1 to 9 of 9

Threaded View

  1. #1
    Join Date
    Jun 2009
    Location
    Somerset England
    Posts
    10

    Default Could I please ask for some help on my code

    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


    Last edited by opticaltrigger; - 20th January 2010 at 00:25.

Similar Threads

  1. Reading in Manchester code
    By brid0030 in forum Code Examples
    Replies: 0
    Last Post: - 10th March 2009, 21:55
  2. How much code space do PBP statements use.
    By Darrel Taylor in forum Code Examples
    Replies: 5
    Last Post: - 13th February 2009, 21:31
  3. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 8th December 2008, 23:40
  4. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  5. Re-Writing IF-THEN-AND-ENDIF code?
    By jessey in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 18th August 2006, 17:23

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts