基于android7.1+msm8937读取ADC采样值
基于android7.1+msm8937讀取ADC采樣值
?
讀取給設(shè)備供電的電壓,比如16V,通過監(jiān)控ADC(Analog-to-Digital Conversion)值來知道電源波動情況和實際給設(shè)備供電的電壓。
?
1.????硬件電路設(shè)計
輸入的VCC_16V_IN經(jīng)過R206和R207分壓連接到MPP1_16V_ADC也就是PMI8937_MPP1
?
ADCs are directly controlled by the PMIfuel gauge
2.????硬件原理
2.1??MPP1路由到SPMI
?
Analog input – inputs are routed to the analog multiplexer switch network; if selected, andthat analog voltage is routed to the HK/XO ADC for digitization(數(shù)字化).
?
2.2??PMI8937模擬輸入通道
PMI8937模擬多路復(fù)用器和掃描功能,見下圖
ADC電壓值=(16*100*1024)/((1024+100)*1024)=1.4234875V。
?
此圖來之于《80-P2561-1_PMI8937 POWER MANAGEMENTIC DEVICE SPECIFICATION》文檔。有兩個MPP_1,選擇哪個通道呢?因為計算出來到MPP1的最大電壓是1.4V<1.5V,所以選擇16通道(十進制),相當(dāng)于十六進制的0x10,確定為16通道后,scaling也確定為1了。
2.3??ADC性能參數(shù)
?
16-bit dedicatedcurrent ADC (15 bits plus sign bit) ,16位的采樣分辨率。
2.4??MPP1配置為ADC的參考示例
驅(qū)動電壓值的驅(qū)動可以參考kernel\msm-3.18\Documentation\devicetree\bindings\hwmon\qpnp-adc-voltage.txt
-------------------------------非常重要----------------------------------
Client device example:
/* Add to the clients node that needs theVADC channel A/D */
client_node {
?????? qcom,client-vadc= <&pm8941_vadc>;
};
?
/* Clients have an option of measuring ananalog signal through an MPP.
??MPP block is not part of the VADC block but is an individual PMIC
??block that has an option to support clients to configure an MPP as
?? ananalog input which can be routed through one of the VADC pre-mux
??inputs. Here is an example of how to configure an MPP as an analog
??input */
?
/* Configure MPP4 as an Analog input toAMUX8 and read from channel 0x23 */
/* MPP DT configuration in the platform DTfile*/
?????? mpp@a300{ /* MPP 4 */
????????????? qcom,mode= <4>; /* AIN input */
????????????? qcom,invert= <1>; /* Enable MPP */
????????????? qcom,ain-route= <3>; /* AMUX 8 */
????????????? qcom,master-en= <1>;
????????????? qcom,src-sel= <0>; /* Function constant */
?????? };
?
/* VADC Channel configuration */
?????? chan@23{
????????????? label= "mpp4_div3";
????????????? reg= <0x23>;
????????????? qcom,decimation= <0>;
????????????? qcom,pre-div-channel-scaling= <1>;
????????????? qcom,calibration-type= "absolute";
????????????? qcom,scale-function= <0>;
????????????? qcom,hw-settle-time= <0>;
????????????? qcom,fast-avg-setup= <0>;
?????? };
?
?
3.????軟件實現(xiàn)
3.1??相關(guān)的驅(qū)動、設(shè)備樹和內(nèi)核文檔
(1)??ADC驅(qū)動
Kernel/msm-3.18/drivers/hwmon/qpnp-adc-common.c
Kernel/msm-3.18/drivers/hwmon/qpnp-adc-voltage.c
qpnp-adc-voltage.c
Qualcomm's QPNP PMIC Voltage ADC Arbiter
?
QPNP PMIC Voltage ADC (VADC) providesinterface to clients to read
Voltage. A 15 bit ADC is used for Voltagemeasurements. There are multiple
peripherals to the VADC and the scope ofthe driver is to provide interface
for the USR peripheral of the VADC.
?
Kernel/msm-3.18/hwmon/qpnp-adc-current.c
(2)??ADC DTS
Kernel/msm-3.18/arch/arm/boot/dts/qcom/msm-pmi8937.dtsi
Kernel/msm-3.18/arch/arm/boot/dts/qcom/msm-pm8937.dtsi
?
(3)??ADC DTSI文檔
Kernel/msm-3.18/Documentation/devicetree/bindings/hwmon/qpnp-adc-voltage.txt
Kernel/msm-3.18/Documentation/devicetree/bindings/hwmon/qpnp-adc-current.txt
?
4.????軟件實現(xiàn)
4.1??設(shè)備樹
Y:\trunk\kernel\msm-3.18\arch\arm\boot\dts\qcom\msm-pmi8937.dtsi
(1)??配置MPP1為模擬輸入
pmi8937_mpps: mpps {
???????????????????? spmi-dev-container;
???????????????????? compatible= "qcom,qpnp-pin";
???????????????????? gpio-controller;
???????????????????? #gpio-cells= <2>;
???????????????????? #address-cells= <1>;
???????????????????? #size-cells= <1>;
???????????????????? label= "pmi8937-mpp";
?
???????????????????? mpp@a000{
??????????????????????????? reg= <0xa000 0x100>;
??????????????????????????? qcom,pin-num= <1>;
??????????????????????????? qcom,mode= <4>; // AIN input ,QPNP_PIN_MODE_AIN
??????????????????????????? qcom,invert= <1>; // Enable MPP,QPNP_PIN_INVERT_ENABLE
??????????????????????????? qcom,ain-route= <0>; //AMUX 5,QPNP_PIN_AIN_AMUX_CH5,AMUX 8----3 ????
??????????????????????????? qcom,master-en= <1>;//Enable features within the pin block based on configurations.(GPIO/MPP)
??????????????????????????? qcom,src-sel= <0>; //Function constant
??????????????????????????? //status= "disabled";
???????????????????? };
?
重點說明下qcom,ain-route = <0>;
- qcom,ain-route: Set the destination for analog input.
???????????????????? QPNP_PIN_AIN_AMUX_CH5?? = 0, (MPP)
???????????????????? QPNP_PIN_AIN_AMUX_CH6?? = 1, (MPP)
???????????????????? QPNP_PIN_AIN_AMUX_CH7?? = 2, (MPP)
???????????????????? QPNP_PIN_AIN_AMUX_CH8?? = 3, (MPP)
???????????????????? QPNP_PIN_AIN_AMUX_ABUS1= 4, (MPP)
???????????????????? QPNP_PIN_AIN_AMUX_ABUS2= 5, (MPP)
???????????????????? QPNP_PIN_AIN_AMUX_ABUS3= 6, (MPP)
???????????????????? QPNP_PIN_AIN_AMUX_ABUS4= 7? (MPP)
從kernel\msm-3.18\arch\arm\boot\dts\qcom\msm-pm8937.dtsi下面的信息
mpp@a300 {
??????????????????????????? /*MPP4 - CASE_THERM config */
??????????????????????????? reg= <0xa300 0x100>;
??????????????????????????? qcom,pin-num= <4>;
??????????????????????????? qcom,mode= <4>; /* AIN input */
??????????????????????????? qcom,invert= <1>; /* Enable MPP */
??????????????????????????? qcom,ain-route= <3>; /* AMUX 8 */
??????????????????????????? qcom,master-en= <1>;
??????????????????????????? qcom,src-sel= <0>; /* Function constant */
??????????????????????????? status= "disabled";
???????????????????? };
知道MPP4是采用AMUX8,推斷為MPP1采用AMUX5,所以配置為qcom,ain-route= <0>;如果配置為AMUX8,經(jīng)測試獲取到的值不正常,而且波動很大。
?
(2)??配置通道16
根據(jù)上面的計算,輸入到MPP1的電壓<1.5V,所以選擇16通道,下面增加通道相關(guān)的
//kandi add for 0x10 channel
???????????????????? chan@10{
??????????????????????????? label= "power16v_detect";
??????????????????????????? reg= <0x10>;
??????????????????????????? qcom,decimation= <0>;// 0 : 512, Sampling rate to use for the individual channelmeasurement.
??????????????????????????? qcom,pre-div-channel-scaling= <0>;//0 : {1, 1},Pre-div used for the channel before the signal isbeing measured
??????????????????????????? qcom,calibration-type= "ratiometric";//Reference voltage to use for channel calibration.
??????????????????????????? qcom,scale-function= <0>;//0 : Default scaling to convert raw adc code to voltage.
??????????????????????????? qcom,hw-settle-time= <0>;//Settling period for the channel before ADC read.
??????????????????????????? qcom,fast-avg-setup= <0>;//0 : 1,Average number of samples to be used for measurement
???????????????????? };
(3)???
pmi8937_vadc: vadc@3100 {
?????? compatible= "qcom,qpnp-vadc";
?????? reg= <0x3100 0x100>;
…
?
4.2??Lk階段讀取電壓值
bootable\bootloader\lk\dev\pmic\pm8x41\include\pm_vadc_hc.h
/* API: Set the PM8x41 MPP pin as ADC */
void pm8x41_enable_mpp_as_adc(uint16_tmpp_num);
沒有驗證過。
?
Qcom LK階段如何使用ADC介紹
https://blog.csdn.net/loongembedded/article/details/80577667
?
4.3??ADB讀取電壓值
adb root
adb shell
cat/sys/bus/spmi/devices/qpnp-vadc-15/power_in_detect
4.4??內(nèi)核上讀取adb數(shù)值
(1)?? 獲取ADC設(shè)備
pdata->id_vadc_dev =qpnp_get_vadc(&(pdata ->dev), "ltp_tem");
(2)?? 讀取電壓值
rc = qpnp_vadc_read(data->id_vadc_dev,P_MUX4_1_1, &results); //0x13=19=P_MUX4_1_1
?
相關(guān)的API接口和結(jié)構(gòu)體
?
示例代碼
參考:
VADC獲取溫度值
https://blog.csdn.net/u012719256/article/details/79296034
《新程序員》:云原生和全面數(shù)字化實踐50位技術(shù)專家共同創(chuàng)作,文字、視頻、音頻交互閱讀總結(jié)
以上是生活随笔為你收集整理的基于android7.1+msm8937读取ADC采样值的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: How to use USB to do
- 下一篇: linux qcom LCD framw