Skip to content

Instantly share code, notes, and snippets.

@Jacajack
Created October 29, 2017 22:24
Show Gist options
  • Save Jacajack/ee5bb24ee0c5298dfd5d035f1e1ff9a9 to your computer and use it in GitHub Desktop.
Save Jacajack/ee5bb24ee0c5298dfd5d035f1e1ff9a9 to your computer and use it in GitHub Desktop.
Scilab script for calculating AVR synth comparator values
clear
fcpu = 20000000;
prescaler = 1;
samplesize = 16;
noterange = 1:88;
//Calculate timer frequency
ftimer = fcpu / prescaler;
//Calculate note frequencies
fnote = [];
for i = noterange do
fnote( i ) = ( 2 ^ ( 1 / 12 ) ) ^ ( i - 49 ) * 440;
end
//Calculate comparator values
compv = [];
for i = noterange do
compv( i ) = ftimer / fnote( i ) / samplesize;
end
//Print data in form of C array
printf( "\n{\n" );
for i = noterange do
printf( "\t%5d, //[%02d] - %0.2fHz\n", round( compv( i ) ), i, fnote( i ) );
end
printf( "}\n" );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment