Function generator

Dependencies:   Serial_HL mbed

Committer:
hollegha2
Date:
Thu Mar 17 13:45:13 2016 +0000
Revision:
2:100244cef3d6
Child:
3:c8c3b755ef54
V1.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hollegha2 2:100244cef3d6 1
hollegha2 2:100244cef3d6 2 #include "FuncGen.h"
hollegha2 2:100244cef3d6 3
hollegha2 2:100244cef3d6 4 // Konstruktor
hollegha2 2:100244cef3d6 5 SignedRampGen::SignedRampGen()
hollegha2 2:100244cef3d6 6 {
hollegha2 2:100244cef3d6 7 val=0;
hollegha2 2:100244cef3d6 8 SetPointsPerPeriod(10);
hollegha2 2:100244cef3d6 9 }
hollegha2 2:100244cef3d6 10
hollegha2 2:100244cef3d6 11 void SignedRampGen::SetPointsPerPeriod(int aPoints)
hollegha2 2:100244cef3d6 12 {
hollegha2 2:100244cef3d6 13 _inc = 2.0/aPoints;
hollegha2 2:100244cef3d6 14 }
hollegha2 2:100244cef3d6 15
hollegha2 2:100244cef3d6 16 void SignedRampGen::SetFrequ(float aFrequ)
hollegha2 2:100244cef3d6 17 {
hollegha2 2:100244cef3d6 18 SetPointsPerPeriod(1.0/aFrequ);
hollegha2 2:100244cef3d6 19 }
hollegha2 2:100244cef3d6 20
hollegha2 2:100244cef3d6 21 void SignedRampGen::CalcOneStep()
hollegha2 2:100244cef3d6 22 {
hollegha2 2:100244cef3d6 23 val = val + _inc;
hollegha2 2:100244cef3d6 24 if( val>=1.0 )
hollegha2 2:100244cef3d6 25 val = -1 + (val - 1.0);
hollegha2 2:100244cef3d6 26 }
hollegha2 2:100244cef3d6 27
hollegha2 2:100244cef3d6 28
hollegha2 2:100244cef3d6 29
hollegha2 2:100244cef3d6 30 TriangleGen::TriangleGen()
hollegha2 2:100244cef3d6 31 {
hollegha2 2:100244cef3d6 32 val=0;
hollegha2 2:100244cef3d6 33 _state=1;
hollegha2 2:100244cef3d6 34 SetPointsPerPeriod(10);
hollegha2 2:100244cef3d6 35 }
hollegha2 2:100244cef3d6 36
hollegha2 2:100244cef3d6 37 void TriangleGen::SetPointsPerPeriod(int aPoints)
hollegha2 2:100244cef3d6 38 {
hollegha2 2:100244cef3d6 39 _inc = 4.0/aPoints;
hollegha2 2:100244cef3d6 40 }
hollegha2 2:100244cef3d6 41
hollegha2 2:100244cef3d6 42 void TriangleGen::SetFrequ(float aFrequ)
hollegha2 2:100244cef3d6 43 {
hollegha2 2:100244cef3d6 44 SetPointsPerPeriod(1.0/aFrequ);
hollegha2 2:100244cef3d6 45 }
hollegha2 2:100244cef3d6 46
hollegha2 2:100244cef3d6 47 void TriangleGen::CalcOneStep()
hollegha2 2:100244cef3d6 48 {
hollegha2 2:100244cef3d6 49 if( _state==1 ) {
hollegha2 2:100244cef3d6 50 val = val + _inc;
hollegha2 2:100244cef3d6 51 if( val>1.0 ) {
hollegha2 2:100244cef3d6 52 val = val - _inc;
hollegha2 2:100244cef3d6 53 _state = 2;
hollegha2 2:100244cef3d6 54 }
hollegha2 2:100244cef3d6 55 } else if( _state==2 ) {
hollegha2 2:100244cef3d6 56 val = val - _inc;
hollegha2 2:100244cef3d6 57 if( val<-1.0 ) {
hollegha2 2:100244cef3d6 58 val = val + _inc;
hollegha2 2:100244cef3d6 59 _state = 1;
hollegha2 2:100244cef3d6 60 }
hollegha2 2:100244cef3d6 61 }
hollegha2 2:100244cef3d6 62 }
hollegha2 2:100244cef3d6 63
hollegha2 2:100244cef3d6 64
hollegha2 2:100244cef3d6 65
hollegha2 2:100244cef3d6 66 RectGen::RectGen()
hollegha2 2:100244cef3d6 67 {
hollegha2 2:100244cef3d6 68 val=0;
hollegha2 2:100244cef3d6 69 _inc=_phase=0;
hollegha2 2:100244cef3d6 70 SetPointsPerPeriod(10);
hollegha2 2:100244cef3d6 71 }
hollegha2 2:100244cef3d6 72
hollegha2 2:100244cef3d6 73 void RectGen::SetPointsPerPeriod(int aPoints)
hollegha2 2:100244cef3d6 74 {
hollegha2 2:100244cef3d6 75 _inc = 1.0/aPoints;
hollegha2 2:100244cef3d6 76 }
hollegha2 2:100244cef3d6 77
hollegha2 2:100244cef3d6 78 void RectGen::SetFrequ(float aFrequ)
hollegha2 2:100244cef3d6 79 {
hollegha2 2:100244cef3d6 80 SetPointsPerPeriod(1.0/aFrequ);
hollegha2 2:100244cef3d6 81 }
hollegha2 2:100244cef3d6 82
hollegha2 2:100244cef3d6 83 void RectGen::CalcOneStep()
hollegha2 2:100244cef3d6 84 {
hollegha2 2:100244cef3d6 85 _phase += _inc;
hollegha2 2:100244cef3d6 86 if( _phase>=1.0 )
hollegha2 2:100244cef3d6 87 _phase = _phase - 1.0;
hollegha2 2:100244cef3d6 88 if( _phase>0.5 )
hollegha2 2:100244cef3d6 89 val = 1.0;
hollegha2 2:100244cef3d6 90 else
hollegha2 2:100244cef3d6 91 val = -1.0;
hollegha2 2:100244cef3d6 92 }
hollegha2 2:100244cef3d6 93
hollegha2 2:100244cef3d6 94