fertiger TP mit allen FG

Dependencies:   Serial_HL mbed

Fork of TiefpassundFG by julian Roll

Files at this revision

API Documentation at this revision

Comitter:
Polteko123
Date:
Thu May 04 08:19:15 2017 +0000
Commit message:
TP;

Changed in this revision

FuncGenFSST2.cpp Show annotated file Show diff for this revision Revisions of this file
FuncGenFSST2.h Show annotated file Show diff for this revision Revisions of this file
Serial_HL.lib Show annotated file Show diff for this revision Revisions of this file
TP1Ord_V2.cpp Show annotated file Show diff for this revision Revisions of this file
TP1Ord_V2.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/FuncGenFSST2.cpp	Thu May 04 08:19:15 2017 +0000
@@ -0,0 +1,110 @@
+#include "FuncGenFSST2.h"
+
+SignedRampGen::SignedRampGen()
+{
+  val = 0;
+  SetPointsPerPeriod(10); // Default ist 10Pts/Periode
+}
+
+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); 
+}
+
+
+
+TriangleGen::TriangleGen()
+{
+  val=_phase=0;
+  SetPointsPerPeriod(100);
+}
+
+void TriangleGen::SetPointsPerPeriod(float aPoints)
+{
+  _inc = 4.0/aPoints;
+}
+
+void TriangleGen::SetFrequ(float aFrequ)
+{
+  SetPointsPerPeriod(1.0/aFrequ);
+}
+
+void TriangleGen::CalcOneStep()
+{
+  _phase = _phase + _inc;
+  if( _phase>1.0 ) {
+    _phase = -1 + (_phase - 1.0);
+    if( _state==1 )
+      _state=2;
+    else
+      _state=1;
+  }
+  if( _state==1 )
+    val = _phase;
+  else
+    val = -_phase;
+}
+
+
+
+RectGen::RectGen()
+{
+  val=0; _phase=0; _thrs=0;
+  SetPointsPerPeriod(10); // Default ist 10Pts/Periode
+}
+
+void RectGen::SetPointsPerPeriod(float aPoints)
+{
+  _inc = 2.0/aPoints;
+}
+
+void RectGen::SetFrequ(float aFrequ)
+{
+  SetPointsPerPeriod(1.0/aFrequ);
+}
+
+void RectGen::SetPulsWidth(float aPercent)
+{
+  _thrs = 1.0-aPercent;
+}
+
+void RectGen::CalcOneStep()
+{
+  _phase = _phase + _inc;
+  if( _phase>1.0 )
+    _phase = -1 + (_phase - 1.0); 
+    if( _phase>_thrs )
+    val = 1.0;
+  else
+    val = -1.0;
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/FuncGenFSST2.h	Thu May 04 08:19:15 2017 +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;
+    float _phase;
+    public:
+        TriangleGen();
+    
+        void SetPointsPerPeriod(float 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;
+    float _thrs; // Threshold für die PulsWidth
+    public:
+        RectGen();
+    
+        void SetPointsPerPeriod(float 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/Serial_HL.lib	Thu May 04 08:19:15 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/hollegha2/code/Serial_HL/#1a03b6d5226f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TP1Ord_V2.cpp	Thu May 04 08:19:15 2017 +0000
@@ -0,0 +1,18 @@
+#include "TP1Ord_V2.h"
+
+Tp1Ord::Tp1Ord()
+{
+    // sinnvolles Alpha setzen
+    SetAlpha(0.1);
+}
+
+void Tp1Ord::SetAlpha(float aAlpha)
+{
+    _alpha = aAlpha;
+    _beta = (1.0-aAlpha);
+}
+
+void Tp1Ord::CalcOneStep(float aX)
+{
+    y = aX*_alpha + y*_beta;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TP1Ord_V2.h	Thu May 04 08:19:15 2017 +0000
@@ -0,0 +1,21 @@
+#ifndef TP1Ord_V2_h
+#define TP1Ord_V2_h
+
+class Tp1Ord
+{
+    public:
+        float y;        // Ausgangswert des Filters
+    private:
+        float _alpha, _beta;        // Koeffizienten für die Grenzfrequenz
+    public:
+        Tp1Ord();
+    
+    // Grenzfrequenz (Zeitkonstante des Filters setzen)
+    // aAlpha 0...1
+    void SetAlpha(float aAlpha);
+    
+    // einen Abtastschritt des Filters rechnen
+    // es entsteht ein neues y
+    void CalcOneStep(float aX);
+};
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu May 04 08:19:15 2017 +0000
@@ -0,0 +1,112 @@
+#include "mbed.h"
+#include "Serial_HL.h"
+#include "FuncGenFSST2.h"
+#include "TP1Ord_V2.h"
+
+// 2 Generatoren mit switch umschalten
+ 
+SerialBLK pc(USBTX, USBRX);
+SvProtocol ua0(&pc);
+
+void CommandHandler();
+void ExecSignalChain();
+
+SignedRampGen fg1;
+RectGen fg2;
+Tp1Ord tp;
+float amp1 = 1.0;
+float v1; // Ausgangswert mit amp1 multipliziert
+
+int swt=2; // 1..v1 auf fg1 geschaltet    2..v1 auf fg2 geschaltet
+
+int main(void)
+{
+    pc.format(8,SerialBLK::None,1); pc.baud(500000); // 115200
+  
+  ua0.SvMessage("FuncGenMain3"); // Meldung zum PC senden
+  
+  Timer stw; stw.start();
+  while(1) //  while(1)-Loop der mit dem PC kommuniziert
+  {
+    CommandHandler();
+    if( (stw.read_ms()>10) ) // 100Hz
+    { // dieser Teil wird mit 100Hz aufgerufen
+      stw.reset();
+      ExecSignalChain(); // Funktionsgeneratoren rechnen
+      if( ua0.acqON ) {
+        // ua0.WriteSV(1, v1);
+        // ua0.WriteSV(2, tp.y);
+        ua0.WriteSV(1, fg2.val);
+      }
+    }
+  }
+  return 1;
+}
+
+void ExecSignalChain()
+{
+  fg1.CalcOneStep();
+    fg2.CalcOneStep();
+    if( swt==1 )
+        v1 = amp1*fg1.val;
+    if( swt==2 )
+        v1 = amp1*fg2.val;
+    tp.CalcOneStep(v1);
+}
+
+void CommandHandler()
+{
+  uint8_t cmd;
+  if( !pc.IsDataAvail() )
+    return;
+  cmd = ua0.GetCommand();
+
+  // mithilfe von Kommandos vom PC Frequenz und Amplitude verstellen
+
+  if( cmd==2 ) // Frequenz
+  {
+        float frequ = ua0.ReadF();
+    fg1.SetFrequ(frequ); fg2.SetFrequ(frequ);
+        ua0.SvMessage("Set Frequ");
+  }
+  
+  if( cmd==3 ) // Amplitute
+  {
+    amp1 = ua0.ReadF();
+    ua0.SvMessage("Set Frequ");
+  }
+    
+    if( cmd==4 ) // Funktionsgeneratoren umschalten
+    {
+        swt = ua0.ReadI16();
+        ua0.SvMessage("Switch FG");
+    }
+    
+    if( cmd==5 )    // Set alpha
+    {
+        tp.SetAlpha(ua0.ReadF());
+        ua0.SvMessage("SetAlpha");
+    }
+    
+    if(cmd == 6)
+    {
+        fg2.SetPulsWidth(ua0.ReadF());
+    }
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu May 04 08:19:15 2017 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/mbed_official/code/mbed/builds/794e51388b66
\ No newline at end of file