STM32L443RC PWM library

General discussion on mikroBasic PRO for ARM.
Post Reply
Author
Message
devrim
Posts: 17
Joined: 17 Oct 2014 12:14

STM32L443RC PWM library

#1 Post by devrim » 01 Feb 2021 13:43

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..

User avatar
filip.grujcic
Posts: 822
Joined: 14 May 2018 08:34

Re: STM32L443RC PWM library

#2 Post by filip.grujcic » 03 Feb 2021 10:08

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,
Filip Grujcic

devrim
Posts: 17
Joined: 17 Oct 2014 12:14

Re: STM32L443RC PWM library

#3 Post by devrim » 06 Feb 2021 11:20

Hi Filip,
Thanks for your reply, but "@" operator not work.
Attachments
syntax error.png
syntax error.png (39.83 KiB) Viewed 1984 times

devrim
Posts: 17
Joined: 17 Oct 2014 12:14

Re: STM32L443RC PWM library

#4 Post by devrim » 07 Feb 2021 09:10

:roll:

User avatar
filip.grujcic
Posts: 822
Joined: 14 May 2018 08:34

Re: STM32L443RC PWM library

#5 Post by filip.grujcic » 08 Feb 2021 11:24

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,
Attachments
__Lib_GPIO_32L43x_Defs.zip
(2.22 KiB) Downloaded 53 times
Filip Grujcic

devrim
Posts: 17
Joined: 17 Oct 2014 12:14

Re: STM32L443RC PWM library

#6 Post by devrim » 08 Feb 2021 17:46

Many Thanks for your reply,
I understood how it should be. But other PWM channels still missing but I can add myself.
Thanks again

devrim
Posts: 17
Joined: 17 Oct 2014 12:14

Re: STM32L443RC PWM library

#7 Post by devrim » 09 Feb 2021 08:13

Hi,
I added all PWM channels to the defs file.
But PORTC alternate functions still missing. Is it possible to add ?
Attachments
__Lib_GPIO_32L43x_Defs.rar
(2.09 KiB) Downloaded 63 times

User avatar
filip.grujcic
Posts: 822
Joined: 14 May 2018 08:34

Re: STM32L443RC PWM library

#8 Post by filip.grujcic » 10 Feb 2021 16:59

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,
Filip Grujcic

Post Reply

Return to “mikroBasic PRO for ARM General”