WRITE prob during power cycle 18f6722


Results 1 to 11 of 11

Threaded View

  1. #10
    Join Date
    Mar 2009
    Location
    Colorado
    Posts
    378


    Did you find this post helpful? Yes | No

    Default PBP to use the HLVD but one statement doesn't execute??

    Quote Originally Posted by jason View Post
    this is to be fabricated by the hundreds, price is an issue.

    What about the onboard "HLVD"

    But then again its all in ASM. It talks about these steps

    1. Write the value to the HLVDL3:HLVDL0 bits that
    selects the desired HLVD trip point.
    2. Set the VDIRMAG bit to detect high voltage
    (VDIRMAG = 1) or low voltage (VDIRMAG = 0).
    3. Enable the HLVD module by setting the
    HLVDEN bit.
    4. Clear the HLVD interrupt flag (PIR2<2>), which
    may have been set from a previous interrupt.
    5. Enable the HLVD interrupt if interrupts are
    desired by setting the HLVDIE and GIE bits
    (PIE2<2> and INTCON<7>). An interrupt will not
    be generated until the IRVST bit is set.

    How do I write these values that it needs. Can I do it in PicBasic pro?
    I have been working with the onboard HLVD module in a 18F4550 to use it as a low voltage monitor for my application. I am posting my current PBP code below that is suppose to do steps 1-5 you list above that are called out in the Data Sheet. I am prettry sure this is the right code, but it wasn't working, so I ran an ICD on it and discovered that when it gets to this procedure which is located in my main program loop, the first HLVDCON statement executes to clear HLVDCON.4, however the next statement (HLVDCON = %00011101) which is suppose to perform steps 1-3 in your above listing, doesn't execute....nor do any of the remaining statements in this process block execute...instead the program always jumps to an Interrupt Service Routine that is suppose to service a DT_INTS-18 interrupt triggered by a real-time clock. However the RTC interrupt isn't timed to happen when this happens. I can't figure out why this this HLVDCON statement is not executing and the rest of this block is not executing in the main loop before the interrupt happens.

    Can anyone advise me what is happening here and how to fix it??

    Code:
    ' Test for low battery conditon
            ' Set registers for using HLVD feature
                HLVDCON.4 = 0   'Disable the module by clearing HLVDCON.4
                ' Set the trip point at Vdd=4.4 vdc by setting HLVD3:HLVDL0=1101
                ' Set VDIRMAG=0 (HLVDCON.7) to detect low voltage transition
                ' Enable the HLVD module (HLVDCON.4=1)
                  HLVDCON = %00011101
                ' Clear the HLVDIF interrupt flage (PIR2<2>)
                  PIR2.2 = 0 
                ' Enable the HLVD interrupt
                  PIE2.2 = 1
                  INTCON.7 = 1
                ' Set IRVST bit (HLVDCON.5 =1) to allow interrupt generation
                  HLVDCON.5 =1
            If PIR2.2 =1 THEN ' Test for HLVD interrupt (HLVDIF bit = 1)
               For I = 0 TO 4 ' Blink the RED LED 5X as low battery warning
                   High LED_RED   
                   Pause 500
                   LOW LED_RED
                   pause 500
               next
            ENDIF
    Last edited by jellis00; - 22nd May 2010 at 03:33. Reason: Code correction

Similar Threads

  1. WRITE: One more PBP 2.60 Surprise ...
    By Acetronics2 in forum mel PIC BASIC Pro
    Replies: 22
    Last Post: - 26th August 2009, 09:10
  2. Battery powered applications
    By NavMicroSystems in forum Off Topic
    Replies: 7
    Last Post: - 22nd June 2009, 07:12
  3. Need the code to write to a memory
    By Hamlet in forum General
    Replies: 0
    Last Post: - 20th August 2007, 00:22
  4. Changing declared variables names on the fly
    By jessey in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 16th December 2006, 06:34
  5. Storing Strings using the Write command
    By BobP in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 1st November 2005, 11:31

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