User Tools

Site Tools


uphp:functions:adc_read

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
uphp:functions:adc_read [2017/04/13 06:47]
jeff
uphp:functions:adc_read [2021/09/13 05:57] (current)
Line 7: Line 7:
 ====Description==== ====Description====
  
-<well size="sm"> +<well size="sm"><html>
-<html>+
 <span style="font-size:125%;color:green">int <span style="font-size:125%;color:green">int
-<span style="color:black"> +<span style="color:black">adc_read (
-</html> +
-[[adc_read]] ( +
-<html>+
 <span style="color:green">int <span style="color:green">int
 <span style="color:blue">$channel <span style="color:blue">$channel
 <span style="color:black">) <span style="color:black">)
-</html> +</html></well>
-</well>+
  
 Return the raw <tooltip title="Analog to Digital Converter">ADC</tooltip> value of a channel Return the raw <tooltip title="Analog to Digital Converter">ADC</tooltip> value of a channel
Line 32: Line 27:
 Channel 2 is connected to pin A3, which reads 0-5V DC. Channel 2 is connected to pin A3, which reads 0-5V DC.
  
-====Return Value====+====Return Values====
  
 <html><b><span style="color:green">Integer<span style="color:black"></b></html> ADC value: <html><b><span style="color:green">Integer<span style="color:black"></b></html> ADC value:
Line 43: Line 38:
  
 ===Example #1=== ===Example #1===
-Read Channel 0 and use the constants v_adc_offset and v_adc_mul to obtain a calibrated voltage((**Example #1** demonstrates a legacy method to obtain a calibrated voltage, which was the primary method in early Wattmon releases, and has not yet been removed from the OS. The calibration constants are loaded automatically into [[uphp:uphp_special_variables|$_GLOBALS]] from the SD Card [[os:config:battery.ini|/config/battery.ini]]. These constants can be calculated and set using Control Panel > Voltage Calibration (Calibrate Voltage Sensor). However, that Control Panel interface does not produce or set calibration constants for Channels 1 and 2, and as mentioned, it stores the constants on the SD Card. This "old method" has been superseded by "a new method" that stores the calibration constants for A1, A2 and A3 in NVRAM. The new calibration method is accessed in Control Panel > Devices. There it is possible to calibrate any device on the Wattmon or attached by ModBus, and the constants are then stored in NVRAM on the device itself, instead of on the SD Card. See [[#Additional Information]] for how to obtain calibrated values using the new method.)):+ 
 +Read Channel 0 and use the constants v_adc_offset and v_adc_mul to obtain a calibrated voltage((**Example #1** demonstrates a legacy method to obtain a calibrated voltage, which was the primary method in early [[hardware:wattmons|Wattmon]] releases, and has not yet been removed from the OS. The calibration constants are loaded automatically into [[uphp:uphp_special_variables|$_GLOBALS]] from the SD Card [[software:os:config:battery.ini|/config/battery.ini]]. These constants can be calculated and set using Control Panel > Voltage Calibration (Calibrate Voltage Sensor). However, that Control Panel interface does not produce or set calibration constants for Channels 1 and 2, and as mentioned, it stores the constants on the SD Card. This "old method" has been superseded by "a new method" that stores the calibration constants for A1, A2 and A3 in <tooltip title="Non-Volatile RAM">NVRAM</tooltip>. The new calibration method is accessed in Control Panel > Devices. There it is possible to calibrate any device on the [[hardware:wattmons|Wattmon]] or attached by ModBus, and the constants are then stored in <tooltip title="Non-Volatile RAM">NVRAM</tooltip> on the device itself, instead of on the SD Card. See [[#Additional Information]] for how to obtain calibrated values using the new method.)):
  
 <code php> <code php>
Line 66: Line 62:
 ====Additional Information==== ====Additional Information====
  
-The raw ADC values can be accessed using [[adc_read()]], but it is recommended to use the functions [[mb_get_val_by_role()]] or [[mb_get_dev_by_id()]] in order to obtain calculated values for A1, A2 and A3 that are adjusted by the calibration values stored in //NVRAM//.+The raw ADC values can be accessed using [[adc_read()]], but it is recommended to use the functions [[mb_get_val_by_role()]] or [[mb_get_dev_by_id()]] in order to obtain calculated values for A1, A2 and A3 that are adjusted by the calibration values stored in //<tooltip title="Non-Volatile RAM">NVRAM</tooltip>//.
  
 ===Example #2=== ===Example #2===
 +
 Use [[mb_get_dev_by_id()]] to obtain calibrated values for A1, A2 and A3: Use [[mb_get_dev_by_id()]] to obtain calibrated values for A1, A2 and A3:
  
Line 93: Line 90:
  
 [[uphp:uphp_special_variables]] - Special arrays that are populated automatically (including ''$_GLOBALS'') [[uphp:uphp_special_variables]] - Special arrays that are populated automatically (including ''$_GLOBALS'')
 +
 +[[pin_configure()]] - Configure an <tooltip title="Input/Output">I/O</tooltip> pin as a digital input, output, or analog input [for more information on Channel numbers which are also known as Pin Indexes]
  
 [[floatval()]] - <html>Return the <b><span style="color:green">float<span style="color:black"></b> value of a <b><span style="color:green">number<span style="color:black"></b> or <b><span style="color:green">string<span style="color:black"></b></html> [[floatval()]] - <html>Return the <b><span style="color:green">float<span style="color:black"></b> value of a <b><span style="color:green">number<span style="color:black"></b> or <b><span style="color:green">string<span style="color:black"></b></html>
  
uphp/functions/adc_read.1492066065.txt.gz · Last modified: 2021/09/13 05:56 (external edit)