sandeepmistry/arduino-nRF5

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

Open

#169 aperta il 19 giu 2017

Vedi su GitHub
 (13 commenti) (0 reazioni) (0 assegnatari)C (288 fork)github user discovery
bughelp wanted

Metriche repository

Star
 (952 star)
Metriche merge PR
 (Metriche PR in attesa)

Descrizione

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

Guida contributor