Embedded System Design 2 - Project
|
All code for the ADXL362 accelerometer. More...
#include <stdint.h>
#include <stdbool.h>
Go to the source code of this file.
Typedefs | |
typedef enum adxl_range | ADXL_Range_t |
typedef enum adxl_odr | ADXL_ODR_t |
Enumerations | |
enum | adxl_range { ADXL_RANGE_2G, ADXL_RANGE_4G, ADXL_RANGE_8G } |
enum | adxl_odr { ADXL_ODR_12_5_HZ, ADXL_ODR_25_HZ, ADXL_ODR_50_HZ, ADXL_ODR_100_HZ, ADXL_ODR_200_HZ, ADXL_ODR_400_HZ } |
Functions | |
void | initADXL (void) |
Initialize the accelerometer. More... | |
void | ADXL_setTriggered (bool triggered) |
Setter for the ADXL_triggered variable. More... | |
bool | ADXL_getTriggered (void) |
Getter for the ADXL_triggered variable. More... | |
void | ADXL_ackInterrupt (void) |
Acknowledge the interrupt from the accelerometer. More... | |
uint16_t | ADXL_getCounter (void) |
Getter for the ADXL_triggercounter variable. More... | |
void | ADXL_clearCounter (void) |
Method to set the ADXL_triggercounter variable back to zero. More... | |
void | ADXL_enableSPI (bool enabled) |
Enable or disable the SPI pins and USART0/1 clock and peripheral to the accelerometer. More... | |
void | ADXL_enableMeasure (bool enabled) |
Enable or disable measurement mode. More... | |
void | ADXL_configRange (ADXL_Range_t givenRange) |
Configure the measurement range and store the selected one in a global variable for later (internal) use. More... | |
void | ADXL_configODR (ADXL_ODR_t givenODR) |
Configure the Output Data Rate (ODR). More... | |
void | ADXL_configActivity (uint8_t gThreshold) |
Configure the accelerometer to work in (referenced) activity threshold mode. More... | |
void | ADXL_readValues (void) |
Read and display "g" values forever with a 100ms interval. More... | |
void | testADXL (void) |
This method goes through all of the ODR settings to see the influence they have on power usage. The measurement range is the default one (+-2g). More... | |
All code for the ADXL362 accelerometer.
Copyright (C) 2019 - Brecht Van Eeckhoudt
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
A copy of the GNU General Public License can be found in the LICENSE
file along with this source code.
Some methods use code obtained from examples from Silicon Labs' GitHub. These sections are licensed under the Silabs License Agreement. See the file "Silabs_License_Agreement.txt" for details. Before using this software for any purpose, you must agree to the terms of that agreement.
Definition in file ADXL362.h.
typedef enum adxl_odr ADXL_ODR_t |
Enum type for the ODR
typedef enum adxl_range ADXL_Range_t |
Enum type for the measurement range
enum adxl_odr |
Enum type for the ODR
Enumerator | |
---|---|
ADXL_ODR_12_5_HZ | |
ADXL_ODR_25_HZ | |
ADXL_ODR_50_HZ | |
ADXL_ODR_100_HZ | |
ADXL_ODR_200_HZ | |
ADXL_ODR_400_HZ |
Definition at line 55 of file ADXL362.h.
enum adxl_range |
Enum type for the measurement range
Enumerator | |
---|---|
ADXL_RANGE_2G | |
ADXL_RANGE_4G | |
ADXL_RANGE_8G |
Definition at line 47 of file ADXL362.h.
void ADXL_ackInterrupt | ( | void | ) |
Acknowledge the interrupt from the accelerometer.
Read a certain register (necessary if the accelerometer is not in linked-loop mode) and clear the variable.
Definition at line 230 of file ADXL362.c.
void ADXL_clearCounter | ( | void | ) |
void ADXL_configActivity | ( | uint8_t | gThreshold | ) |
Configure the accelerometer to work in (referenced) activity threshold mode.
Route activity detector to INT1 pin using INTMAP1, isolate bits and write settings to both threshold registers.
Referenced means that during the initialization a reference acceleration gets measured (like for example 1 g
on a certain axis) and stored internally. This value always gets internally subtracted from a measured acceleration value to calculate the final value and check if it exceeds the set threshold:
ABS(acceleration - reference) > threshold
[in] | gThreshold | Threshold [g]. |
Definition at line 468 of file ADXL362.c.
void ADXL_configODR | ( | ADXL_ODR_t | givenODR | ) |
Configure the Output Data Rate (ODR).
[in] | givenODR | The selected ODR. |
Definition at line 411 of file ADXL362.c.
void ADXL_configRange | ( | ADXL_Range_t | givenRange | ) |
Configure the measurement range and store the selected one in a global variable for later (internal) use.
When a range of, for example "2g" is selected, the real range is "+-2g".
[in] | givenRange | The selected range. |
Definition at line 358 of file ADXL362.c.
void ADXL_enableMeasure | ( | bool | enabled | ) |
Enable or disable measurement mode.
[in] | enabled |
|
Definition at line 310 of file ADXL362.c.
void ADXL_enableSPI | ( | bool | enabled | ) |
Enable or disable the SPI pins and USART0/1 clock and peripheral to the accelerometer.
[in] | enabled |
|
Definition at line 245 of file ADXL362.c.
uint16_t ADXL_getCounter | ( | void | ) |
bool ADXL_getTriggered | ( | void | ) |
void ADXL_readValues | ( | void | ) |
Read and display "g" values forever with a 100ms interval.
Definition at line 515 of file ADXL362.c.
void ADXL_setTriggered | ( | bool | triggered | ) |
void initADXL | ( | void | ) |
Initialize the accelerometer.
This method calls all the other internal necessary functions. Clock enable functionality is gathered here instead of in lower (static) functions.
Definition at line 132 of file ADXL362.c.
void testADXL | ( | void | ) |
This method goes through all of the ODR settings to see the influence they have on power usage. The measurement range is the default one (+-2g).
To get the "correct" currents the delay method puts the MCU to EM2/3 sleep and the SPI lines are disabled. The order of the test is:
Definition at line 571 of file ADXL362.c.