'STM32F103C8T6' not work PWM Function.

Post here first, or if you can't find a relevant section!
Post Reply
myksj1105
Posts: 54
Joined: Sun Jun 18, 2023 11:35 am

'STM32F103C8T6' not work PWM Function.

Post by myksj1105 »

'STM32F103C8T6' not work PWM Function.


Image

hello. Nice to meet you. If you look at the picture, it is marked 'PWM' in 'PB_4'.
I tried driving it, but the PWM doesn't work. What's the reason?

Code: Select all

#define BACKLIGHT_LED   PB4
void setup(){
  pinMode(BACKLIGHT_LED, PWM); 
  analogWrite(BACKLIGHT_LED, 255);
}
by GonzoG » Sun Jun 25, 2023 6:08 am
@myksj1105
If you use Roger's/Steve's core then with most hardware setup you are limited to standard setup.
With STM32 core all pins connected to timers work in PWM mode.
Go to full post
GonzoG
Posts: 403
Joined: Wed Jan 15, 2020 11:30 am
Answers: 26
Location: Prudnik, Poland

Re: 'STM32F103C8T6' not work PWM Function.

Post by GonzoG »

There is no such thing as PWM mode for pins.
You can set pin in INPUT or OUTPUT (with pull-up or pull-down also) mode.
For analogWrite you don't need to set pin mode, as analogWrite does it.

How do you check if PWM works ??
myksj1105
Posts: 54
Joined: Sun Jun 18, 2023 11:35 am

Re: 'STM32F103C8T6' not work PWM Function.

Post by myksj1105 »

Code: Select all

#define BACKLIGHT_LED   PB4
void setup(){
  pinMode(BACKLIGHT_LED, OUTPUT); 
  analogWrite(BACKLIGHT_LED, 255);
}

@GonzoG

Thank you for leaving an answer. Even if you proceed with the source code as follows, it does not solve the problem.

The PWM is connecting to the LED to test its brightness. As far as I know, Arduino's PWM range is 0 to 255.
Extreme values of 0 and 255 do not produce the desired results.
GonzoG
Posts: 403
Joined: Wed Jan 15, 2020 11:30 am
Answers: 26
Location: Prudnik, Poland

Re: 'STM32F103C8T6' not work PWM Function.

Post by GonzoG »

@myksj1105
What do you mean by "desired results".
At 0 it's off, at 255, it's on.
myksj1105
Posts: 54
Joined: Sun Jun 18, 2023 11:35 am

Re: 'STM32F103C8T6' not work PWM Function.

Post by myksj1105 »

@GonzoG


Code: Select all

const byte PWM_PIN[20] = {
  PA1, PA2, PA3,
  PA6, PA7, PB0, PB1, PB10, PB11,
  PB5, PB4, PB3, PA15, PA11, PA10, PA9, PA8, PB15, PB14, PB13,
};
#define LED   PC13

void setup(){
  
  //------------------------------------------------------------------------//
  Serial.begin(115200);
  for (uint8_t i = 0; i < 20; i++) { pinMode(PWM_PIN[i],OUTPUT);  }    
  pinMode(LED, OUTPUT);   
  delay(100);
  //------------------------------------------------------------------------//

  //------------------------------------------------------------------------//
  digitalWrite(LED,LOW);
  for (uint8_t i = 0; i < 20; i++) {  analogWrite(PWM_PIN[i], 150);  }  
  delay(1000); 
  //------------------------------------------------------------------------//

  //------------------------------------------------------------------------//
  Serial.println(" SETUP OK!"); 
  //------------------------------------------------------------------------//
  
}
Image


Only 10 out of 20 'PWM PIN' works.
What's the reason?
I wonder. I can't understand.
User avatar
fpiSTM
Posts: 1723
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: 'STM32F103C8T6' not work PWM Function.

Post by fpiSTM »

I can't help as I do not use this core: https://github.com/rogerclarkmelbourne/Arduino_STM32
I maintain the STM32 core.
Maybe your chip is a fake which could explain your issues.
GonzoG
Posts: 403
Joined: Wed Jan 15, 2020 11:30 am
Answers: 26
Location: Prudnik, Poland

Re: 'STM32F103C8T6' not work PWM Function.

Post by GonzoG »

@myksj1105
If you use Roger's/Steve's core then with most hardware setup you are limited to standard setup.
With STM32 core all pins connected to timers work in PWM mode.
myksj1105
Posts: 54
Joined: Sun Jun 18, 2023 11:35 am

Re: 'STM32F103C8T6' not work PWM Function.

Post by myksj1105 »

@GonzoG

Image

It seems you are right.
It seems to be correct that it depends on the core.
trimarco232
Posts: 13
Joined: Wed Jul 12, 2023 11:09 am
Answers: 1

Re: 'STM32F103C8T6' not work PWM Function.

Post by trimarco232 »

STM32C8T6 has only 3 timers with each 4 capture compare channels , so you can only get 12 pwm outputs a time
dannyf
Posts: 446
Joined: Sat Jul 04, 2020 7:46 pm

Re: 'STM32F103C8T6' not work PWM Function.

Post by dannyf »

3 general purpose timer (each with 4 channels) + 1 advanced timer (with 4 channels + 3 compl. channels).
Post Reply

Return to “General discussion”