cancel
Showing results for 
Search instead for 
Did you mean: 

Interrrupt on every rising edge of input signale(square wave)

LFerr.7
Associate II

Using an input capture ch2 of TIM1 ,i want to generate interrupts at every rising edge of input signal(square wave) and call a call back function to do something.The output is is an output compare ch1 of the same timer1. Can you help me?

10 REPLIES 10
Javier1
Principal

>Can you help me?

google "EXTI interrupts stm32"

https://www.youtube.com/watch?v=w_81fHydEoE

>The output is is an output compare ch1 of the same timer1.

You lost me there...

we dont need to firmware by ourselves, lets talk
LFerr.7
Associate II

@Javier Muñoz​  thank you for your answer. I have an input capture square wave of 20ms of period. I want to generate interrupt on both edges ,so i want to call a call back function on rising edge and generate a pulse for example {TIM1->CCR1=x ;TIM-> ARR=x+y;}the same thing on the falling edge to generate a pulse . But most difficult thing is to have two pin or output that contain the pulses, in first output the pulses of rising edge and in the second output the pulses of falling edge.

I am trying a lot, can you help me please? some suggestion or idea to do it! thank you sir!

>I have an input capture square wave of 20ms of period.

This doesnt make any sense to me. Input capture what?

>I want to generate interrupt on both edges

google "EXTI interrupts stm32 both edges"

>to have two pin or output that contain the pulses,

Im also lost here.... maybe try to explain it in your original languaje? Im spanish and i know a bit of italian.

we dont need to firmware by ourselves, lets talk
LFerr.7
Associate II

i have an external signal , this is a square wave of 20 ms of period. i will put this signal on input capture channel of the timer.

i want to generate interrupts on rising and falling edge of input capture , but i want to do it in separate or differently output as the photo 0693W00000NpMB0QAN.jpg

LFerr.7
Associate II

0693W00000NpM4PQAV.jpgstatic void MX_TIM1_Init(void)

{

{

  __HAL_RCC_TIM1_CLK_ENABLE(); // Enable Timer 1 clock

  TIM1->CR1  = 0x0089;    // Auto-reload, One-Pulse-Mode

  TIM1->CR2  = 0x0000;    // Idle-state configuration

  TIM1->SMCR = 0x0066;    // Trigger-Mode, Timer input 2

  TIM1->DIER = 0x0000;    // Disable interrupts

  TIM1->SR  = 0x0000;    // Clear status register

  TIM1->EGR  = 0x0000;    // Clear event generation register

  TIM1->CCMR1 = 0x0178;    // OC1: PWM2-Mode, Preload, IC2: IC2 on TI2

  TIM1->CCMR2 = 0x0000;    // OC3/OC4, IC3/IC4 off

  TIM1->CCER = 0x00A1;    // OC1: On, AH; IC2: On, Both edges

  TIM1->CNT  = 0;       // Clear timer 1 counter

  TIM1->PSC  = 168-1;     // Set prescaler to 168

  TIM1->ARR  = 0x0000;    // Initialize Auto-reload register

  TIM1->RCR  = 0x0000;    // Clear repetition counter

  TIM1->CCR1 = 0x0000;    // Initialize Capture/Compare register 1

  TIM1->CCR2 = 0x0000;    // Clear Capture/Compare register 2

  TIM1->CCR3 = 0x0000;    // Clear Capture/Compare register 3

  TIM1->CCR4 = 0x0000;    // Clear Capture/Compare register 4

  TIM1->BDTR = 0x8000;    // Main output enable

  TIM1->DCR  = 0x0000;    // Clear DMA configuration (DMA not needed)

  // TIM1->DMAR = ......;   // DO NOT WRITE TO THIS REGISTER!

  TIM1->CR1 |= 0x0001;    // Timer 1 Enable

}

at the moment with this code i have only one output and the pulses are 10ms of period but i want two differently output like the first photo

  sorry for my bad english ! Thank you that are dedicating time to me

You can use the fact that input capture can work on the neighbouring channel. For example, you can input your signal onto TIMx_CH1 pin and capture the same signal at both CH1 and CH2 (similarly you can connect it to CH2 and capture on both CH1/CH2, the same with the CH3+CH4 pair - but in following I assume signal is on the TIMx_CH1 pin).

Set TIMx_CCMR1.CC1S to 0b01 and TIMx_CCMR1.CC2S to 0b10.

In TIMx_CCER, set CC1E and CC2E, and set CC2P. In this way CH1 will capture on rising edge and CH2 on falling edge of the same signal.

In TIMx_DIER enable both CC1 and CC2 interrupts.

In the ISR, you would need to check which of the CC1 and CC2 bit is set in TIMx_SR and act accordingly.

JW

i am using this configuration. Should have 2 outputs and 1 input signal that is an external square wave0693W00000NpMuKQAV.jpg

They do that in this video, once in the interrupt capture ISR function they check if it was a rising or falling edge wat triggered it,

https://www.youtube.com/watch?v=rh4pdNWKLJY

Thats how they measure pulse width, and thats how you coould implement your thing.

we dont need to firmware by ourselves, lets talk

Why do you need to discriminate between rising and falling edges? it looks like you trigger the same pulse in both

we dont need to firmware by ourselves, lets talk