Interrupts question


Closed Thread
Results 1 to 12 of 12

Hybrid View

  1. #1
    Join Date
    Feb 2005
    Location
    brookfield, ct, usa
    Posts
    24

    Default Interrupts question

    Hi all
    I've been trying to control a triac using an interrupt on RB0 and going to an interrupt handler - been basing it on the discussion surrounding Mr E's lamp dimmer code.

    Code:
    '****************************************************************
    '*  Name    : triac_force.pbp                                     *
    '*  Author  : Alec Noble                                        *
    '*  Notice  : Copyright (c) 2011 Alec Noble                     *
    '*          : All Rights Reserved                               *
    '*  Date    : 6/18/2011                                         *
    '*  Version : 1.0                                               *
    '*  Notes   :                                                   *
    '*          :                                                   *
    '****************************************************************
    @ DEVICE PIC16F819, WDT_OFF, LVP_OFF, PWRT_ON, PROTECT_OFF, BOD_OFF, INTRC_OSC_NOCLKOUT
    
        DEFINE OSC           8        ' Set the Xtal frequency to 8mHz
        OSCCON = %01110100
    ' ** Setup the interrupts   **
    
    INTCON.7 = 1                    'GIE - enable global interrupts
    INTCON.4 = 1                    'Enable RB0 interrupt
    
                                   
    
    on interrupt goto AC_detect
    
          trisa   = %11111111         'Port A all inputs
          trisb   = %00000001         'Port B.0 input,  all others outputs
          
    main:
        
        goto main
          
    
    
    
    
        '
        ' Interrupt routine called by ACLine (RB0) pin state change
        '
    disable
    AC_Detect:
        pauseus 100
        pulsout portb.1, 25
        INTCON.1=0 ' Clear interrrupt flag
    resume
    enable
    My input pulse train to RB0 is clean - 8.3 ms apart as it should be. However, the output pulses are about 90 MS apart. Am I misunderstanding how to configure the interrupts, doing something else foolish or what? Any help would be appreciated...
    Thanks
    Alec

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


    Did you find this post helpful? Yes | No

    Default Re: Interrupts question

    "ON INTERRUPT GOTO" Checks the interrupt flag after each major instruction. My guess is that it is "blind" during the PULSOUT command. If you want PORTB.1 to go high, and stay high whenever there is AC present. This won't do it.

    I would use DT-INTS to handle this. Since DT-INTS has an ASM "core", no PBP command can block it.
    Charles Linquist

  3. #3
    Join Date
    Mar 2009
    Location
    Colorado
    Posts
    378


    Did you find this post helpful? Yes | No

    Default Re: Interrupts question

    Alec, I totally agree with Charles. Don't waste your time with ON INTERRUPT...go download Darrel Taylor's DT_INT at http://darreltaylor.com/DT_INTS-18/home.html . Lot's of help available on this forum for using them.
    Regards, John Ellis

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default Re: Interrupts question

    IMHO, and even if I agre with the previous suggestions, it Shouldn't be that messy since you have nothing in the mainloop. Do you have a square wave signal generator (or anything who can produce 50/60 hz with TTL logic level)? try it. If it works, you may have to rethink about your zero crossing circuit.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default Re: Interrupts question

    Another thing that spring to mind, are you expecting a low to high pulse on PORTB.1 or a high to low pulse?

    If you expect a LOW to HIGH, then you should clear PORTB.1 at the beginning of your code, and set it it you expect a High to low one.

    It's always a good idea to set the idle state of any PORT pin as the initial state might be unknown.
    Last edited by Archangel; - 11th August 2011 at 02:59.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

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


    Did you find this post helpful? Yes | No

    Default Re: Interrupts question

    But if you simply want to monitor the AC line, then you don't really need interrupts. I'll attach a circuit that (I think) does what you want. The output is LOW whenever there is AC present. The capacitor keeps it from going high during zero-crossings.

    And - it has isolation.Name:  ACMonitor.jpg
Views: 3378
Size:  31.0 KB


    The circuit works for both 110V and 220V.
    Charles Linquist

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