implemented logic inside draft;
This commit is contained in:
@@ -2,21 +2,122 @@
|
||||
use strict;
|
||||
use warnings;
|
||||
#use Cwd;
|
||||
use Math::Round; # for round()
|
||||
use List::Util; # for max @list
|
||||
|
||||
my $base_freq = 125 000 000;
|
||||
my $divider = 1;
|
||||
my $baudrate = $base_freq/$divider;
|
||||
### configure the pattern here ###
|
||||
my $divider = 1; # configured freq divieder
|
||||
my $sig_period_c = 10; # periode of RF during pulse in [base_cliqs]
|
||||
my $pulse_time = 9000; # B1 puls duration in [ns]
|
||||
my $short_time = 1000; # short switch on time in [ns]
|
||||
my $receive_time = 9900; # receiver on time in [ns]
|
||||
my $recovery_time = 100; # safety buffer between Rx and pulse in [ns]
|
||||
##################################
|
||||
|
||||
my $sig_freq = 10 000 000;
|
||||
my $pulse_time = 9e-6;
|
||||
my $short_time = 1e-6;
|
||||
my $receive_time = 1e-5;
|
||||
my $recovery_time = 1e-7;
|
||||
### these are given or computed parameters ###
|
||||
my $base_freq = 125 000 000; # sample freq of moku:GO
|
||||
my $base_cliq = 8; # sample periode in ns
|
||||
my $max_cliqs = 32764; # max sample length
|
||||
|
||||
mkdir('CODE-AFE_pattern'.sprintf("%.0f", $baud_rate).'MHz', 0777);
|
||||
chdir 'CODE-AFE_pattern'.sprintf("%.0f", $baud_rate).'MHz';
|
||||
my @pins = (1,2,3,4,5,6);
|
||||
my @pin_names = ("LS1", "LS2", "HS", "SS", "LSS", "Rx")
|
||||
|
||||
my $filename = '>>CODE-AFE_pattern'.sprintf("%.0f", $sig_freq).'MHz.csv';
|
||||
open(MYOUTFILE, $filename);
|
||||
$base_cliq *= $divider;
|
||||
my $baudrate = round($base_freq/$divider);
|
||||
my $sig_period = $sig_period_c * $base_cliq * 2;
|
||||
my $sig_freq = round(1/($sig_period*1e-9)); # B1 frequency
|
||||
##############################################
|
||||
|
||||
print MYOURFILE "Pin 1; Pin 2; Pin 3; Pin4; Pin5; Pin6;";
|
||||
### function to return the float remainder of a division ###
|
||||
sub remainder {
|
||||
my ($a, $b) = @_;
|
||||
return undef unless $b;
|
||||
return $a / $b - int($a / $b);
|
||||
}
|
||||
############################################################
|
||||
|
||||
### create outfile in output directory sorted by sampling frequency ###
|
||||
my $dirname = 'CODE-AFE_pattern'.sprintf("%.0f", $baud_rate).'MHz';
|
||||
my $filename = 'CODE-AFE_pattern'.sprintf("%.0f", $sig_freq).'MHz.csv';
|
||||
mkdir($dirname, 0777);
|
||||
open(MYOUTFILE, '>>./'.$dirname.'/'.$filename);
|
||||
#######################################################################
|
||||
|
||||
### create header with pin names ###
|
||||
foreach my $iterator (@pins) {
|
||||
print MYOUTFILE "Pin ";
|
||||
print MYOUTFILE $iterator;
|
||||
if ($iterator != max @pins) {
|
||||
print MYOUTFILE '; ';
|
||||
}
|
||||
}
|
||||
print MYOUTFILE "\n";
|
||||
####################################
|
||||
|
||||
### generate lines each containing one tick of the pattern ###
|
||||
my $last_cliq = 0;
|
||||
my $current_time = 0;
|
||||
my $t1 = $pulse_time;
|
||||
my $t2 = $t1 + $short_time;
|
||||
my $t3 = $t2 + $receive_time;
|
||||
my $t4 = $t3 + $recovery_time;
|
||||
|
||||
for (my $i=0; $i < $max_cliqs; $i++) {
|
||||
$current_time = $i * $base_cliq;
|
||||
if ($current_time <= $t1) {
|
||||
if (remainder($current_time, $sig_period) < 0.5) {
|
||||
print MYOUTFILE "1; "; #LS1
|
||||
print MYOUTFILE "0; "; #LS2
|
||||
}
|
||||
else {
|
||||
print MYOUTFILE "0; "; #LS1
|
||||
print MYOUTFILE "1; "; #LS2
|
||||
}
|
||||
print MYOUTFILE "1; "; #HS
|
||||
print MYOUTFILE "0; "; #SS
|
||||
print MYOUTFILE "1; "; #LSS
|
||||
print MYOUTFILE "0\n"; #Rx
|
||||
}
|
||||
elsif ($current_time <= $t2) {
|
||||
print MYOUTFILE "1; "; #LS1
|
||||
print MYOUTFILE "1; "; #LS2
|
||||
print MYOUTFILE "0; "; #HS
|
||||
print MYOUTFILE "1; "; #SS
|
||||
print MYOUTFILE "1; "; #LSS
|
||||
print MYOUTFILE "0\n"; #Rx
|
||||
}
|
||||
elsif ($current_time <= $t3) {
|
||||
print MYOUTFILE "0; "; #LS1
|
||||
print MYOUTFILE "0; "; #LS2
|
||||
print MYOUTFILE "0; "; #HS
|
||||
print MYOUTFILE "0; "; #SS
|
||||
print MYOUTFILE "0; "; #LSS
|
||||
print MYOUTFILE "1\n"; #Rx
|
||||
}
|
||||
elsif ($current_time <= $t4) {
|
||||
print MYOUTFILE "0; "; #LS1
|
||||
print MYOUTFILE "0; "; #LS2
|
||||
print MYOUTFILE "0; "; #HS
|
||||
print MYOUTFILE "0; "; #SS
|
||||
print MYOUTFILE "1; "; #LSS
|
||||
print MYOUTFILE "0\n"; #Rx
|
||||
}
|
||||
else {
|
||||
$last_cliq = $i;
|
||||
last;
|
||||
}
|
||||
}
|
||||
##############################################################
|
||||
|
||||
### report results ###
|
||||
print "### CODE-AFE pattern file written ###";
|
||||
print "Filename: ".$filename;
|
||||
print "Created in dir: ".$dirname;
|
||||
print "B1 frequency will be: ".sprintf("%3.6f", $sig_freq)."MHz";
|
||||
print "pattern length: ".$last_cliq." of ".$max_cliqs." samples";
|
||||
print "#####################################";
|
||||
######################
|
||||
|
||||
### cleanup ###
|
||||
close MYOUTFILE;
|
||||
###############
|
||||
|
||||
Reference in New Issue
Block a user