Skip to content

Commit

Permalink
March 2020 - Learn Folder Updates
Browse files Browse the repository at this point in the history
Update 3/2/2020 - Simple Libraries v1.4.153 - Tagged Release Version
  • Loading branch information
AndyLindsay committed Mar 2, 2020
1 parent f0a7060 commit 0e9c64d
Show file tree
Hide file tree
Showing 64 changed files with 632 additions and 206 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/*
LIS3DH Test ADC mV with Calibration.c
Test Harness for the Parallax LIS3DH 3 Axis Accelerometer module with ADC.
http://learn.parallax.com/propeller-c-simple-devices/lis3dh-three-axis-accelerometer
I/O Pins connections:
P8 -> CLK (SCK)
P7 <-> DATA (SDI)
P6 -> /ENABLE (CS)
Instructions:
Connect LIS3DH module to Propeller using the pins shown above
Also connect 3.3V and GND to the LIS3DH module
Upload this code to the Propeller
Open SimpleIDE Terminal or Parallax Serial Terminal at 115200 baud to view the output
Apply voltage to measure to any of the three ADC inputs (measurement ranges +- 400mV):
AD1 - Sip header, accepts 0-7800mV (+- 200mV)
AD2 - PCB top pad, accepts 900mV - 1700mV (+- 100mV)
AD3 - PCB top pad, accepts 900mV - 1700mV (+- 100mV)
Note: Voltages lower or higher than the acceptable range will be rounded to
the minimum or maximum range value. Do NOT exceed 2.5VIN on AD2 or AD3.
*/

#include "simpletools.h" // Include simpletools header
#include "lis3dh.h" // Include lis3dh header

lis3dh *LIS3DH;

int main() // Main function
{

pause(1000); // Start-up pause for debug terminal
term_cmd(CLS);
term_cmd(HOME);

print("Parallax LIS3DH 3 Axis Accelerometer module with ADC %c \r", CLREOL);
print("Test ADC (milli-Volt values) %c \r\r", CLREOL);


int ad1, ad2, ad3;

LIS3DH = lis3dh_init(8, 7, 6); // Initialize sensor with pins SCK, SDI, CS

lis3dh_setResolution(LIS3DH, 12); // 8, 10 or 12 bit


lis3dh_adcCal_mV(LIS3DH, 0, 0, 0, 0); // Disable ADC calibration


/* Example of setting calibration values
Substitute the values with your own readings, obtained with ADC calibration disabled
Parameters : (LIS3DH device reference, calibration mV #1, calibration mV #2, mV reading obtained at calibration voltage #1, mV reading obtained at calibration voltage #2)
In the following example, -466 was measured at 0 mV, and 3104 was measured at 3300mV (3.3V) */


//lis3dh_adcCal_mV(LIS3DH, 0, 3300, -466, 3104); // Uncomment to enable ADC Calibration


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

lis3dh_adc_mV(LIS3DH, &ad1, &ad2, &ad3); // Read ADC values

print(" ad1 = %dmV, ad2 = %dmV, ad3 = %dmV %c \r",
ad1, ad2, ad3, CLREOL ); // Display measurements




pause(500); // 1/2 second pause before repeat

print("%c", CRSRUP); // Terminal up one line


}

}



/**
* TERMS OF USE: MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/





Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
LIS3DH Test ADC mV with Calibration.c
>compiler=C
>memtype=cmm main ram compact
>optimize=-Os
>-m32bit-doubles
>-fno-exceptions
>BOARD::ACTIVITYBOARD
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
Upload this code to the Propeller
Open SimpleIDE Terminal or Parallax Serial Terminal at 115200 baud to view the output
Apply voltage to measure to any of the three ADC inputs:
Apply voltage to measure to any of the three ADC inputs (measurement ranges +- 400mV):
AD1 (Sip header, accepts 0-8 VDC)
AD2 (PCB top pad, accepts 900mV - 1800mV)
AD3 (PCB top pad, accepts 900mV - 1800mV)
AD2 (PCB top pad, accepts 900mV - 1700mV)
AD3 (PCB top pad, accepts 900mV - 1700mV)
Note: Voltages lower or higher than the acceptable range will be rounded to
Expand All @@ -46,7 +46,8 @@ int main() // Main function
int ad1, ad2, ad3;

LIS3DH = lis3dh_init(8, 7, 6); // Initialize sensor with pins SCK, SDI, CS




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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Learn/Simple Libraries/Sensor/liblis3dh/accel.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @version 1.0.0
*
* @copyright
* Copyright (C) Parallax, Inc. 2019. All Rights MIT Licensed.
* Copyright (C) Parallax, Inc. 2020. All Rights MIT Licensed.
*
* @brief Gets raw axis measurements for the Parallax LIS3DH 3-Axis Accelerometer Module with ADC.
*
Expand Down
2 changes: 1 addition & 1 deletion Learn/Simple Libraries/Sensor/liblis3dh/accel_mg.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @version 1.0.0
*
* @copyright
* Copyright (C) Parallax, Inc. 2019. All Rights MIT Licensed.
* Copyright (C) Parallax, Inc. 2020. All Rights MIT Licensed.
*
* @brief Read acceleration (G-Force) for the Parallax LIS3DH 3-Axis Accelerometer Module with ADC.
*
Expand Down
2 changes: 1 addition & 1 deletion Learn/Simple Libraries/Sensor/liblis3dh/adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @version 1.0.0
*
* @copyright
* Copyright (C) Parallax, Inc. 2019. All Rights MIT Licensed.
* Copyright (C) Parallax, Inc. 2020. All Rights MIT Licensed.
*
* @brief Reads adc measurements from the Parallax LIS3DH 3-Axis Accelerometer Module with ADC.
*
Expand Down
67 changes: 49 additions & 18 deletions Learn/Simple Libraries/Sensor/liblis3dh/adc_mV.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
*
* @author Michael Mulholland
*
* @version 1.0.0
* @version 1.0.1
*
* @copyright
* Copyright (C) Parallax, Inc. 2019. All Rights MIT Licensed.
* Copyright (C) Parallax, Inc. 2020. All Rights MIT Licensed.
*
* @brief Reads mV adc measurements from the Parallax LIS3DH 3-Axis Accelerometer Module with ADC.
*
Expand All @@ -19,13 +19,15 @@


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


// lis3dh_adcMap(valueToMap, fromLow, fromHigh, toLow, toHigh)
int lis3dh_adcMap(int valueToMap, int fromLow, int fromHigh, int toLow, int toHigh) {
return (valueToMap - fromLow) * (toHigh - toLow) / (fromHigh - fromLow) + toLow;

return ((valueToMap - fromLow) * (toHigh - toLow) / (fromHigh - fromLow) + toLow);

}


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

int res = lis3dh_getResolution(device);

if (res == 8) { // 8-bit samples

if (res == 8) { // 8-bit samples, -128 to 127

*ad1 = lis3dh_adcMap(a1, 69, -128, 0, 8000);
*ad2 = lis3dh_adcMap(a2, 127, -128, 900, 1800);
*ad3 = lis3dh_adcMap(a3, 127, -128, 900, 1800);
*ad1 = lis3dh_adcMap(a1, 87, -128, 0, 7800);
*ad2 = lis3dh_adcMap(a2, 127, -128, 900, 1700);
*ad3 = lis3dh_adcMap(a3, 127, -128, 900, 1700);

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

*ad1 = lis3dh_adcMap(a1, 400, -508, 0, 8000);
*ad2 = lis3dh_adcMap(a2, 508, -508, 900, 1800);
*ad3 = lis3dh_adcMap(a3, 508, -508, 900, 1800);
*ad1 = lis3dh_adcMap(a1, 350, -508, 0, 7800);
*ad2 = lis3dh_adcMap(a2, 508, -508, 900, 1700);
*ad3 = lis3dh_adcMap(a3, 508, -508, 900, 1700);

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

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

}
}


// Calibration of AD1

if ((device->adccal_m1000 != 0) || (device->adccal_b1000 != 0)) {

*ad1 = ((*ad1 * device->adccal_m1000) + device->adccal_b1000) / 1000;

}


}


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


void lis3dh_adcCal_mV(lis3dh_t *device, int mV_L, int mV_H, int value_L, int value_H)
{

if (mV_L == 0 & mV_H == 0 & value_L == 0 & value_H == 0) {

device->adccal_m1000 = 0;
device->adccal_b1000 = 0;

} else {

device->adccal_m1000 = (1000 * mV_H) / (value_H + (value_L * -1));
device->adccal_b1000 = (device->adccal_m1000 * value_L) * -1;

}
}





Expand Down
Binary file modified Learn/Simple Libraries/Sensor/liblis3dh/cmm/liblis3dh.a
Binary file not shown.
2 changes: 1 addition & 1 deletion Learn/Simple Libraries/Sensor/liblis3dh/getRange.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @version 1.0.0
*
* @copyright
* Copyright (C) Parallax, Inc. 2019. All Rights MIT Licensed.
* Copyright (C) Parallax, Inc. 2020. All Rights MIT Licensed.
*
* @brief Gets g acceleration range of the Parallax LIS3DH 3-Axis Accelerometer Module with ADC.
*
Expand Down
2 changes: 1 addition & 1 deletion Learn/Simple Libraries/Sensor/liblis3dh/getResolution.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @version 1.0.0
*
* @copyright
* Copyright (C) Parallax, Inc. 2019. All Rights MIT Licensed.
* Copyright (C) Parallax, Inc. 2020. All Rights MIT Licensed.
*
* @brief Gets resolution mode from the Parallax LIS3DH 3-Axis Accelerometer Module with ADC.
*
Expand Down
2 changes: 1 addition & 1 deletion Learn/Simple Libraries/Sensor/liblis3dh/getSPImode.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @version 1.0.0
*
* @copyright
* Copyright (C) Parallax, Inc. 2019. All Rights MIT Licensed.
* Copyright (C) Parallax, Inc. 2020. All Rights MIT Licensed.
*
* @brief Gets SPI mode for the Parallax LIS3DH 3-Axis Accelerometer Module with ADC.
*
Expand Down
2 changes: 1 addition & 1 deletion Learn/Simple Libraries/Sensor/liblis3dh/getWhoAmI.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @version 1.0.0
*
* @copyright
* Copyright (C) Parallax, Inc. 2019. All Rights MIT Licensed.
* Copyright (C) Parallax, Inc. 2020. All Rights MIT Licensed.
*
* @brief Gets g acceleration range of the Parallax LIS3DH 3-Axis Accelerometer Module with ADC.
*
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified Learn/Simple Libraries/Sensor/liblis3dh/html/bc_s.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Learn/Simple Libraries/Sensor/liblis3dh/html/bdwn.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion Learn/Simple Libraries/Sensor/liblis3dh/html/classes.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified Learn/Simple Libraries/Sensor/liblis3dh/html/closed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Learn/Simple Libraries/Sensor/liblis3dh/html/doc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Learn/Simple Libraries/Sensor/liblis3dh/html/doxygen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion Learn/Simple Libraries/Sensor/liblis3dh/html/files.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified Learn/Simple Libraries/Sensor/liblis3dh/html/folderclosed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Learn/Simple Libraries/Sensor/liblis3dh/html/folderopen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 0e9c64d

Please sign in to comment.