Searching \ for '[PIC]: HiTech pre-processor' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/devices.htm?key=pic
Search entire site for: 'HiTech pre-processor'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: HiTech pre-processor'
2002\05\01@152240 by Michael Rigby-Jones

flavicon
face
I'm having some snags trying to perform some conditional compilation based
on the magnitude of a literal:

       TecDrive = (int)(
#if ((P_GAIN < 1) && (P_GAIN > 0))
       (TemperatureError / (int)(1/P_GAIN))+
#else
       (TemperatureError * P_GAIN )+
#endif

#if ((I_GAIN < 1) && (I_GAIN > 0))
       (TemperatureIntegral / (int)(1/I_GAIN));
#else
       (TemperatureIntegral * I_GAIN));
#endif

This is part of a PI (no D) control loop.  I want to be able to specify the
various gains as literals in an include file, and I wish to be able to use
gains below 1 e.g. 0.5.  However I am using integer math, and I am basicaly
trying to make the compiler replace the multiply with a divide by 1/GAIN is
the gain is less than 1 but greater than 0.

This scheme works for integer values of 1 or greater, but whenever I try to
use a fractional value I get the error "Illegal #if line (error)".  After
some experiementation is seems that any floating point value within a #if
line throws this error e.g. #if (1.0 < 2.0)  will throw the same error.

Has anyone seen this and is it an inherent limitation of the pre-processor,
or am I (most likely) doing something stupid?

Regards

Mike

--
http://www.piclist.com hint: To leave the PICList
spam_OUTpiclist-unsubscribe-requestTakeThisOuTspammitvma.mit.edu


2002\05\01@163725 by Nick Veys

flavicon
face
I was about to ask a similar question.  I tried to do compilation based
on a XTAL frequency.  I had 1.8432 and 3.6864 as the options.  When I
try to use the "#if XTAL == 1.8432" I get that very same error.  I don't
see anything in the manual about specifics of using the conditional
assembly with floating point values.

Right now my only solution is to use the x10000.  i.e. 18432 and 36864.
Both work.

Hope you/I find some help! :)

.....nickKILLspamspam@spam@veys.com | http://www.veys.com/nick

> {Original Message removed}

2002\05\03@042214 by Peter L. Peres

picon face
The standard C preprocessor uses integers only in conditionals. You can
scale your coefficients by a suitable Exp.10 and divide them again in the
C expression (define a constant like #define MULT 1000). This will not
complicate the C code because the compiler should reduce the
divide-constant-by-constant before generating code.

Peter

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


More... (looser matching)
- Last day of these posts
- In 2002 , 2003 only
- Today
- New search...