/* digOscOP2.c XH@27Jan'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, 200000000L}; #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[]){ printf("* ***********************************************\n" "* dieser Code erzeugt a \"ASCII-Art-Oszillogramm\"\n" "* Uin/t wennma en Kopf 90 Grad rechts draht\n" "* ************************************************\n"); 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=% 6.3f, dUc=% 6.3f, Uc=% 6.3f %-.*s*Uin=% 6.3f\n", Ir,dUc,Uc, (int)(5.*(4.+Uin)), " " " ", Uin ); nanosleep( &t, NULL ); } }