Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Help, CCS PIC-C Compiler...

Status
Not open for further replies.

Kenton

New Member
Hi there,

I'm new to this board and a newbie on both PIC and C programming language. I am 16 years old and also a student. Rigt now I am trying to make a small application on the PIC 16F648A, which I try to turn into a solar panel controller to swing the panel into the most efficient position towards the sun.

So what is my problem?
Well, I use the CCS Pic-C Compiler v3.202. It seems that this version have a bug inside the compiler. If I declare a float and put a floating point value in to it, there will always occur a rounding error. For example:

float num;
num = 5.5;

The content of the variable "num", will now be "5.499999999...". Any float value will have the same effect. Pretty anoying for me, actually.

Yes, a friendly soul from this board have already told me that there is a better compiler from Microchip, called "MCC18". For the next project, I could try to test this one instead. But as it is now, I have already invested some time on a sourcecode for the CSS Compiler. And the time is running out as well, to finnish this current school-project of mine.

So, I would like to get in touch with anyone who is using the CCS compiler today, just to ask some technical questions.

/Kenton
 
Kenton,

Are you aware that CCS has a website and support forums? It would make more sense to look for help at the source.

Mike
 
As I mentioned...
I'm a student and don't have lot's of bucks. If you know what I mean.

Hoped anyone could help me here instead. :cry:
 
Yes, the CCS board is free, and if you go there you will be able to find out if v 3.02 has a bug or not.
It doesn't matter where you go, but you will have to give some example of your code to get help with it.

Yes, a friendly soul from this board have already told me that there is a better compiler from Microchip, called "MCC18". For the next project, I could try to test this one instead. But as it is now, I have already invested some time on a sourcecode for the CSS Compiler.

The compiler from Microchip is good, but it is for the high end PICs (18xxx.) Unlike the CCS compiler, mc18 can produce object files; it uses a linker. Also, CCS has a ton of drivers, and library functions which make it easy, which mc18 does not, so probably a lot of what you developed in ccs will not help you with other compilers, but the knowlege you gained will.

Why are you using an f84? That is a typo, isn't it?
on the PIC 16F648A, which
The 16F628 or 16F88 are both 18 pin, and way mo' better chips!

So what, is this a stolen version...
As I mentioned...
I'm a student and don't have lot's of bucks. If you know what I mean.

Anyway, good luck if you don't want to give out any info. The best place to get help would be the CCS forum!

Regards,
Robert
 
That's how floating point numbers work. Since they provide enormous range their accuracy is quite limited. You might take a look at fixed point math if you want to avoid rounding errors (with the penalty of limited range and precision).

Dan East
 
BeeBop said:
The compiler from Microchip is good, but it is for the high end PICs (18xxx.) Unlike the CCS compiler, mc18 can produce object files; it uses a linker. Also, CCS has a ton of drivers, and library functions which make it easy, which mc18 does not, so probably a lot of what you developed in ccs will not help you with other compilers, but the knowlege you gained will.

MCC18 does have built-in functions, but for MCC18, CCS, or any compiler they're really not such a good idea. CCS overpromotes theirs to the point where they actually discourage you from even writing C in favor of using their tasks. Me, I hate preprogrammed functions for the most part. They are not portable to other compilers, won't necessarily do what what you need it to do, and most of all are a crutch that keep you from learning how the PIC works and how C works.

I tried to use CCS once and quickly found it was basically junk, it does NOT implement all of the C-language. In fact it was apparent that the tasks I'd solved with other compilers were flat out impossible in CCS no matter how you tried to write it because of terrible deficiencies in the compiler. I inquired on that point with them and verified, yep, there would never be a way to write certain types of code. It led me to conclude that the compiler was written by people who had no idea how to write even moderately advanced C code. In case you can't tell their deficiencies just pissed me off big time.
 
Hmm....

Still no one here, who is actually using the CSS compiler. If there is anyone here that does, please PM me.

I'm currently working on a school-project, where I'm actually in short of time. I don't wanna think right now of learning myself a new compiler. As soon as this project is over, I will probably do.

Any nice guy out there, is most welcome to send me a PM!

/Kenton
 
Your logic is fault.

5.499999999 is no difference to 5.5 in everyday maths and application. If your software has to depends on 5.5 to work but failed with 5.499999999, then it is badly designed in the first place.

Can you enlighten us here in the forum why it is so?

Do not place the blame on the compiler.
 
Well...
Sounds like the Intel Pentium Bug I've read about, doesn't it? Luckily I was too young at the time when Intel sold those CPU:s.

About the CCS... I have been spoken with an older friend that used to make programs for smaller CPU:s, but today only make software for Windows. He said that this was a very strange and serious bug for a compiler. He have never stumbled into something like this before.

I think I got your point, anyway. "5.5" and "5.499999999..." is... well, almost the same. But would you buy a pocket calculator that displayed "5.49999...." instead of "5.5"? A bit anoying, I'll guess. And as I get some other strange results from math operations in this compiler, I'm not sure if only the storage of a float is the only problem with this version.

/Kenton
 
Kenton said:
Well...
Sounds like the Intel Pentium Bug I've read about, doesn't it? Luckily I was too young at the time when Intel sold those CPU:s.

About the CCS... I have been spoken with an older friend that used to make programs for smaller CPU:s, but today only make software for Windows. He said that this was a very strange and serious bug for a compiler. He have never stumbled into something like this before.

I think I got your point, anyway. "5.5" and "5.499999999..." is... well, almost the same. But would you buy a pocket calculator that displayed "5.49999...." instead of "5.5"? A bit anoying, I'll guess. And as I get some other strange results from math operations in this compiler, I'm not sure if only the storage of a float is the only problem with this version.

As everyone else has said, this isn't a problem with the compiler, it's a problem with using floating point maths - which isn't accurate. As for pocket calculators they give exactly the same problems, but not as noticeably as they use many more bits.

The 'problem' is down to your use of floating point, when it's probably not required? - suitable scaling, and using integer maths will be much faster, much shorter, and much more accurate. For an example, instead of using £1.27 or $1.27, use 127 pence or 127 cents instead - if you need to display a decimal point, simply add it at the end.

So there's no bug, no problem, and it sounds like your friend doesn't know what he's talking about?.
 
Probably true...
Maybe the CSS Compiler lacks in resolution bits for the floats then. I wonder if this is the case with later versions than I use then...

I would love to rewrite the source using only integer math, but my project will be overdue in time then, for my exam... :cry:

I hoped to find anyone here that could tell me about similar experiences on using the CSS Pic-C compiler...
 
Kenton said:
Probably true...
Maybe the CSS Compiler lacks in resolution bits for the floats then. I wonder if this is the case with later versions than I use then...

It's the same with any compiler, including Windows ones - it's just a question of how many bits you want to waste on your variables. With a PIC you've only got very limited memory space, so you can't afford to waste them for no reason.

I would love to rewrite the source using only integer math, but my project will be overdue in time then, for my exam... :cry:

Why are you using floats anyway?, there doesn't seem any need for them for your application.

BTW, don't want to dismiss your project (and I'm sure the exam board will like it), but have you measured the amount of extra energy generated by having the panel move, as against having it accurately fixed in the optimum fixed position?. Then measure how much power you lose by moving the dish - I suspect you may be disappointed with the results - particularly considering the much greater failure risk of a steerable panel.
 
Kenton said:
Probably true...
Maybe the CSS Compiler lacks in resolution bits for the floats then. I wonder if this is the case with later versions than I use then...

I would love to rewrite the source using only integer math, but my project will be overdue in time then, for my exam... :cry:

No, the CCS compiler uses 32 bit floats in the "Microchip" format. The problem is still unusual.

Now when you say you "get" 5.499999, how are you "getting" it? Is this what a simulator tells you or what?

Any time you need to do rounding, it is advisable to round it properly. For example, if you need to treat this float with 0.1 accuracy, you should add 0.05 to it if positive or subtract 0.05 if negative. So 5.45-5.5499999 will round to 5.5 which is what you want.

Converting the code you describe to the proper integer math should take less time than it took to discuss this question, frankly. Also since this is for a grade, you should consider how your instructor will view this code. It's inappropriate and does not demonstrate an understanding of how to write microcontroller code. If this is college-level, I'd give it a pretty low grade.
 
but have you measured the amount of extra energy generated by having the panel move, as against having it accurately fixed in the optimum fixed position?. Then measure how much power you lose by moving the dish - I suspect you may be disappointed with the results - particularly considering the much greater failure risk of a steerable panel.

:) That's an application issue! My concern is only about the technical part! My hope is to work one day as an engineer, only to solve things that are requested to me to solve (and hopefully very good). In this case, there were no agenda about taking the power loss into calculation. I don't believe my small project can solve the earths energi crise! :lol:

Sincerely,
Kenton
 
Oznog said:
No, the CCS compiler uses 32 bit floats in the "Microchip" format. The problem is still unusual.

Yes... 32 bits should actually be a quite good margin for float resolution, I think. The way I've been testing the results, is by putting sections from the sourcecode (full source still not finnished) into a PIC and monitor the result as numbers thru the RS232 port into a PC (Hyperterminal).

I would like (or love) to get in touch with someone here that is using a later version of the CSS Compiler and ask for a small compiling favor on a small section of my source, in order to investigate if there is a bug or not in the version I'm using.

/Kenton
 
Still, back to the original suggestion- while the problem is an interesting curiousity, in any case it's the wrong solution for your task and it should only take a very short time to do the task properly with integers anyways. Why spend effort diagnosing a problem with a poor compiler instead of learning how to do uC math? uC code is 99.9% dealing with ints because they're far superior to floats.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top