/* MDS Oct 22
* TeensyLogger - a high speed data logger initially intended to record current profile for Gerald's Bumper Car
*
* The objective is to use a current trnasformer (CT) to measure the current taken by a car on the track to assess
* real load current and, in particular, overload current at motor start up. A 1v/100A CT provides an analogue voltage
* to the Teensy 4.1. This is sampled at high rate (tbc but nominally 500usec between samples) for 10seconds and stored
* on the T4.1's SD card. A Bluetooth link provides a means to start/stop recording and replay the data using a mobile phone.
*
Start points are:
20samples per 50Hz 1/2 cycle (0.5usec.)
steady state motor current 6.25A (500W at 80v)
Overload/start up motor current 62.5A (x10)
Analogue input resolution = 3/3v/1025 = 3.22mV
1V/100A = 10mV/A
input FSD = 3.3V = 330A (may exceed CT's ability or linearity)
to minimise 'lost time/data' whilst data is saved, samples will have to be saved on batches/blocks (using SdFat and possibly PIFFS)
This example code is in the public domain.
*/
int Tstart;//recording start time reference
int Ival = 500;//current value (0 - 1024)
int cnt;
int led = 13;
bool LED = LOW;
elapsedMillis whiletime;
DataT = 10000;//sets the recording time (in ms)
void setup()
{
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
Serial.begin(9600);
Serial.print("getting started.....");
}
void loop()
//loop structure contains:
//inputs via BT to start recording/saving samples, replay data to BT for display
//a 10sec 'do..while' call to collect samples and store them
{
Tstart = whiletime;
cnt = 0;
//set the LED to show recording is activated
//collect and save samples
while (whiletime <= Tstart + DataT){
Ival = analogRead(0);
cnt = cnt + 1;
}
Serial.print("out of while.....");
Serial.print("analog 0 is: ");
Serial.println(Ival);
Serial.print("Number of reads in 10sec. = ");
Serial.println(cnt);
if(LED == HIGH){
digitalWrite(led, LOW);
LED = LOW;
}
else {
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
LED = HIGH;
}
}