Last active
August 29, 2015 13:58
-
-
Save Hardolaf/10311806 to your computer and use it in GitHub Desktop.
This is for the OSU ATLAS Group, just a proof of concept so far. Very far from feature complete.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
40 to 50 channel data acquisition | |
TODO: Detection of optional channels 41 to 50 | |
TODO: Collect only when data is incoming | |
created 09 April 2014 | |
by Joseph Warner | |
*/ | |
#include <Bridge.h> | |
// Define the pins on the MUX from lsb | |
#define MUX_PIN_1 2 | |
#define MUX_PIN_2 3 | |
#define MUX_PIN_3 4 | |
#define MUX_PIN_4 5 | |
#define MUX_PIN_5 6 | |
#define MUX_PIN_6 7 | |
// Define the ADC pins from LSB | |
#define ADC_PIN_1 8 | |
#define ADC_PIN_2 9 | |
#define ADC_PIN_3 10 | |
#define ADC_PIN_4 11 | |
// Current channel we're getting data from | |
int addr = 0x0; | |
// Last channel currently available | |
int last_addr = 40; | |
// Time of the collection period (ms) | |
int collection_period = 100; | |
void setup() { | |
// Set MUX pins as output pins | |
pinMode(MUX_PIN_1, OUTPUT); | |
pinMode(MUX_PIN_2, OUTPUT); | |
pinMode(MUX_PIN_3, OUTPUT); | |
pinMode(MUX_PIN_4, OUTPUT); | |
pinMode(MUX_PIN_5, OUTPUT); | |
pinMode(MUX_PIN_6, OUTPUT); | |
// Set ADC pins as input pins | |
pinMode(ADC_PIN_1, INPUT); | |
pinMode(ADC_PIN_2, INPUT); | |
pinMode(ADC_PIN_3, INPUT); | |
pinMode(ADC_PIN_4, INPUT); | |
// Begin the Bridge to the Atheros processor | |
Bridge.begin(); | |
Serial.begin(9600); | |
while(!Serial); | |
Serial.println("Serial data logger started\n"); | |
} | |
void loop() { | |
int i = 0; | |
int data = 0; | |
String dataString; | |
// Reset addr to 0 | |
addr = 0; | |
writeAddrToMux(); | |
// Start timing | |
int startTime = millis(); | |
int endTime = startTime + collection_period; | |
while (endTime < millis()) { | |
dataString = ""; | |
dataString += millis() - startTime; | |
dataString += ";"; | |
dataString += addr; | |
dataString += ";"; | |
dataString += getDataFromAdc(); | |
Serial.println(dataString); | |
nextAddrToMux(); | |
} | |
} | |
// Gets data from the ADC | |
int getDataFromAdc() { | |
int data = 0x0; | |
data ^= digitalRead(ADC_PIN_1); | |
data ^= (digitalRead(ADC_PIN_1) << 1); | |
data ^= (digitalRead(ADC_PIN_1) << 2); | |
data ^= (digitalRead(ADC_PIN_1) << 3); | |
return data; | |
} | |
// Increments the MUX to the next address | |
void nextAddrToMux() { | |
if (addr != last_addr) { | |
addr++; | |
} else { | |
addr = 0x0; | |
} | |
writeAddrToMux(); | |
} | |
// Writes the current addr to the MUX | |
void writeAddrToMux() { | |
digitalWrite(MUX_PIN_1, addr & 1); | |
digitalWrite(MUX_PIN_2, addr & (1 << 1)); | |
digitalWrite(MUX_PIN_3, addr & (1 << 2)); | |
digitalWrite(MUX_PIN_4, addr & (1 << 3)); | |
digitalWrite(MUX_PIN_5, addr & (1 << 4)); | |
digitalWrite(MUX_PIN_6, addr & (1 << 5)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment