interrupt handling faster than if's?


Results 1 to 14 of 14

Threaded View

  1. #3
    Join Date
    Feb 2003
    Posts
    432


    Did you find this post helpful? Yes | No

    Default

    How are the PICs connected together ? by a wire or by radio/IR link

    Do you really need the PRE and SYNCH values to be sent ?

    If there is only ever going to be the actual values sent between the PICs then just send the actual values and constantly loop the receiver program like this

    Code:
    Main:
    hserin 20,Main [Msg]
    
    Select Case Msg
       Case "1"
              high PORTA.0
       Case "2"
              low PORTA.0
       Case "3"
              high PORTA.1
       Case "4"
              low PORTA.1
       Case "5"
              high PORTA.2
       Case "6"
              low PORTA.2
       Case "7"
              high PORTA.3
       Case "8"
              low PORTA.3
    end select
    goto main
    When no data is being received your program will sit at the Hserin command and return to Main every 20mS if nothing is recevied. Because you are constantly waiting for the Msg the reponse will be instant and because you are only sending one character there should be no possibility of overflow unless three messages are sent in very quick succession but even then it should process them fast enough.

    You can then reduce the pause in your transmit program to get a very fast response. Currently you have 200*8 mS of pause in the transmit program so it will take a minimum of 1.6 seconds to complete one loop.

    You could also speed up the send program by changing

    Code:
    if (PORTA.0 = 0) AND (sone = 0) then
        hserout [Pre,Synch,"1"]
        sone = 1
        pause 200
    endif
    if (PORTA.0 = 1) AND (sone = 1) then
        hserout [Pre,Synch,"2"] 
        sone = 0
        pause 200
    endif
    to
    Code:
    if (PORTA.0 = sone) then           '  input state has changed
      if  PORTA.0 = 0 then               '  port has gone low
            hserout ["1"]                    '  send the command
            sone = 1                         ' record the state
      else
            hserout ["2"]                    ' port has gone high so send the command
            sone = 0                         ' record the state
      end if
      pause 10                     ' may not even need a pause
    endif
    That way with no switches being changed you only perform 4 tests each program loop and if a switch has changed you perform an additional test. Can probably be optimised further but brain is not fully functional yet... need more coffee

    Out of curiosity, why are you storing values opposite to the current state of the pin ?

    Personally I would store the current value and detect when it was different. eg

    Code:
    if (PORTA.0<>sone) then      ' state has changed
           sone = PORTA.0           ' store new state
           { do all the other stuff }
    endif
    Last edited by keithdoxey; - 21st October 2006 at 11:12.
    Keith

    www.diyha.co.uk
    www.kat5.tv

Similar Threads

  1. 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
  2. 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
  3. Help with Analog Interrupt
    By brid0030 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 13th February 2008, 18:14
  4. NEWBIE: Some basic questions using interrupts
    By JackPollack in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 8th March 2006, 02:59
  5. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 01:07

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