Code: Select all
analogWrite()
Code: Select all
pwmWrite()
Code: Select all
digitalWrite
Code: Select all
pinMode(...,OUTPUT)
Code: Select all
pinMode(...,PWM)
Code: Select all
analogWrite()
Code: Select all
pwmWrite()
Code: Select all
digitalWrite
Code: Select all
pinMode(...,OUTPUT)
Code: Select all
pinMode(...,PWM)
Code: Select all
Timer1.init(); // initializes and stops the timer
pinMode(PA8, PWM); // sets the pin mode
Timer1.setPeriod(<micro_seconds>); // replace with your needed value
Timer1.resume(); // start the timer
Code: Select all
#define PWMPin PA8
int PWMval;
void setup() {
Serial1.begin(9600);
pinMode(PWMPin,PWM);
}
void loop() {
PWMval = millis()%(65535);
pwmWrite(PWMPin, PWMval);
}
I tried both pwmWrite and analogWrite, neither worksfpiSTM wrote: Wed Oct 21, 2020 9:21 pm I guess it is libmaple as STM32 core does not have pwmWrite API nor PWM as argument of pin mode.
Code: Select all
Timer1.init(); // initializes and stops the timer
pinMode(PA8, PWM); // sets the pin mode
Timer1.setPeriod(<micro_seconds>); // replace with your needed value
Timer1.resume(); // start the timer
Thank you, it helped, but TimerX.setPeriod is not nessesary, and I want to point out that the PWM works invertedly (0 = HIGH, 65535 = LOW)stevestrong wrote: Thu Oct 22, 2020 9:15 am It is not enough to set the pin mode.
You have to setup the timer corresponding to the used pin (PA8 in your example is mapped to timer 1 channel 1, see here).
A usual setup looks like this:Only after this you should use pwmWrite().Code: Select all
Timer1.init(); // initializes and stops the timer pinMode(PA8, PWM); // sets the pin mode Timer1.setPeriod(<micro_seconds>); // replace with your needed value Timer1.resume(); // start the timer
Code: Select all
int PWMval = 0;
void setup()
{
Timer3.init();
pinMode(PA6, PWM);
//Timer3.setPeriod(1000);
Timer3.refresh();
Timer3.resume();
}
void loop()
{
PWMval = micros()%65535;
pwmWrite(PA6,PWMval);
}