STM32 F0 PWM function not working

General discussion on mikroBasic PRO for ARM.
Author
Message
RobotPower
Posts: 7
Joined: 25 Nov 2015 22:22
Location: USA

STM32 F0 PWM function not working

#1 Post by RobotPower » 15 Dec 2015 01:21

Hi All,

I have tried to get PWM output of the STM32F030 but no luck. Here is my code

Code: Select all

program STM32F030_PWM

' Declarations section 

dim period as word
dim LED as sbit  at GPIOA_ODR.B8

sub procedure Init_GPIO()
  GPIO_Digital_Output(@GPIOA_BASE, _GPIO_PINMASK_8)     ' LED output

end sub


main:
'   Main program 

   Init_GPIO()
  
   ' Nothing output on PA6
   period = PWM_TIM3_Init(5000)
   PWM_TIM3_Set_Duty(period/4, _PWM_NON_INVERTED, _PWM_CHANNEL1)
   PWM_TIM3_Start(_PWM_CHANNEL1,  @_GPIO_MODULE_TIM3_CH1_PA6)

  ' This works
  while(TRUE)
      LED = NOT LED
      Delay_uS(100)
  wend

end.
Is there something in the clock settings that I should look for?

Thanks,

Chris

RobotPower
Posts: 7
Joined: 25 Nov 2015 22:22
Location: USA

Re: STM32 F0 PWM function not working

#2 Post by RobotPower » 15 Dec 2015 19:01

Messed around with the Alternate Function enable for those pins and still nothing working.

Will stand by for a reply here but will start investigating setting the registers directly without using the library.

User avatar
Aleksandar.Mitrovic
mikroElektronika team
Posts: 1697
Joined: 11 Mar 2015 12:48

Re: STM32 F0 PWM function not working

#3 Post by Aleksandar.Mitrovic » 16 Dec 2015 16:39

Hi,

Yes, you will have to set correct click settings since you will need to use Timer clock to generate pulse for the PWM.

Please refer to the datasheet for this MCU:
http://www.st.com/web/en/resource/techn ... 088500.pdf

Best regards,
Aleksandar

RobotPower
Posts: 7
Joined: 25 Nov 2015 22:22
Location: USA

Re: STM32 F0 PWM function not working

#4 Post by RobotPower » 18 Dec 2015 00:03

The system clock is set correctly and the CPU runs at the proper frequency so that is not the problem.

Why doesn't the example show other settings needed for PWM?

Why does TIM3_PWM_INIT() not do set this properly?

I think the TIMx_PWM_INIT() function and/or other PWM library functions are broken.

Chris

User avatar
Aleksandar.Mitrovic
mikroElektronika team
Posts: 1697
Joined: 11 Mar 2015 12:48

Re: STM32 F0 PWM function not working

#5 Post by Aleksandar.Mitrovic » 18 Dec 2015 15:31

Hi,

We will try to find some STM32F030 microcontroller to run some tests.

Best regards,
Aleksandar

alex_cnc
Posts: 4
Joined: 09 Mar 2016 08:28

Re: STM32 F0 PWM function not working

#6 Post by alex_cnc » 09 Mar 2016 08:33

Hello.
PWM does not work on my STM32F030 . Code tested on STM32F103 there all right . This library problem?

User avatar
Aleksandar.Mitrovic
mikroElektronika team
Posts: 1697
Joined: 11 Mar 2015 12:48

Re: STM32 F0 PWM function not working

#7 Post by Aleksandar.Mitrovic » 10 Mar 2016 17:18

Hi Alex,

Can you please tell me did you try with different channel maybe?

Code: Select all

  PWM_TIM3_Set_Duty(100, _PWM_NON_INVERTED, _PWM_CHANNEL2)
   
  PWM_TIM3_Start(_PWM_CHANNEL2,  @_GPIO_MODULE_TIM3_CH2_PA7)
Best regards,
Aleksandar

alex_cnc
Posts: 4
Joined: 09 Mar 2016 08:28

Re: STM32 F0 PWM function not working

#8 Post by alex_cnc » 11 Mar 2016 06:13

Hi, Alexandar
I checked TIM14 and other timers on the other outputs. Positive results are not received . My code ...

Code: Select all

ratio = PWM_TIM3_Init(25000)
    PWM_TIM3_Set_Duty(ratio/2,_PWM_non_INVERTED,_PWM_CHANNEL2)
    PWM_TIM3_Start(_PWM_CHANNEL2,@_GPIO_MODULE_TIM3_CH2_PA7

alex_cnc
Posts: 4
Joined: 09 Mar 2016 08:28

Re: STM32 F0 PWM function not working

#9 Post by alex_cnc » 14 Mar 2016 10:41

Hi,Aleksandar
ADC also did not work ( the program hangs at runtime )

User avatar
Aleksandar.Mitrovic
mikroElektronika team
Posts: 1697
Joined: 11 Mar 2015 12:48

Re: STM32 F0 PWM function not working

#10 Post by Aleksandar.Mitrovic » 16 Mar 2016 16:17

Hi,

I have tested this on STM32F030R8 and I manage to reproduce the problem with PWM in mikroBasic.
Can you please try the hex file below for PWM on MODULE_TIM3_CH1_PA6 generated from the mikroC.

Is this working on your board? Do you have something on the PA6 pin?

Can you please explain me the problem which you have with your ADC on this chip?
I have tested the ADC on this board and its working.

Best regards,
Aleksandar
Attachments
PWM.rar
(2.79 KiB) Downloaded 259 times

alex_cnc
Posts: 4
Joined: 09 Mar 2016 08:28

Re: STM32 F0 PWM function not working

#11 Post by alex_cnc » 19 Mar 2016 11:46

Hi, Aleksandar.
I have just tested your code on my STM32F030F4P6, and my result is nothing.
Hardly I tried to init this timer in PWM mode using C in Keil-MDK v4.74, and...profit! it works!
But I want to have it working using mikroBasic. C is too hard for me.
Best regards,
Alex.

User avatar
Aleksandar.Mitrovic
mikroElektronika team
Posts: 1697
Joined: 11 Mar 2015 12:48

Re: STM32 F0 PWM function not working

#12 Post by Aleksandar.Mitrovic » 21 Mar 2016 09:24

Hi Alex,

I have reported this bug with PWM to our developers.

They will try to fix this problem as soon as possible.

Kind regards,
Aleksandar

hariri.hamed
Posts: 3
Joined: 16 May 2016 11:17

Re: STM32 F0 PWM function not working

#13 Post by hariri.hamed » 27 Sep 2016 16:47

hi
i test your pwm.hex .
it not working with stm32f030f4p6
please you test with stm32f030f4p6
tanks.

hariri.hamed
Posts: 3
Joined: 16 May 2016 11:17

Re: STM32 F0 PWM function not working

#14 Post by hariri.hamed » 28 Sep 2016 08:34

hi all
Don't fix problem pwm stm32f0?
Please report this problem resolved.
tanks.

User avatar
Aleksandar.Mitrovic
mikroElektronika team
Posts: 1697
Joined: 11 Mar 2015 12:48

Re: STM32 F0 PWM function not working

#15 Post by Aleksandar.Mitrovic » 28 Sep 2016 11:54

Hi,

The example which I have attached is tested on STM32F030R8 and written in microC, and it generates a PWM signal on pin.
I do not have other microcontroller to test it.

This problem is reported to our developers and waiting for release to be fixed in Pascal and Basic.

Kind regards,
Aleksandar

Post Reply

Return to “mikroBasic PRO for ARM General”