Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAX32660 Examples TMR #1122

Closed
tk2themax opened this issue Aug 19, 2024 · 2 comments · Fixed by #1131
Closed

MAX32660 Examples TMR #1122

tk2themax opened this issue Aug 19, 2024 · 2 comments · Fixed by #1131

Comments

@tk2themax
Copy link

tk2themax commented Aug 19, 2024

On build for MAX32660, TMR example project warns "function call is not allowed in a constant expression" on line 72(Main)

Guidance suggests that The error "function call is not allowed in a constant expression" typically occurs when you try to use a function call in a context where a compile-time constant is expected

Although this does not stop the build/compile, there is a possible linked manifestation of this in that when the DUTY_CYCLE, as DEFINED in Main(line46), value is changed in the source and recompiled and flashed, the physical PWM duty cycle on TMR GPIO 3.7 PIN does not actually change from the 50% originally set. However, when FREQ is changed (line 45), and recompiled, flashed, the frequency does change as expected.

This suggests that there is a value being set for DUTY_CYCLE which, once set is not cleared and reassigned any given new value on recompile.

CLEAN_PERIPH on build/flash did not alleviate.

@Jake-Carter
Copy link
Contributor

Thanks @tk2themax,

I think the issue was just that the DUTY_CYCLE macro was just never actually used in the example...

Can you try the fix below and confirm?

 #include "led.h"
 
 /***** Definitions *****/
-#define MAX_TICKS pow(2, 32)
+#define MAX_TICKS 4294967296
+// 2^32
 
 // Parameters for PWM output
 #define FREQ 1000 // (Hz)
@@ -77,7 +78,7 @@ void PWMTimer(void)
     // Declare variables
     mxc_tmr_cfg_t tmr; // to configure timer
     unsigned int periodTicks = MXC_TMR_GetPeriod(PWM_TIMER, 1, FREQ);
-    unsigned int dutyTicks = periodTicks / 100 * 50;
+    unsigned int dutyTicks = periodTicks * (DUTY_CYCLE / 100.0f);
 
     //Configure PWM GPIO Pin
     mxc_gpio_cfg_t pwmOut;

@tk2themax
Copy link
Author

Oh my - I missed that ! But at least there was a problem - even if my diag was off ! Thanks - all good now with this fixes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants