Matlab-Simulink device driver Blockset for Microchip dsPIC / PIC24 / PIC32 Microcontrollers.
DsPIC Block/ADC Analog to Digital Converter
Input driver for Analog-to-Digital Converter peripheral
The ADC Input block convert an analog signal from the PIC input channel selected. For each channel you can, at each time step, either read one sample (get a scalar result) or several samples equaly time spreaded separated (with a period time inferior to the block time step). Thus, you get a vector result within one step time. Result format is specified as signed/unsigned and fractional/integer. The input pin "voltage reference" can be selected as voltage reference. 10 or 12 bits choice for conversion is available for dsPIC 33f family. On dsPIC 30f, PIC 24F and PIC 24H family, the bit resolution is fixed and device dependant.
- 1 Dialog Box Parameters
Dialog Box Parameters
10 or 12 bits resolution depending on the microcontroller used (set in the Master block). The two choices are available for the dsPIC 33f family.
- Continuous Sampling and get last channel value : In this mode, all selected channel are continuously scanned and converted at high speed. When the simulink block outputs are read, the last value converted from each channel is used. This method provide the minimum time lag between the end of conversions and the calculations using theses values.
- Continuous Sampling get output vector : In this mode, all channel selected are scanned and converted at low speed allowing to get exactly the number of sample defined in 1 time step. For example, you can get 6 samples from both channels AN0 and AN1. The samples of AN0 (resp AN1) will have a fixed sample rate. To avoid missalignment between end of time step and sampling rate, considere using ADC as timer refference in the master block. In this case, the time step is triggered by the end of the ADC conversions.
Number of output samples for each channel at each step
Only available if Mode is set to "Continuous Sampling get output vector". Set the number of sample desired for each output. All outputs have the same number of sample.
Select the Conversion voltage reference. It can be the microcontroller alimentation, or external voltage reference when using external PIN reference.
Select the output. Choice are integer or fractional (right or left justification) and signed/unsigned.
Used when mode is set to "Continuous Sampling get output vector".
AN Channel to convert
Choose AN input pins (enter the vector with channel number to convert). This will also set the number of output of the block. Starting at 0 for AN0. For example, [0 1] will convert channels AN0 and AN1 and block will have two outputs.
Max Value ANmax
Simulink set the ANmax variable equal to the max value for the AN converter. For 10 bits, it is 1024 and for 12 bits it is 4096. This ANmax variable is evaluated in the matlab workspace. It allows to normalise the output of the ADC and to keep calculation correct while changing from 10 bits to 12 bits mode.
External Input Resistor
Define the value (in ohm) of the input resistor. The bigger, the slower is the charge of the capacity and the slower is the conversion time.
Define the ambiant temperature. The higher, the slower the conversion time is. (see Microchip Refference manual)
-1 mean inherited (Define the time step of this block, -1 or a multiple of the diagram time step)
Provides the following informations :
- Tsmp : Time to sample 1 channel
- T/Channel : Time of sample and convert 1 channel
- Tall : Conversion time for all samples
Should be auto convert for most case. When another mode is selected, the mode should be Continous Sampling & get last channel value. Thus, the conversion will only occurs when the selected event occurs. If no event occurs between two simulink time step, the previoius value remains.
- auto convert (default)
- Motor Control PWM
- Timer3 (OC_HW PWM)
- Low to High transition on INT0 pin