-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflyback.c
More file actions
46 lines (44 loc) · 884 Bytes
/
flyback.c
File metadata and controls
46 lines (44 loc) · 884 Bytes
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
#include <stdio.h>
#include "libsimul.h"
const double dt = 1e-7; // 100 ns
int main(int argc, char **argv)
{
size_t i;
int switch_state = 1;
int cnt_remain = 500;
struct libsimul_ctx ctx;
libsimul_init(&ctx, dt);
read_file(&ctx, "flyback.txt");
init_simulation(&ctx);
if (set_switch_state(&ctx, "S1", switch_state) != 0)
{
set_diode_hint(&ctx, "D1", !switch_state);
recalc(&ctx);
}
for (i = 0; i < 3*1000*1000; i++)
{
simulation_step(&ctx);
printf("%zu %g\n", i, get_V(&ctx, 5) - get_V(&ctx, 3));
cnt_remain--;
if (cnt_remain == 0)
{
switch_state = !switch_state;
//switch_state = 1;
if (set_switch_state(&ctx, "S1", switch_state) != 0)
{
set_diode_hint(&ctx, "D1", !switch_state);
recalc(&ctx);
}
if (switch_state)
{
cnt_remain = 500;
}
else
{
cnt_remain = 100;
}
}
}
libsimul_free(&ctx);
return 0;
}