View previous topic :: View next topic |
Author |
Message |
gjm27n
Joined: 15 Jun 2016 Posts: 23
|
Port B interrupts no longer working using 5.061 |
Posted: Sun Jul 03, 2016 1:13 am |
|
|
I just updated my compiler version from 4.016 to 5.061 and suddenly my code to process Port B interrupts is never getting called. It worked fine with the prior version. In fact, if I burn a chip from a hex file built with the previous version of the compiler, they still work. Other than the compiler, nothing has changed. I have optimization turned off and am using a 18F452.
Snippets of code
Setup for Port B in .h file
Code: | #use fixed_io(b_outputs = PIN_B0, PIN_B1, PIN_B2, PIN_B3) |
Setup for Port B in .c file
Code: | port_b_pullups(TRUE); |
Setup of interrupts in main
Code: |
delay_ms(500);
disable_interrupts(GLOBAL);
Setup_Ports();
enable_interrupts(INT_RDA);
enable_interrupts(INT_RB);
disable_interrupts(INT_TIMER1);
disable_interrupts(INT_TIMER2);
enable_interrupts(INT_TIMER3);
enable_interrupts(GLOBAL);
|
Interrupt handler (never gets called and I verified there are interrupts)
Code: | #int_rb
void encoder_cnt()
{
...
} |
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19516
|
|
Posted: Sun Jul 03, 2016 1:25 am |
|
|
Make a small test program that demonstrates what you are seeing.
You can have just fuses, processor setup, the portB code, and then have this do something like toggle a pin. This wants to be a program _we can compile_.
The odds are, once you do this things will suddenly start working. However if they don't, then we have something we can try.
4.016!..... This is well before V4, was really considered a working compiler!.... Ouch.
However that being said, are there any warning messages in the V5 compile?.
It may be you have found some oddity in .061, but equally it may be that the compiler is seeing a previous problem, and 'fixing' it by disabling the interrupt. However there should be a warning if so.
Are the other interrupts being called?. 'GLOBAL' getting disabled, is much more common than a single interrupt. Classic things might be related to the use if 'DISABLE_INTS' in an RS232 setup. |
|
|
gjm27n
Joined: 15 Jun 2016 Posts: 23
|
|
Posted: Sun Jul 03, 2016 1:45 am |
|
|
I don't get any warnings that would matter, just variables not used. i could write a simple program but wouldn't have an easy way of testing it. This chip goes into a board that controls industrial equipment and the Port B interrupts don't happen until an extensive set of operations complete.
It is likely a change to the interrupt processing or a code issue that was ignored in the previous version is at fault since the same code compiled with 4.016 works and if I compile it with 5.061, it doesn't.
Do you know of any working code in the code library that used Port B interrupts that I can compare against?
Or even bug fixes to the compiler that may have affected this? |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1908
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jul 03, 2016 10:47 am |
|
|
I tested INT_RB with vs. 5.061 and it works. I have a pushbutton switch
to ground, with a 4.7K pullup to +5v, connected to Pin B4 on the PIC.
When I push and release the switch, I get "AB" and then "CD", etc.,
displayed on TeraTerm. Sometimes I get a double tap, probably because
of contact bounce noise from the switch.
I don't use fixed_io() myself, but I left it in below because you had it.
Code: | #include <18F452.h>
#fuses HS,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=20M)
#use rs232(baud=9600, UART1, ERRORS)
#use fixed_io(b_outputs = PIN_B0, PIN_B1, PIN_B2, PIN_B3)
#byte PortB = getenv("SFR:PORTB")
//------------------------------------
#int_rb
void encoder_cnt()
{
static int8 c = 'A';
int8 temp;
putc(c); // Send a char to Teraterm for every RB interrupt
c++; // Increment char for next time A,B,C,D, etc.
temp = PortB; // Read PortB to clear change condition latch
}
//=====================================
void main()
{
int8 temp;
port_b_pullups(TRUE);
delay_us(10); // Allow time for weak pullups to go active
temp = PORTB; // Read PortB to clear change condition latch
clear_interrupt(INT_RB);
enable_interrupts(INT_RB);
enable_interrupts(GLOBAL);
while(TRUE);
} |
|
|
|
gjm27n
Joined: 15 Jun 2016 Posts: 23
|
|
Posted: Sun Jul 03, 2016 7:25 pm |
|
|
Thanks, knowing it still works means my code is the issue and gives me a direction forward. Something may have changed between 4.016 and 5.061 that allowed it before and needs to be fixed now. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jul 03, 2016 7:55 pm |
|
|
Quote: | I have optimization turned off |
What does that mean ? Post the line of code that does that. |
|
|
gjm27n
Joined: 15 Jun 2016 Posts: 23
|
|
Posted: Sun Jul 03, 2016 10:35 pm |
|
|
In MPLAB, Project->Build Options->Project
Under CCS Compiler Tab, Category->Optimization, slider to low.
+DF +LN I+="$(INCDIR)" +T +A +M -Z +Y=0 +EA
The Y value is optimization |
|
|
gjm27n
Joined: 15 Jun 2016 Posts: 23
|
|
Posted: Mon Jul 04, 2016 11:57 am |
|
|
Out of desperation (I have an angry customer and this is way overdue), I decided to re-wire stuff so I can test the simple routine.
I wired B6 & B7 with 10K pull-ups and a switch to ground so I can run a simple program to catch interrupts.
I only made 2 small modifications to your test code. I changed the terminal baud rate to 57600 and added a putc() at the start just to make sure I was sending data.
Still no interrupts so it must be my development environment/configuration. I'm running an older version of MPLAB (ver 8.63) with CCS (ver 5.061). I have the optimization level set at 0.
Code: |
#include <18F452.h>
#fuses HS,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=20M)
#use rs232(baud=57600, UART1, ERRORS)
#use fixed_io(b_outputs = PIN_B0, PIN_B1, PIN_B2, PIN_B3)
#byte PortB = getenv("SFR:PORTB")
//------------------------------------
#int_rb
void encoder_cnt()
{
static int8 c = 'A';
int8 temp;
putc(c); // Send a char to Teraterm for every RB interrupt
c++; // Increment char for next time A,B,C,D, etc.
temp = PortB; // Read PortB to clear change condition latch
}
//=====================================
void main()
{
int8 temp;
port_b_pullups(TRUE);
delay_us(10); // Allow time for weak pullups to go active
temp = PORTB; // Read PortB to clear change condition latch
clear_interrupt(INT_RB);
enable_interrupts(INT_RB);
enable_interrupts(GLOBAL);
delay_us(500); // Allow time for RS232 caps to charge
putc('X');
while(TRUE);
} |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jul 04, 2016 1:48 pm |
|
|
It works for me on my PicDem2-Plus (non-rohs vs.) board.
Can you compile this latest program with your vs. 4.016 compiler ?
Does it work ? If so, post the .HEX file.
Also, can you post the .HEX file contents for the vs. 5.061 compilation ?
I'll compare it to mine, and I'll test it too.
Quote: | so it must be my development environment/configuration |
I'm using MPLAB vs. 8.92 which is the last of vs. 8.xx.
I tested the program in Release and Debug modes. It worked on both.
I tested pins B4, B6 and B7, moving a pushbutton to each one. It all worked.
I am using a Pickit3 programmer. I have been leaving it connected
to the board during testing. But it works if the Pickit3 is disconnected.
I can't make it fail. I'm trying to think of some mechanism where it
could fail.
What is the silicon revision of your 18F452 ? Mine says this:
Quote: | Device ID Revision = 00000006 |
Last edited by PCM programmer on Mon Jul 04, 2016 2:13 pm; edited 1 time in total |
|
|
gjm27n
Joined: 15 Jun 2016 Posts: 23
|
|
Posted: Mon Jul 04, 2016 2:13 pm |
|
|
I have a dumb question, how do I post a hex file? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jul 04, 2016 2:15 pm |
|
|
You open the .HEX file in a text editor (could be MPLAB), and press Ctrl-A
to select all the text. Then Ctrl-C to copy it to the Windows clipboard.
Then open a reply box on the forum and press Ctrl-V to paste it in.
Be sure to tell me which CCS version the HEX file was compiled with.
Note that I was still editing and adding text to my previous post.
Please read it again. |
|
|
gjm27n
Joined: 15 Jun 2016 Posts: 23
|
|
Posted: Mon Jul 04, 2016 2:53 pm |
|
|
I have version 4.119 and MPLAB 8.63 on my notebook and compiled the code. Burned a chip and tested it. It didn't generate an interrupt. Ran a diff on the files and there is a bit of difference. Couldn't figure out how to rev number on chip.
ver 4.119 & MPLAB 8.63
Code: |
:0400000078EF00F0A5
:08000800046ED8CF05F0E0CF33
:1000100006F00001E9CF0CF0EACF07F0E1CF08F0DD
:10002000E2CF09F0D9CF0AF0DACF0BF0F3CF12F01C
:10003000F4CF13F0FACF14F0F5CF15F0F6CF16F099
:10004000F7CF17F000C00EF001C00FF002C010F0A3
:1000500003C011F0F2A630EF00F0F2B05CEF00F058
:100060000EC000F00FC001F010C002F011C003F08C
:100070000CC0E9FF07C0EAFF078E08C0E1FF09C016
:10008000E2FF0AC0D9FF0BC0DAFF12C0F3FF13C0B2
:10009000F4FF14C0FAFF15C0F5FF16C0F6FF17C035
:1000A000F7FF045006C0E0FF05C0D8FF10009EA86F
:1000B00057EF00F0AD6E000C1B5057EC00F01B2A00
:1000C00081CF1FF0F29030EF00F0030E1E5ED8A03B
:1000D00076EF00F0EA6A1E0EE96EEF50D8B476EFC4
:1000E00000F074EF00F000D0EF2EFDD79CEF00F091
:1000F000F86AD09E078EEA6AE96A1A6A150EAF6E30
:10010000A60EAC6E900EAB6E410E1B6EC180C1820E
:10011000C184C196F19E100E006E002EFED7000025
:1001200081CF1CF0F290F286C00EF212020E1D6E0C
:10013000F90E1E6E65EF00F01D2EFAD7580E57EC23
:0A01400000F0A1EF00F0A3EF00F0C3
:020000040030CA
:0E00000000220D0E000101000FC00FE00F40A6
:00000001FF
;PIC18F452
;CRC=4E11 CREATED="04-Jul-16 13:44"
|
ver 5.061 & MPLAB 8.63
Code: |
:0400000078EF00F0A5
:08000800046ED8CF05F0E0CF33
:1000100006F00001E9CF0CF0EACF07F0E1CF08F0DD
:10002000E2CF09F0D9CF0AF0DACF0BF0F3CF12F01C
:10003000F4CF13F0FACF14F0F5CF15F0F6CF16F099
:10004000F7CF17F000C00EF001C00FF002C010F0A3
:1000500003C011F0F2A630EF00F0F2B05CEF00F058
:100060000EC000F00FC001F010C002F011C003F08C
:100070000CC0E9FF07C0EAFF078E08C0E1FF09C016
:10008000E2FF0AC0D9FF0BC0DAFF12C0F3FF13C0B2
:10009000F4FF14C0FAFF15C0F5FF16C0F6FF17C035
:1000A000F7FF045006C0E0FF05C0D8FF10009EA86F
:1000B00057EF00F0AD6E12001B5057EC00F01B2AFA
:1000C00081CF1FF0F29030EF00F0030E1E5ED8A03B
:1000D00076EF00F0EA6A1E0EE96EEF50D8B476EFC4
:1000E00000F074EF00F000D0EF2EFDD79AEF00F093
:1000F000F86AD09E078E1A6A150EAF6EA60EAC6E09
:10010000900EAB6E410E1B6EC180C182C184C19640
:10011000F19E100E006E002EFED7000081CF1CF065
:100120008150F286C00EF212020E1D6EF90E1E6E86
:1001300065EF00F01D2EFAD7580E57EC00F09FEF38
:0601400000F0A1EF00F049
:020000040030CA
:0E00000000220D0E000101000FC00FE00F40A6
:00000001FF
;PIC18F452
;CRC=D09E CREATED="04-Jul-16 13:49"
|
|
|
|
gjm27n
Joined: 15 Jun 2016 Posts: 23
|
|
Posted: Mon Jul 04, 2016 2:55 pm |
|
|
Can you post a copy of your hex file that works? Also let me know what baud it uses. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jul 04, 2016 3:04 pm |
|
|
This hex file works. It uses #opt 0 and the baud is 57600. I wanted it to
be the same as your setup. So I did that.
Code: | :0400000078EF00F0A5
:08000800046ED8CF05F0E0CF33
:1000100006F00001E9CF0CF0EACF07F0E1CF08F0DD
:10002000E2CF09F0D9CF0AF0DACF0BF0F3CF12F01C
:10003000F4CF13F0FACF14F0F5CF15F0F6CF16F099
:10004000F7CF17F000C00EF001C00FF002C010F0A3
:1000500003C011F0F2A630EF00F0F2B05CEF00F058
:100060000EC000F00FC001F010C002F011C003F08C
:100070000CC0E9FF07C0EAFF078E08C0E1FF09C016
:10008000E2FF0AC0D9FF0BC0DAFF12C0F3FF13C0B2
:10009000F4FF14C0FAFF15C0F5FF16C0F6FF17C035
:1000A000F7FF045006C0E0FF05C0D8FF10009EA86F
:1000B00057EF00F0AD6E12001B5057EC00F01B2AFA
:1000C00081CF1FF0F29030EF00F0030E1E5ED8A03B
:1000D00076EF00F0EA6A1E0EE96EEF50D8B476EFC4
:1000E00000F074EF00F000D0EF2EFDD79AEF00F093
:1000F000F86AD09E078E1A6A150EAF6EA60EAC6E09
:10010000900EAB6E410E1B6EC180C182C184C19640
:10011000F19E100E006E002EFED7000081CF1CF065
:100120008150F286C00EF212020E1D6EF90E1E6E86
:1001300065EF00F01D2EFAD7580E57EC00F09FEF38
:0401400000F00300C8
:020000040030CA
:0E00000000220E0E000181000FC00FE00F4025
:00000001FF
;PIC18F452
;CRC=6CFB CREATED="04-Jul-16 13:59" |
|
|
|
|