View previous topic :: View next topic |
Author |
Message |
Mrinmoy
Joined: 20 Dec 2023 Posts: 15
|
PIC24F Series 64-bit data handling Problem |
Posted: Wed Nov 13, 2024 3:29 am |
|
|
Hi,
I am using PIC24FJ512GU406 in one of my project and my CCS compiler version is V-5.101.
Code: |
unsigned int64 g_ui64TestTemp = 1270000;
unsigned int64 g_ui64WtSum = 0;
for(g_stADCDataQ.m_i16Rear = 0; g_stADCDataQ.m_i16Rear < 4196; g_stADCDataQ.m_i16Rear++)
{
g_ui64WtSum = g_ui64WtSum + g_ui64TestTemp;
}
|
This is a sample code that I have tried and in my actual application the same thing I have to implement. But in both cases I have seen that the Sum variable can not contain data that cross 32-bit; i.e. the answer should come 5328920000 but actually it comes 1033952704. If I down the range from 4196 to 2048 or something nearby then the sum value comes accurate which is within 32-bit range.
Can anyone please help me about this. Its urgent.
Thanks in Advance. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Wed Nov 13, 2024 6:35 am |
|
|
I just cut your code down to a mini test version, and ran it on your compiler
version:
Code: |
#include <main64.h> //processor clock etc..
void main(void)
{
int16 g_stADCDataQ;
char result[32];
unsigned int64 g_ui64TestTemp = 1270000;
unsigned int64 g_ui64WtSum = 0;
for(g_stADCDataQ = 0; g_stADCDataQ < 4196; g_stADCDataQ++)
{
g_ui64WtSum = g_ui64WtSum + g_ui64TestTemp;
}
sprintf(result, "%lu", g_ui64WtSum);
while(TRUE)
{
delay_cycles(1);
}
}
|
and 'result' contains 5228920000
It works fine.
Whatever you are doing with this afterwards, or how you are displaying it,
is where the 32bit limitation is appearing. |
|
|
Mrinmoy
Joined: 20 Dec 2023 Posts: 15
|
|
Posted: Thu Nov 14, 2024 12:04 am |
|
|
Yes. You are right.
This limitation has MPLAB IDE itself, but internally it is working perfectly.
You just show a good way to handle such problems that I learned.
Thanks for support. |
|
|
|