Skip to content

Commit

Permalink
increased sampling rate
Browse files Browse the repository at this point in the history
  • Loading branch information
HarveyBates committed Mar 4, 2021
1 parent 602842e commit 3a14802
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
10 changes: 8 additions & 2 deletions Firmware/v0.3/Teensy_3.6/Teensy_3.6.ino
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,20 @@
#include "sensitivity.h"
#include "actinic.h"
#include "fluorescence.h"
#include <ADC.h>

ADC *adc = new ADC();

Fluorescence fluorescence;
Sensitivity sensitivity;
Actinic actinic;

void setup() {
Serial.begin(115200); // Initalise serial communications at specific baud rate
analogReadResolution(12); // Set the resolution of the microcontroller in bits
adc->adc0->setAveraging(0);
adc->adc0->setResolution(12);
adc->adc0->setConversionSpeed(ADC_CONVERSION_SPEED::VERY_HIGH_SPEED);
adc->adc0->setSamplingSpeed(ADC_SAMPLING_SPEED::VERY_HIGH_SPEED);
pinMode(13, OUTPUT); // Sets the microcontrollers LED pin as an output

sensitivity.refresh(); // Switch off all gain pathways
Expand All @@ -41,7 +47,7 @@ void loop(){
if(Serial.available()){
String command = Serial.readStringUntil('\n');
if(command.equals("MF")){
fluorescence.measure_fluorescence(actinic.intensity_pin);
fluorescence.measure_fluorescence(actinic.intensity_pin, adc);
}
else if(command.startsWith("A")){
unsigned int intensity = command.substring(1, command.length()).toInt();
Expand Down
20 changes: 10 additions & 10 deletions Firmware/v0.3/Teensy_3.6/fluorescence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,22 +91,22 @@ void Fluorescence::wave(Actinic actinic){
}
}

void Fluorescence::measure_fluorescence(unsigned int actinicPin) {
void Fluorescence::measure_fluorescence(unsigned int actinicPin, ADC *adc) {
digitalWrite(actinicPin, HIGH);

long long timer = micros(); // Start timer

// Read microsecond fluorescence values and corresponding timestamps
for (unsigned int i = 0; i < sizeof(microRead) / sizeof(int); i++)
{
microRead[i] = analogRead(readPin);
microRead[i] = adc->adc0->analogRead(readPin);
microTime[i] = micros() - timer;
}

// Read millisecond fluorescence values and corresponding timestamps
for (unsigned int i = 0; i < sizeof(milliRead) / sizeof(int); i++)
{
milliRead[i] = analogRead(readPin);
milliRead[i] = adc->adc0->analogRead(readPin);
milliTime[i] = micros() - timer;
delay(1);
}
Expand All @@ -117,32 +117,32 @@ void Fluorescence::measure_fluorescence(unsigned int actinicPin) {
// Convert micros() to milliseconds (ms) for microsecond values and convert bits to voltage
for (unsigned int i = 0; i < sizeof(microRead) / sizeof(int); i++)
{
float milliReal = microTime[i]/1000; // Convert micros() to ms
// Find fm value, we do this here while data are still ints
float milliReal = microTime[i]/1000.0; // Convert micros() to ms
// Find fm value, we do this here while the data is an interger
if (microRead[i] > fm){
fm = microRead[i];
}
fluorescenceValues[i] = (microRead[i] * refVoltage) / 4096; // Convert to volts and append to final array
fluorescenceValues[i] = (microRead[i] * refVoltage) / 4096.0; // Convert to volts and append to final array
timeStamps[i] = milliReal; // Append time to final array
Serial.print(milliReal, 3);
Serial.print("\t");
Serial.println((microRead[i] * refVoltage) / 4096, 4);
Serial.println((microRead[i] * refVoltage) / 4096.0, 4);
delay(1);
}

// Convert micros() to milliseconds for millsecond values and convert bits to voltage
for (unsigned int i = 0; i < sizeof(milliRead) / sizeof(int); i++)
{
float milliReal = milliTime[i]/1000; // Convert micros() to ms
float milliReal = milliTime[i]/1000.0; // Convert micros() to ms
// Find fm value if not in microsecond range
if (milliRead[i] > fm){
fm = milliRead[i];
}
fluorescenceValues[i + microLength] = (milliRead[i] * refVoltage) / 4096; // Convert to V and append
fluorescenceValues[i + microLength] = (milliRead[i] * refVoltage) / 4096.0; // Convert to V and append
timeStamps[i + microLength] = milliReal; // Append to timestamps after microRead data
Serial.print(milliReal, 3);
Serial.print("\t");
Serial.println((milliRead[i] * refVoltage) / 4096, 4);
Serial.println((milliRead[i] * refVoltage) / 4096.0, 4);
delay(1);
}
}
Expand Down
4 changes: 2 additions & 2 deletions Firmware/v0.3/Teensy_3.6/fluorescence.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
#ifndef Fluorescence_H
#define Fluorescence_H

#pragma once
#include <Arduino.h>
#include "actinic.h"
#include "sensitivity.h"
#include <ADC.h>

/* Fluorescence analogread pin */
#define readPin 14
Expand Down Expand Up @@ -102,7 +102,7 @@ class Fluorescence{
void measure_j_step(Actinic actinic);
void calculate_parameters();
void wave(Actinic actinic);
void measure_fluorescence(unsigned int actinicPin);
void measure_fluorescence(unsigned int actinicPin, ADC *adc);

// Debugging commands
void calibrate_fo(Actinic actinic);
Expand Down

0 comments on commit 3a14802

Please sign in to comment.