PIC16F877A PAUSE command


Closed Thread
Results 1 to 10 of 10
  1. #1
    Join Date
    Dec 2006
    Posts
    9

    Question PIC16F877A PAUSE command

    Hi,

    Am having trouble with the "PAUSE" command in my code. Am not sure what additional registers need to be set to enable this command. When I remove the ,PAUSE, before the goto Lowvoltagecheck the LED lights up and stays on (whether LowVoltage is 1 or 0). If I keep the pause on the program the LED never goes ON. The LED should flash or stay on for 5 seconds but stays on indefinitely meaning my PAUSES are not working.

    What more is needed?

    ;************************************************* *******
    CMCON = %00000111 'Port A all digital
    CVRCON = %00000000 'CVref turned off
    OPTION_REG = %10000111

    Main:

    low HoldTxON ; Initialize by clearing all the outputs
    low LED
    Low MotorControl_1
    LOW MotorControl_2

    pause 5000
    goto Lowvoltagecheck

    end
    ;************************************************* ******************************
    ; Subroutine to check for battery voltage at the beginning and end of
    ; transmission flashing to signify low voltage or high voltage

    LowVoltageCheck:
    If lowVoltage = 1 then ; If the battery voltage is OK
    high led ; turn on the LED for 5 seconds
    pause 5000
    LOw LEd
    else
    for loop = 1 to 10 ; If the battery voltage is low
    high led ; Flash the LED 10 times
    Pause 500 ; at a rate discernable from the
    low led ; transmit LED flash rate
    next
    endif
    return
    ;************************************************* *******

    Thanks,
    Nicholas.

  2. #2
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    You're using GOTO with RETURN in the sub-routine. Try this version;
    Code:
    ;************************************************* *******
    CMCON = %00000111 'Port A all digital
    CVRCON = %00000000 'CVref turned off
    OPTION_REG = %10000111
    
    Main:
    
    low HoldTxON ; Initialize by clearing all the outputs
    low LED
    Low MotorControl_1
    LOW MotorControl_2
    
    pause 5000
    gosub Lowvoltagecheck
    goto Main
    
    end
    ;************************************************* ******************************
    ; Subroutine to check for battery voltage at the beginning and end of
    ; transmission flashing to signify low voltage or high voltage
    
    LowVoltageCheck:
    If lowVoltage = 1 then ; If the battery voltage is OK
    high led ; turn on the LED for 5 seconds
    pause 5000
    LOw LEd
    else
    for loop = 1 to 10 ; If the battery voltage is low
    high led ; Flash the LED 10 times
    Pause 500 ; at a rate discernable from the 
    low led ; transmit LED flash rate
    next
    endif
    return
    ;************************************************* *******
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  3. #3
    Join Date
    Dec 2006
    Posts
    9


    Did you find this post helpful? Yes | No

    Default PIC16F877A PAUSE command

    Bruce thanks for your prompt reply and advice.
    However, that didn't seem to fix the issue. I think I should mention this is a small part of a bigger program but this is the code am using to test this part. Am actually going to be using a PIC16F627A but am using the 16F877A to test the logic of the code. (Am using a LabX1 programmer and its the only 40pin I have). Haven't successfully been able to jumper the board to program an 18pin.

  4. #4
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Hi Nicholas,

    Can you post all of your code? It helps to know which pins you have defined,
    and how you have things configured.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  5. #5
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    i agree to see the whole thing.

    I find something strange here...
    Code:
    for loop = 1 to 10 ; If the battery voltage is low
    high led ; Flash the LED 10 times
    Pause 500 ; at a rate discernable from the
    low led ; transmit LED flash rate
    next
    There's something missing... a simple pause after the Low LED.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  6. #6
    Join Date
    Dec 2006
    Posts
    9


    Did you find this post helpful? Yes | No

    Default Code

    Here's the whole Code, I tried to use NAP in place of PAUSE and the LED stays on for the alloted time but the blink part does not work. I've also attached a variant to the blink part which also failed to blink the LED.

    ;************************************************* ********

    ; Define statements.
    define NO_CLRWDT 1 ;Don't insert CLRWDTs
    define OSC 20 ;every MPU used is 20mhz

    'Port operation configurations
    CMCON0 = %00000111 'Port A all digital
    VRCON = %00000000 'CVref turned off
    OPTION_REG = %10000111 'Disable PORTA pullups, set TMR0 scaler to 1:256

    ; Program Variables
    Loop VAR BYTE ;general loop counter for LED flashing

    Outp CON 0
    Inp CON 1

    'Assign Ports to simple name
    LowVoltage VAR PortA.0 'Battery low voltage detection port
    ReedSwitchState var PORTA.1 'Reed Switch ON and OFF state line
    LED VAR PORTA.2 'Turn LED ON and OFF
    HoldTxON VAR PORTC.0 'Hold Tx ON when water contacts activated
    Tx_Data VAR PORTC.1 'Transmit Data Line
    Tx1_Enable VAR PORTC.2 'Transmit 121.5Mhz Line
    Tx2_Enable VAR PORTC.3 'Tranmit 156MHz Line
    MotorControl_1 VAR PORTC.4 'Activate Release Mechanism
    MotorControl_2 VAR PORTC.5 'Activate Latch Mechanism

    'Initialize port states
    TrisA.0=Inp 'set batt low voltage detection to input
    TrisA.1=Inp 'set Reed switch state to input
    TrisA.2=Outp 'set led transmission to output
    TrisC.0=Outp 'set Hold Tx Line ON to output
    TrisC.1=Outp 'set Transmit data line to output
    TrisC.2=Outp 'set Transmit @121.5 to output
    TrisC.3=Outp 'set Transmit @156 to output
    TrisC.4=Outp 'set Motorcontrol_1 to output
    TrisC.5=Outp 'set Motorcontrol_2 to output

    'Goto Main
    ;************************************************* ******************************
    Main:

    low HoldTxON ; Initialize by clearing all the outputs
    low LED
    low Tx_Data
    Low Tx1_Enable
    low Tx2_Enable
    Low MotorControl_1
    LOW MotorControl_2

    GOSUB Lowvoltagecheck

    end
    ;************************************************* ******************************
    ; Subroutine to check for battery voltage at the beginning and end of
    ; transmission flashing to signify low voltage or high voltage

    LowVoltageCheck:

    If lowVoltage = 1 then ; If the battery voltage is OK
    high led ; turn on the LED for 5 seconds
    pause 5000
    LOw LEd
    else
    for loop = 1 to 10 ; If the battery voltage is low
    high led ; Flash the LED 10 times
    Pause 500 ; at a rate discernable from the
    low led ; transmit LED flash rate
    next
    endif
    return
    ;************************************************* ********


    PS: This is the code I used to try and break up the subroutine further for testing but failed to work also.

    ;************************************************* ******************************
    ; Subroutine to check for battery voltage at the beginning and end of
    ; transmission flashing to signify low voltage or high voltage

    LowVoltageCheck:
    If lowVoltage = 1 then GoodBattery
    if lowvoltage = 0 then LowBattery

    LowBattery:
    for loop = 1 to 10 ; If the battery voltage is low
    gosub Blink
    next loop

    Blink:
    high led ; Flash the LED 10 times
    pause 500 ; at a rate discernable from the
    low led ; transmit LED flash rate
    return

    GoodBattery: ; If the battery voltage is OK
    high led ; turn on the LED for 5 seconds
    pause 5000
    LOw LEd
    return
    ;************************************************* ********

  7. #7
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Nicholas
    Here's the whole Code, I tried to use NAP in place of PAUSE and the LED stays on for the alloted time but the blink part does not work. I've also attached a variant to the blink part which also failed to blink the LED.

    ;************************************************* ********

    ; Define statements.
    define NO_CLRWDT 1 ;Don't insert CLRWDTs
    define OSC 20 ;every MPU used is 20mhz

    'Port operation configurations
    CMCON0 = %00000111 'Port A all digital
    VRCON = %00000000 'CVref turned off
    OPTION_REG = %10000111 'Disable PORTA pullups, set TMR0 scaler to 1:256

    ; Program Variables
    Loop VAR BYTE ;general loop counter for LED flashing

    Outp CON 0
    Inp CON 1

    'Assign Ports to simple name
    LowVoltage VAR PortA.0 'Battery low voltage detection port
    ReedSwitchState var PORTA.1 'Reed Switch ON and OFF state line
    LED VAR PORTA.2 'Turn LED ON and OFF
    HoldTxON VAR PORTC.0 'Hold Tx ON when water contacts activated
    Tx_Data VAR PORTC.1 'Transmit Data Line
    Tx1_Enable VAR PORTC.2 'Transmit 121.5Mhz Line
    Tx2_Enable VAR PORTC.3 'Tranmit 156MHz Line
    MotorControl_1 VAR PORTC.4 'Activate Release Mechanism
    MotorControl_2 VAR PORTC.5 'Activate Latch Mechanism

    'Initialize port states
    TrisA.0=Inp 'set batt low voltage detection to input
    TrisA.1=Inp 'set Reed switch state to input
    TrisA.2=Outp 'set led transmission to output
    TrisC.0=Outp 'set Hold Tx Line ON to output
    TrisC.1=Outp 'set Transmit data line to output
    TrisC.2=Outp 'set Transmit @121.5 to output
    TrisC.3=Outp 'set Transmit @156 to output
    TrisC.4=Outp 'set Motorcontrol_1 to output
    TrisC.5=Outp 'set Motorcontrol_2 to output

    'Goto Main
    ;************************************************* ******************************
    Main:

    low HoldTxON ; Initialize by clearing all the outputs
    low LED
    low Tx_Data
    Low Tx1_Enable
    low Tx2_Enable
    Low MotorControl_1
    LOW MotorControl_2

    GOSUB Lowvoltagecheck

    end
    ;************************************************* ******************************
    ; Subroutine to check for battery voltage at the beginning and end of
    ; transmission flashing to signify low voltage or high voltage

    LowVoltageCheck:

    If lowVoltage = 1 then ; If the battery voltage is OK
    high led ; turn on the LED for 5 seconds
    pause 5000
    LOw LEd
    else
    for loop = 1 to 10 ; If the battery voltage is low
    high led ; Flash the LED 10 times
    Pause 500 ; at a rate discernable from the
    low led ; transmit LED flash rate
    next
    endif
    return
    ;************************************************* ********


    PS: This is the code I used to try and break up the subroutine further for testing but failed to work also.

    ;************************************************* ******************************
    ; Subroutine to check for battery voltage at the beginning and end of
    ; transmission flashing to signify low voltage or high voltage

    LowVoltageCheck:
    If lowVoltage = 1 then GoodBattery
    if lowvoltage = 0 then LowBattery

    LowBattery:
    for loop = 1 to 10 ; If the battery voltage is low
    gosub Blink
    next loop

    Blink:
    high led ; Flash the LED 10 times
    pause 500 ; at a rate discernable from the
    low led ; transmit LED flash rate
    return

    GoodBattery: ; If the battery voltage is OK
    high led ; turn on the LED for 5 seconds
    pause 5000
    LOw LEd
    return
    ;************************************************* ********

    Don't you need another RETURN after the LOWBATTERY blinks?
    JDG

  8. #8
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    I've inserted comments where I added a few things. Let us know if this
    version works.
    Code:
    ;************************************************* ********
    
    ; Define statements.
    ' Now you know for sure what these are set for
    @ device  pic16F877A, hs_osc, wdt_off, lvp_off, protect_off
    
    ' Potential problem below unless you're disabling WDT in config fuse
    ' (like above) you do not want to use this define. PBP needs to insert
    ' CLRWDT commands throughout your code to make sure the WDT does
    ' not cause a device reset
    define NO_CLRWDT 1 ;Don't insert CLRWDTs
    
    define OSC 20 ;every MPU used is 20mhz
    
    'Port operation configurations
    CMCON0 = %00000111 'Port A all digital
    VRCON = %00000000 'CVref turned off
    
    ' Added this to disable A/D. Now you can use ports A/E for digital I/O
    ADCON1 = 7
    
    OPTION_REG = %10000111 'Disable PORTA pullups, set TMR0 scaler to 1:256
    
    ; Program Variables
    Loop VAR BYTE ;general loop counter for LED flashing
    
    Outp CON 0
    Inp CON 1
    
    'Assign Ports to simple name
    LowVoltage VAR PortA.0 'Battery low voltage detection port
    ReedSwitchState var PORTA.1 'Reed Switch ON and OFF state line
    LED VAR PORTA.2 'Turn LED ON and OFF
    HoldTxON VAR PORTC.0 'Hold Tx ON when water contacts activated
    Tx_Data VAR PORTC.1 'Transmit Data Line
    Tx1_Enable VAR PORTC.2 'Transmit 121.5Mhz Line
    Tx2_Enable VAR PORTC.3 'Tranmit 156MHz Line
    MotorControl_1 VAR PORTC.4 'Activate Release Mechanism
    MotorControl_2 VAR PORTC.5 'Activate Latch Mechanism
    
    'Initialize port states
    TrisA.0=Inp 'set batt low voltage detection to input
    TrisA.1=Inp 'set Reed switch state to input
    TrisA.2=Outp 'set led transmission to output
    TrisC.0=Outp 'set Hold Tx Line ON to output
    TrisC.1=Outp 'set Transmit data line to output
    TrisC.2=Outp 'set Transmit @121.5 to output
    TrisC.3=Outp 'set Transmit @156 to output
    TrisC.4=Outp 'set Motorcontrol_1 to output
    TrisC.5=Outp 'set Motorcontrol_2 to output
    
    'Goto Main
    ;************************************************* ******************************
    Main:
    
        low HoldTxON ; Initialize by clearing all the outputs
        low LED
        low Tx_Data
        Low Tx1_Enable
        low Tx2_Enable
        Low MotorControl_1
        LOW MotorControl_2 
        
        GOSUB Lowvoltagecheck ' <-- problem area here. When program flow returns
                              ' from Lowvoltagecheck, it lands on END and the PIC
                              ' enters a continuous sleep loop
        GOTO Main             ' <-- this fixes the problem
    
        end
    ;************************************************* ******************************
    ; Subroutine to check for battery voltage at the beginning and end of
    ; transmission flashing to signify low voltage or high voltage
    
    LowVoltageCheck:
        If lowVoltage = 1 then ; If the battery voltage is OK
          high led ; turn on the LED for 5 seconds
          pause 5000
          LOw LEd
        else
          for loop = 1 to 10 ; If the battery voltage is low
            high led ; Flash the LED 10 times
            Pause 500 ; at a rate discernable from the 
            low led ; transmit LED flash rate
            PAUSE 500  ' <-- added this pause so you can see the LED blink
          next
        endif
        return
    If this "doesn't" work, make sure you have a pull-up on /MCLR to Vcc, at least
    a 0.1uF cap between PIC Vcc/GND pins, and a clean/stable power supply.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  9. #9
    Join Date
    Dec 2006
    Posts
    9


    Did you find this post helpful? Yes | No

    Thumbs up Success!

    I finally got it to work through two changes. First I had to remove the CLRWDT define term and I was able to get the LED to blink accordingly. I also had to add the Analog Select Command (ANSEL) to set some of my pins to make the whole program work. Although am not quite clear how that affected my program, the ANSEL changes seemed to make it work.
    Thanks for all your assistance.
    Nicholas.

  10. #10
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Nicholas
    I finally got it to work through two changes. First I had to remove the CLRWDT define term and I was able to get the LED to blink accordingly. I also had to add the Analog Select Command (ANSEL) to set some of my pins to make the whole program work. Although am not quite clear how that affected my program, the ANSEL changes seemed to make it work.
    Thanks for all your assistance.
    Nicholas.


    The CLRWDT has tripped me up on a few projects myself, and this was with the WDT disabled, not running, and otherwise not a factor... Somehow it seemed to have something to do with PBP's timing underneath somewhere, don't know where, don't really care. All I know is, if I'm having an under-fixable problem, either adding or removing the CLRWDT define is one of my personal 'troubleshooting' steps.
    JDG

Similar Threads

  1. Delayed output 10 secs
    By lilimike in forum mel PIC BASIC Pro
    Replies: 37
    Last Post: - 14th October 2011, 06:28
  2. Old and beyond help ?
    By DavidFMarks in forum mel PIC BASIC Pro
    Replies: 46
    Last Post: - 11th December 2008, 15:23
  3. Replies: 11
    Last Post: - 12th July 2008, 02:36
  4. Fade out LEDs question
    By Sam in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 22nd June 2008, 10:50
  5. Help Quick Need to make code smaller
    By Programmednew in forum mel PIC BASIC Pro
    Replies: 41
    Last Post: - 25th January 2005, 03:46

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