Alexander Welz
/
FunkGenerator
FunkGen_Rechteck_Sägezahn
Revision 2:4d43beb83247, committed 2019-05-14
- Comitter:
- WelzAlex
- Date:
- Tue May 14 12:55:41 2019 +0000
- Parent:
- 1:e88b745f2ca2
- Commit message:
- FunkGen_Rechteck_Saegezahn
Changed in this revision
diff -r e88b745f2ca2 -r 4d43beb83247 FuncGenFSST/FuncGenFSST.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/FuncGenFSST/FuncGenFSST.cpp Tue May 14 12:55:41 2019 +0000 @@ -0,0 +1,73 @@ + +#include "FuncGenFSST.h" + + +RectGen::RectGen() +{ + val=0; + SetPointsPerPeriod(20); +} + +void RectGen::SetPointsPerPeriod(int aPoints) +{ + _inc = 2.0/aPoints; +} + +void RectGen::SetFrequ(float aFrequ) +{ + SetPointsPerPeriod(1.0/aFrequ); +} + +void RectGen::CalcOneStep() +{ + _phase = _phase + _inc; + if( _phase>1.0 ) + _phase = -1 + (_phase - 1.0); + val_orginal = _phase; + + if(_phase > 0) + val = 1; + else + val = -1; +} + + + +SignedRampGen::SignedRampGen() +{ + val=0; + SetPointsPerPeriod(20); +} + +void SignedRampGen::SetPointsPerPeriod(float aPoints) +{ + _inc = 2.0/aPoints; +} + +void SignedRampGen::SetFrequ(float aFrequ) +{ + SetPointsPerPeriod(1.0/aFrequ); +} + +void SignedRampGen::CalcOneStep() +{ + val = val + _inc; + if( val>1.0 ) + val = -1 + (val - 1.0); +} + + + + + + + + + + + + + + + +
diff -r e88b745f2ca2 -r 4d43beb83247 FuncGenFSST/FuncGenFSST.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/FuncGenFSST/FuncGenFSST.h Tue May 14 12:55:41 2019 +0000 @@ -0,0 +1,86 @@ + +#ifndef FuncGenFSST_h +#define FuncGenFSST_h + +// Amplituden fix auf +/-1 + +class SignedRampGen { + public: + float val; // momentaner Ausgangswert + private: + float _inc; + public: + SignedRampGen(); // Konstruktor + + void SetPointsPerPeriod(float aPoints); + + // bezogen auf Fsample 0..0.5 + void SetFrequ(float aFrequ); + + // Einen Abtastwert berechnen + // wird bei z.B. Fsample=100Hz 100x pro sec afgerufen + void CalcOneStep(); +}; + + +class TriangleGen { + public: + float val; // momentaner Ausgangswert + private: + float _inc; + int _state; + public: + TriangleGen(); + + void SetPointsPerPeriod(int aPoints); + + // bezogen auf Fsample 0..0.5 + void SetFrequ(float aFrequ); + + // Einen Abtastwert berechnen + void CalcOneStep(); +}; + + +class RectGen { + public: + float val_orginal; // momentaner Ausgangswert + float val; + private: + float _inc; + float _phase; + public: + RectGen(); + + void SetPointsPerPeriod(int aPoints); + + void SetFrequ(float aFrequ); + + // Dauer des ON-Pulses in Prozent ( 0..1 ) + void SetPulsWidth(float aPercent); + + // Einen Abtastwert berechnen + void CalcOneStep(); +}; + +#endif + + + + + + + + + + + + + + + + + + + +
diff -r e88b745f2ca2 -r 4d43beb83247 FuncGenFSST/FuncGenMain3.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/FuncGenFSST/FuncGenMain3.cpp Tue May 14 12:55:41 2019 +0000 @@ -0,0 +1,107 @@ + +#include "mbed.h" +#include "Serial_HL.h" +#include "FuncGenFSST.h" + +SerialBLK pc(USBTX, USBRX); +SvProtocol ua0(&pc); + +SignedRampGen fg1; +RectGen rg1; + + + +float ampl1 = 1.0; +float ampl2 = 0.5; +float v1 = 0; // signal nach dem Verstellen der Amplidute +float v2 = 0; + + +void CommandHandler(); + +void ExecSignalChain(); // Signalverarbeitungskette 1x durchrechen + +int main(void) +{ + pc.format(8,SerialBLK::None,1); pc.baud(115200); // 115200 + ua0.SvMessage("FuncGen"); // Meldung zum PC senden + + Timer stw; stw.start(); + while(1) + { + CommandHandler(); + + if( (stw.read_ms()>10) ) // 100Hz + { // dieser Teil wird mit 100Hz aufgerufen + ExecSignalChain(); + stw.reset(); + if( ua0.acqON ) + { + ua0.WriteSV(1, v1); // v1 anzeigen + ua0.WriteSV(2, v2); // v1 anzeigen + } + } + } + return 1; +} + +// wird mit 100Hz (Analyse) oder 44kHz (Echtzeit) aufgerufen +void ExecSignalChain() +{ + fg1.CalcOneStep(); + v1 = fg1.val*ampl1; + + rg1.CalcOneStep(); + v2 = rg1.val*ampl2; + //v1 = rg1.val_orginal*ampl2; +} + +void CommandHandler() +{ + uint8_t cmd; + if( !pc.IsDataAvail() ) + return; + + cmd = ua0.GetCommand(); + + if( cmd==2 ) // Set Frequ. + { + fg1.SetFrequ(ua0.ReadF()); + ua0.SvMessage("Set Frequ1"); + } + + if( cmd==3 ) // Set ampl + { + ampl1 = ua0.ReadF(); + ua0.SvMessage("Set Ampl1"); + } + + if( cmd==4 ) // Set Frequ2 + { + rg1.SetFrequ(ua0.ReadF()); + ua0.SvMessage("Set Frequ2"); + } + + if( cmd==5 ) // Set ampl2 + { + ampl2 = ua0.ReadF(); + ua0.SvMessage("Set Ampl2"); + } +} + + + + + + + + + + + + + + + + +
diff -r e88b745f2ca2 -r 4d43beb83247 ProcVisDemo.cpp --- a/ProcVisDemo.cpp Fri Oct 09 07:58:26 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,66 +0,0 @@ -#include "mbed.h" -#include "Serial_HL.h" - -SerialBLK pc(USBTX, USBRX); -SvProtocol ua0(&pc); - -// V2.0 -// BusOut leds(LED1,LED2,LED3,LED4); Bertl14 -// M0-Board -BusOut leds(P1_13,P1_12,P1_7,P1_6,P1_4,P1_3,P1_1,P1_0,LED4,LED3,LED2,LED1); - - -void CommandHandler(); - -int main(void) -{ - pc.format(8,SerialBLK::None,1); - pc.baud(115200); - leds = 9; - - ua0.SvMessage("SvTest_Serial_HL"); // Meldung zum PC senden - - int16_t sv1=0, sv2=100; - Timer stw; - stw.start(); - while(1) { - CommandHandler(); - if( ua0.acqON && (stw.read_ms()>100) ) { // 10Hz - // dieser Teil wird mit 10Hz aufgerufen - stw.reset(); - sv1++; - sv2++; - if( ua0.acqON ) { - // nur wenn vom PC aus das Senden eingeschaltet wurde - // wird auch etwas gesendet - ua0.WriteSvI16(1, sv1); - ua0.WriteSvI16(2, sv2); - } - } - } - return 1; -} - -void CommandHandler() -{ - uint8_t cmd; - int16_t idata1, idata2; - - // Fragen ob überhaupt etwas im RX-Reg steht - if( !pc.IsDataAvail() ) - return; - - // wenn etwas im RX-Reg steht - // Kommando lesen - cmd = ua0.GetCommand(); - - if( cmd==2 ) { - // cmd2 hat 2 int16 Parameter - idata1 = ua0.ReadI16(); - idata2 = ua0.ReadI16(); - // für die Analyse den Wert einfach nur zum PC zurücksenden - ua0.SvPrintf("Command2 %d %d", idata1, idata2); - } -} - -