Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Weird interrupt problem pic16f690

Status
Not open for further replies.

Lipton2

Newbie level 4
Newbie level 4
Joined
Jun 6, 2014
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
55
Hello guys!
I have been struggeling with this problem for hours now and i can't seem to get it fixed.
Maybe it is just is simple mistake, but i hope you can help me.
I am trying to make a simple interrupt with a PIC16F690 that blinks a LED every second.
As you can see i first declared all the INTCON en OPTION registers that were needed.
And since i have a default internal oscillator of 4Mhz I used a Fosc of 1 Mhz to calculate the count of overflows.

But when i program my device, instead of 1, all four LED's are on and they are not blinking.
What is wrong?

I hope you can help me!
Thanks in advance!

Oh btw, I use the XC8 compiler



Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <htc.h>
#include <pic16f690.h>
 
 
    unsigned char counter=0;//Overflow counter
    //void interrupt ISR(void);
    void main()
    {
       //Setup Timer0
       OPTION_REGbits.PS0=1; //Prescaler is divide by 256
       OPTION_REGbits.PS1=1;
       OPTION_REGbits.PS0=1;
 
       OPTION_REGbits.PSA=0;      //Timer Clock Source is from Prescaler
 
       OPTION_REGbits.T0CS=0;     //Prescaler gets clock from FCPU (1MHz)
 
       INTCONbits.T0IE=1;   //Enable TIMER0 Interrupt
       INTCONbits.T0IF=0;
       INTCONbits.PEIE=1;     //Enable Peripheral Interrupt
       INTCONbits.GIE=1;      //Enable INTs globally
 
       TRISC=0;
      while(1)
      {
          
      };  
    }
 
    //Main Interrupt Service Routine (ISR)
    void interrupt ISR ()
    {
       //Check if it is TMR0 Overflow ISR
       if(INTCONbits.T0IE && INTCONbits.T0IF)
       {
           counter ++;
           if (counter == 15)
           {
 
         PORTCbits.RC0;
         counter = 0;
           }
         INTCONbits.T0IF=0;
      }
   }

 
Last edited by a moderator:

Thanks for your reply!
When I implement this in my code, all four LED´s (RC0-RC3) are on, but after a second or so, three (RC1-RC3) LED's turn off again. Isn't that very weird since I only gave an action to RC0? It seems like the program only goes through the interrupt once and then gets stuck in the main loop. How can I fix this?

Thanks!
 

Yes whatchdog timer was disabled, but i already fixed the problem I think!
I added an else statement to the if statement with the counter.
The LED now blinks every second!

Thanks for your help!

Code:
    //Main Interrupt Service Routine (ISR)
    void interrupt ISR ()
    {
       //Check if it is TMR0 Overflow ISR
       if(INTCONbits.T0IF==1)
       {
           counter ++;
           if (counter == 15)
           {
                PORTC=0b00000001;
                counter = 0;
           }
           else PORTC =0;

         INTCONbits.T0IF=0;
      }
   }
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top