Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of ProcVisDemo by
Main.cpp
00001 #include "mbed.h" 00002 #include "Serial_HL.h" 00003 #include "FunkGen.h" 00004 #include "TP1Ord.h" 00005 00006 // 2 Generatoren mit switch umschalten 00007 00008 SerialBLK pc(USBTX, USBRX); 00009 SvProtocol ua0(&pc); 00010 00011 void CommandHandler(); 00012 void ExecSignalChain(); 00013 00014 SignedRampGen fg1; 00015 RectGen fg2; 00016 TP1Ord tp1; 00017 float amp1 = 1.0; 00018 float v1; // Ausgangswert mit amp1 multipliziert 00019 00020 00021 int swt=1; // 1..v1 auf fg1 geschaltet 2..v1 auf fg2 geschaltet 00022 00023 int main(void) 00024 { 00025 pc.format(8,SerialBLK::None,1); pc.baud(500000); // 115200 00026 00027 ua0.SvMessage("FuncGenMain3"); // Meldung zum PC senden 00028 00029 Timer stw; stw.start(); 00030 while(1) // while(1)-Loop der mit dem PC kommuniziert 00031 { 00032 CommandHandler(); 00033 if( (stw.read_ms()>10) ) // 100Hz 00034 { // dieser Teil wird mit 100Hz aufgerufen 00035 stw.reset(); 00036 ExecSignalChain(); // Funktionsgeneratoren rechnen 00037 if( ua0.acqON ) { 00038 ua0.WriteSV(1, tp1.y); 00039 } 00040 } 00041 } 00042 return 1; 00043 } 00044 00045 void ExecSignalChain() 00046 { 00047 fg1.CalcOneStep(); 00048 fg2.CalcOneStep(); 00049 if( swt==1 ) 00050 v1 = amp1*fg1.val; 00051 if( swt==2 ) 00052 v1 = amp1*fg2.val; 00053 00054 tp1.CalcOneStep(v1); 00055 } 00056 00057 void CommandHandler() 00058 { 00059 uint8_t cmd; 00060 if( !pc.IsDataAvail() ) 00061 return; 00062 cmd = ua0.GetCommand(); 00063 00064 // mithilfe von Kommandos vom PC Frequenz und Amplitude verstellen 00065 00066 if( cmd==2 ) // Frequenz 00067 { 00068 float frequ = ua0.ReadF(); 00069 fg1.SetFrequ(frequ); fg2.SetFrequ(frequ); 00070 ua0.SvMessage("Set Frequ"); 00071 } 00072 00073 if( cmd==3 ) // Amplitute 00074 { 00075 amp1 = ua0.ReadF(); 00076 ua0.SvMessage("Set Frequ"); 00077 } 00078 00079 if( cmd==4 ) // Funktionsgeneratoren umschalten 00080 { 00081 swt = ua0.ReadI16(); 00082 ua0.SvMessage("Switch FG"); 00083 } 00084 if( cmd==5 ) // Funktionsgeneratoren umschalten 00085 { 00086 tp1.SetAlpha(ua0.ReadF()); 00087 ua0.SvMessage("Set Alpha"); 00088 } 00089 } 00090 00091 00092 00093 00094 00095 00096 00097 00098 00099 00100 00101 00102 00103 00104 00105
Generated on Sat Jul 30 2022 21:10:34 by
