sandeepmistry/arduino-nRF5

PWM signal from analogWrite does not stop when pin is set to different mode

Open

#169 opened on 2017年6月19日

GitHub で見る
 (13 comments) (0 reactions) (0 assignees)C (288 forks)github user discovery
bughelp wanted

Repository metrics

Stars
 (952 stars)
PR merge metrics
 (PR metrics pending)

説明

Looks the analogWrite() "pwm" signal on the nRF51 (now PWM hardware, so uses a timer instead) does not stop operation even after pinMode() and digitalWrite() has been applied to the same pin.

Simple sketch for testing:

const int analogOutPin = 9;

void setup() {
  // put your setup code here, to run once:
  
}

void loop() {
  // Increase PWM until maximun value, takes around a couple of seconds
  for (byte i = 0; i<255; i++) {
    analogWrite(analogOutPin, i);
    delay(10);
  }

  // Toggle the same pin high and low a couple of times
  delay(1000);
  pinMode(analogOutPin, OUTPUT);
  digitalWrite(analogOutPin, HIGH);
  delay(1000);
  digitalWrite(analogOutPin, LOW);
  delay(1000);
  digitalWrite(analogOutPin, HIGH);
  delay(1000);
  digitalWrite(analogOutPin, LOW);
  delay(1000);
}

Expected behaviour:

  • PWM signal increasing from minimum to maximum
  • Same pin signal toggled high and low a couple of times
  • loop iterates

Recorded behaviour:

  • PWM signal increasing from minimum to maximum
  • PWM signal stays at maximum value
  • loop iterates

コントリビューターガイド