Skip to content

Commit 0e9c64d

Browse files
committed
March 2020 - Learn Folder Updates
Update 3/2/2020 - Simple Libraries v1.4.153 - Tagged Release Version
1 parent f0a7060 commit 0e9c64d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+632
-206
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/*
2+
LIS3DH Test ADC mV with Calibration.c
3+
4+
Test Harness for the Parallax LIS3DH 3 Axis Accelerometer module with ADC.
5+
6+
http://learn.parallax.com/propeller-c-simple-devices/lis3dh-three-axis-accelerometer
7+
8+
9+
I/O Pins connections:
10+
11+
P8 -> CLK (SCK)
12+
P7 <-> DATA (SDI)
13+
P6 -> /ENABLE (CS)
14+
15+
16+
Instructions:
17+
18+
Connect LIS3DH module to Propeller using the pins shown above
19+
Also connect 3.3V and GND to the LIS3DH module
20+
Upload this code to the Propeller
21+
Open SimpleIDE Terminal or Parallax Serial Terminal at 115200 baud to view the output
22+
23+
24+
Apply voltage to measure to any of the three ADC inputs (measurement ranges +- 400mV):
25+
26+
AD1 - Sip header, accepts 0-7800mV (+- 200mV)
27+
AD2 - PCB top pad, accepts 900mV - 1700mV (+- 100mV)
28+
AD3 - PCB top pad, accepts 900mV - 1700mV (+- 100mV)
29+
30+
31+
Note: Voltages lower or higher than the acceptable range will be rounded to
32+
the minimum or maximum range value. Do NOT exceed 2.5VIN on AD2 or AD3.
33+
34+
35+
36+
*/
37+
38+
#include "simpletools.h" // Include simpletools header
39+
#include "lis3dh.h" // Include lis3dh header
40+
41+
lis3dh *LIS3DH;
42+
43+
int main() // Main function
44+
{
45+
46+
pause(1000); // Start-up pause for debug terminal
47+
term_cmd(CLS);
48+
term_cmd(HOME);
49+
50+
print("Parallax LIS3DH 3 Axis Accelerometer module with ADC %c \r", CLREOL);
51+
print("Test ADC (milli-Volt values) %c \r\r", CLREOL);
52+
53+
54+
int ad1, ad2, ad3;
55+
56+
LIS3DH = lis3dh_init(8, 7, 6); // Initialize sensor with pins SCK, SDI, CS
57+
58+
lis3dh_setResolution(LIS3DH, 12); // 8, 10 or 12 bit
59+
60+
61+
lis3dh_adcCal_mV(LIS3DH, 0, 0, 0, 0); // Disable ADC calibration
62+
63+
64+
/* Example of setting calibration values
65+
Substitute the values with your own readings, obtained with ADC calibration disabled
66+
Parameters : (LIS3DH device reference, calibration mV #1, calibration mV #2, mV reading obtained at calibration voltage #1, mV reading obtained at calibration voltage #2)
67+
68+
In the following example, -466 was measured at 0 mV, and 3104 was measured at 3300mV (3.3V) */
69+
70+
71+
//lis3dh_adcCal_mV(LIS3DH, 0, 3300, -466, 3104); // Uncomment to enable ADC Calibration
72+
73+
74+
while(1) {
75+
// Continuously read from sensor and print results to debug terminal
76+
77+
lis3dh_adc_mV(LIS3DH, &ad1, &ad2, &ad3); // Read ADC values
78+
79+
print(" ad1 = %dmV, ad2 = %dmV, ad3 = %dmV %c \r",
80+
ad1, ad2, ad3, CLREOL ); // Display measurements
81+
82+
83+
84+
85+
pause(500); // 1/2 second pause before repeat
86+
87+
print("%c", CRSRUP); // Terminal up one line
88+
89+
90+
}
91+
92+
}
93+
94+
95+
96+
/**
97+
* TERMS OF USE: MIT License
98+
*
99+
* Permission is hereby granted, free of charge, to any person obtaining a
100+
* copy of this software and associated documentation files (the "Software"),
101+
* to deal in the Software without restriction, including without limitation
102+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
103+
* and/or sell copies of the Software, and to permit persons to whom the
104+
* Software is furnished to do so, subject to the following conditions:
105+
*
106+
* The above copyright notice and this permission notice shall be included in
107+
* all copies or substantial portions of the Software.
108+
*
109+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
110+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
111+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
112+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
113+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
114+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
115+
* DEALINGS IN THE SOFTWARE.
116+
*/
117+
118+
119+
120+
121+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
LIS3DH Test ADC mV with Calibration.c
2+
>compiler=C
3+
>memtype=cmm main ram compact
4+
>optimize=-Os
5+
>-m32bit-doubles
6+
>-fno-exceptions
7+
>BOARD::ACTIVITYBOARD

Learn/Examples/Devices/Sensor/Accelerometer 3-Axis LIS3DH/LIS3DH Test ADC mV.c

+5-4
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
Upload this code to the Propeller
1717
Open SimpleIDE Terminal or Parallax Serial Terminal at 115200 baud to view the output
1818
19-
Apply voltage to measure to any of the three ADC inputs:
19+
Apply voltage to measure to any of the three ADC inputs (measurement ranges +- 400mV):
2020
2121
AD1 (Sip header, accepts 0-8 VDC)
22-
AD2 (PCB top pad, accepts 900mV - 1800mV)
23-
AD3 (PCB top pad, accepts 900mV - 1800mV)
22+
AD2 (PCB top pad, accepts 900mV - 1700mV)
23+
AD3 (PCB top pad, accepts 900mV - 1700mV)
2424
2525
2626
Note: Voltages lower or higher than the acceptable range will be rounded to
@@ -46,7 +46,8 @@ int main() // Main function
4646
int ad1, ad2, ad3;
4747

4848
LIS3DH = lis3dh_init(8, 7, 6); // Initialize sensor with pins SCK, SDI, CS
49-
49+
50+
5051

5152
while(1) {
5253
// Continuously read from sensor and print results to debug terminal

Learn/Simple Libraries/Sensor/liblis3dh/Documentation lis3dh Library.html

+6-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Learn/Simple Libraries/Sensor/liblis3dh/accel.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* @version 1.0.0
77
*
88
* @copyright
9-
* Copyright (C) Parallax, Inc. 2019. All Rights MIT Licensed.
9+
* Copyright (C) Parallax, Inc. 2020. All Rights MIT Licensed.
1010
*
1111
* @brief Gets raw axis measurements for the Parallax LIS3DH 3-Axis Accelerometer Module with ADC.
1212
*

Learn/Simple Libraries/Sensor/liblis3dh/accel_mg.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* @version 1.0.0
77
*
88
* @copyright
9-
* Copyright (C) Parallax, Inc. 2019. All Rights MIT Licensed.
9+
* Copyright (C) Parallax, Inc. 2020. All Rights MIT Licensed.
1010
*
1111
* @brief Read acceleration (G-Force) for the Parallax LIS3DH 3-Axis Accelerometer Module with ADC.
1212
*

Learn/Simple Libraries/Sensor/liblis3dh/adc.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* @version 1.0.0
77
*
88
* @copyright
9-
* Copyright (C) Parallax, Inc. 2019. All Rights MIT Licensed.
9+
* Copyright (C) Parallax, Inc. 2020. All Rights MIT Licensed.
1010
*
1111
* @brief Reads adc measurements from the Parallax LIS3DH 3-Axis Accelerometer Module with ADC.
1212
*

Learn/Simple Libraries/Sensor/liblis3dh/adc_mV.c

+49-18
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
*
44
* @author Michael Mulholland
55
*
6-
* @version 1.0.0
6+
* @version 1.0.1
77
*
88
* @copyright
9-
* Copyright (C) Parallax, Inc. 2019. All Rights MIT Licensed.
9+
* Copyright (C) Parallax, Inc. 2020. All Rights MIT Licensed.
1010
*
1111
* @brief Reads mV adc measurements from the Parallax LIS3DH 3-Axis Accelerometer Module with ADC.
1212
*
@@ -19,13 +19,15 @@
1919

2020

2121
// Helper functions for ADC to mV conversion
22-
// ADC Channel 1 accepts 0-8V (+- 400mV); fromLow is offset to ensure readings at low adc voltages accounting for tolerances
23-
// ADC Channels 2 and 3 accept 900mV to 1800mV (+- 400mV)
22+
// ADC Channel 1 accepts 0-7800mV (+- 200mV); fromLow is offset to ensure readings at low adc voltages accounting for tolerances
23+
// ADC Channels 2 and 3 accept 900mV to 1700mV (+- 100mV)
2424

2525

2626
// lis3dh_adcMap(valueToMap, fromLow, fromHigh, toLow, toHigh)
2727
int lis3dh_adcMap(int valueToMap, int fromLow, int fromHigh, int toLow, int toHigh) {
28-
return (valueToMap - fromLow) * (toHigh - toLow) / (fromHigh - fromLow) + toLow;
28+
29+
return ((valueToMap - fromLow) * (toHigh - toLow) / (fromHigh - fromLow) + toLow);
30+
2931
}
3032

3133

@@ -38,26 +40,38 @@ void lis3dh_adc_mV(lis3dh_t *device, int *ad1, int *ad2, int *ad3)
3840

3941
int res = lis3dh_getResolution(device);
4042

41-
if (res == 8) { // 8-bit samples
43+
44+
if (res == 8) { // 8-bit samples, -128 to 127
4245

43-
*ad1 = lis3dh_adcMap(a1, 69, -128, 0, 8000);
44-
*ad2 = lis3dh_adcMap(a2, 127, -128, 900, 1800);
45-
*ad3 = lis3dh_adcMap(a3, 127, -128, 900, 1800);
46+
*ad1 = lis3dh_adcMap(a1, 87, -128, 0, 7800);
47+
*ad2 = lis3dh_adcMap(a2, 127, -128, 900, 1700);
48+
*ad3 = lis3dh_adcMap(a3, 127, -128, 900, 1700);
4649

47-
} else if (res == 10) { // 10-bit samples
50+
} else if (res == 10) { // 10-bit samples, -512 to 511
4851

49-
*ad1 = lis3dh_adcMap(a1, 400, -508, 0, 8000);
50-
*ad2 = lis3dh_adcMap(a2, 508, -508, 900, 1800);
51-
*ad3 = lis3dh_adcMap(a3, 508, -508, 900, 1800);
52+
*ad1 = lis3dh_adcMap(a1, 350, -508, 0, 7800);
53+
*ad2 = lis3dh_adcMap(a2, 508, -508, 900, 1700);
54+
*ad3 = lis3dh_adcMap(a3, 508, -508, 900, 1700);
5255

53-
} else { // 12-bit samples (Note- 10 bit is maximum ADC resolution, but data presented as 12-bit if XYZ sampling is 12-bit)
56+
} else { // 12-bit samples, -2048 to 2047
57+
// (Note- 10 bit is maximum ADC resolution, but data presented as 12-bit if XYZ sampling is 12-bit)
5458

55-
*ad1 = lis3dh_adcMap(a1, 1600, -2032, 0, 8000);
56-
*ad2 = lis3dh_adcMap(a2, 2032, -2032, 900, 1800);
57-
*ad3 = lis3dh_adcMap(a3, 2032, -2032, 900, 1800);
59+
*ad1 = lis3dh_adcMap(a1, 1400, -2032, 0, 7800); // Offset the minimum value as lowest AD1 voltage about 0.97V (post divider)
60+
*ad2 = lis3dh_adcMap(a2, 2032, -2032, 900, 1700);
61+
*ad3 = lis3dh_adcMap(a3, 2032, -2032, 900, 1700);
5862

59-
}
63+
}
64+
6065

66+
// Calibration of AD1
67+
68+
if ((device->adccal_m1000 != 0) || (device->adccal_b1000 != 0)) {
69+
70+
*ad1 = ((*ad1 * device->adccal_m1000) + device->adccal_b1000) / 1000;
71+
72+
}
73+
74+
6175
}
6276

6377

@@ -80,6 +94,23 @@ int lis3dh_getADC_mV(lis3dh_t *device, int channel)
8094
}
8195

8296

97+
void lis3dh_adcCal_mV(lis3dh_t *device, int mV_L, int mV_H, int value_L, int value_H)
98+
{
99+
100+
if (mV_L == 0 & mV_H == 0 & value_L == 0 & value_H == 0) {
101+
102+
device->adccal_m1000 = 0;
103+
device->adccal_b1000 = 0;
104+
105+
} else {
106+
107+
device->adccal_m1000 = (1000 * mV_H) / (value_H + (value_L * -1));
108+
device->adccal_b1000 = (device->adccal_m1000 * value_L) * -1;
109+
110+
}
111+
}
112+
113+
83114

84115

85116

Binary file not shown.

Learn/Simple Libraries/Sensor/liblis3dh/getRange.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* @version 1.0.0
77
*
88
* @copyright
9-
* Copyright (C) Parallax, Inc. 2019. All Rights MIT Licensed.
9+
* Copyright (C) Parallax, Inc. 2020. All Rights MIT Licensed.
1010
*
1111
* @brief Gets g acceleration range of the Parallax LIS3DH 3-Axis Accelerometer Module with ADC.
1212
*

Learn/Simple Libraries/Sensor/liblis3dh/getResolution.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* @version 1.0.0
77
*
88
* @copyright
9-
* Copyright (C) Parallax, Inc. 2019. All Rights MIT Licensed.
9+
* Copyright (C) Parallax, Inc. 2020. All Rights MIT Licensed.
1010
*
1111
* @brief Gets resolution mode from the Parallax LIS3DH 3-Axis Accelerometer Module with ADC.
1212
*

Learn/Simple Libraries/Sensor/liblis3dh/getSPImode.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* @version 1.0.0
77
*
88
* @copyright
9-
* Copyright (C) Parallax, Inc. 2019. All Rights MIT Licensed.
9+
* Copyright (C) Parallax, Inc. 2020. All Rights MIT Licensed.
1010
*
1111
* @brief Gets SPI mode for the Parallax LIS3DH 3-Axis Accelerometer Module with ADC.
1212
*

Learn/Simple Libraries/Sensor/liblis3dh/getWhoAmI.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* @version 1.0.0
77
*
88
* @copyright
9-
* Copyright (C) Parallax, Inc. 2019. All Rights MIT Licensed.
9+
* Copyright (C) Parallax, Inc. 2020. All Rights MIT Licensed.
1010
*
1111
* @brief Gets g acceleration range of the Parallax LIS3DH 3-Axis Accelerometer Module with ADC.
1212
*

Learn/Simple Libraries/Sensor/liblis3dh/html/annotated.html

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Loading
Loading

Learn/Simple Libraries/Sensor/liblis3dh/html/classes.html

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Loading
-618 Bytes
Loading
Loading

Learn/Simple Libraries/Sensor/liblis3dh/html/files.html

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Loading
Loading

0 commit comments

Comments
 (0)