cancel
Showing results for 
Search instead for 
Did you mean: 

External trigger for TIMER 3

asecen89
Associate II
Posted on September 03, 2013 at 13:00

Hi,

I have a working piece of code that takes an input signal on tim3_ch2 (pc7) and outputs a pulse on every 390 counts on tim3_ch1 (pc6). However, i need to use tim3_ch4 (pc9) as input pin for clock signal. I tried to replace pc7 with pc9 and TIM_Channel_2; with TIM_Channel_4 in my code, but that did not work. Can you help me please? My code is below.

  TIM_TimeBaseStructure.TIM_Prescaler = 0;

  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

  TIM_TimeBaseStructure.TIM_Period = TIM3_period;//TimerPeriod;

  TIM_TimeBaseStructure.TIM_ClockDivision = 0;

TIM_ETRClockMode1Config(TIM3, TIM_ExtTRGPSC_OFF, TIM_ExtTRGPolarity_NonInverted, 0);

// Input Trigger selection 

  TIM_TIxExternalClockConfig(TIM3, TIM_TIxExternalCLK1Source_TI2, TIM_ICPolarity_Rising, 0);

//TIM_SelectInputTrigger (TIM3, TIM_TS_TI2FP2);

// Slave Mode selection: Trigger Mode 

  TIM_SelectSlaveMode(TIM3, TIM_SlaveMode_External1);

  TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);

TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;

TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;

TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;

TIM_ICInitStructure.TIM_ICFilter = 0;

//TI2_Config(TIM3, TIM_ICPolarity_Rising, TIM_ICSelection_DirectTI , 0x00); 

TIM_ICInit(TIM3, &TIM_ICInitStructure);

TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;

  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;

  TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable;

  TIM_OCInitStructure.TIM_Pulse = 10;

  TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;

  TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Reset;

  TIM_OC1Init(TIM3, &TIM_OCInitStructure);

6 REPLIES 6
Posted on September 03, 2013 at 13:55

How's CH4 possibly going to route in this scenario?

0690X00000605VcQAI.png

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
asecen89
Associate II
Posted on September 03, 2013 at 14:16

Oh, i missed that! It should be possible to use channel 3 instead of channel 4, right?

Posted on September 03, 2013 at 18:26

You might be able to do something with the XOR, but that would be the only path I can see.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
asecen89
Associate II
Posted on September 04, 2013 at 10:56

I achieved to use channel 3 as input to clock signal. The hall sensor for timer 3 should be enabled to do that though. I think it must have something to do with xor gate.

Thanks again clive.
ing
Associate II
Posted on June 26, 2014 at 15:11

Hi there

I know that ths post is quite old, but I have to do exactly the same thing, on a stm32f373: I have an input signal on ch3 to capture and need to output a different signal based on the first on ch4.

How do I use the XOR/how do enable the hall sensor? :\

Please advise me on that!

Thank you very much.

Posted on June 27, 2014 at 05:25

The thread is really about using CH3 as an external clock, clocking the whole timer. You can use CH3 in Input Capture mode without any drama, but not PWM Input mode (duty/period).

Provided the frequency isn't too high, you can catch the CC3 interrupt, and program the values you want into CH4. You likely want to use Toggle mode, and place the edges with advancing values in CCR4. This will however require maximal values for the Period (technically you could have lesser values, but it makes life more difficult perhaps tightening your interrupt deadlines, and requiring MOD operations). What's happening with CH1 and CH2?

Motors and Hall Sensors really aren't my thing, so I'll suggest you review/digest the documentation and experiment.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..