In ST motor control code I have a section that compiles with warnings in the STM32CubeIDE & build okay but in Keil MDK gives an error and won't build.
#define PH_KIDIV_LOG 38 #define PH_KDDIV_LOG 10 #define PH_KPDIV (1<<PH_KPDIV_LOG) #define PH_KIDIV (1<<PH_KIDIV_LOG) #define PH_KDDIV (1<<PH_KDDIV_LOG) PID64_Handle_t g_PhaseLockPID = { .hDefKpGain = 27586, .hDefKiGain = 22611, .wUpperIntegralLimit = (int64_t) IQMAX * (int64_t)PH_KIDIV, // HERE
The left shift is 38 but it is a 64-bit word. This is error #63: shift count is too large. Can someone explain why I get the error in this case? How can I fix this or make Keil ignore it?
#define PH_KIDIV ( 1ULL << PH_KIDIV_LOG) will fix it.
#define PH_KIDIV (1<<PH_KIDIV_LOG)
both "1" and "PH_KIDIV_LOG" are integers. so it will do a 32-bit shift, not 64.
Forcing the "1" to 64-bits makes it all ok.
Thanks so much for the quick response & the explanation. Much appreciated ;)