I don't understand this program


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2006
    Location
    New Hampshire, USA
    Posts
    107

    Default I don't understand this program

    REM TEST 3
    REM 16F627A
    PORTA =0
    TRISA = %00010000
    TRISB = %00111111

    LOOP:
    HIGH PORTB.6
    PAUSE 1000
    HIGH PORTB.7
    PAUSE 100

    LOW PORTB.6 'DOES NOT GO LOW!
    LOW PORTB.7
    PAUSE 1 ' WHY DO I NEED THIS PAUSE STATEMENT? WITHOUT IT,
    'PORTB.6 NEVER GOES LOW. WITH IT, PORTB.6 IS
    'LOW ONLY 1 mS.
    LOW PORTB.6 'DOES NOT STAY LOW
    GOTO LOOP
    END

  2. #2
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Default

    Russ,

    I am not sure what you are trying to do. Without an OScope, you probably cannot see what your program is doing because it is doing it so fast.

    PAUSE 1 ' WHY DO I NEED THIS PAUSE STATEMENT? WITHOUT IT,
    'PORTB.6 NEVER GOES LOW. WITH IT, PORTB.6 IS
    'LOW ONLY 1 mS
    It will and does go low with or without your Pause statement. Without the Pause, RB6 is low only for a few uS, which is hard to detect. Your program is humming along at 1,000,000 instructions per second. You make RB6 low with line 5 and then immediately make it high again with line 1) with only a few instruction in between. With the pause of 1 (= 1000uS) inlcuded on line 7, you basically get a 1mS off time before you turn it back on with line 1. Clear as mud?

    For reference

    LOOP:
    1) HIGH PORTB.6
    2) PAUSE 1000
    3) HIGH PORTB.7
    4) PAUSE 100

    5) LOW PORTB.6 'DOES NOT GO LOW!
    6) LOW PORTB.7
    7) PAUSE 1 ' WHY DO I NEED THIS PAUSE STATEMENT? WITHOUT IT,
    'PORTB.6 NEVER GOES LOW. WITH IT, PORTB.6 IS
    'LOW ONLY 1 mS.
    8) LOW PORTB.6 'DOES NOT STAY LOW
    9) GOTO LOOP

    Paul Borgmeier
    Salt Lake City, Utah
    USA

  3. #3
    Join Date
    Jan 2006
    Location
    New Hampshire, USA
    Posts
    107


    Did you find this post helpful? Yes | No

    Default

    Oh, thanks. I am glad you can't see my red face!

  4. #4
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Russ,

    Try an experiment with the delay timing.

    1) HIGH PORTB.6
    2) PAUSE 1000
    3) HIGH PORTB.7
    4) PAUSE 1000

    5) LOW PORTB.7
    6) LOW PORTB.6
    7) pause 1000
    8) GOTO LOOP

    I've not tested this, but logic states that PORTB.6 goes high, waits a second, then PORTB.7 will go high, waits a second then both PORTB.6 & 7 goes low, waits a second then loops round.

    It will prove the the program is actually turning on and off the ports, and then you can play with the timing to get the desired effect you're after. As Paul stated, unless you have really keen eyesight, 1ms is very hard to see. Blink and you'll miss it

  5. #5
    Join Date
    Oct 2004
    Location
    Hangover, Germany
    Posts
    289


    Did you find this post helpful? Yes | No

    Default

    What is connected to PortB.6 ?
    Maybe you struggled into the read-modify-write-trouble...
    PBP 2.50C, MCS+ 3.0.0.5, MPLAB 8, MPASM 5.14, ASIX Presto, PoScope, mE mikroBasic V7.2, PICKIT2

  6. #6
    Join Date
    Jan 2006
    Location
    New Hampshire, USA
    Posts
    107


    Did you find this post helpful? Yes | No

    Default

    Portb.6 connects to a 1K resistor and NPN base. My original post was a logical error, the basic problem that I was trying to solve, was that portb.6 was not producing an output sometimes. It turned out that the 5 volt supply was sagging after 4 seconds causing brownout reset. I was confused by the program running so long before failing.

Similar Threads

  1. Presetting Configuration Fuses (PIC Defines) into your Program
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 82
    Last Post: - 15th December 2013, 09:54
  2. Replies: 1
    Last Post: - 23rd May 2009, 09:22
  3. Compile and Program help using PICKit2
    By ozarkshermit in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 10th March 2009, 14:51
  4. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  5. PIC16F684 Program question
    By Nicholas in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 28th December 2006, 14:30

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