Instant Interrupts - Revisited


Closed Thread
Results 1 to 40 of 773

Hybrid View

  1. #1
    Join Date
    Nov 2007
    Location
    West Covina, CA
    Posts
    219


    Did you find this post helpful? Yes | No

    Default Disturbance in the force

    Hi everyone,
    I think I'm getting very close to understanding DT's interrupt routine but need some direction.
    I'm using a PIC16F688 to make myself a test fixture to test some product but pretty sure I did something wrong in the setups.
    Using this small test program and a scope to monitor an output, I see the "Toggling" led stop during the interrupt routine. This only happens when PAUSE, FOR/NEXT and PAUSEUS is used in the main.
    Ultimately, I will need to send serial data using SEROUT2 continueously in the background so I can do other chores in the foreground that will use TMR1, A/D and some simple LED indications.

    Code:
    '*************************************************************************
    '*  Name    : Test fixture.BAS                                 
    '*  Author  : Louis Chagoya                                     
    '*  Notice  : Copyright (c) 2008 Link M Technologies            
    '*          : All Rights Reserved                               
    '*  Date    : 8/24/2009                                       
    '*  Version : 1.1                                         
    '*  Notes   : This system uses the PIC16F688 to learn DT's Interrupt system
    '*  while utilizing other signalling functions at the same time.
    '*************************************************************************
    '/////////////////////////////////////////////////////////////////////////
    '                       Configs
    '/////////////////////////////////////////////////////////////////////////
    @ __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _CP_OFF
    OSCCON = %01100001      ' Oscillator set to 4MHz, bits 6-4
    CMCON0 = 7		        ' Analog comparators off
    ADCON0 = %10010000      ' A/D right justified, Vref=VDD, AN2 selected
    ADCON1 = %01010000      ' A/D conversion CLK/16
    ANSEL = %00000100       ' AN2 set to analog input rest digital
    TRISA = %00101101       ' Set ports 0,2,3 and 5 as inputs, rest outputs
    TRISC = %00000000       ' Set all pins as outputs
    
    'DEFINE OSC 8           ' Define OSC to 8Mhz for PAUSE setting
    DEFINE ADC_BITS 10     ' ADCIN resolution  (Bits)
    DEFINE ADC_CLOCK 5     ' ADC clock source  (Fosc/16)
    DEFINE ADC_SAMPLEUS 7  ' ADC sampling time (uSec)
    DEFINE SER2_BITS 8     ' Set up baud rate for 7812bps
    
    '/////////////////////////////////////////////////////////////////////////
    '                        Pin I/O naming
    '/////////////////////////////////////////////////////////////////////////
    Data_In VAR PORTA.0     ' Pin 13 Data from UUT
    Data_Out VAR PORTA.1    ' Pin 12 Data to UUT
    '        VAR PORTA.2    ' Pin 11 GPS input from UUT
    Test VAR PORTA.3        ' Pin 4 Push button to begin test
    Bypass VAR PORTA.4      ' Pin 3 Puts UUT into Bypass or Active mode
    Byp_Sel VAR PORTA.5     ' Pin 2 Select type switch input
    BCDval var PORTC        ' All of PortC declared as variable
    Ready VAR PORTC.0       ' Pin 10 READY LED
    Byp_Pass VAR PORTC.1    ' PIn 9 BYPASS test PASS LED - Green
    Byp_Fail VAR PORTC.2    ' PIn 8 BYPASS test FAIL LED - Red
    Act_Pass VAR PORTC.3    ' PIn 7 ACTIVE test PASS LED - Green
    Act_Fail VAR PORTC.4    ' PIn 6 ACTIVE test FAIL LED - Red
    Pwr_ON VAR PORTC.5      ' PIn 5 Provides power to UUT
    
    
    '/////////////////////////////////////////////////////////////////////////
    '                        Variable declarations
    '/////////////////////////////////////////////////////////////////////////  
    i VAR BYTE              ' Increment counter when needed
    cksm VAR BYTE           ' Checksum variable
    
    
    '/////////////////////////////////////////////////////////////////////////
    '                       DT's Interrupt Routine
    '/////////////////////////////////////////////////////////////////////////
    INCLUDE "DT_INTS-14.bas"     ' Base Interrupt System
    INCLUDE "ReEnterPBP.bas"     ' Include if using PBP interrupts
    
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler   TMR0_INT,    _Gen_Data,   PBP,  YES
        endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
    
    '.....Various OPT_Reg tries....
    
    'OPTION_REG.3 = 1             ' Prescaler is assigned to the WDT
    'OPTION_REG.2 = 1             ' N/G, even with WDT ON
    'OPTION_REG.1 = 1
    'OPTION_REG.0 = 1             ; REGISTER 5-1: Prescaler = 1:1 via WDT rate
    
    OPTION_REG = 7               ' Times out in 65.2ms. Will need 100ms when
                                 ' get it to work
    @ INT_ENABLE  TMR0_INT       ; enable Timer 0 interrupts
    
    cksm = 85
    
    '/////////////////////////////////////////////////////////////////////////
    '                           Main Program
    '/////////////////////////////////////////////////////////////////////////
    start:     
         
         TOGGLE act_fail    ' Use this output to monitor routine
         PAUSE 1
         TOGGLE act_fail
         PAUSE 1
           
    GOTO start
    
    '---[TMR0 - interrupt handler]--------------------------------------------
    
    Gen_Data:
    
        SEROUT2 Data_out, 108, [cksm]   ' Serial out cksm value at 7812bps
        PAUSEUS 3720                    ' Total time= 5ms
    
    @ INT_RETURN
    
    
    END
    My understanding is that main program should not be disturbed by the interrupt routine if done properly. In this case, I'm hoping I'm not being proper rather than using the wrong PIC for my app.

    Thank for your help...
    Louie

  2. #2


    Did you find this post helpful? Yes | No

    Default 16f688

    Louie,

    There are a couple of things I found while using Instant Ints. that may be worth looking at.
    I am not an expert on them, I have found out what works for me by trial and error, and error and error as with all things Pic. But when you find the solution they work great!

    When entering the interrupt, I stop additional interrupts from being serviced or re-serviced until I am ready to release control again.

    INTCON needs to be set, looking at bits 7,6,5 and 2 page 15 and 45-47 of the data sheet.

    Code:
    INTCON = %111xx1xx      ' with x set for other functions and the 1's are a guess for your application
    Code suggestion
    Code:
    '---[TMR0 - interrupt handler]--------------------------------------------
    
    Gen_Data:
    @ INT_DISABLE TMR0_INT
        SEROUT2 Data_out, 108, [cksm]   ' Serial out cksm value at 7812bps
        PAUSEUS 3720                    ' Total time= 5ms
    
    @ INT_CLEAR TMR0_INT
    @ INT_ENABLE TMR0_INT
    @ INT_RETURN
    
    
    END
    Kevin

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Kevin,

    You should NOT set INTCON, PIEx, PIRx, IPRx or any other interrupt related registers manually. DT_INTS handles all of those bits for you.

    There is NO reason to INT_DISABLE / INT_ENABLE inside of an interrupt handler. Interrupts are automatically disabled by the hardware during an interrupt event, and can not cause another interrupt until the current one is finished. You are confusing things with ON INTERRUPT which must have DISABLE/ENABLE wrapped around them.

    Louie,

    When an interrupt occurs, the main program STOPS.
    Program execution jumps to the ISR where it remains until the handlers have completed.
    The main program will continue only after the entire ISR is finished.

    The ISR and the main program do not execute at the same time.

    It's why they're called Interrupts.
    They Interrupt the main program to go do something else.
    <br>
    DT

  4. #4


    Did you find this post helpful? Yes | No

    Default

    Darrel,

    Thanks! I will modify my code, this will reduce overhead. Like I tried to say I do not know much about this, just enought to be dangerous and wrong most of the time.

    I have been using the 16F688 and the 16F883 on a couple of projects, your routines work great.

    When wanting to use the RBC_INT I found I had to set IOCB to get the interrupt to work on one input of PORTB.


    Thanks,
    Kevin

    ____________________

    If you want the best seat in the house, you will have to move the Cat.

  5. #5
    Join Date
    Nov 2007
    Location
    West Covina, CA
    Posts
    219


    Did you find this post helpful? Yes | No

    Default

    Thanks for ending the misery Darrel.
    I guess I was seeing too much into it. I still need to learn to juggle the events properly so they don't clash.
    When I read the second post that says "Well, for one, this Blinky Light program will continue Blinking at the same rate, no matter what else you add to the Main: program loop. Try doing that with pauses.", it's true, but I made the mistake of assumming that the main program would go along like some absent minded fool without a bother in the world.


    Thanks for all your contributions,
    Louie

  6. #6
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by LinkMTech View Post
    Thanks for ending the misery Darrel.
    I guess I was seeing too much into it.
    Well don't end it there ...
    It's probably that you're "not seeing enough into it".

    Interrupts can definitely be used to make multiple things happen at the same time.
    It's just that those things need to be happening in hardware.

    If you want to send RS232 from an interrupt, then you should use the USART.
    If you want to have an interrupt driven PAUSE, then use a Timer.

    Jumping to the ISR and executing a software routine like serout(2) is not normally very productive, because the same routine could have been run from the main program without interrupts without much additional overhead. And since either way ... the program can't continue until the serout has completed, with or without interrupts makes little difference.

    But if that interrupt uses the hardware USART, only a few instructions need to be executed to start the USART sending data, then it immediately returns from the interrupt and continues running the main program at the same time that the USART is sending the data.

    There are several hardware peripherals on the various PIC's, and you might have 5 or 6 things all happening at the same time.

    While software timed, bit-bang routines in your interrupts will occasionally be very useful ... avoid them at all cost.

    Hardware and Interrupts make good companions.

    hth,
    DT

  7. #7
    Join Date
    Nov 2007
    Location
    West Covina, CA
    Posts
    219


    Did you find this post helpful? Yes | No

    Default

    Well don't end it there ...
    Alrighty then! Just when I was about to go with plan "B", add a PIC12F683 as a stand alone serial generator.
    I just took a look at USART along with Mister E's PIC calculator and found that 7812 baud is configurable. A first glance some time ago gave me the impression that only common baud rates were available. I just recently discovered SEROUT2!
    Is the USART hardware like the HPWM that can run continueously in the background?
    If so, which commands will disrupt it or vice versa? I ran into some surprises when trying to use the HPWM while using the A/D in a WHILE:WEND. So went with PWM sprinkled through out the program along with a nice filter to hold my Vout.

    The RS232 does not have to be interrupt started, just running all the time with the same 8x8 bytes of data. It will be processed and returned without any delay so I will have to act on it immediately.
    Do you think this is still possible? Or go with plan "B"?
    Louie

  8. #8
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by hatchethand1000 View Post
    I have been using the 16F688 and the 16F883 on a couple of projects, your routines work great.
    Sweet!

    When wanting to use the RBC_INT I found I had to set IOCB to get the interrupt to work on one input of PORTB.
    Yes, you're correct.
    I shouldn't have said "... or any other interrupt related registers manually". That was a little too broad.
    There are several registers like IOCB that will need to be changed.

    I probably should have limited it to ... "You should NOT set INTCON, PIEx, PIRx, IPRx". As those are the only interrupt bits that DT_INTS does handle for you.

    Thanks for the correction.

    If you want the best seat in the house, you will have to move the Cat.
    Which is why the "best" seats in my house "belong" to the cats.
    They know not to sit in mine ... they might get sat on.
    DT

  9. #9
    Join Date
    Feb 2006
    Location
    Brussels, Belgium
    Posts
    104


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post

    You should NOT set INTCON, PIEx, PIRx, IPRx or any other interrupt related registers manually. DT_INTS handles all of those bits for you.
    So where in D_INTS do you configure if you want to trigger off a rising or falling edge for something like INT0 ?

    Thanks, Andrew

  10. #10
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,132


    Did you find this post helpful? Yes | No

    Default

    This is supposed to be done in the option register, isn't it?

    DT-INTS are not for settings.

    Ioannis

  11. #11
    Join Date
    Feb 2006
    Location
    Brussels, Belgium
    Posts
    104


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Ioannis View Post
    This is supposed to be done in the option register, isn't it?

    DT-INTS are not for settings.

    Ioannis
    See my first post - Darrel says not to set the interrupt registers manually.

    Andrew

  12. #12
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,132


    Did you find this post helpful? Yes | No

    Default

    This one you should set it yourself. Otherwise how would the system know what you want?

    Ioannis

Similar Threads

  1. Clock using Instant Interrupts
    By PICpocket in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 16th February 2009, 21:43
  2. DT instant interrupts with mister_e keypad
    By Tomexx in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 26th November 2008, 20:02
  3. DT's Instant Interrupts trouble
    By Tomexx in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 24th November 2008, 20:48
  4. Keypad and DT's Instant Interrupts
    By Homerclese in forum General
    Replies: 11
    Last Post: - 27th April 2007, 06:32
  5. Replies: 1
    Last Post: - 1st November 2006, 03:11

Members who have read this thread : 8

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts