PWM input from Simulink-> PWM output TIM1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-02-05 1:08 PM
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:
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.
Thanks!
#stm32-mat/target-matlab #simulink #tim1 #tim-pwm #nucleo-stm32f7- Labels:
-
STM32-MatTarget
-
STM32F7 Series
-
TIM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-02-05 1:25 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-02-05 2:28 PM
Thanks for your answer, but the PWM that I need to use as input is not external, it is generated by Simulink.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-02-05 2:34 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-02-05 2:39 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-02-05 3:06 PM
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.
