OpenCores
URL https://opencores.org/ocsvn/uart2bus/uart2bus/trunk

Subversion Repositories uart2bus

[/] [uart2bus/] [trunk/] [scilab/] [calc_baud_gen.sce] - Blame information for rev 7

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 motilito
// a short script to calaculate the baud rate generation parameters for the
2
// UART to Bus core
3
mode(-1)
4
 
5
// define the GCD function since Scilab prefers to use a different function as gcd
6
function x = gcdn(a,b)
7
x = zeros(length(b),length(a));
8
for n=1:length(a),
9
        for m=1:length(b),
10
                x=a(n);
11
                y=b(m);
12
                while y~=0
13
                        r=modulo(x,y);
14
                        x=y;
15
                        y=r;
16
                end
17
                x(m,n) = x;
18
        end
19
end
20
endfunction
21
 
22
// request the required clock rate and baud rate parameters
23
dig_labels = ["Clock Frequency in MHz"; "UART Baud Rate in bps"];
24 7 motilito
default_val = ["40"; "115200"];
25 2 motilito
params = evstr(x_mdialog("Enter Core Parameters", dig_labels, default_val));
26
 
27
// extract the parameters
28
global_clock_freq = params(1)*1e6;
29
baud_rate = params(2);
30
 
31
// calculate the baud rate generator parameters
32
D_BAUD_FREQ = 16*baud_rate / gcdn(global_clock_freq, 16*baud_rate);
33
D_BAUD_LIMIT = (global_clock_freq / gcdn(global_clock_freq, 16*baud_rate)) - D_BAUD_FREQ;
34
 
35
// print the values to the command window
36
printf("Calculated core baud rate generator parameters:\n");
37
printf("    D_BAUD_FREQ  = 12''d%d\n", D_BAUD_FREQ);
38
printf("    D_BAUD_LIMIT = 16''d%d\n", D_BAUD_LIMIT);
39
 
40
// open a message with the calculated values
41
mes_str = ["Calculated core baud rate generator parameters:"; ...
42
           "    D_BAUD_FREQ  = "+string(D_BAUD_FREQ); ...
43
           "    D_BAUD_LIMIT = "+string(D_BAUD_LIMIT); ...
44
           ""; ...
45
           "The verilog definition can be copied from the following lines:"; ...
46
           "`define D_BAUD_FREQ  12''d"+string(D_BAUD_FREQ); ...
47
           "`define D_BAUD_LIMIT 16''d"+string(D_BAUD_LIMIT);
48
           ];
49 7 motilito
messagebox(mes_str);

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.