Stefan Kiegerl
/
FuncGen17
Func-Gen - basic setup
Revision 3:9fd12684fa88, committed 2021-03-23
- Comitter:
- stkiegerl
- Date:
- Tue Mar 23 17:13:12 2021 +0000
- Parent:
- 2:3abf5ddd9fc0
- Commit message:
- -
Changed in this revision
diff -r 3abf5ddd9fc0 -r 9fd12684fa88 FuncGenFSST.h --- a/FuncGenFSST.h Tue Mar 23 17:06:24 2021 +0000 +++ b/FuncGenFSST.h Tue Mar 23 17:13:12 2021 +0000 @@ -60,7 +60,7 @@ // Dauer des ON-Pulses in Prozent ( 0..1 ) void SetPulsWidth(float aPercent) { - _thrs=aPercent; // möglicherweise andere Formel + _thrs=aPercent; // möglicherweise andere Formel } // Einen Abtastwert berechnen @@ -87,4 +87,3 @@ -
diff -r 3abf5ddd9fc0 -r 9fd12684fa88 FuncGenFSST_21.cpp --- a/FuncGenFSST_21.cpp Tue Mar 23 17:06:24 2021 +0000 +++ b/FuncGenFSST_21.cpp Tue Mar 23 17:13:12 2021 +0000 @@ -1,14 +1,25 @@ #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); +} \ No newline at end of file
diff -r 3abf5ddd9fc0 -r 9fd12684fa88 FuncGenMain_21.cpp --- a/FuncGenMain_21.cpp Tue Mar 23 17:06:24 2021 +0000 +++ b/FuncGenMain_21.cpp Tue Mar 23 17:13:12 2021 +0000 @@ -1,49 +1,77 @@ #include "mbed.h" #include "Serial_HL.h" #include "FuncGenFSST.h" +#include "Tp1Ord.h" SerialBLK pc(USBTX, USBRX); SvProtocol ua0(&pc); +SignedRampGen fg1; +float ampl1 = 1.0; +float v1 = 0; // ausgang nach der Amplitude +Tp1Ord tp1; + void CommandHandler(); +void ExecSignalChain(); + +Ticker tc; + +AnalogOut dac1(PA_5); + int main(void) { pc.format(8,SerialBLK::None,1); pc.baud(500000); // 115200 ua0.SvMessage("FuncGen"); // Meldung zum PC senden + // tc.attach_us(&ExecSignalChain, 100); // Mit timer-Interrupt für 10khz audio + Timer stw; stw.start(); while(1) { CommandHandler(); - if( stw.read_ms()>10 ) { // 100Hz + if( stw.read_us()>10000 ) { // 100Hz stw.reset(); + ExecSignalChain(); // zur simulation mit 100Hz aufrufen if( ua0.acqON ) { + ua0.WriteSV(1, v1); + ua0.WriteSV(2, tp1.y); } } } return 1; } +void ExecSignalChain() +{ + fg1.CalcOneStep(); + v1 = ampl1*fg1.val; + tp1.CalcOneStep(v1); + // Achtung skalierung und Ãbersteuerung bedenken + // dac1.write( 0.5 + 0.5*v1); +} + void CommandHandler() { uint8_t cmd; if( !pc.IsDataAvail() ) return; -} - - - - - - - - - - - - - - - - + + cmd = ua0.GetCommand(); + + if( cmd==2 ) + { + fg1.SetFrequ(ua0.ReadF()); + ua0.SvMessage("Set Frequ"); + } + if( cmd==3 ) + { + ampl1=ua0.ReadF(); + ua0.SvMessage("Set Ampl."); + } + if( cmd==4 ) + { + tp1.SetAlpha(ua0.ReadF()); + ua0.SvMessage("Set Alpha"); + } +} \ No newline at end of file
diff -r 3abf5ddd9fc0 -r 9fd12684fa88 Tp1Ord.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Tp1Ord.h Tue Mar 23 17:13:12 2021 +0000 @@ -0,0 +1,60 @@ + +#ifndef Tp1Ord_h +#define Tp1Ord_h + +class Tp1Ord { + private: + float _alpha; + float _beta; + float yn_1; // um eine Abtastung verzögertes y + public: + float y; // momentaner ausgangswert des Filtes + public: + Tp1Ord(); + + // Grenzfrequenz verstellen + void SetAlpha(float aAlpha); + + void CalcOneStep(float aX); +}; + +Tp1Ord::Tp1Ord() +{ + y=yn_1=0; + SetAlpha(0.1); // Vernünftiges Alpha setzen +} + +void Tp1Ord::SetAlpha(float aAlpha) +{ + _alpha=aAlpha; + _beta=1.0f-aAlpha; +} + +void Tp1Ord::CalcOneStep(float aX) +{ + y = _alpha*aX + _beta*yn_1; + // Verzögerung berechnen + yn_1 = y; +} + +#endif + + + + + + + + + + + + + + + + + + + +