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

Strange jumps after printf

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ljbeng



Joined: 10 Feb 2004
Posts: 205

View user's profile Send private message

Strange jumps after printf
PostPosted: Wed Oct 04, 2006 8:14 am     Reply with quote

This is an 18F4620 chip and version 3.249.

I have a program that takes >45ms at 4MHz to display 10 characters on an lcd. That's ~ 45,000 clock cycles. So I started digging. If I do a break in the lst file and step through the program in the problem area, I get some strange jumps.

Code:
....................       printf(lcd_putc," %c%c %05.1w%c",egc1,egc2,position,temp8);
E0F0:  MOVLW  20
E0F2:  MOVLB  7
E0F4:  MOVWF  x5C
E0F6:  MOVLB  0
E0F8:  CALL   2598
E0FC:  MOVFF  1F2,75C
E100:  CALL   2598
E104:  MOVFF  1F3,75C
E108:  CALL   2598
E10C:  MOVLW  20
E10E:  MOVLB  7
E110:  MOVWF  x5C
E112:  MOVLB  0
E114:  CALL   2598
.
.
.
....................             if (systype == 0) printf(lcd_putc,"\b%c100%% ",rvc);
E3D4:  MOVF   20,F
E3D6:  BNZ   E42A
E3D8:  MOVLW  08
E3DA:  MOVLB  7
E3DC:  MOVWF  x5C
E3DE:  MOVLB  0
E3E0:  CALL   2598
E3E4:  MOVFF  18D,75C
E3E8:  CALL   2598
.
.
.
....................                printf(lcd_putc,"\t%c%04.2w%c",fwc,fwdepth,0x22);
DFD2:  MOVLW  09
DFD4:  MOVLB  7
DFD6:  MOVWF  x5C
DFD8:  MOVLB  0
DFDA:  CALL   2598
DFDE:  MOVFF  18C,75C
DFE2:  CALL   2598



When I get to E0F8 and call 2598 (lcd_putc) the program jumps to E3E4 which is the middle of an IF statement later in the program that just happens to have a printf statement as well. When that part of the program gets to CALL 2598, it jumps to DFDE which is another printf statement later in the program. Then the next CALL 2598 jumps back to E3E4. If I just keep stepping, it looks like it will do this forever but if I press GO, the program loops back to the top of my main loop. Visibly, it looks like the program is working and the data is displayed ok. I am trying to shorten my scan time in my main routine. I even tried this with interrupts disabled and it still does this. Can anyone help? Thanks.
Ttelmah
Guest







PostPosted: Wed Oct 04, 2006 9:12 am     Reply with quote

You can see from the listing, that the code does not jump to E3D4, so what you have to ask is 'why does my debugging enviroment think the code jumps to E3D4'?. Now, you don't say what the debugging enviroment is, but I'd perhaps suspect this is an ICD?. If so, your code addresses, suggest that you may be running into the problem of the code overlaying part of the ICD code. The ICD itself, needs a number of resources. Normally a few hundred bytes at the top of memory, two stack levels, some RAM etc.. If these are not available, then behaviours like you describe will occur. I think for your chip, it is 12 RAM locations, and about 640 ROM locations that are needed.
Another possibility is if you are loading the wrong ICD code for the chip, but this is normally automatic. However if the file from an older ICD setup is in the directory, confusion can result...
Have you tried the code with debugging disabled?. Does the delay disappear?.

Best Wishes
ljbeng



Joined: 10 Feb 2004
Posts: 205

View user's profile Send private message

PostPosted: Wed Oct 04, 2006 9:28 am     Reply with quote

Yes, it is the CCS ICD with 1.39 loaded. I just tried the program without debug turned on and it still has this long delay. I have 95% of rom used with debug on and 47% of RAM.
mpfj



Joined: 09 Sep 2003
Posts: 95
Location: UK

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Wed Oct 04, 2006 10:28 am     Reply with quote

Are you sure the listing file matches what's actually programmed inot the PIC ? A couple of times, I've fooled myself by compiling code into one directory, and then loading the COFF file from another Embarassed and then speding ages trying to work out what's going on !?!

Also, does this only occur when you're doing a CALL instruction ? Might there be a stack overflow problem ? Check the stack usage in the listing file.
ljbeng



Joined: 10 Feb 2004
Posts: 205

View user's profile Send private message

PostPosted: Wed Oct 04, 2006 10:55 am     Reply with quote

Code:

               ROM used: 61346 bytes (94%)
                         Largest free fragment is 4186
               RAM used: 1872 (47%) at main() level
                         1901 (48%) worst case
               Stack:    8 worst case (6 in main + 2 for interrupts)
Ttelmah
Guest







PostPosted: Wed Oct 04, 2006 2:26 pm     Reply with quote

How are you trying with 'debug turned off'?. You normally need to remove ICD=true, and also switch off loading of the firmware by the ICD (untick the box 'automatically load firmware if needed', in the ICD setup), otherwise the firmware will still be transferred into the chip when you program it.

Best Wishes
ljbeng



Joined: 10 Feb 2004
Posts: 205

View user's profile Send private message

PostPosted: Wed Oct 04, 2006 3:54 pm     Reply with quote

Ttelmah,

I do remove ICD=TRUE (and the program gets slightly smaller) but I do not see this firmware check box you speak of. Thanks.
Ttelmah
Guest







PostPosted: Thu Oct 05, 2006 2:39 am     Reply with quote

I have only used these units under MPLAB. In there it is under the settings for the ICD. However if I remember correctly, on the USB units, in the CCS setup, you turn off ICD=true, and then select 'Mach-X', instead of the ICD, which simply programs the chip, rather than handling things as if it is an ICD. I don't know how you do this on the serial units. The key is that there 'has' to be a way of telling the ICD not to transfer the extra code. ICD=true, only changes the 'stubs' in the generated code, to access the ICD, the act of using the ICD, then transfers an extra hex file (the 'icdfirmwarexxx.fw' file), into the chip. If you open this with a text editor, you will get an idea of how much extra code has to be put into the chip, and why I suspect at 94 to 95% 'full', you may be having problems with this.

Best Wishes
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Thu Oct 05, 2006 4:23 am     Reply with quote

The amount of RAM and ROM memory used by the ICD2 depends on the processor you are using. Exact quantities are given in the MPLAB helpfiles, search for the chapter 'Resources Used By MPLAB ICD 2'.

In the PIC18F4620 the ICD-2 uses Program Memory 0xFD80-0xFFFF (640 bytes), RAM 0xEF$ to 0xEFF (12 bytes) and two stack levels.

ROM, RAM and stack levels don't seem to be the limiting factor here.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Thu Oct 05, 2006 4:31 am     Reply with quote

This problem reminds me of a debug session I had. It turned out that the 'Disassembly Listing' window in MPLAB was not properly updated after compiling and I was still working with an old code view. Closing and re-opening the 'Disassembly listing' synchronized things again.
ljbeng



Joined: 10 Feb 2004
Posts: 205

View user's profile Send private message

PostPosted: Thu Oct 05, 2006 7:54 am     Reply with quote

I am only using the CCS 3.249 environment and the ICD-S40 to debug. I even made my program smaller (53%) by removing the setup and programming subroutines. I still get the long printf delays and strange jumps in both debug environment and production chips. I even tried programming the chip with my QuickWriter and still see this problem.

Thanks for all your input, people....

Does CCS have any ideas..... I will email this on....
ljbeng



Joined: 10 Feb 2004
Posts: 205

View user's profile Send private message

PostPosted: Thu Oct 05, 2006 10:37 am     Reply with quote

CCS says it is in the %w command. What can I do about that? I was using a division routine I found here and I changed to %w as it was much cleaner to code.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Oct 05, 2006 11:40 am     Reply with quote

Quote:
CCS says it is in the %w command. What can I do about that?

You're asking for a work-around for the printf %w format specifier,
because CCS tech support says it's buggy.

Post a test program (a short one), that shows a typical usage of %w
in your program. Show all variable declarations, and initialize the
variables to typical values used in your program. Also show what
you would like the output to look like (presumably on an LCD).
If you do these things, we can probably come up with a work-around.
ljbeng



Joined: 10 Feb 2004
Posts: 205

View user's profile Send private message

PostPosted: Thu Oct 05, 2006 2:32 pm     Reply with quote

Here is how I used to do it....

Code:

result = ldiv(fwdepth,100);
printf(lcd_putc,"\t%c%01ld.%02ld%c",fwc,result.quot,result.rem,0x22);


Then I found the %w command and changed them all. I just went back to an old version of the code and loaded it. It uses the ldiv command. It does not have long printf delays.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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