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 CCS Technical Support

Strange loop

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



Joined: 20 Feb 2007
Posts: 48
Location: Essex UK

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

Strange loop
PostPosted: Tue Apr 22, 2008 10:10 am     Reply with quote

This code when compiled it places a BRA instruction immediately after the function heading void calc_x(float32 L1,float32 L2,float32 Lb)

This is incorrect.

This is the code:-

Code:
#include "C:\Program Files\PICC\location x y.h"
#include <math.h>
#define <stdio.h>
#define test pin_c7

void calc_x (float32 L1,float32 L2, float32 Lb);
void calc_y (float32 L1, float32 Xc);

static float32 Xc,Yc;

int number_of_cells;
int number_of_nodes;

void main(void)
 {   
float32 _X, _Y;
float32  L1, L2, L3, L4, Lb, x, y;     

   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF|ADC_TAD_MUL_0);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);

 
  _X=25;    //cell size
  _Y=16;

  L1=4.20;   //shortest distance                   
  L2=13.00;    //next distance
 
  Lb=_Y;

  // We contact four nodes and get four TOF figures.
  calc_x (L1,L2,Lb);     //call to Xc calculation

  Xc=Xc-_Y;                //to reference correct part of cell

  calc_y(L2,Xc);

}
//**************************** End of Main ************

//************************** Xc calculation ************
void calc_x(float32 L1,float32 L2,float32 Lb)
{
Xc=(float32)(((pow( L1,2))-(pow (L2,2))+(pow (Lb,2)))/(2*Lb));
return;
}
//************************** Yc calculation ************

void calc_y(float32 L2, float32 Xc)
{
Yc=sqrt ((pow (L2,2))-( pow (Xc,2)));
return;
}
//*********************************************

Bit of list file

04255 .................... void calc_x(float32 L1,float32 L2,float32 Lb)
04256 .................... {
135E D7FF 04257 BRA 135E
04258 .................... Xc=(float32)(((pow( L1,2))-(pow (L2,2))+(pow (Lb,2)))/(2*Lb));
0EE2 0E80 04259 MOVLW 80
0EE4 6A40 04260 CLRF 40
0EE6 6A41 04261 CLRF 41
0EE8
//*********************************************
Compiler 4.071
PIC 18F4520

.H file
Code:

#include <18F4520.h>
#device ICD=TRUE
#device adc=8

#FUSES NOWDT                      //No Watch Dog Timer
#FUSES WDT128                     //Watch Dog Timer uses 1:128 Postscale
#FUSES HS                         //Crystal osc <= 4mhz
#FUSES NOPROTECT                  //Code not protected from reading
#FUSES BROWNOUT                   //Reset when brownout detected
#FUSES BORV27                     //Brownout reset at 2.7V
#FUSES NOPUT                      //No Power Up Timer
#FUSES NOCPD                      //No EE protection
#FUSES STVREN                     //Stack full/underflow will cause reset
#FUSES DEBUG                      //Debug mode for ICD
#FUSES NOLVP                        //Low Voltage Programming on B3(PIC16) or B5(PIC18)
#FUSES NOWRT                      //Program memory not write protected
#FUSES NOWRTD                     //Data EEPROM not write protected
#FUSES IESO                       //Internal External Switch Over mode enabled
#FUSES FCMEN                      //Fail-safe clock monitor enabled
#FUSES NOPBADEN                     //PORTB pins are configured as analog input channels on RESET
#FUSES NOWRTC                     //configuration not registers write protected
#FUSES NOWRTB                     //Boot block not write protected
#FUSES NOEBTR                     //Memory not protected from table reads
#FUSES NOEBTRB                    //Boot block not protected from table reads
#FUSES NOCPB                      //No Boot Block code protection
#FUSES LPT1OSC                    //Timer1 configured for low-power operation
#FUSES MCLR                       //Master Clear pin enabled
#FUSES NOXINST                    //Extended set extension and Indexed Addressing

#use delay(clock=20000000)
//#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)

Has anyone an idea why this is happening?
_________________
Horkesley Electronics Limited
Matro
Guest







PostPosted: Tue Apr 22, 2008 11:09 am     Reply with quote

The "bug" is that this line doesn't correspond to 1st line of function but to last line of main().

Matro.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Apr 22, 2008 11:09 am     Reply with quote

It's not part of the function. Look at the address. There's no problem.
CCS doesn't write the .LST file so that all addresses are in numerical
order. They have a FAQ article on this:
http://www.ccsinfo.com/faq.php?page=lst_out_of_order
horkesley



Joined: 20 Feb 2007
Posts: 48
Location: Essex UK

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

loop
PostPosted: Tue Apr 22, 2008 11:16 am     Reply with quote

Hi

Thanks for the comments, but the code loops at this point.

Single stepping in the .LST window the code loops at this point, it never gets to the function.

Running the code from debug, it stops at this point.

Regards,
_________________
Horkesley Electronics Limited
Matro
Guest







PostPosted: Tue Apr 22, 2008 11:24 am     Reply with quote

Could you post a range of lines of the .lst file around the call to calc_x() function?

Matro.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Apr 22, 2008 11:33 am     Reply with quote

I don't have a 18F4520, but I do have a 18F452, so I compiled your
program for that PIC, with vs. 4.071. I had to comment out a few
lines such as the ADC setup, comparator setup, etc., and some of the
fuses so it would compile for that PIC.

I then "connected" to the board with an ICD2 in MPLAB. I single-stepped
until I got down to the code inside the calc_x() function. I pressed the
F8 key to execute that line of code. It took 35 seconds. That could give
you the appearance of "locking up". Floating point, especially the pow()
function, takes a massive amount of code execution time on the PIC.
horkesley



Joined: 20 Feb 2007
Posts: 48
Location: Essex UK

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

loop
PostPosted: Tue Apr 22, 2008 11:43 am     Reply with quote

Hi

Matro

Here is part of the .LST file.

04253 ....................
04254 .................... //************************** Xc calculation ***********************************
04255 .................... void calc_x(float32 L1,float32 L2,float32 Lb)
04256 .................... {
135E D7FF 04257 BRA 135E
04258 .................... Xc=(float32)(((pow( L1,2))-(pow (L2,2))+(pow (Lb,2)))/(2*Lb));
0EE2 0E80 04259 MOVLW 80
0EE4 6A40 04260 CLRF 40
0EE6 6A41 04261 CLRF 41
0EE8 6A42 04262 CLRF 42
0EEA C036 F052 04263 MOVFF 36,52
0EEE C035 F051 04264 MOVFF 35,51
0EF2 C034 F050 04265 MOVFF 34,50
0EF6 C033 F04F 04266 MOVFF 33,4F
0EFA C042 F056 04267 MOVFF 42,56
0EFE C041 F055 04268 MOVFF 41,55
0F02 C040 F054 04269 MOVFF 40,54
0F06 6E53 04270 MOVWF 53
0F08 DF74 04271 RCALL 0DF2
0F0A C000 F040 04272 MOVFF 00,40
0F0E C001 F041 04273 MOVFF 01,41
0F12 C002 F042 04274 MOVFF 02,42



PCM programmer

When single stepping in the .LST window, the cursor does not increment.

Regards,
_________________
Horkesley Electronics Limited
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Apr 22, 2008 12:00 pm     Reply with quote

I'm using MPLAB and it sure works for me. In MPLAB, you go to the
View menu, and pick "Disassembly Listing". Then you can press the
F7 or F8 key to single-step through through it. It's really slow. Using
hardware debugging is not like running the MPSIM simulator. But the
cursor is definitly advancing each time I press the key.

If you press the F8 key ("step over"), sometimes, the Output window
displays this message over and over again for several seconds.
For example, on a "call" instruction:
Quote:
MPLAB ICD 2 Ready
Stepping Target
MPLAB ICD 2 Ready
Stepping Target

Hardware debugging is really slow, but it does work. This whole
exercise reminds me of why I don't use the hardware debugger.
It takes too much time. Just write the code so it works, and if you
need to prove some segment of it, just add a printf statement to
display some intermediate values.
Matro
Guest







Re: loop
PostPosted: Tue Apr 22, 2008 12:10 pm     Reply with quote

horkesley wrote:
Hi

Matro

Here is part of the .LST file.

04253 ....................
04254 .................... //************************** Xc calculation ***********************************
04255 .................... void calc_x(float32 L1,float32 L2,float32 Lb)
04256 .................... {
135E D7FF 04257 BRA 135E
04258 .................... Xc=(float32)(((pow( L1,2))-(pow (L2,2))+(pow (Lb,2)))/(2*Lb));
0EE2 0E80 04259 MOVLW 80
0EE4 6A40 04260 CLRF 40
0EE6 6A41 04261 CLRF 41
0EE8 6A42 04262 CLRF 42
0EEA C036 F052 04263 MOVFF 36,52
0EEE C035 F051 04264 MOVFF 35,51
0EF2 C034 F050 04265 MOVFF 34,50
0EF6 C033 F04F 04266 MOVFF 33,4F
0EFA C042 F056 04267 MOVFF 42,56
0EFE C041 F055 04268 MOVFF 41,55
0F02 C040 F054 04269 MOVFF 40,54
0F06 6E53 04270 MOVWF 53
0F08 DF74 04271 RCALL 0DF2
0F0A C000 F040 04272 MOVFF 00,40
0F0E C001 F041 04273 MOVFF 01,41
0F12 C002 F042 04274 MOVFF 02,42



PCM programmer

When single stepping in the .LST window, the cursor does not increment.

Regards,

My request was to see the lines where the call is done (in the main), not where the function is. ;-)

Matro
horkesley



Joined: 20 Feb 2007
Posts: 48
Location: Essex UK

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

loop
PostPosted: Tue Apr 22, 2008 12:41 pm     Reply with quote

Matro

Here's what you asked for.

04189 .................... //We get upto four data.
04190 .................... calc_x (L1,L2,Lb); //call to Xc calculation
12D4 C01A F036 04191 MOVFF 1A,36
12D8 C019 F035 04192 MOVFF 19,35
12DC C018 F034 04193 MOVFF 18,34
12E0 C017 F033 04194 MOVFF 17,33
12E4 C01E F03A 04195 MOVFF 1E,3A
12E8 C01D F039 04196 MOVFF 1D,39
12EC C01C F038 04197 MOVFF 1C,38
12F0 C01B F037 04198 MOVFF 1B,37
12F4 C02A F03E 04199 MOVFF 2A,3E
12F8 C029 F03D 04200 MOVFF 29,3D
12FC C028 F03C 04201 MOVFF 28,3C
1300 C027 F03B 04202 MOVFF 27,3B
1304 D5EE 04203 BRA 0EE2


PCM programmer,

I am investigating various ways of doing this calculation.

I have about 1 second for each loop of calculations.

The source of the data I use is send to me in floating point, but I may be able to change the way I handle the data.


thanks for your comments
_________________
Horkesley Electronics Limited
Matro
Guest







PostPosted: Tue Apr 22, 2008 1:48 pm     Reply with quote

So that's exactly what I said.
This line :
Quote:

135E D7FF 04257 BRA 135E

isn't the first line of the calc_x() function but the last one of the main() function.
And that's normal.
The "bug" is only a presentation problem in the .lst file, and not a compiler bug.

Matro
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

Re: loop
PostPosted: Tue Apr 22, 2008 5:24 pm     Reply with quote

horkesley wrote:

When single stepping in the .LST window, the cursor does not increment.


Look for #nolist because you cant increment through unlisted code.

http://www.ccsinfo.com/forum/viewtopic.php?t=34103&highlight=nolist
Matro
Guest







Re: loop
PostPosted: Wed Apr 23, 2008 1:40 am     Reply with quote

Neutone wrote:
horkesley wrote:

When single stepping in the .LST window, the cursor does not increment.


Look for #nolist because you cant increment through unlisted code.


True! Typically, you have to remove (or comment) the #nolist at the beginning of the header file used for your chip.

Matro.
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