最終更新
最終更新
adc.c
is included as common/Source/adc.c
in much of the sample code.
The following code is relevant:
There may be differences in the code for each sample.
See the comments in the code below.
Initializes the sensor management structure. Called just before vADC_Init()
.
This function initializes ADC. The tsObjData
structure (for storing results) and the tsSnsObj
structure (for managing ADC) are prepared in advance.
If bInitAPR
is TRUE
, the ADC hardware is initialized. Hardware initialization takes some time, so be sure to run vADC_WaitInit()
and wait for the initialization.
This process is called every time the conversion of one ADC port is completed. To wait for the completion of ADC conversion, E_AHI_DEVICE_ANALOGUE
interrupt is used. This can be done simply after a certain period of time (approximately 100 usec) has elapsed.
In this process, the acquisition of ADC value and the operation to mV value are performed, and the value is stored in the tsSnsObj
structure.
This process is an event processing for the state transition managed by the tsSnsObj
structure. Immediately after this processing, bSnsObj_isComplete()
is called to check whether the processing is completed. To restore the initial state again, this process is executed again with E_ORDER_KICK
as an argument (that is, to execute ADC again, E_ORDER_KICK
is executed twice after completion).
u8SourceMask
A bitmap that specifies the port to be ADCed. The specified port becomes the ADC target.
TEH_ADC_SRC_VOLT
: supply voltage
TEH_ADC_SRC_ADC_1-4
: ADC1,2,3,4
u8InputRangeMask
Specify the range (0-Vref or 0-2Vref) of the ADC target port. The specified port becomes 0-Vref. If not specified, it becomes 0-2Vref.
ai16Result[]
Structure for storing ADC values. The result is stored as mV value.
TEH_ADC_IDX_VOLT
: supply voltage.
TEH_ADC_IDX_ADC_1-4
: ADC1,2,3,4
sensor_driver.h
Abstraction of sensor processing (header files)
sensor_driver.c
Sensor processing using state transitions
adc.h
ADC processing section (header file)
adc.c
ADC processing