Skip to content

Commit

Permalink
Merge pull request #2 from sparkfun/release_candidate
Browse files Browse the repository at this point in the history
Version 2.0
  • Loading branch information
PaulZC authored May 14, 2024
2 parents f09fa70 + 8a7408f commit 9c4ffe7
Show file tree
Hide file tree
Showing 23 changed files with 1,622 additions and 1,037 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ Change Log
v1.0
---------
14th July 2020: Initial release. Based extensively on v1.4 of OpenLog_Artemis.

v2.0
---------
7th May 2024: Second release. Rewritten for the: SparkFun OpenLog Artemis (with or without IMU); ADS1015, ADS1219.
Binary file added Extras/UartPower3.zip
Binary file not shown.
11 changes: 11 additions & 0 deletions Extras/spi.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
diff -u old/SPI.cpp new/SPI.cpp
--- old/SPI.cpp 2023-09-14 12:53:54.000000000 +0200
+++ new/SPI.cpp 2023-09-18 18:45:48.141504930 +0200
@@ -86,6 +86,7 @@
void arduino::MbedSPI::end() {
if (dev) {
delete dev;
+ dev = NULL;
}
}

80 changes: 28 additions & 52 deletions Firmware/OpenLog_Artemis_Geophone_Logger/Geophone.ino
Original file line number Diff line number Diff line change
Expand Up @@ -13,48 +13,15 @@

volatile static bool g_bGeophoneDataReady = false;
volatile static bool g_bUsingGeophoneBuffer1 = true;
volatile static uint32_t g_ui16GeophoneDataBufferPointer = 0;
volatile static int16_t g_ui32GeophoneDataBuffer1[GEOPHONE_FFT_SIZE];
volatile static int16_t g_ui32GeophoneDataBuffer2[GEOPHONE_FFT_SIZE];
volatile static uint32_t g_ui32GeophoneDataBufferPointer = 0;
volatile static int32_t g_ui32GeophoneDataBuffer1[GEOPHONE_FFT_SIZE];
volatile static int32_t g_ui32GeophoneDataBuffer2[GEOPHONE_FFT_SIZE];
float g_fGeophoneTimeDomain[GEOPHONE_FFT_SIZE * 2];
float g_fGeophoneFrequencyDomain[GEOPHONE_FFT_SIZE * 2];
float g_fGeophoneMagnitudes[GEOPHONE_FFT_SIZE * 2];
uint32_t g_ui32SampleFreq = 500; // We'll need to set the ADS122C04 to 600Hz.


// Functions taken from stimer.c
void stimer_init(void)
{
//
// Enable compare F interrupt in STIMER
//
am_hal_stimer_int_enable(AM_HAL_STIMER_INT_COMPAREF);

//
// Enable the timer interrupt in the NVIC.
//
NVIC_EnableIRQ(STIMER_CMPR5_IRQn);

//
// Configure the STIMER and run
//
am_hal_stimer_config(AM_HAL_STIMER_CFG_CLEAR | AM_HAL_STIMER_CFG_FREEZE);
am_hal_stimer_compare_delta_set(5, SAMPLE_INTERVAL);
am_hal_stimer_config(AM_HAL_STIMER_HFRC_3MHZ | AM_HAL_STIMER_CFG_COMPARE_F_ENABLE);
}

/* Setup the geophone data sampling buffers and sampling interrupt. */
void geophone_setup()
{
configureADC(); // Configure the ADC _before_ we start the timer

g_bGeophoneDataReady = false; // Clear the flag
g_bUsingGeophoneBuffer1 = true; // Use buffer 1
g_ui16GeophoneDataBufferPointer = 0; // Reset the pointer

stimer_init(); // Now start the timer
}

/*
* Interrupt service routine for sampling the geodata. The geodata analog
* pin is sampled at each invokation of the ISR. If the buffer is full, a
Expand All @@ -65,35 +32,40 @@ void geophone_setup()
* While not a sampling task, we take advantage of the timer interrupt to
* blink the report LED if enabled.
*/
void sampling_interrupt( )
void sampling_interrupt()
{
if (samplingEnabled == false)
return;

//digitalWrite(PIN_LOGIC_DEBUG, !digitalRead(PIN_LOGIC_DEBUG));

/* Read a sample and store it in the geodata buffer. Apply a Hamming
window as we go along. It involves a cos operation; the alternative
is an array that should be fit into program memory. */

/* Read the geodata sample from the ADS122C04. */
#if defined(TEST_PERIOD_1) && defined(TEST_AMPLITUDE_1) && defined(TEST_PERIOD_2) && defined(TEST_AMPLITUDE_2) // If TEST_PERIOD 1+2 are defined then fake the data
int16_t geodata_sample = (int16_t)((TEST_AMPLITUDE_1 * sin(2.0 * M_PI * ((double)(micros() % TEST_PERIOD_1)) / ((double)TEST_PERIOD_1)))
int32_t geodata_sample = (int32_t)((TEST_AMPLITUDE_1 * sin(2.0 * M_PI * ((double)(micros() % TEST_PERIOD_1)) / ((double)TEST_PERIOD_1)))
+ (TEST_AMPLITUDE_2 * cos(2.0 * M_PI * ((double)(micros() % TEST_PERIOD_2)) / ((double)TEST_PERIOD_2))));
#elif (defined(TEST_PERIOD_1) && defined(TEST_AMPLITUDE_1)) // If TEST_PERIOD 1 is defined then fake the data
int16_t geodata_sample = TEST_AMPLITUDE_1 * sin(2.0 * M_PI * ((double)(micros() % TEST_PERIOD_1)) / ((double)TEST_PERIOD_1));
int32_t geodata_sample = TEST_AMPLITUDE_1 * sin(2.0 * M_PI * ((double)(micros() % TEST_PERIOD_1)) / ((double)TEST_PERIOD_1));
#else
int16_t geodata_sample = gatherADCValue(); // Take a real sample from the ADC
int32_t geodata_sample = gatherADCValue(); // Take a real sample from the ADC
#endif

if (g_bUsingGeophoneBuffer1) // Write the geophone sample into the appropriate buffer
{
g_ui32GeophoneDataBuffer1[g_ui16GeophoneDataBufferPointer] = geodata_sample;
g_ui32GeophoneDataBuffer1[g_ui32GeophoneDataBufferPointer] = geodata_sample;
}
else
{
g_ui32GeophoneDataBuffer2[g_ui16GeophoneDataBufferPointer] = geodata_sample;
g_ui32GeophoneDataBuffer2[g_ui32GeophoneDataBufferPointer] = geodata_sample;
}
g_ui16GeophoneDataBufferPointer++; // Increment the pointer
if (g_ui16GeophoneDataBufferPointer == GEOPHONE_FFT_SIZE) // Have we reached the end of the buffer?
g_ui32GeophoneDataBufferPointer++; // Increment the pointer
if (g_ui32GeophoneDataBufferPointer == GEOPHONE_FFT_SIZE) // Have we reached the end of the buffer?
{
g_bUsingGeophoneBuffer1 ^= 1; // Swap to the other buffer
g_ui16GeophoneDataBufferPointer = 0; // Reset the pointer
g_ui32GeophoneDataBufferPointer = 0; // Reset the pointer
g_bGeophoneDataReady = true; // Set the flag
}
}
Expand All @@ -110,7 +82,7 @@ bool geophone_loop()
{
float fMaxValue;
uint32_t ui32MaxIndex;
int16_t *pi16GeophoneData;
int32_t *pi32GeophoneData;
uint32_t ui32LoudestFrequency;

geophoneData[0] = '\0'; //Clear string contents
Expand All @@ -122,11 +94,11 @@ bool geophone_loop()

if (g_bUsingGeophoneBuffer1)
{
pi16GeophoneData = (int16_t *) g_ui32GeophoneDataBuffer2; // Point to the full buffer
pi32GeophoneData = (int32_t *) g_ui32GeophoneDataBuffer2; // Point to the full buffer
}
else
{
pi16GeophoneData = (int16_t *) g_ui32GeophoneDataBuffer1; // Point to the full buffer
pi32GeophoneData = (int32_t *) g_ui32GeophoneDataBuffer1; // Point to the full buffer
}

//
Expand All @@ -135,7 +107,7 @@ bool geophone_loop()
//
for (uint32_t i = 0; i < GEOPHONE_FFT_SIZE; i++)
{
g_fGeophoneTimeDomain[2 * i] = pi16GeophoneData[i] / 1.0;
g_fGeophoneTimeDomain[2 * i] = pi32GeophoneData[i] / 1.0;
g_fGeophoneTimeDomain[2 * i + 1] = 0.0;
}

Expand All @@ -158,17 +130,21 @@ bool geophone_loop()
{
for (uint32_t i = 1; i < FREQ_LIMIT; i++)
{
sprintf(tempData, "%.2f,", g_fGeophoneMagnitudes[i]);
char tempStr[16];
olaftoa(g_fGeophoneMagnitudes[i], tempStr, 2, sizeof(tempStr) / sizeof(char));
sprintf(tempData, "%s,", tempStr);
strcat(geophoneData, tempData);
sprintf(tempData, "%.2f\n", g_fGeophoneMagnitudes[i]);
sprintf(tempData, "%s\n", tempStr);
strcat(geophoneDataSerial, tempData);
}

sprintf(tempData, "%d", ui32LoudestFrequency);
strcat(geophoneData, tempData);
strcat(peakFreq, tempData);

sprintf(tempData, ",%.2f", fMaxValue);
char tempStr[16];
olaftoa(fMaxValue, tempStr, 2, sizeof(tempStr) / sizeof(char));
sprintf(tempData, ",%s", tempStr);
strcat(peakFreq, tempData);

if (settings.printMeasurementCount)
Expand Down
Loading

0 comments on commit 9c4ffe7

Please sign in to comment.