Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Zhuoyu Zhang
DigitalSystemLabs
Commits
9357384b
Commit
9357384b
authored
May 16, 2023
by
Zhuoyu Zhang
Browse files
Upload New File
parent
133e828c
Changes
1
Hide whitespace changes
Inline
Side-by-side
lab_15/src/SineROMGenerator.c
0 → 100644
View file @
9357384b
#include
<stdio.h>
#include
<math.h>
void
main
()
{
int
i
;
int
data
;
FILE
*
fp
;
if
((
fp
=
fopen
(
"sine_rom.v"
,
"w"
))
==
NULL
)
{
printf
(
"error"
);
exit
(
0
);
}
fprintf
(
fp
,
"%s
\n
"
,
"module sine_rom( "
);
fprintf
(
fp
,
"%s
\n
"
,
" input clk, "
);
fprintf
(
fp
,
"%s
\n
"
,
" input wire[9:0] addr, "
);
fprintf
(
fp
,
"%s
\n
"
,
" output reg[15:0] dout); "
);
fprintf
(
fp
,
"%s
\n
"
,
" always @(posedge clk) "
);
fprintf
(
fp
,
"%s
\n
"
,
" case(addr) "
);
for
(
i
=
0
;
i
<
1024
;
i
++
)
{
data
=
(
int
)(
sin
(
2
*
3
.
1415926
*
i
/
4096
)
*
32767
+
0
.
5
);
data
&=
0x0000ffff
;
fprintf
(
fp
,
"%s%d%s%d%s
\n
"
,
" "
,
i
,
":dout= 16'd"
,
data
,
";"
);
}
fprintf
(
fp
,
"%s
\n
"
,
" endcase "
);
fprintf
(
fp
,
"%s
\n
"
,
"endmodule"
);
fclose
(
fp
);
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment