From 368bc18eeff26b93e50c67d1e59e9d74899e45f6 Mon Sep 17 00:00:00 2001 From: Loic Delattre Date: Fri, 28 Apr 2023 14:40:09 +0200 Subject: [PATCH 1/2] CMR func --- Matlab/determineArduinoUnoInterruptSettings.m | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Matlab/determineArduinoUnoInterruptSettings.m diff --git a/Matlab/determineArduinoUnoInterruptSettings.m b/Matlab/determineArduinoUnoInterruptSettings.m new file mode 100644 index 0000000..1e948e8 --- /dev/null +++ b/Matlab/determineArduinoUnoInterruptSettings.m @@ -0,0 +1,33 @@ +## Copyright (C) 2023 Loic +## +## This program is free software: you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation, either version 3 of the License, or +## (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program. If not, see . + +## -*- texinfo -*- +## @deftypefn {} {@var{retval} =} determineArduinoUnoInterruptSettings (@var{input1}, @var{input2}) +## +## @seealso{} +## @end deftypefn + +## Author: Loic +## Created: 2023-04-28 + +function retval = determineArduinoUnoInterruptSettings (Fs) + +freqClock = 16*10^6; +preDiv = [1, 8, 32, 64, 128, 256, 1024]; +CMR = []; + +for i = 1:length(preDiv) + CMR(i) = freqClock/(preDiv(i)*Fs)-1; +endfunction From 6de8ddfbc9ee82ecd2050ad45a0598dc6da4cc41 Mon Sep 17 00:00:00 2001 From: Loic Delattre Date: Fri, 28 Apr 2023 15:03:38 +0200 Subject: [PATCH 2/2] function done and script --- Matlab/determineArduinoUnoInterruptSettings.m | 25 ++++++++++++++++--- Matlab/testArduinoUnoInterruptSettings.m | 8 ++++++ 2 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 Matlab/testArduinoUnoInterruptSettings.m diff --git a/Matlab/determineArduinoUnoInterruptSettings.m b/Matlab/determineArduinoUnoInterruptSettings.m index 1e948e8..afd69d9 100644 --- a/Matlab/determineArduinoUnoInterruptSettings.m +++ b/Matlab/determineArduinoUnoInterruptSettings.m @@ -22,12 +22,29 @@ ## Author: Loic ## Created: 2023-04-28 -function retval = determineArduinoUnoInterruptSettings (Fs) +function sol = determineArduinoUnoInterruptSettings (Fs, bitSize) freqClock = 16*10^6; -preDiv = [1, 8, 32, 64, 128, 256, 1024]; -CMR = []; +preDiv8 = [1, 8, 64, 256, 1024]; +preDiv16 = [1, 8, 32, 64, 128, 256, 1024]; +if bitSize == 16 + preDiv = preDiv16; +elseif bitSize == 8 + preDiv = preDiv8; +endif + +sol = []; +itr = 1; for i = 1:length(preDiv) - CMR(i) = freqClock/(preDiv(i)*Fs)-1; + CMR = freqClock/(preDiv(i)*Fs)-1; + if round(CMR)-CMR == 0 && CMR < (2^bitSize -1) + CMR + sol(itr) = preDiv(i); + itr ++; + endif +endfor +if itr == 1 + disp("no solution"); +endif endfunction diff --git a/Matlab/testArduinoUnoInterruptSettings.m b/Matlab/testArduinoUnoInterruptSettings.m new file mode 100644 index 0000000..8fffbd7 --- /dev/null +++ b/Matlab/testArduinoUnoInterruptSettings.m @@ -0,0 +1,8 @@ +clear all +close all +clc + +Fs = 2000; %Hz +bitSize = 8; %bitset + +determineArduinoUnoInterruptSettings (Fs, bitSize) \ No newline at end of file