Interrupt mystery - need some guru help


Closed Thread
Results 1 to 40 of 44

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    In my routine, there is a block that will scan the input on the triggering pin for the duration of the expected signal (about 14.4ms) so the interrupts will not be re-enabled until the 14.4ms duration has elapsed.
    Oh, is that what it's supposed to do.
    Might be a problem there. The comment also says 14400 uS, but those loops are going to take about 14.4 seconds instead.
    Code:
    FOR i = 0 TO 960			'total loop time: 14400 uS which is the total length of the bullet
    	PAUSE 15	          	'remember that the minimum delay at 8MHz is 12 uS
    	IF PORTA.0(area) == 1 THEN breakloop2 
    				            'when signal goes high, exit loop and check duration before the change, you need about 600us
    NEXT i
    Actually, it looks like all your comments show PAUSEs in uS. But the PAUSE statement delays in milliseconds.

    You probably wanted PAUSEUS.
    DT

  2. #2
    xnihilo's Avatar
    xnihilo Guest


    Did you find this post helpful? Yes | No

    Smile

    Quote Originally Posted by Darrel Taylor View Post
    Oh, is that what it's supposed to do.
    Might be a problem there. The comment also says 14400 uS, but those loops are going to take about 14.4 seconds instead.
    Code:
    FOR i = 0 TO 960			'total loop time: 14400 uS which is the total length of the bullet
    	PAUSE 15	          	'remember that the minimum delay at 8MHz is 12 uS
    	IF PORTA.0(area) == 1 THEN breakloop2 
    				            'when signal goes high, exit loop and check duration before the change, you need about 600us
    NEXT i
    Actually, it looks like all your comments show PAUSEs in uS. But the PAUSE statement delays in milliseconds.

    You probably wanted PAUSEUS.
    You are right, it is PAUSEus but for the test phase I replaced temporarily by PAUSE to be able to monitor what is going on with a 5V led.

  3. #3
    xnihilo's Avatar
    xnihilo Guest


    Did you find this post helpful? Yes | No

    Red face bad bad RA5

    There is a very strange thing happening.

    I use RC5 without pullup and as an input at default 0V, I make it a 'listening' pin.
    When a 5V pulse gets to this pin, I wait 1ms then set the pin as output and I set it high for 2ms. Then I turn it low and set is as input again to listen to any incoming pulses.

    What's strange is that once the pic is powered on, an int is triggered as if porta was:
    %00111111 while INTCON seems to be 0 (no int flag set).

    Once the int handler has been processed once, the program behaves normaly.

    So, there is obviously something that I don't grasp about setting a pin low or high and using WPU.

    I should set TRISA register to determine which pin is used as input or as output.
    I should use WPUA to determine what pin has its internal WPU enable. if disabled, the pin should stay LOW, shouldn't it?

    If I explicitely write:

    TRISA = %011111 'set RA5 as output, all other pins as inputs
    OPTION_REG = %01111111 'enable individual WPU setting
    WPUA = %011011 'enable WPU for all pins except RA3 and RA5
    PORTA = %011111 'set all pins low except for RA5 (but WPU will bring HIGH all pins that have WPU enabled)

    Like this I can expect to read porta as %011111 (31) but I get %111111 (63)...


    updated code is at http://users.edpnet.be/charlesetchri...se250308-2.pbp
    Last edited by xnihilo; - 25th March 2008 at 13:13.

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


    Did you find this post helpful? Yes | No

    Default

    The link to the code is broken

    Probably it would be safer to clear all interrupts flags before enabling any of them. When you enable the internal pull-up, this could trigger an interrupt.

    i would suggest
    enable the internal pull-up
    clear interrupt flags
    enable interrupts.

    Did you also tried with real pull-up resistors?
    Steve

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

  5. #5
    xnihilo's Avatar
    xnihilo Guest


    Did you find this post helpful? Yes | No

    Smile

    Quote Originally Posted by mister_e View Post
    The link to the code is broken
    Sorry. I edited my post. Now the linked is fixed.

    Probably it would be safer to clear all interrupts flags before enabling any of them. When you enable the internal pull-up, this could trigger an interrupt.
    I take care of TRIS, PORTA, OPTION_REG, WPUA before I use INTCON=%00001000.
    Your suggestion would be to use INTCON=0 before any other register setting and end with INTCON=%00001000
    ?
    I will try this.



    would suggest
    enable the internal pull-up
    clear interrupt flags
    enable interrupts.
    That's what I was doing in my code (in fact I enable porta change interrupts at the same time I clear all int flags). Still an interrupt is occuring but my int handler does not see what pin triggered the int so the handler is left with no action taken.
    Maybe there is something else triggering an int (a timer???) but only porta change interrupts
    are enabled.
    Oh boy, these interrupts are so tricky...

    Did you also tried with real pull-up resistors?
    No because I need to enable and disable WPU in software.

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


    Did you find this post helpful? Yes | No

    Default

    Is there any available schematic of it?

    That's quite an ISR you have.... Usually it has to be kept as short as possible. I'll try having a look at this later.

    Looking at the actual main loop... i'm not even sure if ANY interrupts are needed. Maybe just a read PORTA in a loop would do the job.
    Last edited by mister_e; - 25th March 2008 at 14:04.
    Steve

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

  7. #7
    xnihilo's Avatar
    xnihilo Guest


    Did you find this post helpful? Yes | No

    Smile

    Quote Originally Posted by mister_e View Post
    Is there any available schematic of it?

    That's quite an ISR you have.... Usually it has to be kept as short as possible. I'll try having a look at this later.

    Looking at the actual main loop... i'm not even sure if ANY interrupts are needed. Maybe just a read PORTA in a loop would do the job.
    If fact I'm building 4 projects, all used in a lasergame system, one is the sensors module on the player, one is the gun itself, one is the mag (that manages all the bullets and spare mags) and the last one is the supplier for providing spare mgs and medics to players.

    I've debuged the first three modules these 3 last days and I still have to take care of the supplier module.

    All handshaking between pics is not tested yet, for debugginf phase, I preset the values to what's expected as a reply. The gun encodes a PWM signal to represent a header, a byte and a trailer, the sensors module gets the signal, checks structure validity then extracts the byte and use it.
    I hope I won't encounter timing problems with that part.

    Polling quickly portA won't be enough...

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