Richard Riebenbauer
/
20190919_FunkGenMain1
test
Revision 0:619a9bde29ae, committed 2019-09-24
- Comitter:
- RichardRiebenbauer
- Date:
- Tue Sep 24 16:23:49 2019 +0000
- Commit message:
- jgvjhk.j
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/FuncGenFSST.cpp Tue Sep 24 16:23:49 2019 +0000 @@ -0,0 +1,42 @@ + +#include "FuncGenFSST.h" + + +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); +} + + + + + + + + + + + + + + + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/FuncGenFSST.h Tue Sep 24 16:23:49 2019 +0000 @@ -0,0 +1,85 @@ + +#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; // momentaner Ausgangswert + 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 + + + + + + + + + + + + + + + + + + + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/FuncGenMain.cpp Tue Sep 24 16:23:49 2019 +0000 @@ -0,0 +1,74 @@ + +#include "mbed.h" +#include "Serial_HL.h" +#include "FuncGenFSST.h" + +SerialBLK pc(USBTX, USBRX); +SvProtocol ua0(&pc); + +void CommandHandler(); +void ExecSignalChain(); + +SignedRampGen fg1; +float ampl1=1.0; +float v1=0; + +int main(void) +{ + pc.format(8,SerialBLK::None,1); + pc.baud(500000); + ua0.SvMessage("FuncGen1_1"); + + Timer stw; stw.start(); + while(1) { + CommandHandler(); + if( stw.read_ms()>10 ) { // 100Hz + stw.reset(); + ExecSignalChain(); + if( ua0.acqON ) { + ua0.WriteSV(1, v1); + } + } + } + return 1; +} + +void ExecSignalChain() +{ + fg1.CalcOneStep(); + v1 = fg1.val*ampl1; +} + +void CommandHandler() +{ + uint8_t cmd; + if( !pc.IsDataAvail() ) + return; + cmd = ua0.GetCommand(); + + if( cmd==2 ) { // Frequenz verstellen + fg1.SetFrequ(ua0.ReadF()); + ua0.SvMessage("Set Frequ."); + } + + if( cmd==3 ) { // Amplitude verstellen + ampl1=ua0.ReadF(); + ua0.SvMessage("Set Ampl."); + } +} + + + + + + + + + + + + + + + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Serial_HL.lib Tue Sep 24 16:23:49 2019 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/hollegha2/code/Serial_HL/#b958bdf108cf
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Tue Sep 24 16:23:49 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400 \ No newline at end of file