0
\$\begingroup\$

I am going to generate a PWM with master/slave timer configuration. I prefer that my master timer generates PWM with an interrupt. I need to connect this interrupt to another timer as its input clock to count the number of the pulses.

Based on this diagram, what should I do?

enter image description here

  1. I enable my timer to generate PWM.
  2. Enable timer interrupt for each pulse.
  3. How to connect this interrupt to another timer?
  4. How to configure it as master and the second timer as a salve?
  5. Is it necessary to define these timers as master and slave timer, or is connecting the interrupt as the second timer enough?
\$\endgroup\$
4
  • \$\begingroup\$ What are you trying to modulate, number of pulses or width of the pulses? PWM modulates the width of pulses to affect duty cycle while keeping them at the same frequency, but you haven't made clear how this device will do both. This looks like a course document or reference to a part. If its a reference to a part, you should include the part number and a link to the datasheet. \$\endgroup\$
    – K H
    Jan 28, 2021 at 10:53
  • \$\begingroup\$ @KH , from the previous questions of OP, I know that it's a STM32F1 (or maybe STM32F4, not sure) device. TIM modules are quite similar to each other in this family (STM32). \$\endgroup\$
    – Tagli
    Jan 28, 2021 at 10:56
  • \$\begingroup\$ @Tagli Ah yes I see there's an stm32 tag now, but the question could really be documented better. A link to the previous question might help as well. I'm off to bed though. Happy electronicsing. \$\endgroup\$
    – K H
    Jan 28, 2021 at 11:02
  • \$\begingroup\$ Thank you for your swift comments, I have updated this post. \$\endgroup\$
    – John Jin
    Jan 28, 2021 at 11:10

1 Answer 1

1
\$\begingroup\$

There is no concept of connecting interrupts each other. You need to connect timers in master & slave configuration.

See MMS (Master Mode Selection) bits of TIMx_CR2 register. These must be set to 0b010 (Update), so that the master timer creates a pulse on TRGO (Trigger output) whenever it overflows, in other words, after each PWM pulse it generates. I assume you have made the other settings correctly for the master timer to produce a PWM. Do not enable interrupts for master timer.

In the slave timer, see SMS (Slave Mode Selection) and TS (Trigger Selection) bits in TIMx_SMCR register. SMS must be 0b111 (External clock mode 1). And you must also set TS bits according to the master timer you use, which must be one of the ITRx options.

Slave timer needs a prescaler of 1 (TIMx_PSC = 0). Set the TIMx_ARR register according to the desired pulse count and enable update interrupt of the slave timer. Slave timer interrupt should be triggered when the desired pulse count is reached. And in the slave timer interrupt service routine, you can stop the master timer.

I haven't recently tested these steps and I'm not sure if I missed something or not, but I believe they can put you in the right direction.

\$\endgroup\$
8
  • \$\begingroup\$ Thank you very much for your answer, I need to know how the master timer generates TRGO signal, each PWM pulse produces the TRGO or I should enable other interrupt sources/bit. because you have told me " Do not enable interrupts for master time." \$\endgroup\$
    – John Jin
    Jan 28, 2021 at 11:19
  • \$\begingroup\$ Sorry for the typo, I just corrected it. TRGO signal is internally generated once you correctly set MMS bits in the master timer. It's not related with interrupts. Please see the reference manual. \$\endgroup\$
    – Tagli
    Jan 28, 2021 at 11:23
  • \$\begingroup\$ It is really kind of you. I appreciate your help. I follow your comments and check your answers experimentally. which TRGO sources Should I enable ? (OC1Ref or Update based on st.com/resource/en/application_note/… ) \$\endgroup\$
    – John Jin
    Jan 28, 2021 at 11:32
  • \$\begingroup\$ As I stated in my answer, you need to choose update for TRGO signal. \$\endgroup\$
    – Tagli
    Jan 28, 2021 at 11:53
  • \$\begingroup\$ Dear Tagli, Could you help me how to define the input/output source of slave master? after enabling the TRGO signal I need to know how connect the TRGO to specific timer. It means I need to connect the TRGO of TIM4(Master) to TIM2(Slave) but I don't know how to connect them.(ITR0 up to ITR3, which one?) \$\endgroup\$
    – John Jin
    Feb 2, 2021 at 5:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.