Fertiges FuncGen

Dependencies:   Serial_HL mbed

Fork of ProcVisDemo by michael hollegha

Committer:
Polteko123
Date:
Thu Apr 06 13:17:39 2017 +0000
Revision:
2:6de5bcffd991
Parent:
1:e88b745f2ca2
Fertig_FunkGen

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hollegha2 0:9ac39e20730c 1 #include "mbed.h"
hollegha2 0:9ac39e20730c 2 #include "Serial_HL.h"
Polteko123 2:6de5bcffd991 3 #include "BtnEventM0.h"
Polteko123 2:6de5bcffd991 4 #include "FunkGen.h"
hollegha2 0:9ac39e20730c 5
hollegha2 0:9ac39e20730c 6 SerialBLK pc(USBTX, USBRX);
hollegha2 0:9ac39e20730c 7 SvProtocol ua0(&pc);
hollegha2 0:9ac39e20730c 8
Polteko123 2:6de5bcffd991 9 void CommandHandler();
Polteko123 2:6de5bcffd991 10
Polteko123 2:6de5bcffd991 11 SignedRampGen fg1;
Polteko123 2:6de5bcffd991 12 float ampl=1.0, v1=0.0;
hollegha2 1:e88b745f2ca2 13
Polteko123 2:6de5bcffd991 14 // 2ter Generator + Variablen
Polteko123 2:6de5bcffd991 15 TriangleGen fg2;
Polteko123 2:6de5bcffd991 16 float ampl2=1.0, v2=0.0;
hollegha2 0:9ac39e20730c 17
Polteko123 2:6de5bcffd991 18 // RectangleGen
Polteko123 2:6de5bcffd991 19 RectangleGen fg3;
Polteko123 2:6de5bcffd991 20 float ampl3=1.0, v3=0.0;
Polteko123 2:6de5bcffd991 21
Polteko123 2:6de5bcffd991 22 void ExecSignalChain();
hollegha2 0:9ac39e20730c 23
hollegha2 0:9ac39e20730c 24 int main(void)
hollegha2 0:9ac39e20730c 25 {
hollegha2 0:9ac39e20730c 26 pc.format(8,SerialBLK::None,1);
hollegha2 0:9ac39e20730c 27 pc.baud(115200);
hollegha2 0:9ac39e20730c 28
Polteko123 2:6de5bcffd991 29 ua0.SvMessage("FuncGenMain"); // Meldung zum PC senden
hollegha2 0:9ac39e20730c 30
Polteko123 2:6de5bcffd991 31
hollegha2 0:9ac39e20730c 32 Timer stw;
hollegha2 0:9ac39e20730c 33 stw.start();
hollegha2 0:9ac39e20730c 34 while(1) {
hollegha2 0:9ac39e20730c 35 CommandHandler();
Polteko123 2:6de5bcffd991 36
Polteko123 2:6de5bcffd991 37 if( ua0.acqON && (stw.read_ms()>10) ) { // 100Hz
hollegha2 0:9ac39e20730c 38 // dieser Teil wird mit 10Hz aufgerufen
hollegha2 0:9ac39e20730c 39 stw.reset();
Polteko123 2:6de5bcffd991 40 ExecSignalChain();
hollegha2 0:9ac39e20730c 41 if( ua0.acqON ) {
Polteko123 2:6de5bcffd991 42
Polteko123 2:6de5bcffd991 43 ua0.WriteSV(1, v1);
Polteko123 2:6de5bcffd991 44 ua0.WriteSV(2, v2);
Polteko123 2:6de5bcffd991 45 ua0.WriteSV(3, v3);
hollegha2 0:9ac39e20730c 46 }
hollegha2 0:9ac39e20730c 47 }
hollegha2 0:9ac39e20730c 48 }
hollegha2 0:9ac39e20730c 49 return 1;
hollegha2 0:9ac39e20730c 50 }
hollegha2 0:9ac39e20730c 51
Polteko123 2:6de5bcffd991 52 void ExecSignalChain()
Polteko123 2:6de5bcffd991 53 {
Polteko123 2:6de5bcffd991 54 fg1.CalcOneStep();
Polteko123 2:6de5bcffd991 55 v1 = fg1.val*ampl;
Polteko123 2:6de5bcffd991 56
Polteko123 2:6de5bcffd991 57 // 2ten Generator rechnen
Polteko123 2:6de5bcffd991 58 fg2.CalcOneStep();
Polteko123 2:6de5bcffd991 59 v2 = fg2.val*ampl2;
Polteko123 2:6de5bcffd991 60
Polteko123 2:6de5bcffd991 61 fg3.CalcOneStep();
Polteko123 2:6de5bcffd991 62 v3 = fg3.val*ampl3;
Polteko123 2:6de5bcffd991 63 }
Polteko123 2:6de5bcffd991 64
hollegha2 0:9ac39e20730c 65 void CommandHandler()
hollegha2 0:9ac39e20730c 66 {
hollegha2 0:9ac39e20730c 67 uint8_t cmd;
hollegha2 0:9ac39e20730c 68
hollegha2 0:9ac39e20730c 69 if( !pc.IsDataAvail() )
hollegha2 0:9ac39e20730c 70 return;
hollegha2 0:9ac39e20730c 71 cmd = ua0.GetCommand();
hollegha2 0:9ac39e20730c 72
Polteko123 2:6de5bcffd991 73 if(cmd==2) // Set Frequ
Polteko123 2:6de5bcffd991 74 {
Polteko123 2:6de5bcffd991 75 fg1.SetFrequ(ua0.ReadF());
Polteko123 2:6de5bcffd991 76 fg2.SetFrequ(ua0.ReadF());
Polteko123 2:6de5bcffd991 77 fg3.SetFrequ(ua0.ReadF());
Polteko123 2:6de5bcffd991 78 ua0.SvMessage("SetFrequ");
hollegha2 0:9ac39e20730c 79 }
Polteko123 2:6de5bcffd991 80
Polteko123 2:6de5bcffd991 81 if(cmd==3) // Set Ampl
Polteko123 2:6de5bcffd991 82 {
Polteko123 2:6de5bcffd991 83 ampl = ua0.ReadF();
Polteko123 2:6de5bcffd991 84 ampl2 = ua0.ReadF();
Polteko123 2:6de5bcffd991 85 ampl3 = ua0.ReadF();
Polteko123 2:6de5bcffd991 86 ua0.SvMessage("SetAmpl");
Polteko123 2:6de5bcffd991 87 }
Polteko123 2:6de5bcffd991 88
Polteko123 2:6de5bcffd991 89 // Amplitude und Frequenz auch für 2ten Generator setzen
hollegha2 0:9ac39e20730c 90 }
hollegha2 0:9ac39e20730c 91
hollegha2 0:9ac39e20730c 92