Analog Inputs

When reading analog signals the microcontroller converts the voltage to digital signals using analog to digital conversion (ADC).

The simplest conversation is that of a single input. The signal is converted to a digital signal and stored in a register on the microcontroller. This value is used by the deployed code to reconstruct the analog signal.

1.gif

In some microcontrollers, it is also possible to use differential channels and amplify the signal before doing the conversion.

2.gif

The signals and must be positive.

It is possible to use the voltages , , , or as the input signal.

"c"<|"Type""Analog"|>Ain
{"c+","c-"}<||>ΔAin
"c+" <|,"NegativeDifferentialInput""c-",|>Ain+, assuming Ain- is 0
"c+" <|,"NegativeDifferentialInput" "c-"v,|>Ain+, assuming Ain- is v
"c-" <|,"PositiveDifferentialInput" "c+",|>Ain-, assuming Ain+ is Ref
"c-" <|,"PositiveDifferentialInput" "c+"v,|>Ain-, assuming Ain+ is v
c<|,"Gain""g",|>use gain "g"
c<|,spi,|>use specifications spi

Analog input specifications.

Load the package.
In[1]:=
Click for copyable input
Adjust the brightness of the LED on pin with the potentiometer connected to "A4":
In[2]:=
Click for copyable input
Out[2]=
Use the differential value between pins "A4" and "A5" to get the voltage at pin "A4":
In[3]:=
Click for copyable input
Out[3]=

It may be possible to specify additional options for the ADC conversion. They include "Reference" and "Prescaler".

The following values can be given for the ADC reference voltage:

"AVCC" or Automaticvoltage Vcc at analog voltage pin AVCC
"AREF"arefvoltage aref at the analog reference pin AREF
"Internal"internal reference voltage

Reference voltage for analog inputs.

Use the voltage of at the AREF pin as the reference voltage.
In[4]:=
Click for copyable input
Out[4]=

The ADC may need to happen at a different speed than the microcontroller's system clock speed. There is a prescaler that can be used to do the conversion at the appropriate speed. The prescaler value is automatically selected based on the system clock frequency and information in the datasheet. This value can also be explicitly specified.

Use a prescaler of to scale down the input clock for ADC.
In[5]:=
Click for copyable input
Out[5]=
The actual reference and prescaler values can be obtained from the "ADC" property.
In[6]:=
Click for copyable input
Out[6]=