Reference.AnalogWriteResolution History

Hide minor edits - Show changes to markup

June 05, 2013, at 06:40 PM by Scott Fitzgerald -
Changed line 10 from:
  • 12 pins with 8-bit PWM (as the other AVR based boards)
to:
  • 12 pins which default to 8-bit PWM, like the AVR-based boards. These can be changed to 12-bit resolution.
September 16, 2012, at 11:47 PM by Tom Igoe -
September 16, 2012, at 11:47 PM by Tom Igoe -
Changed line 28 from:

If a resolution higher than the hardware capabilities is set, the Arduino will discard the extra bits.

to:

If you set the analogWriteResolution() value to a value higher than your board's capabilities, the Arduino will discard the extra bits.

Changed line 31 from:

If a resolution lower than the hardware capabilities is set, the missing bits will be padded with zeros to fill the hardware required size.

to:

If you set the analogWriteResolution() value to a value lower than your board's capabilities, the missing bits will be padded with zeros to fill the hardware required size.

September 16, 2012, at 11:41 PM by Tom Igoe -
Changed lines 7-8 from:

analogWriteResolution() sets the resolution of the value that can be used by analogWrite(). It defaults to 8 bits (values between 0-255) for backward compatibility with AVR based boards.

to:

analogWriteResolution() sets the resolution of the analogWrite() function. It defaults to 8 bits (values between 0-255) for backward compatibility with AVR based boards.

Changed lines 13-14 from:

By setting the write resolution to 12, we can use analogWrite() with values between 0 and 4095 to exploit the full DAC resolution or to set the PWM signal without rolling over.

to:

By setting the write resolution to 12, you can use analogWrite() with values between 0 and 4095 to exploit the full DAC resolution or to set the PWM signal without rolling over.

Changed lines 20-21 from:

bits: determines the resolution (in bits) of the values used in analogWrite() function. Valid arguments are between 1 and 32. If a resolution higher or lower than hardware capabilities is set, value used in analogWrite() will be respectively truncated or padded with zeros. See the note below for details.

to:

bits: determines the resolution (in bits) of the values used in the analogWrite() function. The value can range from 1 to 32. If you choose a resolution higher or lower than your board's hardware capabilities, the value used in analogWrite() will be either truncated if it's too high or padded with zeros if it's too low. See the note below for details.

September 16, 2012, at 08:14 PM by Cristian -Vacuum- Maglie -
Changed lines 7-10 from:

analogWriteResolution() sets the resolution of the value that can be used by analogWrite(). It defaults to 8 bits (returns values between 0-255) for backward compatibility with AVR based boards.

The Due has 12-bit PWM capabilities that can be accessed by changing the resolution. At 12 bits, analogWrite() can use values between 0 and 4095 without rolling over.

to:

analogWriteResolution() sets the resolution of the value that can be used by analogWrite(). It defaults to 8 bits (values between 0-255) for backward compatibility with AVR based boards.

The Due has the following hardare capabilities:

  • 12 pins with 8-bit PWM (as the other AVR based boards)
  • 2 pins with 12-bit DAC (Digital-to-Analog Converter)

By setting the write resolution to 12, we can use analogWrite() with values between 0 and 4095 to exploit the full DAC resolution or to set the PWM signal without rolling over.

Changed lines 20-21 from:

bits: determines the resolution (in bits) of the PWM functionality. Valid arguments are between 0 and 12. You can set the resolution larger than 12, but higher values are ignored. See the note below for details.

to:

bits: determines the resolution (in bits) of the values used in analogWrite() function. Valid arguments are between 1 and 32. If a resolution higher or lower than hardware capabilities is set, value used in analogWrite() will be respectively truncated or padded with zeros. See the note below for details.

Changed lines 28-31 from:

If a resolution larger than the hardware capabilities is set, the Arduino will limit to highest supported resolution.

If a resolution lower than the hardware capabilities is set, the least significant bits will be ignored.

to:

If a resolution higher than the hardware capabilities is set, the Arduino will discard the extra bits. For example: using the Due with analogWriteResolution(16) on a 12-bit DAC pin, only the first 12 bits of the values passed to analogWrite() will be used and the last 4 bits will be discarded.

If a resolution lower than the hardware capabilities is set, the missing bits will be padded with zeros to fill the hardware required size. For example: using the Due with analogWriteResolution(8) on a 12-bit DAC pin, the Arduino will add 4 zero bits to the 8-bit value used in analogWrite() to obtain the 12 bits required.

Changed lines 42-44 from:
  pinMode(11,OUTPUT);
to:
  pinMode(11, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);
Changed line 56 from:
  analogWrite(13, map(sensorVal, 0, 1023, 0 ,255));
to:
  analogWrite(11, map(sensorVal, 0, 1023, 0 ,255));
Changed line 64 from:
  analogWrite(13, map(sensorVal, 0, 1023, 0, 4095));
to:
  analogWrite(12, map(sensorVal, 0, 1023, 0, 4095));
Added line 73:
Deleted line 75:
September 12, 2012, at 09:20 AM by Federico -
Changed lines 16-17 from:

bits: bits: determines the resolution (in bits) of the PWM functionality. Valid arguments are between 0 and 12. You can set the resolution larger than 12, but higher values are ignored. See the note below for details.

to:

bits: determines the resolution (in bits) of the PWM functionality. Valid arguments are between 0 and 12. You can set the resolution larger than 12, but higher values are ignored. See the note below for details.

September 12, 2012, at 01:08 AM by Scott Fitzgerald -
Changed lines 7-8 from:

analogWriteResolution() sets the resolution of the value that can be used by analogWrite(). It defaults to 8 bits (returns values between 0-255) for backward compatibility.

to:

analogWriteResolution() sets the resolution of the value that can be used by analogWrite(). It defaults to 8 bits (returns values between 0-255) for backward compatibility with AVR based boards.

Changed lines 16-17 from:

bits: determines the resolution (in bits) of the PWM functionality. You can set the resolution larger than 12 and less than 8, see the note below for how this is dealt with.

to:

bits: bits: determines the resolution (in bits) of the PWM functionality. Valid arguments are between 0 and 12. You can set the resolution larger than 12, but higher values are ignored. See the note below for details.

August 26, 2012, at 02:02 AM by Scott Fitzgerald -
Changed lines 5-6 from:

Sets the resolution of the value that can be used by analogWrite(). It defaults to 8 bits (returns values between 0-255) for backward compatibility.

to:

analogWriteResolution() is an extension of the Analog API for the Arduino Due.

analogWriteResolution() sets the resolution of the value that can be used by analogWrite(). It defaults to 8 bits (returns values between 0-255) for backward compatibility.

Changed lines 24-25 from:

If a resolution larger than the hardware capabilities is set, the Arduino will limit to highest supported resolution. For example, using the Uno with analogWriteResolution(10) will only allow you to use an 8-bit number.

to:

If a resolution larger than the hardware capabilities is set, the Arduino will limit to highest supported resolution.

August 24, 2012, at 11:53 PM by Scott Fitzgerald -
Changed lines 1-2 from:

analogWriteResolution(bits)

to:

analogWriteResolution()

Added lines 9-11:

Syntax

analogWriteResolution(bits)

Changed line 72 from:
to:
August 24, 2012, at 11:50 PM by Scott Fitzgerald -
Changed lines 27-30 from:
 // open a serial connection
 Serial.begin(9600); 
 // make our digital pin an output
 pinMode(11,OUTPUT);
to:
  // open a serial connection
  Serial.begin(9600); 
  // make our digital pin an output
  pinMode(11,OUTPUT);
Changed lines 34-59 from:
 // read the input on A0 and map it to a PWM pin
 // with an attached LED
 int sensorVal = analogRead(A0);
 Serial.print("Analog Read) : ");
 Serial.print(sensorVal);

 // the default PWM resolution
 analogWriteResolution(8);
 analogWrite(13, map(sensorVal, 0, 1023, 0 ,255));
 Serial.print(" , 8-bit PWM value : ");
 Serial.print(map(sensorVal, 0, 1023, 0 ,255));

 // change the PWM resolution to 12 bits
 // the full 12 bit resolution is only supported
 // on the Due
 analogWriteResolution(12);
 analogWrite(13, map(sensorVal, 0, 1023, 0, 4095));
 Serial.print(" , 12-bit PWM value : ");
 Serial.print(map(sensorVal, 0, 1023, 0, 4095));

 // change the PWM resolution to 4 bits
 analogWriteResolution(4);
 analogWrite(13, map(sensorVal, 0, 1023, 0, 127));
 Serial.print(", 4-bit PWM value : ");
 Serial.print(map(sensorVal, 0, 1023, 0, 127));
 delay(5);
to:
  // read the input on A0 and map it to a PWM pin
  // with an attached LED
  int sensorVal = analogRead(A0);
  Serial.print("Analog Read) : ");
  Serial.print(sensorVal);

  // the default PWM resolution
  analogWriteResolution(8);
  analogWrite(13, map(sensorVal, 0, 1023, 0 ,255));
  Serial.print(" , 8-bit PWM value : ");
  Serial.print(map(sensorVal, 0, 1023, 0 ,255));

  // change the PWM resolution to 12 bits
  // the full 12 bit resolution is only supported
  // on the Due
  analogWriteResolution(12);
  analogWrite(13, map(sensorVal, 0, 1023, 0, 4095));
  Serial.print(" , 12-bit PWM value : ");
  Serial.print(map(sensorVal, 0, 1023, 0, 4095));

  // change the PWM resolution to 4 bits
  analogWriteResolution(4);
  analogWrite(13, map(sensorVal, 0, 1023, 0, 127));
  Serial.print(", 4-bit PWM value : ");
  Serial.println(map(sensorVal, 0, 1023, 0, 127));
  delay(5);
Added line 61:
Added line 67:
Added line 69:
August 24, 2012, at 11:39 PM by Scott Fitzgerald -
Changed lines 7-8 from:

The Due has 12-bit DAC capabilities that can be accessed by changing the resolution. A 12 bits, analogWrite() can use values between 0 and 4095 without rolling over.

to:

The Due has 12-bit PWM capabilities that can be accessed by changing the resolution. At 12 bits, analogWrite() can use values between 0 and 4095 without rolling over.

Changed lines 11-12 from:

bits: determines the resolution (in bits) of the ADC. You can set the reolution larger than 12 and less than 8, see the note below for how this is dealt with.

to:

bits: determines the resolution (in bits) of the PWM functionality. You can set the resolution larger than 12 and less than 8, see the note below for how this is dealt with.

Changed lines 19-20 from:

If a resolution larger than the hardware capabilities is set, the Arduino will limit to highest supported resolution. For example, using the Uno with analogReadResolution(10) will only allow you an 8-bit number.

to:

If a resolution larger than the hardware capabilities is set, the Arduino will limit to highest supported resolution. For example, using the Uno with analogWriteResolution(10) will only allow you to use an 8-bit number.

Added lines 29-30:
 // make our digital pin an output
 pinMode(11,OUTPUT);
Changed lines 34-38 from:
 // read the input on A0 at default resolution (10 bits)
 // and send it out the serial connection 
 analogReadResolution(10);
 Serial.print("ADC 10-bit (default) : ");
 Serial.print(analogRead(A0));
to:
 // read the input on A0 and map it to a PWM pin
 // with an attached LED
 int sensorVal = analogRead(A0);
 Serial.print("Analog Read) : ");
 Serial.print(sensorVal);

 // the default PWM resolution
 analogWriteResolution(8);
 analogWrite(13, map(sensorVal, 0, 1023, 0 ,255));
 Serial.print(" , 8-bit PWM value : ");
 Serial.print(map(sensorVal, 0, 1023, 0 ,255));

 // change the PWM resolution to 12 bits
 // the full 12 bit resolution is only supported
 // on the Due
 analogWriteResolution(12);
 analogWrite(13, map(sensorVal, 0, 1023, 0, 4095));
 Serial.print(" , 12-bit PWM value : ");
 Serial.print(map(sensorVal, 0, 1023, 0, 4095));

 // change the PWM resolution to 4 bits
 analogWriteResolution(4);
 analogWrite(13, map(sensorVal, 0, 1023, 0, 127));
 Serial.print(", 4-bit PWM value : ");
 Serial.print(map(sensorVal, 0, 1023, 0, 127));
Deleted lines 59-73:
 // change the resolution to 12 bits and read A0
 analogReadResolution(12);
 Serial.print(", 12-bit : ");
 Serial.print(analogRead(A0));
 delay(5);
  // change the resolution to 16 bits and read A0
 analogReadResolution(12);
 Serial.print(", 16-bit : ");
 Serial.print(analogRead(A0));
 delay(5);
 // change the resolution to 8 bits and read A0
 analogReadResolution(8);
 Serial.print(", 8-bit : ");
 Serial.println(analogRead(A0));
 delay(5);
Added line 67:
August 24, 2012, at 09:57 PM by Scott Fitzgerald -
August 24, 2012, at 08:35 PM by Scott Fitzgerald -
Added lines 1-59:

Share