Interrupts question


Closed Thread
Results 1 to 12 of 12
  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: 3330
Size:  31.0 KB


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

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


    Did you find this post helpful? Yes | No

    Default Re: Interrupts question

    I tend to replace R140 & R141 with a simple capacitor... Xc, seems to work really well.

    Using the secondary winding of your transformer and design the power supply accordingly may works, but I got some weirdness with some transformer brands. There's sometime a unpredictable phase delay between the main and the secondary... and it screw the zero crossing big time
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default Re: Interrupts question

    I'm in agreement that a .47uF cap works well, but you still have to have some sort of resistor in series (1K or so), otherwise really short risetimes will blow the LEDs. I use resistors here because they are smaller than a 400V cap.

    RE: Transformers - I needed to measure the "quality" of the AC line. I thought I would use a cheap transformer. The transformer would power both my PIC and provide the low-voltage isolated signal to the PICs A/D.
    I realized that the peaks would be chopped off by the bridge rectifier as the voltage rose a diode drop higher than the main storage capacitor, so I put a 150 ohm resistor in series with the diode to "soften the blow". The
    PIC didn't take much current, anyway, so the extra drop of the resistor wasn't a problem.
    But I was mistaken! Even with the current limit, the waveform coming from the transformer was horribly distorted. I wound up using a (TAMURA brand) transformer that was about 6X as big (in current ability) than I needed, and one that had TWO separate secondaries. One secondary ran the PIC, and I used the other to measure the line. The "unloaded" secondary fed a bridge rectifier that had only a 680 ohm resistor as a load. That worked.
    Charles Linquist

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


    Did you find this post helpful? Yes | No

    Default Re: Interrupts question

    Good point and tips there. I thought about the dual winding for my application but I needed it really small to fit in an existing installation (kind of reverse engineering job), none of the dual secondary winding tranformer I found locally were small enough, the transformerless solution was REALLY not an option and everything was for...yesterday (yeah it happen ) ... so in the end I added a TLP2098 (if my memory serves me well) i had in stock, problem solved.

    If I had a toroidal one on hand, I would have try to wind a seconday on the top for testing purpose, maybe it would have work... or really not hahaha.
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default Re: Interrupts question

    I couldn't use an opto for my particular application because I needed to know the peak voltages of the AC waveform, cycle-by-cycle.
    Charles Linquist

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


    Did you find this post helpful? Yes | No

    Default Re: Interrupts question

    Hi All, and apologies for not getting back to you all sooner (damned work!!)
    I hate to admit this, but a wire had gotten disconnected on my bread board - amazing how much better a PIC works when it has a five volt supply...
    My zero crossing detector works great, and I'm getting a nice clean pulse train to my triac optocoupler. Now to go back to the code to make my kitchen heater controller - I'm making a sous vide controller for a crockpot..
    Thanks again for all the help - before I tear hair out again I'll make sure to check my hardware first...
    Alec

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


    Did you find this post helpful? Yes | No

    Default Re: Interrupts question

    BTW - I'm using a PS205-1 AC input photocoupler. Works great with a 10k 1 watt resistor in the input.
    Alec

Members who have read this thread : 1

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