cancel
Showing results for 
Search instead for 
Did you mean: 

PWM input from Simulink-> PWM output TIM1

antonio rueda
Associate II
Posted on February 05, 2018 at 22:08

Hi, after some problems with the interface between Simulink and CubeMX, I've managed to get the TIM1 of the STM32F767ZIT working at a desired frequency and duty cycle using the next blocks:

0690X00000609cdQAA.png

My question is, is there any way to input a PWM signal to modify the duty output of the timer instead of inputting the duty cycle to the TIM1 block as a constant? I need to use the next signal from Simulink for example to modify the duty of the TIM1.

0690X00000609bKQAQ.png

Thanks!

#stm32-mat/target-matlab #simulink #tim1 #tim-pwm #nucleo-stm32f7
5 REPLIES 5
T J
Lead
Posted on February 05, 2018 at 22:25

there are 2 classic timer functions:

input Capture :  Time Capture from a pin toggled externally

output Compare: Timed controlled output to a pin. ( PWM uses this style)

If you wanted to capture the timing of an external PWM, you could use the input capture method.

You can capture on rising or falling edges or both.

Posted on February 05, 2018 at 22:28

Thanks for your answer, but the PWM that I need to use as input is not external, it is generated by Simulink.

Posted on February 05, 2018 at 22:34

generally, we use a serial terminal to input commands.

it connects directly to your code, through Uarts 1,2,3,4,5,6,or 7

then the commands are given to change/debug and adjust 'on the fly' the things, like your PWM frequency/dutycycle

Posted on February 05, 2018 at 22:39

If I use the Simulink model to generate the code, the PWM that I want at the output is computed on the micro so in this case there's no serial communication.

Posted on February 05, 2018 at 23:06

never used Simulink sorry...

' My question is, is there any way to input a PWM signal to modify the duty output of the timer,

   instead of inputting the duty cycle to the TIM1 block as a constant? '

to modify the output of a timer..

   htim->Instance->CCR1 = htim->Instance->CNT +1000;

   htim->Instance->SR   =  !TIM_SR_CC1IF;   // clear the flag      // start a compare event

  

if you want to read the PWM timings, you would read the InputCapture Register

//config for rising edge detection

//wait for rising edge

risingEdgeTime =  htim->Instance->CCR1;

//config for falling edge detection

//wait for falling edge

fallingEdgeTime =  htim->Instance->CCR1;

you would enable the toggle pin interrupt for non-blocking code.