Oscillation frequency and dampingfactor

For oscillating transient models the timestep should be set appropriate to the oscillating frequency to get accurate results and capture the maxima and minima. This script will calculate the oscillating frequency and damping factor of an RLC oscillator for you.

Images in dialog:

oscillation.comi
/=============================================================================================================/
/ Thomatronik GmbH	
/ Brückenstr. 1	  Tel.: +49 (0)8031 2175-0     www.thomatronik.de
/ D-83022 Rosenheim	  Fax.: +49 (0)8031 2175-30    info@thomatronik.de
/
/ Author:	       Thomas Müller
/ Date:           10.11.2010
/ Opera-Version:  13.042
/
/ Comiskript for: Modeller Postprocessor Opera2d
/
/ Changes
/ --------
/ 01.01.2010: First Release
/
/=============================================================================================================/
 
/-------------------------------------------------------------------------------------------------------------/
/ Description:
/
/ This script will calculate the oscillating frequency and the damping of on electromagnetic oscillator 
/ with R, L and C
/
/-------------------------------------------------------------------------------------------------------------/
 
/ Preset some variables (only if they are not set yet)
$if %EXISTVAR(#R) Eq 0
  $CONSTANT NAME=#R  VALUE=1
$END IF
/
$if %EXISTVAR(#L) Eq 0
  $CONSTANT NAME=#L   VALUE=100
$END IF
/
$if %EXISTVAR(#C) Eq 0
  $CONSTANT NAME=#C     VALUE=100
$END IF
/
 
$CONSTANT NAME=#C_unit_nanoF    VALUE=1E-9
$CONSTANT NAME=#C_unit_microF   VALUE=1E-6
$CONSTANT NAME=#C_unit_mF       VALUE=1E-3
$CONSTANT NAME=#C_unit_F        VALUE=1
$CONSTANT NAME=#R_unit_microOhm  VALUE=1E-6
$CONSTANT NAME=#R_unit_mOhm      VALUE=1E-3
$CONSTANT NAME=#R_unit_Ohm       VALUE=1
$CONSTANT NAME=#L_unit_microH  VALUE=1E-6
$CONSTANT NAME=#L_unit_mH      VALUE=1E-3
$CONSTANT NAME=#L_unit_H      VALUE=1
 
$if %EXISTSTR(R_unit) Eq 0
  $string name=R_unit value='Ohm'   
$END IF
 
$if %EXISTSTR(C_unit) Eq 0
  $string name=C_unit microF   
$END IF
$if %EXISTSTR(L_unit) Eq 0
  $string name=L_unit mH  
$END IF
 
/ Dialog to ask user information (with defaults set above) 
/ ===========================================================
$constant #state 0
$while #state<2 
  $if #state==0 
    $DIALOG ACTION=START TITLE='Oscillator Data' 
      $DISPLAYLINE '<nobr><div align="center"><b>Please enter the data for the oscillator:</b></div></nobr>' 
      $Layout GRIDLAYOUT on
      $LAYOUT orientation horizontal        
      $groupbox action=start Title='' Orientation=horizontal strips=2
        $displayline 'oscillation_HarmOscLCR.png'  
      $groupbox action=stop
      $groupbox action=start Title='' Orientation=horizontal strips=2
        $Layout spanx 2
        $Displayline ''
        $ASK NAME=#R PROMPT='Resistance:'
        $PROMPT NAME=R_unit PROMPT='' HISTORY='Ohm mOhm microOhm' EDIT=NO
        $Layout spanx 2
        $Displayline ''        
        $ASK NAME=#L PROMPT='Inductance:'
        $PROMPT NAME=L_unit PROMPT='' HISTORY='H mH microH' EDIT=NO
        $Layout spanx 2
        $Displayline ''
        $ASK NAME=#C PROMPT='Capacitance:'
        $PROMPT NAME=C_unit PROMPT='' HISTORY='F mF microF nanoF' EDIT=NO
      $groupbox action=stop
      $Layout GRIDLAYOUT off
    $DIALOG ACTION=First 
    $cons #state #state+VF_ButtonPressed
  $end if
 
/ Factor for units
/ =====================
$STRING NAME=Rfactor VALUE='#R_unit_&R_unit&'
$STRING NAME=Lfactor VALUE='#L_unit_&L_unit&'
$STRING NAME=Cfactor VALUE='#C_unit_&C_unit&'
/
/ The actual Equations
/ =========================
$para #f0 1/(2*PI)*sqrt(1/(#L*&Lfactor&*#C*&Cfactor&)-(#R*&Rfactor&)**2/(4*(#L*&Lfactor&)**2))
$para #T0 1/#f0
$para #delta (#R*&Rfactor&)/(2*#L*&Lfactor&)
 
/ Check if the damping is to big
$if (#R*&Rfactor&)**2/(4*(#L*&Lfactor&)**2) ge 1/(#L*&Lfactor&*#C*&Cfactor&)
    $DIALOG ACTION=start TITLE='No oscillation' 
      $Displayline 'The resistance is to big to allow for oscillation.'
    $Dialog Action=Stop
    $const #state 0
$end if
/
/ Print out the results 
/ ================================
 $if #state==1 
    $DIALOG ACTION=start TITLE='Results for Oscillator' 
      $Layout GRIDLAYOUT on
      $LAYOUT orientation vertical
      $ LAYOUT COLUMNS 2
      $LAYOUT spany 2        
      $displayline 'oscillation_OscillatingKurve.png'  
      $groupbox action=start Title='Frequency and Period' Orientation=horizontal strips=2
        $displayline 'oscillation_Formelf0.png'  
        $groupbox action=start Title='' Orientation=horizontal strips=1
          $Displayline ''
          $DISPLAYLINE TEXT='<nobr><b>Oscillating frequency:</b> %real(#f0) Hz</nobr>' 
          $Displayline ''
          $DISPLAYLINE TEXT='<b>Period:</b> %real(#T0) s' 
        $groupbox action=stop
         $groupbox action=stop 
     $groupbox action=start Title='Damping factor' Orientation=horizontal strips=2
        $displayline 'oscillation_FormelD.png'  
          $groupbox action=start Title='' Orientation=horizontal strips=1
            $DISPLAYLINE TEXT='<b>Dampingfactor:</b> %real(#delta)' 
          $groupbox action=stop 
      $groupbox action=stop 
      $Layout GRIDLAYOUT off
    $DIALOG ACTION=Last
    $cons #state #state+VF_ButtonPressed
  $end if
$end while
scripts/dialogs/oscillation.txt · Last modified: 2013/07/23 13:50 by henschel
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0