From 97d888ab84813aa7731c86b24a88f6d3b9b42c30 Mon Sep 17 00:00:00 2001 From: Gabriel Fedel <gabriel.fedel@esss.se> Date: Tue, 21 Jul 2020 14:24:15 +0200 Subject: [PATCH 1/2] Include option to run a number fix of pulses --- .../ts2evmApp/Db/ts2_evm_controls.template | 91 ++++++++++++++- ts2evm-loc/ts2evmApp/src/evm_subroutines.c | 106 ++++++++++++++---- 2 files changed, 174 insertions(+), 23 deletions(-) diff --git a/ts2evm-loc/ts2evmApp/Db/ts2_evm_controls.template b/ts2evm-loc/ts2evmApp/Db/ts2_evm_controls.template index 033e26d..7760f72 100644 --- a/ts2evm-loc/ts2evmApp/Db/ts2_evm_controls.template +++ b/ts2evm-loc/ts2evmApp/Db/ts2_evm_controls.template @@ -72,6 +72,26 @@ record(ao, "$(P)$(R=)PBDelay-SP") { field(FLNK, "$(P)$(R=)SeqSelecCalc PP") } + + +######################################################## +# Continue pulses or Fixed number +######################################################## +record(bo, "$(P)$(R=)Mode") { + field(DESC, "Choose between continue/fixed pulses") + field(ZNAM, "Continue") + field(ONAM, "Fixed") + field(FLNK, "$(P)$(R=)SeqSelecCalc PP") +} + + +record(ao, "$(P)$(R=)NPulses") { + field(DESC, "Number of pulses for fixed mode") + field(DRVL, "1") + field(DRVH, "100") + field(VAL, "1") + field(PINI, "YES") +} ######################################################## # Record logic to alternate activation of sequencers ######################################################## @@ -119,11 +139,28 @@ record(aSub, "$(P)$(R=)Seq0-Write-aSub") { field(FTD, "FLOAT") field(NOD, "1") + # input E -> Mode + field(INPE, "$(P)$(R=)Mode") + field(FTE, "SHORT") + field(NOE, "1") + + # input F -> Number of pulses + field(INPF, "$(P)$(R=)NPulses") + field(FTF, "SHORT") + field(NOF, "1") + + # input G -> Frequency + field(INPG, "$(P)$(R=)CycleFreq-SP") + field(FTG, "FLOAT") + field(NOG, "1") + # outputs A,B -> EVM Sequencer arrays field(FTVA, "ULONG") field(OUTA, "$(EVGPREFIX)SoftSeq0-EvtCode-SP CP") - field(FTVB, "FLOAT") + field(NOVA, "2047") + field(FTVB, "DOUBLE") field(OUTB, "$(EVGPREFIX)SoftSeq0-Timestamp-SP CP") + field(NOVB, "2047") # output C -> readback of RF Pulse Length field(FTVC, "FLOAT") @@ -133,6 +170,10 @@ record(aSub, "$(P)$(R=)Seq0-Write-aSub") { field(FTVD, "FLOAT") field(OUTD, "$(P)$(R=)PBLen-RB PP") + # output E -> Run Mode + field(FTVE, "SHORT") + field(OUTE, "$(EVGPREFIX)SoftSeq0-RunMode-Sel PP") + # Process the sequencer commands field(FLNK, "$(P)$(R=)Seq0-Enable PP") field(TPRO, "0") @@ -181,11 +222,28 @@ record(aSub, "$(P)$(R=)Seq1-Write-aSub") { field(FTD, "FLOAT") field(NOD, "1") + # input E -> Mode + field(INPE, "$(P)$(R=)Mode") + field(FTE, "SHORT") + field(NOE, "1") + + # input F -> Number of pulses + field(INPF, "$(P)$(R=)NPulses") + field(FTF, "SHORT") + field(NOF, "1") + + # input G -> Frequency + field(INPG, "$(P)$(R=)CycleFreq-SP") + field(FTG, "FLOAT") + field(NOG, "1") + # outputs A,B -> EVM Sequencer arrays field(FTVA, "ULONG") field(OUTA, "$(EVGPREFIX)SoftSeq1-EvtCode-SP CP") - field(FTVB, "FLOAT") + field(NOVA, "2047") + field(FTVB, "DOUBLE") field(OUTB, "$(EVGPREFIX)SoftSeq1-Timestamp-SP CP") + field(NOVB, "2047") # output C -> readback of RF Pulse Length field(FTVC, "FLOAT") @@ -195,6 +253,10 @@ record(aSub, "$(P)$(R=)Seq1-Write-aSub") { field(FTVD, "FLOAT") field(OUTD, "$(P)$(R=)PBLen-RB PP") + # output E -> Run Mode + field(FTVE, "SHORT") + field(OUTE, "$(EVGPREFIX)SoftSeq1-RunMode-Sel PP") + # Process the sequencer commands field(FLNK, "$(P)$(R=)Seq1-Enable PP") field(TPRO, "0") @@ -243,11 +305,28 @@ record(aSub, "$(P)$(R=)Seq2-Write-aSub") { field(FTD, "FLOAT") field(NOD, "1") + # input E -> Mode + field(INPE, "$(P)$(R=)Mode") + field(FTE, "SHORT") + field(NOE, "1") + + # input F -> Number of pulses + field(INPF, "$(P)$(R=)NPulses") + field(FTF, "SHORT") + field(NOF, "1") + + # input G -> Frequency + field(INPG, "$(P)$(R=)CycleFreq-SP") + field(FTG, "FLOAT") + field(NOG, "1") + # outputs A,B -> EVM Sequencer arrays field(FTVA, "ULONG") field(OUTA, "$(EVGPREFIX)SoftSeq2-EvtCode-SP CP") - field(FTVB, "FLOAT") + field(NOVA, "2047") + field(FTVB, "DOUBLE") field(OUTB, "$(EVGPREFIX)SoftSeq2-Timestamp-SP CP") + field(NOVB, "2047") # output C -> readback of RF Pulse Length field(FTVC, "FLOAT") @@ -257,6 +336,10 @@ record(aSub, "$(P)$(R=)Seq2-Write-aSub") { field(FTVD, "FLOAT") field(OUTD, "$(P)$(R=)PBLen-RB PP") + # output E -> Run Mode + field(FTVE, "SHORT") + field(OUTE, "$(EVGPREFIX)SoftSeq1-RunMode-Sel PP") + # Process the sequencer commands # field(FLNK, "$(P)$(R=)Seq2-Enable PP") field(TPRO, "0") @@ -326,4 +409,4 @@ record(int64in, "$(P)$(R=)CycleId-RB") { field(DTYP, "Soft Channel") field(SCAN, "Passive") field(EGU, "id") -} \ No newline at end of file +} diff --git a/ts2evm-loc/ts2evmApp/src/evm_subroutines.c b/ts2evm-loc/ts2evmApp/src/evm_subroutines.c index b325d53..6cedd35 100644 --- a/ts2evm-loc/ts2evmApp/src/evm_subroutines.c +++ b/ts2evm-loc/ts2evmApp/src/evm_subroutines.c @@ -12,6 +12,7 @@ * */ #include <stdio.h> +#include <stdlib.h> #include <aSubRecord.h> #include <registryFunction.h> #include <epicsExport.h> @@ -34,9 +35,10 @@ //------------------------------------------------------------------------ static long seqConfigure(aSubRecord *prec) { - int event_codes[MAX_SEQ_EVENTS]; - float timestamps[MAX_SEQ_EVENTS]; - + int *event_codes; + double *timestamps; + + int run_mode = 0; // Get RF pulse length from INPA float rflen = *(float *)prec->a; @@ -53,27 +55,86 @@ static long seqConfigure(aSubRecord *prec) pblen = rflen - pbdelay - 1.0; } - // Create the array of events - event_codes[0] = RF_ST; - event_codes[1] = BPULSE_ST; - event_codes[2] = BPULSE_END; - event_codes[3] = RF_END; - event_codes[4] = SEQ_END; + //Get the mode + int mode = *(int *)prec->e; + + if (mode == 0) { // continuous mode + event_codes = (int*) malloc(MAX_SEQ_EVENTS * sizeof(int)); + timestamps = (double*) malloc(MAX_SEQ_EVENTS * sizeof(double)); + // Create the array of events + event_codes[0] = RF_ST; + event_codes[1] = BPULSE_ST; + event_codes[2] = BPULSE_END; + event_codes[3] = RF_END; + event_codes[4] = SEQ_END; + + // Create the array of time stamps + timestamps[0] = rfdelay; // RF_ST + timestamps[3] = timestamps[0] + rflen; // RF_END + + timestamps[1] = timestamps[0] + pbdelay; // BPULSE_ST + timestamps[2] = timestamps[1] + pblen; // BPULSE_END + + timestamps[4] = timestamps[3] + 1.0; + + // Write the output arrays + memcpy(prec->vala, event_codes, MAX_SEQ_EVENTS * sizeof(int)); + prec->neva = MAX_SEQ_EVENTS; + memcpy(prec->valb, timestamps, MAX_SEQ_EVENTS * sizeof(double)); + prec->nevb = MAX_SEQ_EVENTS; + + // Write the readback legth PVs + memcpy(prec->valc, &rflen, sizeof(float)); + prec->nevc = 1; + memcpy(prec->vald, &pblen, sizeof(float)); + prec->nevd = 1; + + memcpy(prec->vale, &run_mode, sizeof(int)); + prec->neve = 1; + + free(event_codes); + free(timestamps); + + return 0; + } + // fixed number of pulses + int n_pulses = *(int *)prec->f; + int size_arrays = (MAX_SEQ_EVENTS-1)*n_pulses+1; + + event_codes = (int*) malloc(size_arrays * sizeof(int)); + timestamps = (double*) malloc(size_arrays * sizeof(double)); + + - // Create the array of time stamps - timestamps[0] = rfdelay; // RF_ST - timestamps[3] = timestamps[0] + rflen; // RF_END + float freq = *(float *)prec->g; - timestamps[1] = timestamps[0] + pbdelay; // BPULSE_ST - timestamps[2] = timestamps[1] + pblen; // BPULSE_END + float pulse_size = (1.0/freq)*1000000; //us + float new_ts; //new time stamp for the current pulse - timestamps[4] = timestamps[3] + 1.0; + int i; + for (i = 0; i < n_pulses; i++) { + // Create the array of events + event_codes[i*4] = RF_ST; + event_codes[i*4+1] = BPULSE_ST; + event_codes[i*4+2] = BPULSE_END; + event_codes[i*4+3] = RF_END; + + new_ts = i*pulse_size; + + // Create the array of time stamps + timestamps[i*4] = rfdelay + new_ts; // RF_ST + timestamps[i*4+1] = timestamps[i*4] + pbdelay; // BPULSE_ST + timestamps[i*4+2] = timestamps[i*4+1] + pblen; // BPULSE_END + timestamps[i*4+3] = timestamps[i*4] + rflen; // RF_END + } + event_codes[n_pulses*4] = SEQ_END; + timestamps[n_pulses*4] = timestamps[n_pulses*4 - 1] + 1.0; // Write the output arrays - memcpy(prec->vala, event_codes, MAX_SEQ_EVENTS * sizeof(int)); - prec->neva = MAX_SEQ_EVENTS; - memcpy(prec->valb, timestamps, MAX_SEQ_EVENTS * sizeof(float)); - prec->nevb = MAX_SEQ_EVENTS; + memcpy(prec->vala, event_codes, size_arrays * sizeof(int)); + prec->neva = size_arrays; + memcpy(prec->valb, timestamps, size_arrays * sizeof(double)); + prec->nevb = size_arrays; // Write the readback legth PVs memcpy(prec->valc, &rflen, sizeof(float)); @@ -81,7 +142,14 @@ static long seqConfigure(aSubRecord *prec) memcpy(prec->vald, &pblen, sizeof(float)); prec->nevd = 1; + run_mode = 1; + memcpy(prec->vale, &run_mode, sizeof(int)); + prec->neve = 1; + + free(event_codes); + free(timestamps); return 0; + } epicsRegisterFunction(seqConfigure); -- GitLab From 6080d2e753f773e4d4316ecfa91a645633fd7795 Mon Sep 17 00:00:00 2001 From: Gabriel Fedel <gabriel.fedel@esss.se> Date: Wed, 22 Jul 2020 10:42:54 +0200 Subject: [PATCH 2/2] Update OPI to control fixed number of pulses --- opi/evm-control.bob | 66 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 54 insertions(+), 12 deletions(-) diff --git a/opi/evm-control.bob b/opi/evm-control.bob index 20d069b..f646f68 100644 --- a/opi/evm-control.bob +++ b/opi/evm-control.bob @@ -5,12 +5,10 @@ <widget type="rectangle" version="2.0.0"> <name>Titlebar</name> <class>TITLE-BAR</class> - <x use_class="true">0</x> - <y use_class="true">0</y> <width>920</width> - <height use_class="true">50</height> - <line_width use_class="true">0</line_width> - <background_color use_class="true"> + <height>50</height> + <line_width>0</line_width> + <background_color> <color name="PRIMARY-HEADER-BACKGROUND" red="151" green="188" blue="202"> </color> </background_color> @@ -19,22 +17,21 @@ <name>Title</name> <class>TITLE</class> <text>MRF Event Master Controller for RF Systems</text> - <x use_class="true">20</x> + <x use_class="true">0</x> <y use_class="true">0</y> <width>750</width> - <height use_class="true">50</height> + <height>50</height> <font use_class="true"> - <font name="Header 1" family="Source Sans Pro" style="BOLD_ITALIC" size="36.0"> + <font name="Header 1" family="Liberation Sans" style="BOLD" size="22.0"> </font> </font> <foreground_color use_class="true"> - <color name="HEADER-TEXT" red="0" green="0" blue="0"> + <color name="Text" red="0" green="0" blue="0"> </color> </foreground_color> <transparent use_class="true">true</transparent> - <horizontal_alignment use_class="true">0</horizontal_alignment> - <vertical_alignment use_class="true">1</vertical_alignment> - <wrap_words use_class="true">false</wrap_words> + <vertical_alignment>1</vertical_alignment> + <wrap_words>false</wrap_words> </widget> <widget type="group" version="2.0.0"> <name>MGGrey02</name> @@ -160,6 +157,51 @@ <width>90</width> <height>30</height> </widget> + <widget type="action_button" version="3.0.0"> + <name>Action Button</name> + <actions> + <action type="write_pv"> + <pv_name>$(PREFIX)Mode</pv_name> + <value>0</value> + <description>Write PV</description> + </action> + </actions> + <text>Run Infinite Pulses</text> + <x>680</x> + <y>90</y> + <width>140</width> + </widget> + <widget type="action_button" version="3.0.0"> + <name>Action Button_1</name> + <actions> + <action type="write_pv"> + <pv_name>$(PREFIX)Mode</pv_name> + <value>1</value> + <description>Write PV</description> + </action> + </actions> + <text>Run Fixed Pulses</text> + <x>680</x> + <y>50</y> + <width>140</width> + <tooltip>$(actions)</tooltip> + </widget> + <widget type="label" version="2.0.0"> + <name>Label_11</name> + <text>Number of Pulses</text> + <x>390</x> + <y>50</y> + <width>120</width> + <height>30</height> + </widget> + <widget type="textentry" version="3.0.0"> + <name>Text Entry_4</name> + <pv_name>$(PREFIX)NPulses</pv_name> + <x>520</x> + <y>50</y> + <width>120</width> + <height>30</height> + </widget> </widget> <widget type="group" version="2.0.0"> <name>MGGrey02_1</name> -- GitLab