|
|
|
|
@ -0,0 +1,50 @@
|
|
|
|
|
## 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 <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
## -*- texinfo -*-
|
|
|
|
|
## @deftypefn {} {@var{retval} =} determineArduinoUnoInterruptSettings (@var{input1}, @var{input2})
|
|
|
|
|
##
|
|
|
|
|
## @seealso{}
|
|
|
|
|
## @end deftypefn
|
|
|
|
|
|
|
|
|
|
## Author: Loic <Loic@LAPTOP-1F7SF0F7>
|
|
|
|
|
## Created: 2023-04-28
|
|
|
|
|
|
|
|
|
|
function sol = determineArduinoUnoInterruptSettings (Fs, bitSize)
|
|
|
|
|
|
|
|
|
|
freqClock = 16*10^6;
|
|
|
|
|
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 = 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
|