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

PIC24F Series 64-bit data handling Problem

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



Joined: 20 Dec 2023
Posts: 15

View user's profile Send private message Send e-mail AIM Address

PIC24F Series 64-bit data handling Problem
PostPosted: Wed Nov 13, 2024 3:29 am     Reply with quote

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: 19495

View user's profile Send private message

PostPosted: Wed Nov 13, 2024 6:09 am     Reply with quote

How are you seeing this?. If using an IDE, you need to be very careful of
how it thinks the data is declared. MPLAB has problems with this.
This was described here:
[url]
http://www.ccsinfo.com/forum/viewtopic.php?t=60057&highlight=int64
[/url]
Ttelmah



Joined: 11 Mar 2010
Posts: 19495

View user's profile Send private message

PostPosted: Wed Nov 13, 2024 6:35 am     Reply with quote

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

View user's profile Send private message Send e-mail AIM Address

PostPosted: Thu Nov 14, 2024 12:04 am     Reply with quote

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