Analog Outputs
A microcontroller pin can only output a high Vcc value or . To get values in between the microcontroller uses pulse width modulation (PWM).
PWM works by setting the output high for only a percentage of time during each sampling period. The percentage is called the duty cycle of the PWM signal. If the sampling period is constant and fast enough the end result is a signal whose value is the same percentage of Vcc. Thus to achieve PWM the microcontroller outputs a series of on-off pulses.
To follow along, connect LED-resistor pairs to pins , , and to an Arduino Uno as shown.
The following suboptions can be given:
"MaxValue" | the maximum absolute value ymax of the output |
"Negative" | the pin to indicate a negative output value |
"Positive" | the pin to indicate a positive output value |
"Timer" | the timer to generate the output pulses |
"TimerMode" | the mode to operate the timer |
"TimerTop" | the TOP value of the timer |
"SamplingPeriod" | the sampling period of the output's timer |
"Complementary" | the complementary pins |
For an output value y, the duty cycle is computed as , where ymax is the maximum of the magnitude of possible output values. The duty cycle must be nonnegative and any value greater than 100 is clipped. The maximum absolute value can be explicitly specified as {"pin", "Analog","MaxValue"->ymax}. By default, ymax is the operating voltage Vcc.
The analog pins can only be output positive values. If the output is negative, the absolute value is output. A second digital pin can be used to indicate when a negative value is output on the analog pin.
A pin can also be used to indicate positive values.
Explicitly indicate both positive and negative values using two digital pins.
The suboptions "Timer", "TimerMode", and "TimerTop" specifies the timer to use in generating the waveform and various other parameters of the timer. More information on the timer and the waveforms can be found in the microcontroller's datasheet. The property "PulseWidthWaveform" gives information about the parameters that were used to generate the waveform.
Some microcontrollers can output complementary output values. The "Complementary" suboption specifies the pin to output the complementary value.
Connect LED-resistor pairs to pins and on an Arduino Yun.