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

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))+
       (TemperatureError * P_GAIN )+

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

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?



-- hint: To leave the PICList

2002\05\01@163725 by Nick Veys

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! :) |

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


-- hint: The list server can filter out subtopics
(like ads or off topics) for you. See

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