Funcgen
Embed:
(wiki syntax)
Show/hide line numbers
FuncGenFSST_21.cpp
00001 00002 #include "FuncGenFSST.h" 00003 00004 //SignalRampGen 00005 SignedRampGen::SignedRampGen() 00006 { 00007 val=0; 00008 SetPointsPerPeriod(20); 00009 } 00010 00011 void SignedRampGen::SetPointsPerPeriod(float aPoints) 00012 { 00013 _inc = 2.0/aPoints; 00014 } 00015 00016 void SignedRampGen::SetFrequ(float aFrequ) 00017 { 00018 SetPointsPerPeriod(1.0/aFrequ); 00019 } 00020 00021 void SignedRampGen::CalcOneStep() 00022 { 00023 val = val + _inc; 00024 if( val>1.0 ) 00025 val = -1 + (val - 1.0); 00026 } 00027 //---------------------------------------------------------------------------------- 00028 //TriangleRampGen 00029 TriangleGen::TriangleGen() 00030 { 00031 val = 0; 00032 int _state = 1; 00033 float _phase = 0.0f; 00034 SetPointsPerPeriod(20); 00035 } 00036 00037 void TriangleGen::SetPointsPerPeriod(float aPoints) 00038 { 00039 _inc = 4.0/aPoints; 00040 } 00041 00042 void TriangleGen::SetFrequ(float aFrequ) 00043 { 00044 SetPointsPerPeriod(1.0/aFrequ); 00045 } 00046 00047 void TriangleGen::CalcOneStep() 00048 { 00049 _phase = _phase + _inc; 00050 if( _phase>1.0 ) 00051 { 00052 _phase = -1 + (_phase - 1.0); 00053 if(_state == 1) 00054 _state = 2; 00055 else 00056 _state = 1; 00057 } 00058 00059 if(_state == 1) 00060 val = _phase; 00061 else if(_state == 2) 00062 val = -_phase; 00063 } 00064 00065 00066 //------------------------------------------------------------------------------ 00067 //Rect 00068 RectGen::RectGen() 00069 { 00070 val = 0; 00071 SetPointsPerPeriod(20); 00072 _phase = 0.0f; 00073 _thrs = 0.0f; 00074 } 00075 void RectGen::SetPointsPerPeriod(float aPoints) 00076 { 00077 _inc = 2.0/aPoints; 00078 } 00079 00080 void RectGen::SetFrequ(float aFrequ) 00081 { 00082 SetPointsPerPeriod(1.0/aFrequ); 00083 } 00084 00085 void RectGen::SetPulsWidth(float aPercent) 00086 { 00087 _thrs=aPercent; // möglicherweise andere Formel 00088 } 00089 void RectGen::CalcOneStep() 00090 { 00091 //Erzeugen des SignalRampGen 00092 _phase = _phase + _inc; 00093 if( _phase>1.0 ) 00094 _phase = -1 + (_phase - 1.0); 00095 00096 //Erzeugen des PWMs 00097 if( _phase < _thrs) 00098 val = -1; 00099 else 00100 val = +1; 00101 } 00102 00103 //------------------------------------------------------------------------------
Generated on Thu Jul 14 2022 03:18:04 by
1.7.2