Problem with interrupts

Discussion in 'Embedded Systems and Microcontrollers' started by ecka333, Jun 29, 2010.

  1. ecka333

    Thread Starter Active Member

    Oct 1, 2009
    76
    0
    Hello, i have made audio amplifier, and now i want to make control circuit for amplifier with pic16f876a microcontroller. I first time tried to write program in assembly with interrups. Interrupts must control amplifier channel commutation and commutation between phones/speakers, but interrupts is not working. Maybe someone could help me with the program? Zip file wih shematics and code is attached.
     
  2. ecka333

    Thread Starter Active Member

    Oct 1, 2009
    76
    0
    Ok, i simplified the schematics. There is three switches, connected to RB4, RB5 and RB6 inputs. Inputs RB4-RB7 have pullup resistors to ground. I wrote simply program, to test, how interrupts are working. But problem is, that interrupts work not as i want. All three switches is normally open. When i powerup the microcontroller, all three leds flashes 2 times, as the program is written. But they must flash only then, when one of three switches is pressed. So i cant understand, what is causing interrupt? So, when leds flashes 2 times, they stop. Then i press one of these 3 switches. Leds turn on, but now they do non turn off. Seems like PIC freezes. Where is the problem?
    Below is shematics and code:

    http://hig9vq.bay.livefilestore.com...A9TsRoQEWCQoHfvJPx1lRgsBcPxp9/code.txt?psid=1
     
    Last edited by a moderator: Jul 5, 2010
  3. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    Possibly the problem is in mute-on and mute-off. They change banks but not back again.
     
  4. ecka333

    Thread Starter Active Member

    Oct 1, 2009
    76
    0
    Thank you, i will check. But in second schematics problem remains, as banks there is ok, i think.
     
  5. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    Sorry, didn't notice there were 2 lots of code.

    Page 22 of datasheet:
    Something like movf PORTB, W before clearing RBIF should do the trick.
     
  6. ecka333

    Thread Starter Active Member

    Oct 1, 2009
    76
    0
    I resolved problem with interrupt, there was problem in the code. But now i again encountered one problem. Problem is with microcontroller, it is very unstable. When i powerup the microcontroller, it often goes to state, which is not programmed, sometime freezes. But if microcontroller works normally stright after power up, theh it works normally and further. So the problem arises in the moment of power-up. Maybe someone has faced with similar problem?
     
  7. debjit625

    Well-Known Member

    Apr 17, 2010
    790
    186
    If your MCU have dual pins for VSS and VDD connect them properly (both),next the oscillator make sure that what type of oscillator you are using like HS or XT and config the MCU at programming time ,and also make the oscillator's connection very close to mcu's pins.

    Good luck
     
  8. ecka333

    Thread Starter Active Member

    Oct 1, 2009
    76
    0
    Thanks for answers, i found the problem, why microcontroller is "unstable". I Tried to change crystals, use other power supply, add capacitor to power supply rails. Nothing helped. Then I slightly changed program: in begining i cleared PORTA, PORTB and PORTC files, thats helped wonderfully - microcontroller started act as it should. Now everything is OK:).
     
Loading...