Subversion Repositories svn.mios32

Rev

Rev 1449 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1446 tk 1
#!/usr/bin/perl -w
2
# $Id: curve_c_charge.pl 1960 2014-02-09 20:21:24Z tk $
3
#
4
# Calculates capacitor charge curve and generates a gnuplot for visual check
5
# -> output in c_charge.inc
6
#
7
# Thorsten Klose (2007-08-05)
8
#
9
 
10
 
1960 tk 11
my $tau = 100.0; # exp1
12
#my $tau = 500.0; # exp2
1446 tk 13
my $steps = 1024;
14
my $y_max = 65535.0;
1449 tk 15
my $x_offset = 15.0;
1446 tk 16
 
17
####################################################################################################
18
open(OUT_C_DAT, ">c_charge.dat") || die;
19
open(OUT_C_INC, ">c_charge.inc") || die;
20
open(OUT_D_DAT, ">c_decharge.dat") || die;
21
 
22
my $scale = $y_max * ($y_max / get_exp_charge($y_max, $steps-1+$x_offset));
23
for($i=0; $i<$steps; ++$i) {
24
  my $x = $i+$x_offset;
25
  my $y = get_exp_charge($scale, $x);
26
  printf OUT_C_DAT "%d\t%d\n", $i, $y;
27
  printf OUT_C_INC "    %d, // %d\n", $y, $i;
28
  printf OUT_D_DAT "%d\t%d\n", $i, $y_max-$y;
29
}
30
 
31
close(OUT_C_DAT);
32
close(OUT_C_INC);
33
close(OUT_D_DAT);
34
 
35
####################################################################################################
36
system("gnuplot --persist -e \"plot 'c_charge.dat' title 'Charge' with lines, 'c_decharge.dat' title 'Decharge' with lines\"") && die;
37
 
38
 
39
 
40
####################################################################################################
41
sub get_exp_charge($$)
42
{
43
  my ($U, $x) = @_;
44
  return int($U * exp(-$tau / $x));
45
}