Page 1 of 1

STM32L443RC PWM library

Posted: 01 Feb 2021 13:43
by devrim
Hi Sir,
I have PWM several issue with STM32L443RC mcu.
TIM1,TIM2,TIM15,TIM16 PWM function works only channel1 for each Timer with this code "

main:
GPIO_Digital_output (@GPIOH_BASE,_GPIO_PINMASK_1 )

delay_ms(100)
PWM_TIM2_Init(6000)
PWM_TIM2_Set_Duty(2000,_PWM_NON_INVERTED,_PWM_CHANNEL1)
PWM_TIM2_Start(_PWM_CHANNEL1,@_GPIO_MODULE_TIM2_PA0)

PWM_TIM1_Init(6000)
PWM_TIM1_Set_Duty(2000,_PWM_NON_INVERTED,_PWM_CHANNEL1)
PWM_TIM1_Start(_PWM_CHANNEL1,@_GPIO_MODULE_TIM1_PA8)

PWM_TIM15_Init(6000)
PWM_TIM15_Set_Duty(2000,_PWM_NON_INVERTED,_PWM_CHANNEL1)
PWM_TIM15_Start(_PWM_CHANNEL1,@_GPIO_MODULE_TIM15_PA2)

PWM_TIM16_Init(6000)
PWM_TIM16_Set_Duty(2000,_PWM_NON_INVERTED,_PWM_CHANNEL1)
PWM_TIM16_Start(_PWM_CHANNEL1,@_GPIO_MODULE_TIM16_PA6)

while 1
GPIOH_ODR.B1 = not GPIOH_ODR.B1
delay_ms(100)
wend
end.

But for other PWM channels I could not get PWM output.
With this code MCU hanging !!

main:
GPIO_Digital_output (@GPIOH_BASE,_GPIO_PINMASK_1 )

delay_ms(100)

PWM_TIM1_Init(6000)
PWM_TIM1_Set_Duty(2000,_PWM_NON_INVERTED,_PWM_CHANNEL2)
PWM_TIM1_Start(_PWM_CHANNEL2,_GPIO_TIM1_CH2_PA9)

while 1
GPIOH_ODR.B1 = not GPIOH_ODR.B1
delay_ms(100)
wend
end.

This code also same result;

main:
GPIO_Digital_output (@GPIOH_BASE,_GPIO_PINMASK_1 )

delay_ms(100)
PWM_TIM2_Init(6000)
PWM_TIM2_Set_Duty(2000,_PWM_NON_INVERTED,_PWM_CHANNEL2)
PWM_TIM2_Start(_PWM_CHANNEL2,_GPIO_TIM2_CH2_PA1)

while 1
GPIOH_ODR.B1 = not GPIOH_ODR.B1
delay_ms(100)
wend
end.

So I mean I can use only channel1 for each timers. Other channels not work.

Do you have some commad for this issue..

Re: STM32L443RC PWM library

Posted: 03 Feb 2021 10:08
by filip.grujcic
Hello,

You are missing the @ operator in front of the GPIO structures.

Code: Select all

PWM_TIM1_Start(_PWM_CHANNEL2,@_GPIO_TIM1_CH2_PA9)
PWM_TIM2_Start(_PWM_CHANNEL2,@_GPIO_TIM2_CH2_PA1)
Regards,

Re: STM32L443RC PWM library

Posted: 06 Feb 2021 11:20
by devrim
Hi Filip,
Thanks for your reply, but "@" operator not work.

Re: STM32L443RC PWM library

Posted: 07 Feb 2021 09:10
by devrim
:roll:

Re: STM32L443RC PWM library

Posted: 08 Feb 2021 11:24
by filip.grujcic
Hello,

I apologize I made an oversight -- you are trying to use the predefined library constant instead of the GPIO module structure that you need to be using.
This is the reason it doesn't work.

Code: Select all

PWM_TIM1_Start(_PWM_CHANNEL2,@_GPIO_TIM1_CH2_PA9)
PWM_TIM2_Start(_PWM_CHANNEL2,@_GPIO_TIM2_CH2_PA1)
Should be:

Code: Select all

PWM_TIM1_Start(_PWM_CHANNEL2, @_GPIO_MODULE_TIM1_PA8)
PWM_TIM2_Start(_PWM_CHANNEL2, @_GPIO_MODULE_TIM2_PA1)
These structures are most likely missing from your GPIO defs file. You can add them yourself, since GPIO defs is open source, however I have attached the defs file with the structures already there.
Copy the .mbas file to:
...\Mikroelektronika\mikroBasic PRO for ARM v6.2.0\Uses\ST M4

Regards,

Re: STM32L443RC PWM library

Posted: 08 Feb 2021 17:46
by devrim
Many Thanks for your reply,
I understood how it should be. But other PWM channels still missing but I can add myself.
Thanks again

Re: STM32L443RC PWM library

Posted: 09 Feb 2021 08:13
by devrim
Hi,
I added all PWM channels to the defs file.
But PORTC alternate functions still missing. Is it possible to add ?

Re: STM32L443RC PWM library

Posted: 10 Feb 2021 16:59
by filip.grujcic
Hello,

You can add everything that is in the GPIO defs file. Simply copy the existing structure or constant and alter it according to your needs.

Regards,