Difference between revisions of "Component: ADC Template (Inputs: Analog)"
(2 intermediate revisions by the same user not shown) | |||
Line 52: | Line 52: | ||
Simple ADC example allowing analogue values to be read on ADC inputs AN0 and AN1 as a byte, these are then displayed on the LCD connected to PortB as a number ranging from 0-255 representing 0V to VCC. | Simple ADC example allowing analogue values to be read on ADC inputs AN0 and AN1 as a byte, these are then displayed on the LCD connected to PortB as a number ranging from 0-255 representing 0V to VCC. | ||
+ | |||
{{Fcfile|ADCByte.fcfx|ADCByte}} | {{Fcfile|ADCByte.fcfx|ADCByte}} | ||
+ | |||
[[File:ADCPanel.jpg]] | [[File:ADCPanel.jpg]] | ||
Line 59: | Line 61: | ||
Simple ADC example allowing analogue values to be read on ADC inputs AN0 and AN1 as a 10 or 12-bit value depending on the target microcontroller, these are then displayed on the LCD connected to PortB as a number ranging from 0-1023 or 0-4095 representing 0V to VCC. | Simple ADC example allowing analogue values to be read on ADC inputs AN0 and AN1 as a 10 or 12-bit value depending on the target microcontroller, these are then displayed on the LCD connected to PortB as a number ranging from 0-1023 or 0-4095 representing 0V to VCC. | ||
+ | |||
{{Fcfile|ADCInt.fcfx|ADCInt}} | {{Fcfile|ADCInt.fcfx|ADCInt}} | ||
+ | |||
+ | |||
===Reading a sample as a Voltage=== | ===Reading a sample as a Voltage=== | ||
Simple ADC example allowing analogue Voltages to be read on ADC inputs AN0 and AN1, these are then displayed on the LCD connected to PortB in Volts from 0.0V-VCC. The VRef Voltage property needs to be correct for the Voltage to be calculated correctly. | Simple ADC example allowing analogue Voltages to be read on ADC inputs AN0 and AN1, these are then displayed on the LCD connected to PortB in Volts from 0.0V-VCC. The VRef Voltage property needs to be correct for the Voltage to be calculated correctly. | ||
+ | |||
{{Fcfile|ADCVoltage.fcfx|ADCVoltage}} | {{Fcfile|ADCVoltage.fcfx|ADCVoltage}} | ||
+ | |||
+ | |||
===Filtering ADC Inputs=== | ===Filtering ADC Inputs=== | ||
Simple example which uses a filtering technique to provide a digital low pass filter on the ADC readings. The output of the filter is 50% the ADC reading and 50% the previous reading. | Simple example which uses a filtering technique to provide a digital low pass filter on the ADC readings. The output of the filter is 50% the ADC reading and 50% the previous reading. | ||
+ | |||
{{Fcfile|LPFilter.fcfx|LPFilter}} | {{Fcfile|LPFilter.fcfx|LPFilter}} | ||
+ | |||
In this example the output of the filter is 25% the ADC reading and 75% the previous reading. | In this example the output of the filter is 25% the ADC reading and 75% the previous reading. | ||
+ | |||
{{Fcfile|LPFilter2.fcfx|LPFilter2}} | {{Fcfile|LPFilter2.fcfx|LPFilter2}} | ||
+ | |||
+ | |||
===Analogue Inputs Window=== | ===Analogue Inputs Window=== | ||
Line 86: | Line 99: | ||
===Scope Window=== | ===Scope Window=== | ||
− | An ADC based component will automatically add a trace to the | + | An ADC based component will automatically add a trace to the data recorder window allowing you to get a view of the analogue data over time during simulation. |
[[File:ADCScope.jpg]] | [[File:ADCScope.jpg]] | ||
+ | |||
+ | Based on the Scope Traces component property. | ||
==Downloadable macro reference== | ==Downloadable macro reference== |
Latest revision as of 10:11, 28 August 2019
Author | Matrix Ltd |
Version | 1.3 (Release) |
Category | Inputs: Analog |
Contents
ADC Template component
Base ADC component with no graphical interface. Contains all of the embedded side component calls to provide an ADC interface suitable for wrapping with a new ADC style component.
This component can be used as a base to create child components
The following components all inherit the traits of ADC Template:
Examples
Read a 8-bit Byte
Simple ADC example allowing analogue values to be read on ADC inputs AN0 and AN1 as a byte, these are then displayed on the LCD connected to PortB as a number ranging from 0-255 representing 0V to VCC.
Read a 10-bit or 12-bit sample
Simple ADC example allowing analogue values to be read on ADC inputs AN0 and AN1 as a 10 or 12-bit value depending on the target microcontroller, these are then displayed on the LCD connected to PortB as a number ranging from 0-1023 or 0-4095 representing 0V to VCC.
Reading a sample as a Voltage
Simple ADC example allowing analogue Voltages to be read on ADC inputs AN0 and AN1, these are then displayed on the LCD connected to PortB in Volts from 0.0V-VCC. The VRef Voltage property needs to be correct for the Voltage to be calculated correctly.
Filtering ADC Inputs
Simple example which uses a filtering technique to provide a digital low pass filter on the ADC readings. The output of the filter is 50% the ADC reading and 50% the previous reading.
In this example the output of the filter is 25% the ADC reading and 75% the previous reading.
Analogue Inputs Window
The Analogue inputs window available from the View menu allows you to see the values for all of the analogue inputs which are active in your program. They can also be manually altered by dragging the mouse along one of the sliders.
Chip Diagram
Active analogue inputs are highlighted in yellow on the chip diagram.
Scope Window
An ADC based component will automatically add a trace to the data recorder window allowing you to get a view of the analogue data over time during simulation.
Based on the Scope Traces component property.
Downloadable macro reference
RawSampleInt
Background call to read the ADC at full bit depth
Call Enable() first
Parameters
- This macro has no parameters
Return value
RawAverageByte
Background call to read the ADC as a byte average sample over time
Call Enable() before this
Parameters
- BYTE NumSamples
- BYTE DelayUs
- Number of micro seconds in between taking each sample
Return value
GetString
Reads the ADC as a direct voltage and returns as as String
Parameters
- This macro has no parameters
Return value
GetAverageByte
Function call to read the ADC as a byte average sample over time
Parameters
- BYTE NumSamples
- BYTE DelayUs
- Number of micro seconds in between taking each sample
Return value
RawAverageInt
Background call to read the ADC as a full width average sample over time
Call Enable() before this
Parameters
- BYTE NumSamples
- BYTE DelayUs
Return value
GetAverageInt
Function call to read the ADC as a full width average sample over time
Parameters
- BYTE NumSamples
- BYTE DelayUs
- Number of micro seconds in between taking each sample
Return value
GetVoltage
Reads the ADC as a direct voltage
Parameters
- This macro has no parameters
Return value
RawEnable
Enables and configures the ADC channel to be an analogue input.
Only one ADC channel can be enabled at a time. Any RAW functions will reference the last enabled channel only.
Parameters
- This macro has no parameters
Return value
- This call does not return a value
RawSampleByte
Background call to read the ADC as a byte
Call Enable() before this
Parameters
- This macro has no parameters
Return value
GetInt
Blocking call to read the ADC at full bit depth
Parameters
- This macro has no parameters
Return value
RawDisable
Disables the previously enabled ADC channel and converts back to digital mode.
Parameters
- This macro has no parameters
Return value
- This call does not return a value
GetByte
Blocking call to read the ADC as a byte
Parameters
- This macro has no parameters
Return value
Simulation macro reference
GetSampleBits
Gets the number of bits per sample
Parameters
- This macro has no parameters
Return value
GetSpeedFilter
Gets the Conversion speed filter string
Use in Component.Property.SetFilter()
Parameters
- This macro has no parameters
Return value
SetProperties
Set the VRef options and voltage, ConvSpeed and AcqTime for the ADC component.
Parameters
- INT VRef10Ms
- Voltage Reference x10 mV - Default 500 = 5V
- BOOL VRefOpt
- External VRef 0=Disabled, 1=Enabled
- INT ConvSpdOpt
- Conversion Speed Setting - Refer to numbered list
- INT Aquisitions
- Aquisition time in micro seconds to precharge before sampling
Return value
- This call does not return a value
SetChannel
Sets the channel ID for the component
Parameters
- INT ChannelId
- Chaannel starting at 0, -1 is unconnected
Return value
- This call does not return a value
Property reference
Channel
This property is of type Single analog pin and can be referenced with the variable name channel.
Analogue Input Channel - Which pin is the analogue input connected to?
VRef voltage
This property is of type Signed integer and can be referenced with the variable name vrefvol.
Used by the GetVoltage or GetString component macros to take an ADC reading and convert it into a Voltage.
+VRef voltage x 10mV
Default 500 = 5.0V
VRef option
This property is of type Fixed list of ints and can be referenced with the variable name vrefop.
Defines what is used as the ADC maximum reference. ADC Range = GND to VRef Voltage
VDD - Defines the microcontrollers power supply pin as the max reference,
VREF+ Pin - Dedicated pin on the microcontroller to allow for a variable reference voltage.
Conversion speed
This property is of type Fixed list of ints and can be referenced with the variable name convspd.
Clock setting to select how fast the ADC peripheral will perform an ADC conversion.
The FRC setting is based on a RC time base and so will vary with temperature and pressure.
Other settings are generally based on divisions of the master clock.
Acquisition cycles
This property is of type Signed integer and can be referenced with the variable name actime.
Number of micro seconds to wait for the ADC input to charge before starting the analogue sample.
Bit Depth
This property is of type Signed integer and can be referenced with the variable name bits.
Maximum number of digital bits the ADC can sample.
8 bit = ADC range 0 - 255
10 bit = ADC range 0 - 1023
12 bit = ADC range 0 - 4095
Scope Traces
This property is of type True or false and can be referenced with the variable name ScopeTraces.
Selects if the scope traces are automatically generated or not