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

multiplication...again

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



Joined: 30 Sep 2003
Posts: 89

View user's profile Send private message

multiplication...again
PostPosted: Fri Mar 31, 2006 9:28 am     Reply with quote

PCWH 3.245

I know I asked about multiplying before and I did look at the previous messages on this subject, but this just plain bothers me.

Here is the code.

Code:

#define BIT_RESPONSE_ENTRY_SIZE 9
signed int16 y;
signed int8 x;
x=0;

//y ends up being 1
y=(unsigned)x*(unsigned)BIT_RESPONSE_ENTRY_SIZE;
printf("ux=0x%x, y=0x%x, uBIT_RESPONSE_ENTRY_SIZE=0x%x\n\r",x,y,BIT_RESPONSE_ENTRY_SIZE);

//y still ends up being 1
y=(unsigned int16)x*(unsigned)BIT_RESPONSE_ENTRY_SIZE;
printf("u16x=0x%x, y=0x%x, uBIT_RESPONSE_ENTRY_SIZE=0x%x\n\r",x,y,BIT_RESPONSE_ENTRY_SIZE);

//this works, as I expected it would
y=_mul((unsigned)x,(unsigned)BIT_RESPONSE_ENTRY_SIZE);
printf("x=0x%x, y=0x%x, BIT_RESPONSE_ENTRY_SIZE=0x%x\n\r",x,y,BIT_RESPONSE_ENTRY_SIZE);
/


x always equals 0 in this example, why can't I get 0 as a result?
_________________
-Pete
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Mar 31, 2006 11:29 am     Reply with quote

Quote:
why can't I get 0 as a result?

What PIC are you using ? I made your code into the following test
program, and compiled it for both the 16F877 and 18F452 with vs. 3.245
and got these results:

Code:

ux=0x00, y=0x00, uBIT_RESPONSE_ENTRY_SIZE=0x09

u16x=0x00, y=0x00, uBIT_RESPONSE_ENTRY_SIZE=0x09

x=0x00, y=0x00, BIT_RESPONSE_ENTRY_SIZE=0x09



Code:

#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

#define BIT_RESPONSE_ENTRY_SIZE 9
 
//=======================
void main()
{
signed int16 y;
signed int8 x;
x=0;

//y ends up being 1
y=(unsigned)x*(unsigned)BIT_RESPONSE_ENTRY_SIZE;
printf("ux=0x%x, y=0x%x, uBIT_RESPONSE_ENTRY_SIZE=0x%x\n\r",x,y,BIT_RESPONSE_ENTRY_SIZE);

//y still ends up being 1
y=(unsigned int16)x*(unsigned)BIT_RESPONSE_ENTRY_SIZE;
printf("u16x=0x%x, y=0x%x, uBIT_RESPONSE_ENTRY_SIZE=0x%x\n\r",x,y,BIT_RESPONSE_ENTRY_SIZE);

//this works, as I expected it would
y=_mul((unsigned)x,(unsigned)BIT_RESPONSE_ENTRY_SIZE);
printf("x=0x%x, y=0x%x, BIT_RESPONSE_ENTRY_SIZE=0x%x\n\r",x,y,BIT_RESPONSE_ENTRY_SIZE);

while(1);
}
pfournier



Joined: 30 Sep 2003
Posts: 89

View user's profile Send private message

PostPosted: Fri Mar 31, 2006 12:00 pm     Reply with quote

Sorry about that, I am using the 18LF8622.

That makes for even stranger results.
_________________
-Pete
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Mar 31, 2006 2:02 pm     Reply with quote

I made a test program for the 18F8622 and compiled it with PCH 3.245.
I don't have your hardware so I used MPLAB simulator and used "UART1"
to display the output. It worked OK. Here are the results:
Code:

ux=0x00, y=0x00, uBIT_RESPONSE_ENTRY_SIZE=0x09

u16x=0x00, y=0x00, uBIT_RESPONSE_ENTRY_SIZE=0x09

x=0x00, y=0x00, BIT_RESPONSE_ENTRY_SIZE=0x09

What do you get if you run it in MPLAB simulator ?

(This post gives instructions on using UART1 for output.
http://www.ccsinfo.com/forum/viewtopic.php?t=23408&start=1
The comments about flaky behavior don't apply to current
versions of MPLAB.)
Code:

#include <18F8622.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

#define BIT_RESPONSE_ENTRY_SIZE 9
 
//=======================
void main()
{
signed int16 y;
signed int8 x;
x=0;

//y ends up being 1
y=(unsigned)x*(unsigned)BIT_RESPONSE_ENTRY_SIZE;
printf("ux=0x%x, y=0x%x, uBIT_RESPONSE_ENTRY_SIZE=0x%x\n\r",x,y,BIT_RESPONSE_ENTRY_SIZE);

//y still ends up being 1
y=(unsigned int16)x*(unsigned)BIT_RESPONSE_ENTRY_SIZE;
printf("u16x=0x%x, y=0x%x, uBIT_RESPONSE_ENTRY_SIZE=0x%x\n\r",x,y,BIT_RESPONSE_ENTRY_SIZE);

//this works, as I expected it would
y=_mul((unsigned)x,(unsigned)BIT_RESPONSE_ENTRY_SIZE);
printf("x=0x%x, y=0x%x, BIT_RESPONSE_ENTRY_SIZE=0x%x\n\r",x,y,BIT_RESPONSE_ENTRY_SIZE);

while(1);
}
pfournier



Joined: 30 Sep 2003
Posts: 89

View user's profile Send private message

PostPosted: Fri Mar 31, 2006 2:43 pm     Reply with quote

Sorry, I don't have MPLAB. I'm running on real hardware.
_________________
-Pete
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Mar 31, 2006 3:14 pm     Reply with quote

If you have a high speed internet connection you could download it:
http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en019469&part=SW007002
I'm using MPLAB vs. 7.20. The latest is vs. 7.31.

Suggestions:

1. If you have a hardware debugger, you could step through the code
while it's running in your hardware, and look at the intermediate values
and determine where it does something incorrectly.

2. You could step through the code in the MPLAB simulator and at the
the same time, step through the code with your hardware debugger
(perhaps in the CCS IDE). Compare the results at each step. Look at
the internal registers window for differences.

3. You could greatly simplify your test program. Strip it down to
a very simple printf statement. Don't use casting qualifiers that
could possibly be misinterpreted by the compiler, such as "unsigned".
Use CCS-specific keywords such as "int8" or "int16", which mean
"unsigned 8-bit integer" and "unsigned 16-bit integer". In other
words, don't leave anything to chance. Lock down everything.
Once you've simplified the program, see if you still get the error.
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