Skip to content
This repository was archived by the owner on Apr 16, 2021. It is now read-only.

analogWrite to LED_PWR and digitalWrite after analogWrite #76

Open
FemmeVerbeek opened this issue May 18, 2020 · 3 comments
Open

analogWrite to LED_PWR and digitalWrite after analogWrite #76

FemmeVerbeek opened this issue May 18, 2020 · 3 comments

Comments

@FemmeVerbeek
Copy link

It looks like two bugs to me.

  • analogWrite to LED_PWR hangs up the program
  • digitalWrite to any pin stops working after being preceded by a call to analogWrite to the same pin.

my not so beautiful workaround

void digitalWrite2(int pinnr , boolean pinhigh){
if (pinnr==LED_PWR) digitalWrite(LED_PWR, pinhigh);
else analogWrite(pinnr, 255*pinhigh);
}
void analogWrite2(int pinnr ,uint8_t value){
if (pinnr==LED_PWR) digitalWrite(pinnr,value>127);
else analogWrite(pinnr,value);
}

It would be better to solve it by redefining the functions itself but so that it still compiles for other boards.

  • Is there an #ifdef compiler directive to check that we are compiling for this type of board.
  • while redefining, how would you point back to the orginal funtions
@facchinm
Copy link
Member

Hi @FemmeVerbeek
analogWrite(LED_PWR, 10); should just work in any condition unless you already have more than 4 other PWM active (I just tested it). The reason is this assert (https://github.com/ARMmbed/mbed-os/blob/master/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/pwmout_api.c#L146) that checks how many PWM channels are already in use.
Is this your case?

@FemmeVerbeek
Copy link
Author

FemmeVerbeek commented May 26, 2020 via email

@JeffAnton
Copy link

I've hit this problem also. digitalWrite after an analogWrite to the same pin does not work. Once I saw this report I changed my digitalWrite calls into analogWrite with values of 0 or 255 and my project is working properly. BTW: I have four analogWrite pins in use.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants