On Interrupt question


Closed Thread
Results 1 to 16 of 16

Hybrid View

  1. #1
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563


    Did you find this post helpful? Yes | No

    Default You are using interrupt on change

    Hi,

    It seems at a quick glance that you are using the interrupt on change feature on portb. This means you trigger an interrupt on every change on portb<4:7> . In plain english on every edge , a press or release of the button. So the program is jumping into the routine. Without rewiring your circuit you can disable the interrupt altogether in the interrupt routine and then clear flags and set the interrupt in the main loop.

    BTW its 22:05 here and time to go home so signing off now.

    Regards

    Sougata

  2. #2
    Join Date
    Feb 2005
    Posts
    130


    Did you find this post helpful? Yes | No

    Default

    The interrupt is triggered as soon the pic starts, without even pressing a single time any button.


    I set the OPTION_REG as follows

    bit7 = 1 PORTB pull-ups are disabled
    bit6 = 1 Interrupt on rising edge of RB0/INT pin
    bit5 = 0 Internal instruction cycle clock (CLKOUT)
    bit4 = 1 Increment on high-to-low transition on RA4/T0CKI pin
    bit3 = 0 Prescaler is assigned to the Timer0 module
    bit2 = 0 Prescaler Rate Select bits
    bit1 = 0
    bit0 = 1 TMR0 Rate 1:4 WDT Rate 1:2

    I can rewire the schematic at will, so if you have a solution this way, please let me know.


    Thanks!
    Last edited by peu; - 27th January 2006 at 17:45.

  3. #3
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563


    Did you find this post helpful? Yes | No

    Default Try using the PORTB.0 interrupt

    Hi,

    Try using the portb.0 interrupt pin. Clear the interrupt flags (other than Global int.7) just before the resume and your circuit should work. Try using some sort of debounce circuitry as well. Good Luck. BTW your PIC has a hardware PWM. After the experiment put it to good use.

    Regards

    Sougata

  4. #4
    Join Date
    Feb 2005
    Posts
    130


    Did you find this post helpful? Yes | No

    Default

    Hi again Sougata,

    I need 3 PWM thats why I use the soft version. And regarding the interrupts I need 2 buttons, thats why I choosed the port change instead of the single PortB.0 method.

    Any idea on how to do that?

    Thanks again!

  5. #5
    Join Date
    May 2004
    Location
    New England
    Posts
    164


    Did you find this post helpful? Yes | No

    Default

    Hi Pablo,
    As sougata mentioned, you'll have problems with switch bounce and button press duration causing repeated interrupt flag resets.

    Since your code is not 'seeing' an interrupt until after the PWM statements are finished, why not just test the state of the interrupt flag in the pauses in between your PWM loops?

    As far as interrupting on power up without a button press, you might try a bit a a pause at the start of the program, then clear the interrupt flags.

    Arch

    EDIT - ooh... that won't work 'cause it won't sort out the different buttons - darn!
    Last edited by Archilochus; - 27th January 2006 at 19:36.

  6. #6
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563


    Did you find this post helpful? Yes | No

    Default Why have you turned on Timer0 Interrupt

    Hi,

    On a closer look at your prog I found that you have timer0 to use external clock via RA4. Possibily you did this because there is no timer0 enable disable bit. You wanted your timer not to work. But you have kept the input floating. Spurious counting is going on. Also you have turned on the timer0 interrupt bit in your intcon settings. So a timer0 overflow would trigger the interrupt.

    So my suggestions :

    1. Disable the T0IE bit

    Regards

    Sougata

  7. #7
    Join Date
    Feb 2005
    Posts
    130


    Did you find this post helpful? Yes | No

    Talking

    Thanks Sougata, I changed that bit and now it works as expected.

    A single bit keep me puzzled half week, you gotta love pics...

    Here is the working example, so others can learn too:

    Code:
    @ device pic16F628A, intrc_osc_noclkout, wdt_on, mclr_off, protect_off
    DEFINE OSC 4
    
    trisb   =%11111111
    trisa   =%00000000
    cmcon   =%00000111  'Comparators Off
    vrcon   =%00000000
    intcon  =%10001000'interrupts enable // was  %10101000  
    'OPTION_REG =%11010001 
    
    but1    var PORTB.4
    but2    var PORTB.5
    ledwork var PORTA.0
    led1    var PORTA.1
    led2    var PORTA.2
    led3    var PORTA.3
    rs      var PORTb.2
    
    
    conta   var byte
    
    porta=0
    portb=0
    
    on interrupt goto interrupcion
    
    SerOut rs,2,[" ",10,13]
    SerOut rs,2,["Begin",10,13]
    
    
    LOOP:
    
    SerOut rs,2,["Loop",10,13]
    
    for conta=0 to 255 step 16  'working led rise routine
        pwm ledwork, conta, 10  
    next conta
    high ledwork
    
    for conta =0 to 10
        pause 10
    next conta
    
    low led1   'set button status leds off
    low led2
    low led3
    
    
    goto loop
    
    end
    disable 
    interrupcion:
    SerOut rs,2,["Interrupt",10,13]
        intcon.0=0
        intcon.1=0
        intcon.2=0
            if but1=1 then
                 but1=0
                high led1
                SerOut rs,2,["Set",10,13]
    
            endif
            if but2=1 then
                 but2=0
               high led2
               SerOut rs,2,["Mode",10,13]
            endif
    high led3       
    
        resume
    enable
    I commented out the OPTION_REG because the program worked ok with and without it. Of course the serouts can be removed, I use them to know where the program is.

    Thanks to all for the help provided


    Pablo

Similar Threads

  1. Interrupt question
    By ultiblade in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 26th November 2009, 20:12
  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. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 01:07
  5. Interrupt question
    By stone in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 25th January 2005, 23:11

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