Fading PB1 (D33) LED

Maple Rev3, Maple Rev 5 and Maple Ret 6, iTead Maple etc
Post Reply
Boian Mitov
Posts: 14
Joined: Sun Jul 09, 2017 9:03 pm

Fading PB1 (D33) LED

Post by Boian Mitov » Mon Jul 10, 2017 7:14 pm

I have switched from using the leaflabs to stm32duino for my Maple Mini.
With the leaf I was able to control the LED on D33 with PWM:
http://docs.leaflabs.com/static.leaflab ... mini-gpios

Is this functionality available in the stm32duino version? It is a very nice features, as it allows easily to demonstrate the PWM with the LED in tutorials etc.

stevestrong
Posts: 1327
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: Fading PB1 (D33) LED

Post by stevestrong » Mon Jul 10, 2017 7:43 pm

If it is a Maple mini, then this thread belongs to this group: http://www.stm32duino.com/viewforum.php?f=27

Anyway, if you look at this pinout, it seems that PB1 is the LED pin, so you should be able to control it.

Boian Mitov
Posts: 14
Joined: Sun Jul 09, 2017 9:03 pm

Re: Fading PB1 (D33) LED

Post by Boian Mitov » Wed Jul 12, 2017 5:14 pm

I can control the LED On and Off.
I am asking if I can control it with PWM with AnalogWrite.
With the old library I can use analogWrite( PB1, AValue ) to dim the LED.
This does not seem to work with the new library.
Is PWM intended to still work on PB1?
I need to know that so I can properly map the Maple pins in Visuino - https://www.visuino.com.
In the current version I have made the pin PWM, but I can change this if needed in the future.

stevestrong
Posts: 1327
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: Fading PB1 (D33) LED

Post by stevestrong » Wed Jul 12, 2017 7:03 pm

It should work, timer3 channel 4 is assiciated with this pin.
Which core do you use?

victor_pv
Posts: 1337
Joined: Mon Apr 27, 2015 12:12 pm

Re: Fading PB1 (D33) LED

Post by victor_pv » Wed Jul 12, 2017 7:24 pm

If you are using the libmaple based one, then pwmWrite should be what you look for.
If you are using one of the other cores, then it depends what's implemented on them.

https://github.com/rogerclarkmelbourne/ ... Fading.ino

BTW, Roger wrote a new analogWrite that more closely resembles the arduino one, check here:
https://github.com/rogerclarkmelbourne/ ... le/pwm.cpp

Since pwmwrite takes 16bit values, and arduino uses 8bit values, they were not working the same.
In the original leaflabs code analogWrite was just a define of pwmWrite.

Boian Mitov
Posts: 14
Joined: Sun Jul 09, 2017 9:03 pm

Re: Fading PB1 (D33) LED

Post by Boian Mitov » Wed Jul 12, 2017 8:05 pm

victor_pv wrote:
Wed Jul 12, 2017 7:24 pm
If you are using the libmaple based one, then pwmWrite should be what you look for.
If you are using one of the other cores, then it depends what's implemented on them.
I am not the end user of the libraries. I am adding support for (hopefully all) STM32 boards in Visuino. I am simply testing the functionality, and it will be used by the Visuino https://www.visuino.com users (At the moment 22742 registered users with about new 100 registering daily ), so I need a solution that will easily work for everyone.
One of the users is volunteering to also write Wiki documentation on the stm32duino support, so I am trying to figure out how it all should work.
I am quite new on the stm32duino, I have been adding support for many of the other controllers, including the Arduino boards, Femto IO, PIC chipKIT, ESP8266, ESP32, FreSoC2, LinkIt One, Arduino 101, NRF52832, and many others, so I try to make sure they are all well supported by Visuino. I am trying to do the same for the stm32duino boards. Already added initial Maple Mini support, but still looking if it needs tweaking/improving.
I have couple of other ST boards, and will be fighting with them again, as soon as I find another gap. (Adding some I2C modules to Visuino now...)
Please give me a good direction as to how best to support the stm32duino, and what is the recommended repository/board manager file to use, for all the Visuino users.

victor_pv
Posts: 1337
Joined: Mon Apr 27, 2015 12:12 pm

Re: Fading PB1 (D33) LED

Post by victor_pv » Thu Jul 13, 2017 12:02 am

Boian Mitov wrote:
Wed Jul 12, 2017 8:05 pm
victor_pv wrote:
Wed Jul 12, 2017 7:24 pm
If you are using the libmaple based one, then pwmWrite should be what you look for.
If you are using one of the other cores, then it depends what's implemented on them.
I am not the end user of the libraries. I am adding support for (hopefully all) STM32 boards in Visuino. I am simply testing the functionality, and it will be used by the Visuino https://www.visuino.com users (At the moment 22742 registered users with about new 100 registering daily ), so I need a solution that will easily work for everyone.
One of the users is volunteering to also write Wiki documentation on the stm32duino support, so I am trying to figure out how it all should work.
I am quite new on the stm32duino, I have been adding support for many of the other controllers, including the Arduino boards, Femto IO, PIC chipKIT, ESP8266, ESP32, FreSoC2, LinkIt One, Arduino 101, NRF52832, and many others, so I try to make sure they are all well supported by Visuino. I am trying to do the same for the stm32duino boards. Already added initial Maple Mini support, but still looking if it needs tweaking/improving.
I have couple of other ST boards, and will be fighting with them again, as soon as I find another gap. (Adding some I2C modules to Visuino now...)
Please give me a good direction as to how best to support the stm32duino, and what is the recommended repository/board manager file to use, for all the Visuino users.
If you want code that is compatible with both Arduino and stm32duino with the same input parameters, then the analogWrite() one would be the closet between the two.
It will generate a PWM output with variable duty cycle from 0 to 255 in both Arduino and the libmaple stm32duino.

If you want to fully support the precission available in the stm32, that's 16 bits, the the function to use is pwmWrite(), and the duty cycle parameter can take a 16bit value. But then you will have code that only works on the this core.

I do not know if you want to just create code compatible with many boards, or add code that specific for each board. Depending on that, you can choose which one to use.

Boian Mitov
Posts: 14
Joined: Sun Jul 09, 2017 9:03 pm

Re: Fading PB1 (D33) LED

Post by Boian Mitov » Thu Jul 13, 2017 9:36 pm

victor_pv wrote:
Thu Jul 13, 2017 12:02 am
If you want to fully support the precission available in the stm32, that's 16 bits, the the function to use is pwmWrite(), and the duty cycle parameter can take a 16bit value. But then you will have code that only works on the this core.

I do not know if you want to just create code compatible with many boards, or add code that specific for each board. Depending on that, you can choose which one to use.
You misunderstand the question. pwmWrite does not seem to work. It does not dim the LED :-( .
Is that a bug in the library? It worked fine in the Leaf version.

victor_pv
Posts: 1337
Joined: Mon Apr 27, 2015 12:12 pm

Re: Fading PB1 (D33) LED

Post by victor_pv » Fri Jul 14, 2017 4:36 am

Boian Mitov wrote:
Thu Jul 13, 2017 9:36 pm
victor_pv wrote:
Thu Jul 13, 2017 12:02 am
If you want to fully support the precission available in the stm32, that's 16 bits, the the function to use is pwmWrite(), and the duty cycle parameter can take a 16bit value. But then you will have code that only works on the this core.

I do not know if you want to just create code compatible with many boards, or add code that specific for each board. Depending on that, you can choose which one to use.
You misunderstand the question. pwmWrite does not seem to work. It does not dim the LED :-( .
Is that a bug in the library? It worked fine in the Leaf version.
Sorry you are right I understood something different.
I believe pwmWrite has not been modified.
Since the PWM depends on hw timers, is there any part of your code that modifies any setting related to that timer?
Also did you add the call to pinMode to set the ping as PWM output?

dannyf
Posts: 63
Joined: Wed May 11, 2016 4:29 pm

Re: Fading PB1 (D33) LED

Post by dannyf » Wed Jul 19, 2017 11:17 pm

I am asking if I can control it with PWM with AnalogWrite.
you can check the datasheet to see if it is one of those output compare pins associated with a timer.

if it is not, you may want to write two almost identical timer routines in which you flip the led pin. the two timer routines are identical other than their periods: they differ from each other with a slight offset, so that you will have the duty cycle on the led go up and down and up ...

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest