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

[SOLVED]Basic float type cannot be assigned a value

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



Joined: 07 Dec 2016
Posts: 60
Location: Northeast USA

View user's profile Send private message

[SOLVED]Basic float type cannot be assigned a value
PostPosted: Wed Mar 22, 2017 8:47 am     Reply with quote

CCS v5.070
MPLAB X IDE v3.40
PIC24FJ256GB210

I am trying to figure out if I have a compiler misunderstanding or if MPLAB is somehow not playing nicely with floats.

I am trying to do some basic floating point arithmetic and then set up a Watch within MPLAB's Debug mode to test my assumptions. Entirety of test code is below:

Code:

#include <24FJ256GB210.h>
#fuses NOWDT,NOWRT,NOPROTECT//,NOWPDIS,NOWPCFG,NOIESO,NOWPFP
#device PIC24FJ256GB210 ICD=TRUE 
#use delay(INTERNAL=8MHz, CLOCK=8MHz)


float a;
float b;
float c;

void main (void)
{
   
    a = 1.5;
    b = 2.5;
    c = a + b;
   
    while(1){
        output_toggle(PIN_D0);   // Let me know PIC is operating
        delay_ms(250);
    }
   
   
    return;
}



When I pause the debugger, the Watches / Variables get updated and I can see the current value of a variable. Using int8 or int16 or longs seems to be working fine. Using floats as in the code above shows me this consistently:



Optimizations in CCS are set to 0, and variables a,b,c are global. So I'm not certain what is happening here and why a,b,c never take on a value. Anyone have insight into if this is an MPLAB issue or a CCS idiosyncrasy?


Last edited by apakSeO on Wed Mar 22, 2017 11:39 am; edited 1 time in total
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Wed Mar 22, 2017 9:27 am     Reply with quote

What type are you setting the watch up 'as'?.

MPLAB-X supports a lot of different types for floats.

For the PIC16/18, you need to select MCHP float, with the LSB first option.
For the PIC24/30/33, you need to select Float32 (or 64 for the CCS 'double'). Again LSB first.

Right click, 'display value as'.

You really need to be asking on the MPLAB forum. People there will know MPLAB-X. We mainly try to avoid it, since it is so unreliable (every version I try has different bugs from the one before....).
apakSeO



Joined: 07 Dec 2016
Posts: 60
Location: Northeast USA

View user's profile Send private message

PostPosted: Wed Mar 22, 2017 11:38 am     Reply with quote

Ttelmah wrote:
What type are you setting the watch up 'as'?.

MPLAB-X supports a lot of different types for floats.

For the PIC16/18, you need to select MCHP float, with the LSB first option.
For the PIC24/30/33, you need to select Float32 (or 64 for the CCS 'double'). Again LSB first.

Right click, 'display value as'.

You really need to be asking on the MPLAB forum. People there will know MPLAB-X. We mainly try to avoid it, since it is so unreliable (every version I try has different bugs from the one before....).


Thanks again, Ttelmah. I could not discern if this was a CCS issue or an MPLAB issue, so I posted here first.

It was indeed an issue with MPLAB. Originally, the 'display value as' was set to "Microchip Float". I had to set 'display value as' to "IEEE Float" in order to see the proper values for my floats.

Thanks for the tip, I will look more into these display value types.
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