|
|
View previous topic :: View next topic |
Author |
Message |
richi-d
Joined: 28 Aug 2007 Posts: 106
|
PIC24F no division possible? |
Posted: Sun Jul 05, 2009 8:45 am |
|
|
I use PCD 4.089 and MPLAB 8.33.
I have this program and the Division doesn't work - Why? The variable Rechendummy1 has the value: -1.27393755e-018
Rechendummy2 has the value: -4.20128342e-019
WEG_PRO_ZEIT has the value: 3.28758075e-019
After one run? Why does Rechendummy1+2 not have the values I give them?
MAIN:
Code: |
#include <24FJ128GA106.h>
//#device adc=10
#include <string.h>
#include <math.h>
#include <Main_V01.h>
void main()
{
WEGDIFFERENZ = 376;
ZEITDIFFERENZ = 31;
for(;;)
{
RECHENDUMMY_1 = WEGDIFFERENZ;
RECHENDUMMY_2 = ZEITDIFFERENZ;
WEG_PRO_ZEIT = RECHENDUMMY_1 / RECHENDUMMY_2;
}// for(;;)
}//Main()
|
MAIN_V01.H:
Code: | #FUSES FRC_PLL,NOPROTECT,NOIESO,NOJTAG,ICSP1,DEBUG
#use delay (clock=32000000)
float RECHENDUMMY_1;
unsigned int WEGDIFFERENZ;
float RECHENDUMMY_2;
unsigned int ZEITDIFFERENZ;
float WEG_PRO_ZEIT; |
Last edited by richi-d on Sun Jul 05, 2009 11:06 am; edited 2 times in total |
|
|
Ttelmah Guest
|
|
Posted: Sun Jul 05, 2009 9:35 am |
|
|
You don't actually show 'main.h', being included anywhere. Presumably main_v01....
What are you using to 'see' the values?.
Best Wishes |
|
|
richi-d
Joined: 28 Aug 2007 Posts: 106
|
|
Posted: Sun Jul 05, 2009 11:07 am |
|
|
I edited the error.
I use the MPLAB IDE Watch window. |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Sun Jul 05, 2009 3:39 pm |
|
|
You must select IEEE float format in watch window to see meaningful values. |
|
|
richi-d
Joined: 28 Aug 2007 Posts: 106
|
|
Posted: Mon Jul 06, 2009 12:54 am |
|
|
I tested all formats - no change! I´m wondering why this lines doesn´t work:
Code: |
RECHENDUMMY_1 = WEGDIFFERENZ;
RECHENDUMMY_2 = ZEITDIFFERENZ; |
Is there any other adjustments I need to do? |
|
|
Ttelmah Guest
|
|
Posted: Mon Jul 06, 2009 2:22 am |
|
|
First, I'd prove where the problem is.
If you have a serial link available, simply try printing the result to this. If you haven't, use sprintf, to print the value to a character buffer, and look at this with MPLAB. You can also look at the .sym file, and verify that the address given for the variables, is the address being selected by MPLAB.
The behaviour has all the symptoms of the debugger, either not looking at the right bytes, or using the wrong format for the numbers.
You can also again use the .sym data, and record what the four bytes actually at the location for each variable are.
Remember the default 'float' is a 32bit float for CCS.
Best Wishes |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Mon Jul 06, 2009 4:50 am |
|
|
At least with PCD V4.093, the values are prefectly converted to float. I guess, it's O.K. with your version as well. But you have to select IEEE float format for each individual float variable in the watch window, as said. Of course, printf() works as well, I wonder, why you didn't try before posting in the forum? |
|
|
richi-d
Joined: 28 Aug 2007 Posts: 106
|
|
Posted: Mon Jul 06, 2009 5:18 am |
|
|
I use the IEEE float format!!! But it still don´t show the values correct!
But I used my display now to show the values, and this works. But this is bad for debugging...
Code: | while(1)
{
WEGDIFFERENZ = 381;
ZEITDIFFERENZ = 31;
RECHENDUMMY_1 = WEGDIFFERENZ;
RECHENDUMMY_2 = ZEITDIFFERENZ;
WERT = RECHENDUMMY_1;
GetDigits();
Zahl_6x8_schreiben (THOUS,49,8);
Zahl_6x8_schreiben (HUNS,56,8);
Zahl_6x8_schreiben (TENS,63,8);
Zahl_6x8_schreiben (UNITS,70,8);
delay_ms(250);
WERT = RECHENDUMMY_2;
GetDigits();
Zahl_6x8_schreiben (THOUS,49,20);
Zahl_6x8_schreiben (HUNS,56,20);
Zahl_6x8_schreiben (TENS,63,20);
Zahl_6x8_schreiben (UNITS,70,20);
delay_ms(250);
WEG_PRO_ZEIT = RECHENDUMMY_1 / RECHENDUMMY_2;
WERT = WEG_PRO_ZEIT;
GetDigits();
Zahl_6x8_schreiben (THOUS,49,30);
Zahl_6x8_schreiben (HUNS,56,30);
Zahl_6x8_schreiben (TENS,63,30);
Zahl_6x8_schreiben (UNITS,70,30);
delay_ms(250);
} |
|
|
|
Ttelmah Guest
|
|
Posted: Mon Jul 06, 2009 6:36 am |
|
|
If you had done what I said, and looked directly at the four bytes involved, rather than posting more (totally useless) code, you or we, could have seen what was going on....
Forget about division. The value in RECHENDUMMY_1, should be the byte sequence for an IEEE float32 variable, holding '376', no division involved. This is Hex 43BC0000. The value you are giving '-1.27393755e-018 ', is the value displayed using CCS float format, for the Hex byte sequence 0000BC43. Note the reverse order.
You still have got CCS format selected, and you have the byte order set reversed somewhere (MPLAB allows you to specify this)...
Best Wishes |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Mon Jul 06, 2009 10:26 am |
|
|
It may be the case, that MPLAB behaviour has changed regarding float diisplay. Actually, PCD uses a reversed IEEE float format with the exponent byte at the lowest address. It's correctly displayed by MPLAB V8.20 by simply selecting "IEEE float" format. The byte reverse option isn't provided with this format in V8.20. |
|
|
|
|
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
|