sandeepmistry/arduino-nRF5

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

Open

#169 建立於 2017年6月19日

在 GitHub 查看
 (13 留言) (0 反應) (0 負責人)C (288 fork)github user discovery
bughelp wanted

倉庫指標

Star
 (952 star)
PR 合併指標
 (PR 指標待抓取)

描述

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

貢獻者指南