1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

SETUP AN INTERRUPT IN 16f690

Discussion in 'Microcontrollers' started by c36041254, May 16, 2008.

  1. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,016
    Likes:
    317
    Location:
    Brisbane Australia
    Your code (now) works fine in the simulator and so I would guess that your problem is hardware. Do you have MCLR tied high? Can you do something simple like just lighting the LEDs?

    Mike.
     
  2. c36041254

    c36041254 Member

    Joined:
    Apr 1, 2008
    Messages:
    154
    Likes:
    1
    Location:
    Newzealand, Auckland
    Actually I'm using low pin count demo board supplied with PIC Kit 2, and I'm touching a wire from Vdd to RA2 and then connect it to GND manualy, but as you said that it runs well on simulation I'll check the hardware, by the way, I am tryiing to simulate the codes but don't know how to use stimulus , I have selected pin/register actions from stimulus window then add a signal for RA2 (that has generated a coloumn for RA2), then I ticked repeat and set it for 5 sec,what else I need to do, I been through help file but that is rather confusing. I'm sorry that I ask too much but I'm studying correspondently so internet is the only source where I can learn from and thank you all for the help !
     
  3. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,016
    Likes:
    317
    Location:
    Brisbane Australia
    I just setup the stimulus as shown in the attachment and then do apply. I then set a breakpoint on the first instruction after org 4 (movwf temp) and run it with F9. If you view the SFRs you can see port C increment.

    Mike.
     
    Last edited: Jul 6, 2008
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,185
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    ONLINE

    Hi c360,
    Touching A2 to Ground and Vcc with a piece of wire is about the worst thing you could do to generate an Interrupt!. You will generate multiple interrupts.

    The only reliable way is to use a momentary switch or push button, connect A2 to Vcc with a 4K7 resistor and use the switch to connect A2 to ground.

    The switch should also be debounced by using a simple resistor/capacitor filter between the switch and A2.

    Do you follow.?
     
  6. c36041254

    c36041254 Member

    Joined:
    Apr 1, 2008
    Messages:
    154
    Likes:
    1
    Location:
    Newzealand, Auckland
    How could you be able to set "restart at 0" while there are only 500 and 1500 in time coloumn, I am having problem setting "restart at 0", I have added "0" in time coloumn and respectively put "1" in RA2 coloumn (I could have explained better by sending a pic., how did you copy the whole window as thumbline ?), but that did'nt work, in SFR port c shows all zeros.


    ...........Thanks eric I have a push to on switch at hand ,will try that and tell you
     
  7. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,185
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    ONLINE
    Hi,
    Drawn a pic to explain a little better.:)

    However careful you are touching a PIC input pin with a piece of wire, chances are you will get multiple contacts and the PIC will act in a unpredictable way.
    There are software routines that are used to debounce switch contacts that are being 'polled' by the program, but for switches which generate an Interrupt I have found it better to add hardware debouncing.

    EDIT:
    I would also use hardware debouncing [opt#2] when using the PIC Timers as counters with external clocking inputs.
     
    Last edited: Jul 7, 2008
  8. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,016
    Likes:
    317
    Location:
    Brisbane Australia
    I don't understand your problem. I just typed the various values except for RA2 which I selected from the drop down box. Which bit can't you do?

    Mike.
     
  9. c36041254

    c36041254 Member

    Joined:
    Apr 1, 2008
    Messages:
    154
    Likes:
    1
    Location:
    Newzealand, Auckland
    I knew this will happen :)
    O.K. ,when I go to the restart box the drope out menu appears and it has only two values 500 and 1500 so, how did you select "0" because the value (0) must be in the drope out menu but as I said it (0) is not there. If you still don't get what I'm referring to then tell me how did you make thumbline of the whole stimulus window because I don't know how to do that otherwise I would have sent you a picture of mine stimulus window which I hope have served better, so please tell me how to save stimulus window in picture (JPEG or any other) format so as to post it on blog (just as you did to explain me), I hope this will be understandable.

    Oh! and thank you eric for your ckt this will take some time to build ,so will tell you later about that.
     
    Last edited: May 18, 2008
  10. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,185
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    ONLINE
    hi Mike,
    Which version of MPLAB are you on.? , I'm using V7.6, got the same problem as OP.
    No '0' option a restart, just 500 and 1500

    I wonder if he is also using V7.6..???
     
  11. c36041254

    c36041254 Member

    Joined:
    Apr 1, 2008
    Messages:
    154
    Likes:
    1
    Location:
    Newzealand, Auckland
    I'm using MPLAB 8.0
     
  12. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,016
    Likes:
    317
    Location:
    Brisbane Australia
    I'm using MPLAB V8.02, I just pick the value from the drop down box.:confused:

    Mike.
     
    Last edited: Jul 6, 2008
  13. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,185
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    ONLINE
    hi,
    I have just downloaded from microchip MPLAB IDE V8.10, installing on my second PC, let you know.:)

    EDIT:

    Installed MPLAB IDE V8.10, I am now able to set up the Stimulus the same as you Mike. OK.

    ie: restart at '0' etc.
     
    Last edited: May 18, 2008
  14. c36041254

    c36041254 Member

    Joined:
    Apr 1, 2008
    Messages:
    154
    Likes:
    1
    Location:
    Newzealand, Auckland
    Mine one does'nt have "0" so, I did something awkward, I have added 0 in time coloumn and for this 0 time I set RA2 to 1 and then I have 0 in the dropeout menu..........., oh god I can't go more easy than this in words ,Mike please tell me how did you attach the picture of stimulus window in your last post (I know how to attach a picture, but don't know how to copy an active window as a picture)
     
  15. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,185
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    ONLINE

    hi,
    Google for screenhunter its freeware.
     
  16. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,016
    Likes:
    317
    Location:
    Brisbane Australia
    To copy the screen, press the key that has "Prt Scr/SysRq" (next to scroll lock) on it and the screen is copied to the clipboard. Go into your favourite graphics program and paste it.

    Mike.
     
  17. c36041254

    c36041254 Member

    Joined:
    Apr 1, 2008
    Messages:
    154
    Likes:
    1
    Location:
    Newzealand, Auckland
    O.K. so this is what I have done to get "0" in restart, is it right to do so?
    And the simulatio still does'nt work, after doing whatever in the thumbline I clicked apply then svaed the workbook, so this supposed to work.
     

    Attached Files:

    Last edited: May 18, 2008
  18. c36041254

    c36041254 Member

    Joined:
    Apr 1, 2008
    Messages:
    154
    Likes:
    1
    Location:
    Newzealand, Auckland
    Hey ! that works , 500 and 1500 were too long period ( though I should have some patient, sorry for that)I reduce them to 50 and 150.:)
     

    Attached Files:

  19. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,016
    Likes:
    317
    Location:
    Brisbane Australia
    I guess you were using single step (F8). If you set a breakpoint as shown below, by double clicking in the grey border, then you can press f9 and the program will run until an interrupt occurs.

    Mike.
     
    Last edited: Jul 6, 2008
  20. c36041254

    c36041254 Member

    Joined:
    Apr 1, 2008
    Messages:
    154
    Likes:
    1
    Location:
    Newzealand, Auckland
    I know that but, pressing F9 with a break point runs progarmme only for first interrupt(as it should be) and then when I press agin F9 to cross over break point the whole MPLAB gets hang, only animation runs good but, that takes too much time.
     
    Last edited: May 18, 2008
  21. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,016
    Likes:
    317
    Location:
    Brisbane Australia
    It shouldn't do that, it should stop at the breakpoint every time you press F9. It might be worth downloading and installing the latest version.

    Does it now work on the hardware. A good way to generate interrupts is to turn on the WPUs (WPUA=2 and OPTION.7 = 0) and then just ground the pin. The debounce problem shouldn't matter, it will just jump a few counts.

    Mike.
     

Share This Page