I've found that it only happens with complicated defines. If I set
each of those defines to a literal it compiles properly and reports
the proper value. But, using a bunch of constants with math operations
causes the value of each define to come out properly but doing math on
the defines later on breaks.
Here's a more or less minimal example:
#define PWM_FREQ 7000
#define MAX_PWM_DUTY 1000
#define PWM_CLOCK (PWM_FREQ * MAX_PWM_DUTY * 2ul)
#define PWM_PICO_PER_TICK (1000000000ul / (PWM_CLOCK / 1000ul))
#define PWM_TARGET_DEADTIME 1300
#define PWM_DEADTIME ((PWM_TARGET_DEADTIME * 1000ul) / PWM_PICO_PER_TICK) + 1
#define PWM_BUFFER_NANOS 1000
#define PWM_BUFFER ((PWM_BUFFER_NANOS * 500ul) /
PWM_PICO_PER_TICK) + PWM_DEADTIME + PWM_DEADTIME
void setup() {
}
void loop() {
uint32_t temp = MAX_PWM_DUTY - PWM_BUFFER;
SerialUSB.println(MAX_PWM_DUTY);
SerialUSB.println(PWM_BUFFER);
SerialUSB.println(temp);
SerialUSB.println();
delay(1000);
}
Changing the MAX_PWM_DUTY and PWM_BUFFER defines to just a number
makes it work. Leaving them as-is with math causes them to have the
proper values but temp to be wrong. It might be relevant to mention
two more things:
1. PWM_BUFFER will not have the proper value if that line ends in +
(PWM_DEADTIME * 2) instead of adding the value twice as seen above
2. Even the 1.5.4 version of the IDE seems to have this same problem.
So, the issue is old.