Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

[PIC] Interruption on RB1 not working.

Status
Not open for further replies.

masashi11

Newbie level 5
Joined
Aug 29, 2014
Messages
10
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
77
I am having troubles with the interruptions on the pic18f4550, with the MPLAB 8.89 and c18 compiler.

The point is, the interruption doesnt get in if the pin change is status. I can see the status change, but it just doesnt change. But, if write the interruption as one it goes and enter the routine.

Here is my code, any idea?


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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
////// Autonomated Velocity Transmssion for a Bicycle of 9 gears/////
 
#include <p18f4550.h>
 
//////////////////////////////////////////// Variables /////////////////////////////////////////////////
unsigned int sensors=0;              // Counter of the sensor in the star
unsigned int sensorw=0;              // Counter of the sensor in the wheel
unsigned int rpms=0;                 // Rpms of the star
unsigned int rpmw=0;                 // Rpms of the wheel 
unsigned int velw;  
 
//////////////////////////////////////////// Interruption functions //////////////////////////////////////////////////
void Llanta (void);                  //Wheel 
void Estrella (void);                //Star 
 
 
/////////////////////////////////////// High Priority Interruptions /////////////////////////////////////////////////
 
#pragma code high_vector=0x08 
void high_interrupt (void) 
{   
     _asm nop _endasm 
}
 
//////////////////////////////////////////// Low Priority Interruptions //////////////////////////////////////////////////
 
#pragma code low_vector=0x18
void low_interrupt (void)
{
    if(INTCON3bits.INT1IF==1){      //interruption for INT1 on rising edge
         _asm goto Llanta _endasm   //Wheel
    } 
 
    if(INTCONbits.RBIF==1) {        //Interruption for change on RB port change
        _asm goto Estrella _endasm  //Star
    } 
 
}
 
 
#pragma code                
#pragma interruptlow Llanta 
void Llanta (void)              //Counts when the hall sensor of the wheel is activated
{    
    INTCON3bits.INT1IF=0;           //Turn off flag
    sensorw++;                    //add 
}
 
 
#pragma interruptlow Estrella           //Counts when the hall sensor of the star is activated
void Estrella (void) 
{   
    INTCONbits.RBIF=0;                  //Turn off flag 
    if(PORTBbits.RB4 == 1){       
        sensors++;                      //Add
    }   
}
 
////////////////////////////////////////////// Main program /////////////////////////////////////////////////////////////////////
void main (void) 
{ 
    unsigned int temp16;    
    OSCCON=0b01100000;          //Oscillator 4 MHz
 
    //Pins Configuration
    TRISBbits.RB1=1;            //input sensor wheel
    TRISBbits.RB4=1;            //input sensor star
    TRISB=0xFF;                 //All as inputs 
 
    T1CON=0b01000001;           // Oscillator 4 MHz, timer 1        
    ///////////////////////// Priorities //////////////////////////////// 
 
    RCONbits.IPEN=1;            //Enable priority levels 
    INTCON=0b11001000;          //Enable high, low interrupts and RB port change interrupt 
    INTCON2=0b01110000;         //Pull up disabled, interrupt on rising edge, and low priority on rb change
    INTCON3=0b00011000;         //low priority interruption, and enables external interruptions. 
    ADCON1=0x0F;                //digital input
    do{ 
        INTCON3bits.INT1IF=1;   // This was made to make a test. i put this as one, the interruption works and it goes where it should go. 
    }
    while(1); 
}



View attachment Bicibici.txt
 
Last edited by a moderator:

milan.rajik

Banned
Joined
Apr 1, 2013
Messages
2,528
Helped
540
Reputation
1,078
Reaction score
523
Trophy points
1,393
Activity points
0
Maybe you have to configure ADCON1 regsister and make RBx pins digital input pins.
 

masashi11

Newbie level 5
Joined
Aug 29, 2014
Messages
10
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
77
Hi there.
I already put in the configuration bits option the pbaden option off. And it makes the ports B digital inputs. Any other idea??
 

milan.rajik

Banned
Joined
Apr 1, 2013
Messages
2,528
Helped
540
Reputation
1,078
Reaction score
523
Trophy points
1,393
Activity points
0
Is your Clock properly configured ? Please zip and post complete MPLAB project files so that it can be tested.
 

mdorian

Member level 2
Joined
Oct 15, 2008
Messages
48
Helped
11
Reputation
22
Reaction score
11
Trophy points
1,288
Location
Romania
Activity points
1,566
Sorry for the wrong post , maybe reading portb before activating interrupts could help?
 

masashi11

Newbie level 5
Joined
Aug 29, 2014
Messages
10
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
77
Hi.
Thats an excellent question actually and to be honest i did not think about it.

Here is the code. Do you know what Clock should i check?
View attachment pim14.zip

- - - Updated - - -

No problem. Actually i am reading the value in PORTB all the time and i can see the change in the RB1 & RB2. But thats it, it just change the pins value from 0 to 1.

- - - Updated - - -

Hi. No problem :).
Yeah i read the values in PORTB all the time and i can see the change, but the interruption just does not pop up.
 

milan.rajik

Banned
Joined
Apr 1, 2013
Messages
2,528
Helped
540
Reputation
1,078
Reaction score
523
Trophy points
1,393
Activity points
0
Please mention what clock you are using that is external crystal frequency.
 

masashi11

Newbie level 5
Joined
Aug 29, 2014
Messages
10
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
77
Well thats a very good question I actually did not configure a Clock. What clock can i check?
Here is the project.
 

Attachments


milan.rajik

Banned
Joined
Apr 1, 2013
Messages
2,528
Helped
540
Reputation
1,078
Reaction score
523
Trophy points
1,393
Activity points
0
WDT is enabled, I think. You have to disable it.
 

milan.rajik

Banned
Joined
Apr 1, 2013
Messages
2,528
Helped
540
Reputation
1,078
Reaction score
523
Trophy points
1,393
Activity points
0
Try these config words.


Code C - [expand]
1
2
3
4
5
6
#pragma config PBADEN = OFF, PLLDIV = 1, CPUDIV = OSC1_PLL2, USBDIV = 2, FOSC = XT_XT, FCMEN = ON
#pragma config IESO = OFF, PWRT = ON, BOR = ON, BORV = 2, VREGEN = OFF, WDT = OFF, WDTPS = 2048
#pragma config CCP2MX = ON, LPT1OSC = OFF, MCLRE = OFF, STVREN = OFF, LVP = OFF, ICPRT = OFF
#pragma config XINST = ON, CP0 = OFF, CP1 = OFF, CP2 = OFF, CP3 = OFF, CPB = OFF, CPD = OFF
#pragma config WRT0 = OFF, WRT1 = OFF, WRT2 = OFF, WRT3 = OFF, WRTC = OFF, WRTB = OFF, WRTD = OFF
#pragma config EBTR0 = OFF, EBTR1 = OFF, EBTR2 = OFF, EBTR3 = OFF, EBTRB = OFF

 

masashi11

Newbie level 5
Joined
Aug 29, 2014
Messages
10
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
77
I tried them and it just doesn't work. Is there a possibility where the Pins are burned off?
 

milan.rajik

Banned
Joined
Apr 1, 2013
Messages
2,528
Helped
540
Reputation
1,078
Reaction score
523
Trophy points
1,393
Activity points
0
Even it is not working here. I wrote the code using mikroC and it works. Don't know what is the problem. One problem was RCON.IPEN setting. I removed it and everything worked fine. If Interrupt priority is enabled then you should set INTx interrrupts as high priority. I am attaching mikroC Code which works and also Proteus 8.2 SP2 format file.

I am also posting your code which I modified.


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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
////// Autonomated Velocity Transmssion for a Bicycle of 9 gears/////
 
#include <p18f4550.h>
 
//////////////////////////////////////////// Pragmacode /////////////////////////////////////////////////
#pragma config PBADEN = OFF, PLLDIV = 1, CPUDIV = OSC1_PLL2, USBDIV = 2, FOSC = XT_XT, FCMEN = ON
#pragma config IESO = OFF, PWRT = ON, BOR = ON, BORV = 2, VREGEN = OFF, WDT = OFF, WDTPS = 2048
#pragma config CCP2MX = ON, LPT1OSC = OFF, MCLRE = OFF, STVREN = OFF, LVP = OFF, ICPRT = OFF
#pragma config XINST = OFF, CP0 = OFF, CP1 = OFF, CP2 = OFF, CP3 = OFF, CPB = OFF, CPD = OFF
#pragma config WRT0 = OFF, WRT1 = OFF, WRT2 = OFF, WRT3 = OFF, WRTC = OFF, WRTB = OFF, WRTD = OFF
#pragma config EBTR0 = OFF, EBTR1 = OFF, EBTR2 = OFF, EBTR3 = OFF, EBTRB = OFF
 
 
//////////////////////////////////////////// Variables /////////////////////////////////////////////////
unsigned int sensors = 0;              // Counter of the sensor in the star
unsigned int sensorw = 0;              // Counter of the sensor in the wheel
unsigned int rpms = 0;                 // Rpms of the star
unsigned int rpmw = 0;                 // Rpms of the wheel 
unsigned int velw;  
 
//////////////////////////////////////////// Interruption functions //////////////////////////////////////////////////
void Llanta1 (void);                  //Wheel
void Llanta2 (void);                  //Wheel 
void Llanta3 (void);                  //Wheel  
void Estrella (void);                //Star 
 
 
/////////////////////////////////////// High Priority Interruptions /////////////////////////////////////////////////
 
#pragma code high_vector=0x08 
void high_interrupt (void) 
{   
    INTCONbits.RBIF = 0; 
     _asm nop _endasm 
 
}
 
//////////////////////////////////////////// Low Priority Interruptions //////////////////////////////////////////////////
 
#pragma code low_vector=0x18
void low_interrupt (void)
{
    if(INTCONbits.INT0IF){      //interruption for INT1 on rising edge
        INTCONbits.INT0IF = 0;           //Turn off flag
        LATDbits.LATD0 = ~LATDbits.LATD0; 
        _asm goto Llanta1 _endasm   //Wheel
    } 
 
    if(INTCON3bits.INT1IF){      //interruption for INT1 on rising edge
         _asm goto Llanta2 _endasm   //Wheel
    }
    
    if(INTCON3bits.INT2IF){      //interruption for INT1 on rising edge
         _asm goto Llanta3 _endasm   //Wheel
    }  
 
    if(INTCONbits.RBIF) {        //Interruption for change on RB port change
        _asm goto Estrella _endasm  //Star
    } 
 
}
 
#pragma code
#pragma interruptlow Llanta3 
void Llanta1 (void)              //Counts when the hall sensor of the wheel is activated
{    
    
}
 
#pragma interruptlow Llanta3 
void Llanta2 (void)              //Counts when the hall sensor of the wheel is activated
{    
    INTCON3bits.INT1IF = 0;           //Turn off flag
    LATDbits.LATD1 = ~LATDbits.LATD1;
}
 
#pragma interruptlow Llanta3 
void Llanta3 (void)              //Counts when the hall sensor of the wheel is activated
{    
    INTCON3bits.INT2IF = 0;           //Turn off flag
    LATDbits.LATD2 = ~LATDbits.LATD2;
}
 
 
#pragma interruptlow Estrella           //Counts when the hall sensor of the star is activated
void Estrella (void) 
{   
    if(PORTBbits.RB4){       
        LATDbits.LATD3 = ~LATDbits.LATD3;                      //Add
    } 
 
    INTCONbits.RBIF = 0;                  //Turn off flag   
}
 
////////////////////////////////////////////// Main program /////////////////////////////////////////////////////////////////////
void main (void) 
{ 
    ADCON1 = 0x0F;
    //Pins Configuration
    TRISB = 0xFF;                 //All as inputs 
    TRISD = 0x00;
 
    T1CON = 0b01000001;           // Oscillator 4 MHz, timer 1        
    ///////////////////////// Priorities //////////////////////////////// 
 
    INTCON  = 0b11111000;          //Enable high, low interrupt, INT0 and TMR0overflow and RB port change interrupt 
    INTCON2 = 0b01110000;         //Pull up enabled, interrupt on rising edge, and low priority on rb change and tmr0 interrupt
    INTCON3 = 0b00011000;         //low priority interruption, and enables INT1 & INT2 interruptions. 
                    //digital input
    INTCONbits.INT0IF =  0;     // Initialize flag of interrupt
    INTCON3bits.INT1IF = 0; // Initialize flag of interrupt
    INTCON3bits.INT2IF = 0; // Initialize flag of interrupt
    LATD = 0x00;
 
    do{ 
      
    }
    while(1); 
}




In MPLAB menu Configure > Configuration bits select config bits set in code.
 

Attachments

Last edited:

milan.rajik

Banned
Joined
Apr 1, 2013
Messages
2,528
Helped
540
Reputation
1,078
Reaction score
523
Trophy points
1,393
Activity points
0
Also works with XC8 Compiler. I am sure the problem is with the ISR routines. The same code works fine in mikroC and XC8.

- - - Updated - - -

Fixed C18 code attached. Still there is some problem. INT2 doesn't toggle.
 

Attachments

Last edited:

    V

    points: 2
    Helpful Answer Positive Rating

masashi11

Newbie level 5
Joined
Aug 29, 2014
Messages
10
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
77
Thanks. Going to try this in a moment in the pic with the XC8 compiler and i will tell you what happened.
 

masashi11

Newbie level 5
Joined
Aug 29, 2014
Messages
10
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
77
I tried and something strange happened. It works sometimes.

For example the first time I tried it worked right. But after 6 hour i tried aggain and it didnt work.

Can this be a pic issue related?
 

milan.rajik

Banned
Joined
Apr 1, 2013
Messages
2,528
Helped
540
Reputation
1,078
Reaction score
523
Trophy points
1,393
Activity points
0
The mikroC and XC8 codes work fine for me.
 

    V

    points: 2
    Helpful Answer Positive Rating

masashi11

Newbie level 5
Joined
Aug 29, 2014
Messages
10
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
77
My friend, now its working perfectly. I dont have an exactly idea of what was happenning but it was for sure
a hardware problem. Thanks for your help. Gona put your name in the project.
 

Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top