BULME_AHEL20
/
LPC_HL_FUNC_GENERATOR_DAC
Function generator
FuncGenMain.cpp@2:100244cef3d6, 2016-03-17 (annotated)
- Committer:
- hollegha2
- Date:
- Thu Mar 17 13:45:13 2016 +0000
- Revision:
- 2:100244cef3d6
- Parent:
- ProcVisDemo.cpp@1:e88b745f2ca2
- Child:
- 3:c8c3b755ef54
V1.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hollegha2 | 2:100244cef3d6 | 1 | |
hollegha2 | 0:9ac39e20730c | 2 | #include "mbed.h" |
hollegha2 | 0:9ac39e20730c | 3 | #include "Serial_HL.h" |
hollegha2 | 2:100244cef3d6 | 4 | #include "FuncGen.h" |
hollegha2 | 0:9ac39e20730c | 5 | |
hollegha2 | 0:9ac39e20730c | 6 | SerialBLK pc(USBTX, USBRX); |
hollegha2 | 0:9ac39e20730c | 7 | SvProtocol ua0(&pc); |
hollegha2 | 0:9ac39e20730c | 8 | |
hollegha2 | 1:e88b745f2ca2 | 9 | // BusOut leds(LED1,LED2,LED3,LED4); Bertl14 |
hollegha2 | 1:e88b745f2ca2 | 10 | // M0-Board |
hollegha2 | 1:e88b745f2ca2 | 11 | BusOut leds(P1_13,P1_12,P1_7,P1_6,P1_4,P1_3,P1_1,P1_0,LED4,LED3,LED2,LED1); |
hollegha2 | 1:e88b745f2ca2 | 12 | |
hollegha2 | 2:100244cef3d6 | 13 | void CommandHandler(); |
hollegha2 | 2:100244cef3d6 | 14 | void ExecSignalChain(); |
hollegha2 | 0:9ac39e20730c | 15 | |
hollegha2 | 2:100244cef3d6 | 16 | RectGen fg1; |
hollegha2 | 2:100244cef3d6 | 17 | |
hollegha2 | 2:100244cef3d6 | 18 | float ampl1 = 1.0; // |
hollegha2 | 2:100244cef3d6 | 19 | float v1; // Wert nach dem Koeffizientenglied |
hollegha2 | 0:9ac39e20730c | 20 | |
hollegha2 | 0:9ac39e20730c | 21 | int main(void) |
hollegha2 | 0:9ac39e20730c | 22 | { |
hollegha2 | 0:9ac39e20730c | 23 | pc.format(8,SerialBLK::None,1); |
hollegha2 | 2:100244cef3d6 | 24 | pc.baud(500000); // 115200 |
hollegha2 | 0:9ac39e20730c | 25 | leds = 9; |
hollegha2 | 2:100244cef3d6 | 26 | ua0.SvMessage("FuncGenMain"); // Meldung zum PC senden |
hollegha2 | 0:9ac39e20730c | 27 | |
hollegha2 | 0:9ac39e20730c | 28 | Timer stw; |
hollegha2 | 0:9ac39e20730c | 29 | stw.start(); |
hollegha2 | 0:9ac39e20730c | 30 | while(1) { |
hollegha2 | 0:9ac39e20730c | 31 | CommandHandler(); |
hollegha2 | 2:100244cef3d6 | 32 | if( (stw.read_ms()>10) ) { // 100Hz |
hollegha2 | 0:9ac39e20730c | 33 | // dieser Teil wird mit 10Hz aufgerufen |
hollegha2 | 0:9ac39e20730c | 34 | stw.reset(); |
hollegha2 | 2:100244cef3d6 | 35 | ExecSignalChain(); |
hollegha2 | 0:9ac39e20730c | 36 | if( ua0.acqON ) { |
hollegha2 | 0:9ac39e20730c | 37 | // nur wenn vom PC aus das Senden eingeschaltet wurde |
hollegha2 | 0:9ac39e20730c | 38 | // wird auch etwas gesendet |
hollegha2 | 2:100244cef3d6 | 39 | ua0.WriteSV(1, v1); |
hollegha2 | 0:9ac39e20730c | 40 | } |
hollegha2 | 0:9ac39e20730c | 41 | } |
hollegha2 | 0:9ac39e20730c | 42 | } |
hollegha2 | 0:9ac39e20730c | 43 | return 1; |
hollegha2 | 0:9ac39e20730c | 44 | } |
hollegha2 | 0:9ac39e20730c | 45 | |
hollegha2 | 2:100244cef3d6 | 46 | // Einen Abtastschritt der Signalverarbeitungskette durchrechnen |
hollegha2 | 2:100244cef3d6 | 47 | // 100Hz zum Testen und alles Visualisieren |
hollegha2 | 2:100244cef3d6 | 48 | // 40kHz zum Anhören |
hollegha2 | 2:100244cef3d6 | 49 | void ExecSignalChain() |
hollegha2 | 2:100244cef3d6 | 50 | { |
hollegha2 | 2:100244cef3d6 | 51 | fg1.CalcOneStep(); |
hollegha2 | 2:100244cef3d6 | 52 | v1 = ampl1 * fg1.val; // Koeffizientenglied rechnen |
hollegha2 | 2:100244cef3d6 | 53 | } |
hollegha2 | 2:100244cef3d6 | 54 | |
hollegha2 | 0:9ac39e20730c | 55 | void CommandHandler() |
hollegha2 | 0:9ac39e20730c | 56 | { |
hollegha2 | 0:9ac39e20730c | 57 | uint8_t cmd; |
hollegha2 | 0:9ac39e20730c | 58 | // Fragen ob überhaupt etwas im RX-Reg steht |
hollegha2 | 0:9ac39e20730c | 59 | if( !pc.IsDataAvail() ) |
hollegha2 | 0:9ac39e20730c | 60 | return; |
hollegha2 | 0:9ac39e20730c | 61 | |
hollegha2 | 0:9ac39e20730c | 62 | // wenn etwas im RX-Reg steht |
hollegha2 | 0:9ac39e20730c | 63 | // Kommando lesen |
hollegha2 | 0:9ac39e20730c | 64 | cmd = ua0.GetCommand(); |
hollegha2 | 0:9ac39e20730c | 65 | |
hollegha2 | 2:100244cef3d6 | 66 | // mit dem Command=2 die Frequenz verstellen |
hollegha2 | 0:9ac39e20730c | 67 | if( cmd==2 ) { |
hollegha2 | 2:100244cef3d6 | 68 | float frequ = ua0.ReadF(); |
hollegha2 | 2:100244cef3d6 | 69 | fg1.SetFrequ(frequ); |
hollegha2 | 2:100244cef3d6 | 70 | ua0.SvMessage("Set Frequ"); |
hollegha2 | 2:100244cef3d6 | 71 | } |
hollegha2 | 2:100244cef3d6 | 72 | // mit dem Command=3 die Amplitude verstellen |
hollegha2 | 2:100244cef3d6 | 73 | if( cmd==3 ) { |
hollegha2 | 2:100244cef3d6 | 74 | ampl1 = ua0.ReadF(); |
hollegha2 | 2:100244cef3d6 | 75 | ua0.SvMessage("Set Ampl"); |
hollegha2 | 0:9ac39e20730c | 76 | } |
hollegha2 | 0:9ac39e20730c | 77 | } |
hollegha2 | 0:9ac39e20730c | 78 | |
hollegha2 | 0:9ac39e20730c | 79 |