Sorceress

Linear PSU simulator

Oct 13th, 2019
934
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. VRMS = 10 'Secondary Winding RMS Voltage
  2. VA = 18 'Reactive power of PSU
  3. f = 50 'Frequency Hz
  4. I = 750 / 1E3 'mA / 1E3
  5. C = 2200 / 1E6 'Smoothing Capacitance uF / 1E6
  6. vDrop = 0.9 'Estimated voltage drop of a rectifier diode at rated current
  7.  
  8. PI = 3.14159
  9. SCREEN 12
  10. w = 640: h = 480
  11.  
  12. 'draw axes (5v separation)
  13. FOR V = -15 TO 15 STEP 5
  14.   y = h / 2 - V * 8
  15.   LINE (0, y)-(w, y), 8
  16. NEXT
  17. LINE (0, h / 2)-(w, h / 2), 7
  18.  
  19. dt = 1E-6
  20. FOR t = 0 TO 1 STEP dt
  21.  
  22.   vt = VRMS * SQR(2) * SIN(2 * PI * t * f)
  23.   Ir = ABS(VA / vt)
  24.  
  25.   VR = ABS(vt) - vDrop * 2: IF VR < 0 THEN VR = 0 'full wave rectifier
  26.   'VR = vt - vDrop: IF VR < 0 THEN VR = 0 'half wave rectifier
  27.  
  28.   Q = Q - I * dt: IF Q < 0 THEN Q = 0
  29.   IF vc < VR THEN Q = Q + Ir * dt
  30.   vc = Q / C
  31.  
  32.   PSET (t * w * 20, h / 2 - vt * 8), 9 'no-load unrectified (blue)
  33.   PSET (t * w * 20, h / 2 - VR * 8), 12 'no-load rectified (red)
  34.   PSET (t * w * 20, h / 2 - vc * 8), 14 'loaded output voltage (yellow)
  35.  
  36.   IF t > .5 THEN
  37.     IF vc > vcmax THEN vcmax = vc
  38.     IF vc < vcmin THEN vcmin = vc
  39.   ELSE
  40.     vcmin = 1000: vcmax = 0
  41.   END IF
  42.  
  43. NEXT
  44.  
  45. PRINT "Linear PSU simulator"
  46. PRINT "Rated Voltage      : "; VRMS; "V"
  47. PRINT "PSU Reactive Power : "; VA; "VA"
  48. PRINT "Load Current       : "; I * 1000; "mA"
  49.  
  50. PRINT "Smoothed voltage   : "; vcmin; "->"; vcmax
RAW Paste Data