analogWrite() -> pwm()

What could be included in further releases, or for the forum.
aster
Posts: 29
Joined: Thu Mar 30, 2017 2:41 pm

analogWrite() -> pwm()

Postby aster » Thu Apr 13, 2017 9:30 pm

I know it won't be very well seen for code compatibility, history, habits, ecc

But i think that here everyone know what is a pwm pulse, so why don t use its real name? I always found it confusing to call it analogWrite!

Last but not least pwm() is shorter to write :lol:

racemaniac
Posts: 345
Joined: Sat Nov 07, 2015 9:09 am

Re: analogWrite() -> pwm()

Postby racemaniac » Fri Apr 14, 2017 7:22 am

we could add it as an alias for analogWrite, but the goal of this project is obviously to keep arduino compatibility, so the analogWrite will remain (even though the name is terrible >_<)

User avatar
Pito
Posts: 815
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: analogWrite() -> pwm()

Postby Pito » Fri Apr 14, 2017 7:44 am

analogWrite() has got fixed frequency while it changes duty cycle only.
pwm() usually gets 2 parameters - duty cycle and frequency.
Pukao Hats Cleaning Services Ltd.

edogaldo
Posts: 213
Joined: Fri Jun 03, 2016 8:19 am

Re: analogWrite() -> pwm()

Postby edogaldo » Fri Apr 14, 2017 7:45 am

aster wrote:I know it won't be very well seen for code compatibility, history, habits, ecc

But i think that here everyone know what is a pwm pulse, so why don t use its real name? I always found it confusing to call it analogWrite!

Last but not least pwm() is shorter to write :lol:

The core already provides pwmWrite() (ref. pwm.h/pwm.cpp), it's just 5 letters longer.. ;)

aster
Posts: 29
Joined: Thu Mar 30, 2017 2:41 pm

Re: analogWrite() -> pwm()

Postby aster » Sat Apr 15, 2017 4:24 pm

edogaldo wrote:The core already provides pwmWrite() (ref. pwm.h/pwm.cpp), it's just 5 letters longer.. ;)


it is great

Code: Select all

void analogWrite(uint8 pin, int duty_cycle8)
{
   pinMode(pin,PWM);
   pwmWrite(pin,duty_cycle8 * 257);// 257 maps 255 to 65535 (i.e 255*257 = 65535)
}

void pwmWrite(uint8 pin, uint16 duty_cycle) {
    if (pin >= BOARD_NR_GPIO_PINS) {
        return;
    }
    timer_dev *dev = PIN_MAP[pin].timer_device;
    uint8 cc_channel = PIN_MAP[pin].timer_channel;
    ASSERT(dev && cc_channel);
    timer_set_compare(dev, cc_channel, duty_cycle);
}


so what @racemaniac suggested had already been did, great

Pito wrote:analogWrite() has got fixed frequency while it changes duty cycle only.
pwm() usually gets 2 parameters - duty cycle and frequency.


this would be very good: the possibility to choose the frequency and duty cycle but it would need some effort to make it in arduino style API

User avatar
Pito
Posts: 815
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: analogWrite() -> pwm()

Postby Pito » Sat Apr 15, 2017 5:55 pm

this would be very good: the possibility to choose the frequency and duty cycle but it would need some effort to make it in arduino style API

Everything is available, you can set period/frequency and duty cycle as you wish (with some limitations), just read the libmaple documentation, also discussed few times here, for example:
viewtopic.php?f=3&t=1041&hilit=pito+pwm&start=10
Pukao Hats Cleaning Services Ltd.


Return to “Ideas & suggestions”

Who is online

Users browsing this forum: No registered users and 1 guest