STM32F1xx icon indicating copy to clipboard operation
STM32F1xx copied to clipboard

PA1 for spindle pwm out ?

Open MeKeCNC opened this issue 2 years ago • 11 comments

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

MeKeCNC avatar Oct 24 '22 17:10 MeKeCNC

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?

terjeio avatar Oct 24 '22 17:10 terjeio

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

MeKeCNC avatar Oct 24 '22 17:10 MeKeCNC

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

MeKeCNC avatar Dec 02 '22 14:12 MeKeCNC

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?

terjeio avatar Dec 04 '22 12:12 terjeio

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 avatar Dec 04 '22 12:12 MeKeCNC

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

MeKeCNC avatar Dec 04 '22 12:12 MeKeCNC

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

terjeio avatar Dec 04 '22 12:12 terjeio

$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 avatar Dec 04 '22 12:12 MeKeCNC

#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

MeKeCNC avatar Dec 04 '22 13:12 MeKeCNC

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;

terjeio avatar Dec 05 '22 08:12 terjeio

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

MeKeCNC avatar Dec 06 '22 14:12 MeKeCNC