cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103 Npulses example

jihzed
Associate II

Hello. In order to drive a stepper motor with CanBus, I want driver a L6208. I would use a timer to generate Npulses. I've read AN4776 (General-purpose timer cookbook ) but I don't understand somethink, I can't run the timer.

Any people have example code ?

3 REPLIES 3

I don't have examples for new libraries with old parts.

Find a One Shot/Pulse example. OPM?

Use an Advanced TIM, like TIM1 or TIM8.

The Repetition Count can generate up to 256 pulses as I recall.

You can restart at the completion Update event to batch/chain a series of tight pulse trains.

With other TIM, or for longer counts, you'd need to count Update events, either stopping the TIM, or zeroing the pulse width (off)

@brk​ top level post entry dialog still broken, cursor up/down not working.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

L6208 is not an old part, I think. There is a library for Nucleo with STM32F0 and STM32F3, but not STM32F1.

I will try with event to stop.

Thanks

jihzed
Associate II

0690X00000AsO6fQAF.gifI will explain that I made for other people.

I would N pulses on PB10 (Timer 2 channel 3)

I use TIM2 in PWM mode to generate the signal on Channel3 and :

  • Trigger Output (Master) : Enable
  • Event Selection : Update Event

I use TIM4 in

  • OnePulse mode,
  • Slave Mode : Trigger Mode,
  • Trigger source : ITR1 (it's TIM2 for TIM4)

after calculation for duration, speed, etc.

I start TIM4 with

  • HAL_TIM_Base_Start_IT(&htim4);

and just the line below :

  • TIM2 HAL_TIM_PWM_Start(&htim2,TIM_CHANNEL_3);

at the first front of TIM2 the TIM4 will start.

for the end, in the TIM4_IRQHandler I add the line :

  • HAL_TIM_PWM_Stop(&htim2, TIM_CHANNEL_3);