Beruflich Dokumente
Kultur Dokumente
Register Masks
ChannelMask =
FreqIndexMask=
DataModeMask =
BitDepthMask =
0b11000000;
0b00111100;
0b00000010;
0b00000001;
FilterShiftValMask = 0b00011111;
}
else { // handle all other unknown input values
SendError('d',inChar);
DataOff(); // set flag to stop sending data and sort out confusion
return;
}
} // end of if !settingsflag
} // end of if sendflag
} // end of if serial available
} // end of function
void DataOff(void){
dataflag = false;
}
void DataOn(void){
long tmpL = 128 << FilterShiftVal;
for (int i = 0; i<NChan; i++){
filter_reg[i]=tmpL;
}
// initialize timing and start counter
// Now update dependent variables that may have changed
long measurementdelay = 1000000/long(UserFrequency);// converted to microsecon
ds
downsampleCounter = 0; // for downsampling
updatetime = micros()+measurementdelay-TimingOffset; // reset timer.
dataflag = true;
}
void send10BitRawVals(void){
int tmp = 0;
int val = 0;
if (NChan == 1){
Serial.write('H');
}
else if (NChan == 2){
Serial.write('I');
}
else if (NChan == 4){
Serial.write('J'); // highlight next
}
for (int i = 0; i<NChan; i++){ // loop
val = analogRead(analogPins[i]); //
val = val << 6;
Serial.write(highByte(val)); // 0000
tmp += (lowByte(val)>>(2*i));
}
Serial.write(lowByte(tmp));
}
void send8BitRawVals(void){
int val = 0;
if (NChan == 1){
Serial.write('C');
}
else if (NChan == 2){
Serial.write('D');
}
data packet
through channels
read channel. 10-bit ADC. returns int
00** high byte is mostly 0's
void SendVersionInfo(void){
Serial.write(VERSION);
Serial.write(0);
Serial.write(0);
Serial.write(MODELNUMBER);
}
void UpdateSettings(void){
/*
* Control Words
*
* REG0 = main/basic user settings
* REG0<7:6> = Channels, 11=8, 10=4, 01=2, 00=1
* REG0<5:2> = FreqIndex
* REG0<1> = DataMode (1 = filtered, 0 = raw)
* REG0<0> = Data bit depth. 1=10bits, 0 = 8bits
*
* REG1 = Filter Shift Val + Prescalar Settings
* REG1<4:0> = filter shift val, 0:31, 5-bits
* REG1<7:5> = PS setting.
*
000 = 2
*
001 = 4
*
010 = 8
*
011 = 16 // not likely to be used
*
100 = 32 // not likely to be used
*
101 = 64 // not likely to be used
*
110 = 128// not likely to be used
*
111 = off (just use 48MHz/4)
*
* REG2 = Manual Frequency, low byte (16 bits total)
* REG3 = Manual Frequency, high byte (16 bits total)
*
* REG4 = Time adjust val (8bits, -6:249)
*
* REG5 & REG6 Timer Adjustment
* (add Time Adjust to x out of N total counts to 250)
* REG5<7:0> = partial counter val, low byte, 16 bits total
* REG6<7:0> = partial counter val, high byte, 16 bits total
*
* REG7<7:0> = down sampling value (mainly for smoothed data)
*
* REG8<7:0> = Plug Test Frequency
*/
int tmp = 0;
int tmp2 = 0;
//REG0
tmp = REG[0]&ChannelMask;
tmp = tmp>>6;
//
if (tmp == 3){NChan = 8;}
if (tmp == 2){
NChan = 4;
}
if (tmp == 1){
NChan = 2;
}
if (tmp == 0){
NChan = 1;
}
tmp = REG[0]&FreqIndexMask;
tmp = tmp>>2;
if (tmp >= 0 && tmp < sizeof(UserFreqArray)){ // handle out of bounds
UserFreqIndex = tmp;
UserFrequency = UserFreqArray[UserFreqIndex]; // store new frequency
measurementdelay = 1000000/long(UserFrequency);
}
else {
SendError('I',tmp);
}
tmp = REG[0]&DataModeMask;
if(tmp>0){
sendRaw = false;
sendFiltered = true;
}
else if(tmp == 0){
sendFiltered = false;
sendRaw = true;
}
tmp = REG[0]&BitDepthMask;
if(tmp == 0){
BitDepth = 8;
}
else if(tmp > 0){
BitDepth = 10;
}
// REG1
tmp = REG[1]&FilterShiftValMask;
if (tmp >= 0 && tmp <= MaxFilterShift){
FilterShiftVal = tmp;
}
else{
SendError('f',tmp);
}
//
//
//
//
//
nal
tmp = REG[7];
if (tmp >= DownSampleCountMin && tmp <= DownSampleCountMax){
DownSampleCount = tmp;
}
downsampleCounter = 0;
// REG8 PlugTest. Delay = number of seconds. if 0, no plugtest
tmp = REG[8];
if (tmp == 0){
PlugTestFlag = false;
}
if (tmp > 0 && tmp < MaxPlugTestDelay){
PlugTestFlag = true;
PlugTestDelay = tmp;
PlugTestCount = (UserFrequency*PlugTestDelay)/10; // note the divide by 10!!
if (PlugTestCount <= 0){
PlugTestCount = 1;
}
}
}
void TestPlugs(void){
byte mask = 00000001;
for(int i = 0; i < NChan; i++){ // loop through channels
if(digitalRead(tipSwitches[i]) == HIGH){
tipswitchvals = tipswitchvals | mask;
mask = mask << 1;
}
}
tipswitchCounter++;
if (tipswitchCounter >= tipswitchcountN){
Serial.write('p');
Serial.write(tipswitchvals);
tipswitchvals = 0;
tipswitchCounter = 0;
}
}
void SendError(char code, char msg){
Serial.write('e');
Serial.write(code);
Serial.write(msg);
}