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

PA1 for spindle pwm out ? #24

Open
MeKeCNC opened this issue Oct 24, 2022 · 11 comments
Open

PA1 for spindle pwm out ? #24

MeKeCNC opened this issue Oct 24, 2022 · 11 comments

Comments

@MeKeCNC
Copy link
Contributor

MeKeCNC commented Oct 24, 2022

Can we use PA1 instead of PA8 as spindle pwm output?

@terjeio
Copy link
Contributor

terjeio commented Oct 24, 2022

Seems it is possible, from PA1 spec: USART2_RTS(9)/ADC12_IN1/TIM2_CH2(9)
driver.h must be modified for that, STEPPER_TIMER has to be changed as well as it is mapped to timer 2.

You can do it?

@MeKeCNC
Copy link
Contributor Author

MeKeCNC commented Oct 24, 2022

I will try to do it. If I am not successful, I will inform you,

@MeKeCNC
Copy link
Contributor Author

MeKeCNC commented Dec 2, 2022

Seems it is possible, from PA1 spec: USART2_RTS(9)/ADC12_IN1/TIM2_CH2(9) driver.h must be modified for that, STEPPER_TIMER has to be changed as well as it is mapped to timer 2.

You can do it?

I have modified the driver.h file for SPINDLE PWM on PA1, gives output when SPINDLE_PWM_TIMER_INV set to 1, output does not work when set to 0

// Define timer allocations.
#define STEPPER_TIMER TIM5
#define PULSE_TIMER TIM3
#define DEBOUNCE_TIMER TIM4

#ifdef SPINDLE_PWM_PORT_BASE

#if SPINDLE_PWM_PORT_BASE == GPIOA_BASE
#if SPINDLE_PWM_PIN == 1 // PA1 - TIM2_CH2
#define SPINDLE_PWM_TIMER_N 2
#define SPINDLE_PWM_TIMER_CH 2
#define SPINDLE_PWM_TIMER_INV 1
#define SPINDLE_PWM_AF_REMAP 0
#endif
#if SPINDLE_PWM_PIN == 8 // PA8 - TIM1_CH1
#define SPINDLE_PWM_TIMER_N 1
#define SPINDLE_PWM_TIMER_CH 1
#define SPINDLE_PWM_TIMER_INV 0
#define SPINDLE_PWM_AF_REMAP 0
#endif
#elif SPINDLE_PWM_PORT_BASE == GPIOB_BASE
#if SPINDLE_PWM_PIN == 0 // PB0 - TIM1_CH2N
#define SPINDLE_PWM_TIMER_N 1
#define SPINDLE_PWM_TIMER_CH 2
#define SPINDLE_PWM_TIMER_INV 1
#define SPINDLE_PWM_AF_REMAP 0b01
#endif
#endif

I want normal output of this signal
1

@terjeio
Copy link
Contributor

terjeio commented Dec 4, 2022

I have modified the driver.h file for SPINDLE PWM on PA1, gives output when SPINDLE_PWM_TIMER_INV set to 1, output does not work when set to 0

That is a bit odd, is this with a cloned MCU or genuine one?

I want normal output of this signal

The scope trace does not tell me anything. What is wrong with it? Should it be 5KHz?

@MeKeCNC
Copy link
Contributor Author

MeKeCNC commented Dec 4, 2022

The scope trace does not tell me anything. What is wrong with it? Should it be 5KHz?

I guess I didn't fully explain the problem. The output of the oscilloscope indicates that the output of the generated signal is inverted. The expected signal should be invertesd to the signal on the oscilloscope, how should we set it up?

The generated PWM signal should be a signal for the BESC spindle as shown below appears on the oscilloscope.

expexted pwm out signal
2

@MeKeCNC
Copy link
Contributor Author

MeKeCNC commented Dec 4, 2022

That is a bit odd, is this with a cloned MCU or genuine one?

real mcu, i am using BTT SKR MINI E3 V2.0 3D printer board

@terjeio
Copy link
Contributor

terjeio commented Dec 4, 2022

$16=4 works? ($$=16 for info)

@MeKeCNC
Copy link
Contributor Author

MeKeCNC commented Dec 4, 2022

$16=4 works? ($$=16 for info)

$16=4 ,I did nothing changed
$$=16
0 - Spindle enable (1)
1 - Spindle direction (2)
2 - PWM (4)
Inverts the spindle on, counterclockwise and PWM signals (active low).

3

4

5

@MeKeCNC
Copy link
Contributor Author

MeKeCNC commented Dec 4, 2022

#define SPINDLE_PWM_TIMER_INV 1

when SPINDLE_PWM_TIMER_INV set to 0
#define SPINDLE_PWM_TIMER_INV 0

no pwm output on PA1

6

@terjeio
Copy link
Contributor

terjeio commented Dec 5, 2022

There is a nasty bug here, wonder if it is this that trips it up for PA1? The line should be:

SPINDLE_PWM_TIMER->CCER |= SPINDLE_PWM_CCER_EN;

@MeKeCNC
Copy link
Contributor Author

MeKeCNC commented Dec 6, 2022

There is a nasty bug here, wonder if it is this that trips it up for PA1? The line should be:

SPINDLE_PWM_TIMER->CCER |= SPINDLE_PWM_CCER_EN;

good catch, it works now. that is, we can use two different pins (PA1 and PA8) for the pwm spindle output on the BTT SKR MINI E3 V2.0 3D printer board. in driver.h latest revision code as below

// Define timer allocations.
#define STEPPER_TIMER TIM2
#define PULSE_TIMER TIM3
#define DEBOUNCE_TIMER TIM4

#ifdef SPINDLE_PWM_PORT_BASE

#if SPINDLE_PWM_PORT_BASE == GPIOA_BASE
#if SPINDLE_PWM_PIN == 1 // PA1 - TIM5_CH2
#define SPINDLE_PWM_TIMER_N 5
#define SPINDLE_PWM_TIMER_CH 2
#define SPINDLE_PWM_TIMER_INV 0
#define SPINDLE_PWM_AF_REMAP 0
#endif
#if SPINDLE_PWM_PIN == 8 // PA8 - TIM1_CH1
#define SPINDLE_PWM_TIMER_N 1
#define SPINDLE_PWM_TIMER_CH 1
#define SPINDLE_PWM_TIMER_INV 0
#define SPINDLE_PWM_AF_REMAP 0
#endif
#elif SPINDLE_PWM_PORT_BASE == GPIOB_BASE
#if SPINDLE_PWM_PIN == 0 // PB0 - TIM1_CH2N
#define SPINDLE_PWM_TIMER_N 1
#define SPINDLE_PWM_TIMER_CH 2
#define SPINDLE_PWM_TIMER_INV 1
#define SPINDLE_PWM_AF_REMAP 0b01
#endif
#endif

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