pwm functions not working

The official STMicroelectronics Arduino core
Post Reply
SHARANYA
Posts: 3
Joined: Fri Aug 18, 2017 8:24 pm

pwm functions not working

Post by SHARANYA » Mon Sep 18, 2017 9:00 pm

Dear experts
I have installed the board support to program my nucleo l476rg board by adding the line "http://github.com/stm32duino/BoardManag ... index.json" to File>preferences>additional boards manager in the Arduino IDE.
I am now able to successfully run the uart,adc & blink test progrm.
But
today i was going through pwm examples in your websites and tried the pwm functions like setting up pwm by writting like this below:

Code: Select all

 pinMode(PA0,PWM)
This is throwing errors : PWM not declared.
Also other pwm functions like pwmWrite is also not working.
How to make them work??

fpiSTM
Posts: 227
Joined: Fri Sep 16, 2016 12:33 pm
Location: Le Mans, France

Re: pwm functions not working

Post by fpiSTM » Tue Sep 19, 2017 4:35 am

Hi,

you should see:
https://www.arduino.cc/en/Reference/AnalogWrite

And do it on a pin which have PWM capability, see PeripheralPins.cpp in the Nucleo L476 variant folder:
https://github.com/stm32duino/Arduino_C ... ins.c#L111

So for example for the L476:

Code: Select all

int ledPin = PA_0;      // LED connected to digital pin PA0 (you can also use those alias A0 or D46 or 46)
int analogPin = 3;   // potentiometer connected to analog pin 3 (A3)
int val = 0;         // variable to store the read value

void setup()
{
  pinMode(ledPin, OUTPUT);   // sets the pin as output
}

void loop()
{
  val = analogRead(analogPin);   // read the input pin
  analogWrite(ledPin, val / 4);  // analogRead values go from 0 to 1023, analogWrite values from 0 to 255
}

SHARANYA
Posts: 3
Joined: Fri Aug 18, 2017 8:24 pm

Re: pwm functions not working

Post by SHARANYA » Tue Sep 19, 2017 5:35 am

That is ok.But in that case,i can't change the pwm frequency.So in order to change,i must use pwm functions as far as i can understand.

fpiSTM
Posts: 227
Joined: Fri Sep 16, 2016 12:33 pm
Location: Le Mans, France

Re: pwm functions not working

Post by fpiSTM » Tue Sep 19, 2017 7:02 am

Currently, this core implement the Arduino API an so there is no API to do this.
PWM_FREQUENCY in variant.h could be changed at this time.
This is planned to add this function when the PWM (analog feature) will be enhanced

SHARANYA
Posts: 3
Joined: Fri Aug 18, 2017 8:24 pm

Re: pwm functions not working

Post by SHARANYA » Tue Sep 19, 2017 7:34 am

Ok...
So how to change in variant.h??Blease be a little bit elaborate as I am comparatively new to arduino IDE.Bascically I program avr micros directly from atmel studio.

fpiSTM
Posts: 227
Joined: Fri Sep 16, 2016 12:33 pm
Location: Le Mans, France

Re: pwm functions not working

Post by fpiSTM » Tue Sep 19, 2017 9:30 am

the define for the L476 is here:
https://github.com/stm32duino/Arduino_C ... ant.h#L120

So you have to go in the core installation folder:
https://github.com/stm32duino/wiki/wiki ... re-sources
and edit:
variants/NUCLEO_L476RG/variant.h

Post Reply