Function Generator for TINF 2021

Revision:
1:dbd814e65f1d
Parent:
0:464b401734fd
diff -r 464b401734fd -r dbd814e65f1d src/FuncGenMain_21.cpp
--- a/src/FuncGenMain_21.cpp	Tue Mar 09 20:46:10 2021 +0000
+++ b/src/FuncGenMain_21.cpp	Thu Mar 18 21:23:40 2021 +0100
@@ -5,31 +5,69 @@
 SerialBLK pc(USBTX, USBRX);
 SvProtocol ua0(&pc);
 
+SignedRampGen fg1;
+float ampl1 = 1.0;
+float v1 = 0; // ausgang nach der Amplitude
+
 void CommandHandler();
 
+void ExecSignalChain();
+
+Ticker tc;
+
+AnalogOut dac1(PA_5);
+
 int main(void)
 {
 	pc.format(8,SerialBLK::None,1);
 	pc.baud(115200); // 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) {
+        
+	ua0.SvMessage("Communicating"); // send test message
+    ThisThread::sleep_for(1000);
+    
 		CommandHandler();
-	  ua0.SvMessage("FuncGen is communicating"); // send test message - delete this line
-    ThisThread::sleep_for(1000); // delete this line
-		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);
 			}
 		}
 	}
 	return 1;
 }
 
+void ExecSignalChain()
+{
+	fg1.CalcOneStep();
+	v1 = ampl1*fg1.val;
+	// 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.");
+	}
+}
\ No newline at end of file