Hello all,

I'm somewhat in a jam.

I have a multiplication to do however it only works partially:

T2 = 11 * (C6 +24) * (200 - TEMP) * (200 - TEMP) / 2^20

I have made a C Code box with the following lines:

long t2;

t2 = 11 * (FCV_C6 + 24); This parts is alwas 561

t2 = t2 * (200-FCV_TEMP); TEMP can be anywhere from -150 to 199

t2 = t2 * (200-FCV_TEMP);

t2 = t2 >> 20;

FCV_T2 = t2;

The problem is that the calculation works untill TEMP = -55. As soon as the TEMP is lower as -55 the T2 goes to 0

My question is; Can a PIC18F4685 actally handly such a calculation?

If it does, what am I doing wrong?

Thanks

Henk

## Large multiplication

- DavidA
- Matrix Staff
**Posts:**1065**Joined:**Fri Apr 23, 2010 2:18 pm**Location:**Matrix Multimedia Ltd-
**Contact:**

### Re: Large multiplication

Hello,

I would imagine that you are using a BYTE to store one of your variables, the maximum value a byte can hold is 255. Try changing them to integers. If this isnt the case, attach your fcf file to the post and ill take a look at it.

I would imagine that you are using a BYTE to store one of your variables, the maximum value a byte can hold is 255. Try changing them to integers. If this isnt the case, attach your fcf file to the post and ill take a look at it.

### Re: Large multiplication

You could try this instead:

Code: Select all

```
long t2;
t2 = 11 * (FCV_C6 + 24);
t2 = t2 * (long)(200-FCV_TEMP);
t2 = t2 * (long)(200-FCV_TEMP);
t2 = t2 >> 20;
FCV_T2 = t2;
```

### Re: Large multiplication

Thanks Guys,

I'm using all INT so that shouldn't be a problem.

I will try your comments later Steve.

Thanks for the help.

Henk

I'm using all INT so that shouldn't be a problem.

I will try your comments later Steve.

Thanks for the help.

Henk

### Re: Large multiplication

OK, I got it working.

This is the solution:

t2 = 11 * (FCV_C6 + 24);

t2 = t2 * ((long) 200-FCV_TEMP);

t2 = t2 * ((long) 200-FCV_TEMP);

t2 = t2 >> 20;

FCV_T2 = t2;

Thanks for bringing me in the right direction.

Henk

This is the solution:

t2 = 11 * (FCV_C6 + 24);

t2 = t2 * ((long) 200-FCV_TEMP);

t2 = t2 * ((long) 200-FCV_TEMP);

t2 = t2 >> 20;

FCV_T2 = t2;

Thanks for bringing me in the right direction.

Henk

### Re: Large multiplication

Hi Henk,

Glad you got it working. Instead of "long", you can probably get away with "int" or "signed int" (this may save a small amount of processing and variable space if that's important to you).

Glad you got it working. Instead of "long", you can probably get away with "int" or "signed int" (this may save a small amount of processing and variable space if that's important to you).