Compare commits
6 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
27cb5fcdcd | |
|
|
27f75cf72e | |
|
|
6bf457693e | |
|
|
3d5396d0cb | |
|
|
3bfa687809 | |
|
|
b8db21ac8c |
|
|
@ -22,7 +22,7 @@
|
|||
## Author: Loic <Loic@LAPTOP-1F7SF0F7>
|
||||
## Created: 2023-04-28
|
||||
|
||||
function sol = determineArduinoUnoInterruptSettings (Fs, bitSize)
|
||||
function [sol, CMR] = determineArduinoUnoInterruptSettings (Fs, bitSize)
|
||||
|
||||
freqClock = 16*10^6;
|
||||
preDiv8 = [1, 8, 64, 256, 1024];
|
||||
|
|
@ -34,12 +34,13 @@ elseif bitSize == 8
|
|||
endif
|
||||
|
||||
sol = [];
|
||||
CMR = [];
|
||||
itr = 1;
|
||||
|
||||
for i = 1:length(preDiv)
|
||||
CMR = freqClock/(preDiv(i)*Fs)-1;
|
||||
if round(CMR)-CMR == 0 && CMR < (2^bitSize -1)
|
||||
CMR
|
||||
cmr = freqClock/(preDiv(i)*Fs)-1;
|
||||
if round(cmr)-cmr == 0 && cmr < (2^bitSize -1)
|
||||
CMR(itr) = cmr;
|
||||
sol(itr) = preDiv(i);
|
||||
itr ++;
|
||||
endif
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ clear all
|
|||
close all
|
||||
clc
|
||||
|
||||
Fs = 2000; %Hz
|
||||
bitSize = 8; %bitset
|
||||
Fs = 100; %Hz
|
||||
bitSize = 16; %bitset
|
||||
|
||||
determineArduinoUnoInterruptSettings (Fs, bitSize)
|
||||
[preDivisor, CMR] = determineArduinoUnoInterruptSettings (Fs, bitSize) %any of the pair of solutions work here
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
int const Fs = 20;
|
||||
int const N = 100;
|
||||
int const timePeriod = 1000/Fs; //for delay
|
||||
int const clockFreq = pow(10, 6);
|
||||
|
||||
int mySensor = A0;
|
||||
|
||||
double myPeriods[N];
|
||||
double Avg;
|
||||
double stDev;
|
||||
|
||||
int itr = 0;
|
||||
float timeStart = 0;
|
||||
|
||||
void setup() {
|
||||
// put your setup code here, to run once:
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// put your main code here, to run repeatedly:
|
||||
timeStart = micros();
|
||||
int myValue = analogRead(mySensor);
|
||||
int readTime = timeStart - micros();
|
||||
delay(timePeriod-readTime/1000);
|
||||
|
||||
myPeriods[itr] = micros() - timeStart;
|
||||
Serial.println(myPeriods[itr]);
|
||||
|
||||
//calculating the std and mean
|
||||
itr++;
|
||||
if (itr == N){
|
||||
double sum = 0;
|
||||
for (int i = 0; i < N; i++){
|
||||
sum = sum + myPeriods[i];
|
||||
}
|
||||
Avg = sum/100;
|
||||
int i = 0;
|
||||
double sumSTD = 0;
|
||||
while (i < N){
|
||||
sumSTD = sumSTD + (myPeriods[i]-Avg)*(myPeriods[i]-Avg);
|
||||
i++;
|
||||
}
|
||||
stDev = sqrt(sum/N);
|
||||
Serial.print("Average = ");
|
||||
Serial.print(Avg/1000);
|
||||
Serial.println("ms");
|
||||
Serial.print("Standard Deviation = ");
|
||||
Serial.print(stDev/1000);
|
||||
Serial.println("ms");
|
||||
while(1);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue