PIC16F84A using pulsout and TMR0


Results 1 to 33 of 33

Threaded View

  1. #13
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default

    Hi,
    Basicly you can have as many interrupts sources as the PIC has (TMR0, TMR1, USART, RB0, RBChange, CMP, ADC, whatever.....). When the program interrupts and starts executing the ISR (InterruptServiceRoutine) you need to check what caused the interrupt and act uppon it accordingly.

    My approach to this would be to use an external 32.768kHz xtal, set the TMR of your choise up to generate an interrupt at 100Hz, then in the ISR count those ticks. When you have 100 ticks you have a second. When you have 216 ticks, toggle your step pin.

    Code:
    Ticks var byte             '1/100th seconds
    StepTicks Var Byte      '1/100th seconds, used for step pulse timing
    Seconds var Byte        'Seconds
    Minutes Var Byte         'Minutes
    Hours var Byte            'Hours
    Days var Byte             'Days, perhaps change this to a Word.
    
    Goto Main                  'Jump over ISR.
    
    DISABLE
    
    ISR:
    'Reload timer with correct value here, and restart it.
    
    Ticks = Ticks + 1
    If Ticks = 100 then
      Ticks = 0
      Seconds = Seconds + 1
        If Seconds = 60 then
          Seconds = 0  
            Minutes = Minutes + 1
            If Minutes = 60 then
              Minutes = 0
              Hours = Hours + 1
                If Hours = 24 Then
                  Hours = 0
                  Days = Days + 1
                Endif
            Endif
         Endif
    Endif
    
    StepTicks = StepTicks + 1
    If StepTicks = 216 then        '2.16s, time to toggle the step pin.
      StepTicks = 0
      Toggle StepPin
    Endif
    
    RESUME
    ENABLE
    
    Main:
    
    '---------------------------------------------
    'Your main code here.......
    'remember, NO time consuming commands, like Pause, sleep, nap etc.
    '----------------------------------------------
    Goto Main
    This is completely untested and just something to show you one approach. Also, I suggest you'll have a look at Darrel Taylors Instant Interrupts, search the forum, it makes interrupts a breeze but MAY be overkill in this application.

    About that LCD, if your connections ARE fine and matches your DEFINES then the only thing I can think of is a longer pause at the beginning OR you could try to increase the command and data delay with:
    Code:
    DEFINE LCD_COMMANDUS 2000    '<-----Increase this...
    DEFINE LCD_DATAUS 50             '<----and this.
    /Henrik Olsson.
    Last edited by HenrikOlsson; - 5th December 2006 at 06:42. Reason: Moved ISR to beginning.

Similar Threads

  1. Pin won't stay high during Repeat...Until loop??
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 16th August 2009, 23:57
  2. Won't go back to SLEEP after 1st Interrupt
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 29th June 2009, 09:00
  3. Battery powered applications
    By NavMicroSystems in forum Off Topic
    Replies: 7
    Last Post: - 22nd June 2009, 07:12
  4. COUNT is not counting again
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 33
    Last Post: - 19th June 2009, 04:52
  5. Can't ID interrupt source with this IntHandler??
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 3rd June 2009, 02:35

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