what's wrong 16F877A simple code?


Closed Thread
Results 1 to 12 of 12

Hybrid View

  1. #1
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Wink Harware issue ??? forgotten action ???

    Hi,

    1) If your opto- transistor emitter has no load to ground , no chance it works properly.

    add to that you are supposed to have a HIGH level @ input when there's nothing between photodiode and and photo transistor.


    2)

    Code:
    checkopt:
    if portb.2 = 1 then
    portc = runmot
    else
    goto checkopt
    endif 
    return
    This is an endless loop that DOESN'T CHANGES ANYTHING !!!! if you reach required position ...

    I do not think you wanted that ... ( stopping motor is doing something ... don't you think ??? so ... )

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  2. #2


    Did you find this post helpful? Yes | No

    Question

    thanks for the feedback. Faulty ground on optical switch is not the problem. Like I said I can take out a portion of the code and the optical switch works well..... I rewrote the code yet again and see the same issue. I realize it is not elegant, and it should dwell in each loop until the correct cadence....but what I see is it vectors outside of the loop and enables the start switch which is deliberated left out of the normal loop....it is only used once upon start up to kick start the checkleaf and checkopt loops. see below.

    Code:
    @ device pic16F877A, HS_OSC, LVP_OFF, WDT_OFF
    ; @ Device pic16F877A, HS_OSC, BOD_OFF, PWRT_ON, WDT_ON, PROTECT_OFF
    		
    		
    DEFINE OSC 20
    
    
    ;set ports to output
    TRISA = %00000000
    TRISB = %00000111
    TRISC = %00000000
    TRISD = %00000000
    
    ; analog portA direction
    ADCON1 = 7
    CMCON = 7
    
    
    ;constants
    brake  Con  %00000011
    stmot  con  %00000000
    runmot con  %00000001
    
    ;variables
    timeout  var byte
    
    ;initialization
    portc = stmot
    
    
    
    HomeStart:
           if portb.0 = 0 then
              portc = runmot
              goto checkleaf
           endif
           goto homestart
           
    checkleaf:       
           if portb.1 = 0 then
              portc = brake
              pause 500
              portc = stmot
              goto checkopt
           endif
           goto checkleaf
    
    checkopt:
          if portb.2 = 1 then
             portc = runmot
             goto checkleaf
          endif
             goto checkopt

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Would you like some Marinara to go with that spaghetti?

    Welll, here's my interpretation of your program.

    HomeStart:
      Wait for button press on RB0
      When pressed, start motor

    checkleaf:
      Wait for Leaf switch on RB1
      When triggered, apply brake for .5 sec. then stop motor

    checkopt:
      Wait for Optical interrupter on RB2
      When triggered, start motor, and go back to checkleaf:
      Never ending loop
    <br>
    DT

  4. #4


    Did you find this post helpful? Yes | No

    Question

    Yes, not elegant at all but it should run. The never ending loop is supposed to tell me whether it got to this point and it should dwell there.
    It was supposed to go back originally to checkleaf but that seemed not to work either. The end result is still the same, It would get to the never ending loop and fall out going back to homestart which should never happen since I trap it in the lower loops.

    Just wondering if somehow it is being vectored back to the beginning of the code or what. I turn off analog channels, comps, interrupts are not used, watchdog is off....

    I guess I am having one of those days.

    Nick

  5. #5
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Why do you think it's somehow jumping where it shouldn't?
    Are you running it on a simulator?

    The only indication of what the program is doing is a motor running.
    And according to your program it's going to be doing a LOT of running, with no way to stop it.
    DT

  6. #6


    Did you find this post helpful? Yes | No

    Question

    I know it jumps out and goes back to homestart because that button when pressed retriggers the sequence of loops over again when it shouldn't. If I am stuck in an endless loop at checkleaf, homestart shouldn't do anything after the first time it falls through the code upon startup correct?

    As far as motor running, the motor runs only when homestart is triggered, it goes through homestart (1 time upon start up of MCU), then when I hit checkleaf it works correctly (since it sits in a loop)....but after that the motor is off at checkopt and does not sit in that loop. The motor stays off until I hit homestart again (which should never happen except on power up).

    I may start from scratch....I don't know. Any reference code to get started would help since I seem to be stuck in a loop mentally

    Nick

  7. #7
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Question ...

    Are the Brake and the Motor supposed to run at the same time?

    ;constants
    brake Con %00000011
    stmot con %00000000
    runmot con %00000001

    The only way I can see that your symptoms can happen is if the PIC gets reset at the point where it applies the brake.
    Possibly from over current (Brake+Motor).

    The code itself will not do that.
    <br>
    DT

Similar Threads

  1. How much code space do PBP statements use.
    By Darrel Taylor in forum Code Examples
    Replies: 5
    Last Post: - 13th February 2009, 22:31
  2. LCD Showes Some Wrong Letters
    By sbobowski in forum General
    Replies: 2
    Last Post: - 23rd September 2008, 20:15
  3. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 09:26
  4. hopefully simple code
    By hoyles in forum General
    Replies: 3
    Last Post: - 9th September 2005, 00:24
  5. Problems with 16F877A code
    By NightHawk2 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 20th August 2003, 02:36

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