-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_counters.c
167 lines (158 loc) · 3.75 KB
/
test_counters.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*
* test_counters.c -- Test de los contadores implementados.
* Ultima modificaci'on: 23-11-00.
* gse.
*/
#include "gates.h"
#include "latches.h"
#include "flip-flops.h"
#include "counters.h"
#include "clock.h"
#include <stdio.h>
#ifdef _AU_4BIN_COUNTER_
int main() {
FILE *data=fopen("data","w");
FILE *data_sdl=fopen("data.sdl","w");
int iter=5000;
WIRE c=0,Q0=0,Q1=0,Q2=0,Q3=0;
AU_4BIN_COUNTER co;
CLOCK clock(50);
fprintf(data,"c Q0 Q1 Q2 Q3");
while(iter--) {
clock.run(iter,c);
co.run(c,Q0,Q1,Q2,Q3);
fprintf(data_sdl,"%3d %3d %3d %3d %3d\n",c,Q0,Q1,Q2,Q3);
}
}
#endif
#ifdef _AU_8BIN_COUNTER_
int main() {
FILE *data=fopen("data","w");
FILE *data_sdl=fopen("data.sdl","w");
int iter=2500;
WIRE c,Q0,Q1,Q2,Q3,Q4,Q5,Q6,Q7;
AU_8BIN_COUNTER co;
CLOCK clock(7);
fprintf(data,"c Q0 Q1 Q2 Q3 Q4 Q5 Q6 Q7");
while(iter--) {
clock.run(iter,c);
co.run(c,Q0,Q1,Q2,Q3,Q4,Q5,Q6,Q7);
fprintf(data_sdl,"%3d %3d %3d %3d %3d %3d %3d %3d %3d\n",
c,Q0,Q1,Q2,Q3,Q4,Q5,Q6,Q7);
}
}
#endif
#ifdef _AD_4BIN_COUNTER_
int main() {
FILE *data=fopen("data","w");
FILE *data_sdl=fopen("data.sdl","w");
int iter=5000;
WIRE c=0,Q0=0,Q1=0,Q2=0,Q3=0;
AD_4BIN_COUNTER co;
CLOCK clock(50);
fprintf(data,"c Q0 Q1 Q2 Q3");
while(iter--) {
clock.run(iter,c);
co.run(c,Q0,Q1,Q2,Q3);
fprintf(data_sdl,"%3d %3d %3d %3d %3d\n",c,Q0,Q1,Q2,Q3);
}
}
#endif
#ifdef _AU_BCD_COUNTER_
int main() {
FILE *data=fopen("data","w");
FILE *data_sdl=fopen("data.sdl","w");
int iter=2000;
WIRE c=0,Q0=0,Q1=0,Q2=0,Q3=0;
AU_BCD_COUNTER co;
CLOCK clock(50);
fprintf(data,"c Q0 Q1 Q2 Q3");
while(iter--) {
clock.run(iter,c);
co.run(c,Q0,Q1,Q2,Q3);
fprintf(data_sdl,"%3d %3d %3d %3d %3d\n",c,Q0,Q1,Q2,Q3);
}
}
#endif
#ifdef _AU_BCD_COUNTER_CLR_
int main() {
FILE *data=fopen("data","w");
FILE *data_sdl=fopen("data.sdl","w");
int iter=3000;
WIRE c=0,Q0=0,Q1=0,Q2=0,Q3=0;
AU_BCD_COUNTER_CLR co;
CLOCK clock(50);
fprintf(data,"c Q0 Q1 Q2 Q3");
while(iter--) {
clock.run(iter,c);
co.run(c,Q0,Q1,Q2,Q3);
fprintf(data_sdl,"%3d %3d %3d %3d %3d\n",c,Q0,Q1,Q2,Q3);
}
}
#endif
#ifdef _SU_4BIN_COUNTER_
int main() {
FILE *data=fopen("data","w");
FILE *data_sdl=fopen("data.sdl","w");
int iter=1000;
WIRE c=0,Q[4]={0,0,0,0};
SU_4BIN_COUNTER co;
CLOCK clock(5);
fprintf(data,"c Q[0] Q[1] Q[2] Q[3]");
while(iter--) {
clock.run(iter,c);
co.run(c,Q);
fprintf(data_sdl,"%3d %3d %3d %3d %3d\n",c,Q[0],Q[1],Q[2],Q[3]);
}
}
#endif
#ifdef _SU_8BIN_COUNTER_
int main() {
FILE *data=fopen("data","w");
FILE *data_sdl=fopen("data.sdl","w");
int iter=2500;
WIRE c=0,Q[8]={0,0,0,0,0,0,0,0};
SU_8BIN_COUNTER co;
CLOCK clock(10);
fprintf(data,"c Q[0] Q[1] Q[2] Q[3] Q[4] Q[5] Q[6] Q[7]");
while(iter--) {
clock.run(iter,c);
co.run(c,Q);
fprintf(data_sdl,"%3d",c);
for(int i=0;i<8;i++) {
fprintf(data_sdl," %3d",Q[i]);
}
fprintf(data_sdl,"\n");
}
}
#endif
#ifdef _SU_BIN_COUNTER_
#include <stdlib.h> /* atoi() */
int main(int argc, char *argv[]) {
if(argc<3) {
fprintf(stderr,"%s tama~no_del_contador n'umero_de_iteraciones\n",argv[0]);
return 1;
}
FILE *data=fopen("data","w");
FILE *data_sdl=fopen("data.sdl","w");
int bits = atoi(argv[1]);
int iters = atoi(argv[2]);
WIRE ck; // Reloj
WIRE *Q = new WIRE[bits]; // Salidas del contador
SU_BIN_COUNTER co; // Contador de tama~no variable
co.create(bits);
CLOCK clock(10);
fprintf(data,"ck");
for(int i=0;i<bits;i++) fprintf(data," Q[%d]",i);
while(iters--) {
clock.run(iters,ck);
co.run(ck,Q);
fprintf(data_sdl,"%3d",ck);
for(int i=0;i<bits;i++) {
fprintf(data_sdl," %3d",Q[i]);
}
fprintf(data_sdl,"\n");
}
co.destroy();
}
#endif