126 lines
4.0 KiB
Perl
126 lines
4.0 KiB
Perl
#!/usr/bin/perl -w
|
|
use strict;
|
|
use warnings;
|
|
#use Cwd;
|
|
use Math::Round; # for round()
|
|
use List::Util qw(max); # for max @list
|
|
|
|
### configure the pattern here ###
|
|
my $divider = 1; # configured freq divider
|
|
my $sig_freq = 13700000; # freq of RF during pulse in [Hz]
|
|
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]
|
|
##################################
|
|
|
|
### these are given or computed parameters ###
|
|
my $base_freq = 125000000; # sample freq of moku:GO
|
|
my $base_cliq = 8; # sample periode in ns
|
|
my $max_cliqs = 32764; # max sample length
|
|
|
|
my @pins = (1,2,3,4,5,6);
|
|
my @pin_names = ("LS1", "LS2", "HS", "SS", "LSS", "Rx");
|
|
|
|
$base_cliq *= $divider; # apply pre-division
|
|
my $baudrate = round($base_freq/$divider); # sample rate after pre-divider
|
|
my $sig_period = 1e9/$sigfreq; # RF period time in [ns]
|
|
##############################################
|
|
|
|
### 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("%3.6f", ($baudrate * 1e-6)).'MHz';
|
|
my $filename = 'CODE-AFE_pattern_'.sprintf("%3.6f", ($sig_freq * 1e-6)).'MHz.txt';
|
|
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 ',';
|
|
}
|
|
}
|
|
####################################
|
|
|
|
### 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) {
|
|
print MYOUTFILE "\n";
|
|
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"; #Rx
|
|
}
|
|
elsif ($current_time <= $t2) {
|
|
print MYOUTFILE "\n";
|
|
print MYOUTFILE "1,"; #LS1
|
|
print MYOUTFILE "1,"; #LS2
|
|
print MYOUTFILE "0,"; #HS
|
|
print MYOUTFILE "1,"; #SS
|
|
print MYOUTFILE "1,"; #LSS
|
|
print MYOUTFILE "0"; #Rx
|
|
}
|
|
elsif ($current_time <= $t3) {
|
|
print MYOUTFILE "\n";
|
|
print MYOUTFILE "0,"; #LS1
|
|
print MYOUTFILE "0,"; #LS2
|
|
print MYOUTFILE "0,"; #HS
|
|
print MYOUTFILE "0,"; #SS
|
|
print MYOUTFILE "0,"; #LSS
|
|
print MYOUTFILE "1"; #Rx
|
|
}
|
|
elsif ($current_time <= $t4) {
|
|
print MYOUTFILE "\n";
|
|
print MYOUTFILE "0,"; #LS1
|
|
print MYOUTFILE "0,"; #LS2
|
|
print MYOUTFILE "0,"; #HS
|
|
print MYOUTFILE "0,"; #SS
|
|
print MYOUTFILE "1,"; #LSS
|
|
print MYOUTFILE "0"; #Rx
|
|
}
|
|
else {
|
|
$last_cliq = $i;
|
|
last;
|
|
}
|
|
}
|
|
##############################################################
|
|
|
|
### report results ###
|
|
print "### CODE-AFE pattern file written ###\n";
|
|
print "Filename: ".$filename."\n";
|
|
print "Created in dir: ".$dirname."\n";
|
|
print "B1 frequency will be: ".sprintf("%3.6f", ($sig_freq * 1e-6))."MHz\n";
|
|
print "pattern length: ".$last_cliq." of ".$max_cliqs." samples\n";
|
|
print "#####################################\n";
|
|
######################
|
|
|
|
### cleanup ###
|
|
close MYOUTFILE;
|
|
###############
|