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

Bug with PWM when frequency is reduced #26

Closed
mstrens opened this issue Feb 9, 2020 · 1 comment
Closed

Bug with PWM when frequency is reduced #26

mstrens opened this issue Feb 9, 2020 · 1 comment

Comments

@mstrens
Copy link

mstrens commented Feb 9, 2020

For STM32, the timer used by PWM is a 16 bit.
In file spindle_control.c a new type (SPINDLE_PWM_TYPE) has been define to take care of this.

Still in file stepper.c, there are 2 fields that are used to store rpm values (converted in PWM timer values). Those 2 fields should be defined as SPINDLE_PWM_TYPE too.
Otherwise, when frequency is reduced to e.g. 2000Hz, the max value for the timer is 500 and exceed a uint8_t and stepper.c generates wrong PWM.

The 2 fields to redefine are :
Here my changes:

#ifdef VARIABLE_SPINDLE
//uint8_t spindle_pwm; replaced by mstrens for STM32 by next line
SPINDLE_PWM_TYPE spindle_pwm; // SPINDLE_PWM_TYPE is Uint16_t for STM32 and uint8_t for AVR
#endif

and the second:

#ifdef VARIABLE_SPINDLE
float inv_rate; // Used by PWM laser mode to speed up segment calculations.
//uint8_t current_spindle_pwm; // replaced by mstrens by next line for STM32
SPINDLE_PWM_TYPE current_spindle_pwm; // for STM32 SPINDLE_PWM_TYPE must be uint16_t
#endif

@robomechs
Copy link
Owner

fixed

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

No branches or pull requests

2 participants