/* digOscOP1.c XH@26Jan'21 * Berechnung des Digitaloszillator-Arbeitspunktes * mittels FE-numerischer Integration * compile: 'gcc digOscOP1.c -o digOsc.exe' * run: './digOsc.exe' * stop: Strg+C * OS: Linux (Knoppix v8.6) */ #include #include struct timespec t={0L, 300000000L}; #define Vcc 5.0 double Uc = 0.0; double Uin; double R1 = 1000.; double C = 1E-7; double dt = 1E-5; double Ir,dUc,Uin; int inv1=0; int inv2=1; int main(int argc, char *argv[]){ for(;;){ Uin = (inv2*Vcc) + Uc; if( Uin > Vcc/2 ){ inv1 = 0; }else{ inv1 = 1; } inv2 = inv1 ? 0 : 1; Ir = (inv1*Vcc-Uin)/R1; dUc = dt*Ir/C; Uc += dUc; printf("Ir=%9g, dUc=%9g, Uc=%9g, Uin=%9g\n", Ir,dUc,Uc,Uin); nanosleep( &t, NULL ); } }