CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Port B interrupts no longer working using 5.061
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
gjm27n



Joined: 15 Jun 2016
Posts: 23

View user's profile Send private message AIM Address

Port B interrupts no longer working using 5.061
PostPosted: Sun Jul 03, 2016 1:13 am     Reply with quote

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: 19255

View user's profile Send private message

PostPosted: Sun Jul 03, 2016 1:25 am     Reply with quote

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

View user's profile Send private message AIM Address

PostPosted: Sun Jul 03, 2016 1:45 am     Reply with quote

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: 1903

View user's profile Send private message

PostPosted: Sun Jul 03, 2016 7:28 am     Reply with quote

http://www.ccsinfo.com/forum/viewtopic.php?t=19726&highlight=interrupt+keypad
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jul 03, 2016 10:47 am     Reply with quote

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

View user's profile Send private message AIM Address

PostPosted: Sun Jul 03, 2016 7:25 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Jul 03, 2016 7:55 pm     Reply with quote

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

View user's profile Send private message AIM Address

PostPosted: Sun Jul 03, 2016 10:35 pm     Reply with quote

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

View user's profile Send private message AIM Address

PostPosted: Mon Jul 04, 2016 11:57 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Jul 04, 2016 1:48 pm     Reply with quote

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

View user's profile Send private message AIM Address

PostPosted: Mon Jul 04, 2016 2:13 pm     Reply with quote

I have a dumb question, how do I post a hex file? Embarassed
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jul 04, 2016 2:15 pm     Reply with quote

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

View user's profile Send private message AIM Address

PostPosted: Mon Jul 04, 2016 2:53 pm     Reply with quote

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

View user's profile Send private message AIM Address

PostPosted: Mon Jul 04, 2016 2:55 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Jul 04, 2016 3:04 pm     Reply with quote

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"
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group