Timing issue


Closed Thread
Results 1 to 10 of 10

Thread: Timing issue

Hybrid View

  1. #1
    Join Date
    Aug 2008
    Location
    Portugal
    Posts
    240

    Default Timing issue

    Hi everyone;

    I'm facing a problem with the code below. IT works everything fine, except the timing. It takes always the double of the time in the "pause" instructuion. For instance, if i put PAUSE 5000, it takes 10s to execute.
    The micro is 12F683 and is powered by a CR2032 battery.

    Can some one help me? Thanks!!!

    Code:
    @ __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _BOD_OFF & _CPD_OFF & _CP_OFF & _FCMEN_OFF & _IESO_OFF  
     DEFINE OSC 4
              '76543210
     OSCCON = %01100111  
     
     '===================SRF AND PINOUT CONFIGURATION - 1-In / 0-Out=================
              '76543210
     TRISIO = %00000001
       GPIO = %00000000       
        IOC = %00000001
        WPU = %00000001   
     INTCON = %00001000
     CMCON0 = 7              
      VRCON = 0   
      ANSEL = %00000000
      OPTION_REG.7=0
    '==================================ALIAS========================================
     BOTAO   VAR GPIO.0
     VAZIO1  VAR GPIO.1
     VAZIO2  VAR GPIO.2
     VAZIO3  VAR GPIO.3
     VAZIO4  VAR GPIO.4
     LED     vAR GPIO.5
    '================================MAIN LOOP======================================
    Main:
    @ SLEEP
     INTCON.0 = 0
     High led
     Pause 5000
     low led 
    GOTO Main
    END
    Thanks and Regards;
    Gadelhas

  2. #2
    Join Date
    Aug 2008
    Location
    Portugal
    Posts
    240


    Did you find this post helpful? Yes | No

    Default Re: Timing issue

    HI again;

    One more thing that i notice is that when i power the circuit for the first time, it always turn on the led, however, the first instruction is "sleep", but it is not executed, but only when i power the circuit, after that it works fine, like it should work!
    Thanks and Regards;
    Gadelhas

  3. #3
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default Re: Timing issue

    You should confirm that the device is really running at 4Mhz. Perhaps it is running at 2. You often have to set up the OSCCON register. Check the datasheet.
    Also, the interrupt is triggered right away beause you have not cleared the interrupt flag BEFORE enabling the interrupt (usually PIR.x, but again, check your device).
    Charles Linquist

  4. #4
    Join Date
    Aug 2008
    Location
    Portugal
    Posts
    240


    Did you find this post helpful? Yes | No

    Default Re: Timing issue

    Quote Originally Posted by Charles Linquis View Post
    You should confirm that the device is really running at 4Mhz. Perhaps it is running at 2. You often have to set up the OSCCON register. Check the datasheet.
    Also, the interrupt is triggered right away beause you have not cleared the interrupt flag BEFORE enabling the interrupt (usually PIR.x, but again, check your device).
    Hi Charles;

    First of all, thanks for your answer.

    If you look at my code, you can see that the OSCCON is configured correctly. I allready found the time issue. The pic was actually running at 4Mhz, however the main code was executed 2 times. To resolve this problem, i change this code:

    Code:
    Main:
      @ SLEEP
      INTCON.0 = 0
      High led
      Pause 5000
      low led 
      GOTO Main
    With this, just changed one line;

    Code:
    Main:
      @ SLEEP
      High led
      Pause 5000
      low led 
      INTCON.0 = 0
    GOTO Main
    Now the main code is only executed one time and them goes to sleep.

    However, on power up the led still turns on, but it shoul not, because the first instruction is sleep. I follow your advice of clearing the interrupt flag before, however the behavior is the same.
    I'm still try to figure it out. If someone has any idea please let me know.

    Thanks
    Thanks and Regards;
    Gadelhas

  5. #5
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: Timing issue

    It should not make a difference, but it might... Bits 0 - 3 in the OSCCON are status bits. Try setting OSCCON = %01100000

    You have the LED pin TRISed correctly in the setup but you did not make it LOW in the setup.
    TRIS sets direction, the state should also be set.
    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    Aug 2008
    Location
    Portugal
    Posts
    240


    Did you find this post helpful? Yes | No

    Default Re: Timing issue

    Quote Originally Posted by mackrackit View Post
    It should not make a difference, but it might... Bits 0 - 3 in the OSCCON are status bits. Try setting OSCCON = 100000

    You have the LED pin TRISed correctly in the setup but you did not make it LOW in the setup.
    TRIS sets direction, the state should also be set.
    Already tried to put the OSCCON like you said. It is the same thing. like you said, they are status bits.

    You can see on my code, after the TRIS instruction, that i put all the GPIO low, with:

    Code:
              '76543210
    TRISIO = %00000001
       GPIO = %00000000
    Thanks and Regards;
    Gadelhas

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