adc.c
adc.c
is included as common/Source/adc.c
in much of the sample code.
The following code is relevant:
Filename | Remark |
---|---|
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 |
There may be differences in the code for each sample.
Usage
See the comments in the code below.
functions
void vSnsObj_Init(tsSnsObj _*_pSnsObj)
Initializes the sensor management structure. Called just before vADC_Init()
.
void vADC_Init(tsObjData_ADC *pData,_ _tsSnsObj _*_pSnsObj, bool_t bInitAPR)
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.
void vSnsObj_Process(tsSnsObj *pObj, teEvent eEv)
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).
tsObjData_ADC structure
Members | Remark |
---|---|
u8SourceMask | A bitmap that specifies the port to be ADCed. The specified port becomes the ADC target.
|
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.
|
最終更新