This sketch takes voltage measurements at regular intervals and stores the data in non-volatile internal FRAM.
The sketch was designed specically for use with an MSP430FR2433 LaunchPad powered with a solar panel, but could be adapted to other boards (particularly other "FR" variants of the MSP430) and other power sources or data collection needs.
The MspTandV library is used to get calibrated measurements of
By storing the data in FRAM, the sketch can be run without being connected to a computer and the data can be retrieved at a later time.
The sketch has been tested on the FR2433 variant and should work on other FR variants supported by the MspTandV library (FR4133, FR6989, FR5969).
The sketch has several #define
statements that can be updated to fit the project's needs:
Parameter | Default Value | Description |
---|---|---|
LOOP_TIME |
60000UL | Time in ms between voltage readings. |
LED_TIME |
3000UL | Time in ms between LED toggling on and off. |
SAMPLE_COUNT |
1536 | Number of samples stored in FRAM. Each sample takes 4 bytes. |
REBOOT_DETECTED |
5555 | Value to store when board is rebooted without clearing previously stored data. |
V_DIV_SCALE_FACTOR |
0.3197 | Scaling factor from the voltage divider. See below. |
RAW_ADC_PIN |
5 | Analog pin used to measure the raw voltage (typically through a voltage divider). |
LED_PWM_LEVEL |
32 | Controls LED brightness (0 to 255). Higher is brighter and uses more current. |
The V_DIV_SCALE_FACTOR
is used to calculate an actual voltage value based on the calibrated ADC reading using the chip's internal voltage reference:
V_DIV_SCALE_FACTOR
needs to be calculated specific to your setup::
Then calculate and use the result to update #define V_DIV_SCALE_FACTOR
:
For example, if V_DIV_SCALE_FACTOR
should be set to 0.3197.
Holding down PUSH1 at reboot prints the stored data over the serial port.
Holding down PUSH2 at reboot clears the data store in FRAM. The LED is briefly flashed when FRAM is cleared.
If a reboot is detected (e.g., due to loss of power from the solar panel), then 5555 (i.e., whatever is defined as REBOOT_DETECTED) is stored in the next data cell.
The LED is flashed every few seconds (per #define LED_TIME
). Since this takes a little extra power, it may be useful to remove the LED jumper after confirming that the program is running so that the measurements aren't affected by the LED current draw.
By default, the FRAM is configured as read-only in the FR2433 variant, so there is a compiler directive to unlock it for write access. This is not needed for other supported FR variants. See here, here, and here.
- MspTandV library
- MS430FR4xx and MSP430FR2xx Family User Guide
- FRAM FAQ from Texas Instruments
The software and other files in this repository are released under what is commonly called the MIT License. See the file LICENSE.txt
in this repository.