Need help - 16f876 - strange results


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2012
    Posts
    1

    Unhappy Need help - 16f876 - strange results

    All,
    I am trying to build a simple robot for my daughter and have run into a snag. The code seems to run normal for some time then it will just stop and the hserout command will just start displaying 111111 or 222222 or 33333 over and over again. Every time I reset, it runs for a while and then displays 1 number higher, but over and over again. I am including the code below.
    Of note, when this program is running, I can hear the ultrasonic ping sensor happily pinging away, but once it starts displaying the number repeatedly, everything stops, including the blinking LED and the ping sensor, only the hserout keeps repeating the number.

    I am using a HS setting and disabling the WDT, Brown out, and power up timer.
    Code:
    define OSC 20
    DEFINE  HSER_BAUD 9600
    
    TRISC     = %00000000  'All C's are outputs
    TRISB     = %00100000  'All B's are outputs except b5
    CCP1CON   = %00001100  ' Mode select = PWM1
    CCP2CON   = %00001100  ' Mode select = PWM2
    
    TRIGGER var PortB.4
    ECHO var PortB.5
    IN1 VAR PortC.3
    IN2 VAR PortC.4
    IN3 var PortC.5
    IN4 var PortB.1
    
    'i var byte
    'duty var byte
    RAWDATA var word
    inINCHES var word
    low IN1
    low IN2
    low IN3
    LOW IN4
    pause 1000
    HSEROUT ["Starting", 10, 13]
    
    MAIN:
    HSEROUT ["GOSUB PING first entry", 10, 13]
    gosub PING
    
      IF inInches <= 9 THEN Obstacle
      high IN1
      high IN3
      hpwm 1, 250, 2000    ' Forward left motor
      hpwm 2, 250, 2000 ' Forward right motor 
    
    
    
    
    goto MAIN
    
    Obstacle:                 ' Backwards
     HSEROUT ["backing up", 10, 13]
     low IN1
     low IN3
     while inInches < 12
        high IN2
        high IN4
        hpwm 1, 150, 2000
        hpwm 2, 150, 2000
        gosub Ping
        wend
        low IN2
        LOW IN4
        return
    
    PING:
     pulsout TRIGGER, 5
     PUlsin ECHO, 1, RAWDATA
     pause 100
     inINCHES = RAWDATA / 74
     hserout ["RAWDATA ",DEC RAWDATA, 10, 13]
     hserout ["inINCHES ",DEC inINCHES, 10, 13]
     return
    Last edited by Archangel; - 4th October 2013 at 04:52.

  2. #2
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Re: Need help - 16f876 - strange results

    Ok only thing I see

    Obstacle is a subprogram and you are getting there from a then goto so return does not do what you are asking.
    try IF inInches <= 9 THEN gosub Obstacle
    Last edited by Archangel; - 4th October 2013 at 05:18.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  3. #3
    Join Date
    Apr 2011
    Location
    Welches, Oregon
    Posts
    198


    Did you find this post helpful? Yes | No

    Default Re: Need help - 16f876 - strange results

    I am not so experienced as others here, but would offer what help and encouragement that I may. It is my experience that coding never fails, some outside factor is introducing change. Odd behavior is often a power issue. Is your power well suppled? Does the pwm continue during the problem? I did not see configuration; could it be watchdog, a poor ground or other exteral condition?

Similar Threads

  1. Strange results with PBP3 and instant interrupts
    By R.G.Keen in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 13th December 2011, 15:57
  2. RC - connection using RCTime produces strange results
    By selbstdual in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 8th February 2007, 17:16
  3. Strange Results in Math
    By CocaColaKid in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 31st August 2005, 08:09
  4. Help! - Very strange results with ShiftIn/ShiftOut
    By khufumen in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 23rd February 2005, 23:21
  5. First test program, but strange results
    By bartman in forum General
    Replies: 12
    Last Post: - 19th November 2004, 04:14

Members who have read this thread : 1

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