Add Trigger pin option (set pin in low state on trigger event in band:

PB13 Pin 1 for band 1
PA14 Pin 2 for band 2
PA9  Pin 3 for band 3 (on enable USART pins redefined to USART mode)
PA10 Pin 4 for band 4 (on enable USART pins redefined to USART mode)
DiSlord_Pinout
DiSlord 1 year ago
parent 1dd6b0764f
commit 9a4ea2dcee

@ -81,6 +81,11 @@
#define GPIO_PE_SEL 15
#define LINE_PE_SEL PAL_LINE(GPIOA,GPIO_PE_SEL)
#define LINE_PINOUT_1 PAL_LINE(GPIOB,13) // PB13 Pin 1
#define LINE_PINOUT_2 PAL_LINE(GPIOB,14) // PA14 Pin 2
#define LINE_PINOUT_3 PAL_LINE(GPIOA, 9) // PA9 Pin 3
#define LINE_PINOUT_4 PAL_LINE(GPIOA,10) // PA10 Pin 4
#define GPIOB_XN 0
#define GPIOB_YN 1
#define GPIO_LCD_RESET 2

@ -2596,6 +2596,9 @@ void shell_update_speed(void){
}
void shell_reset_console(void){
#ifdef __TRIGGER_PINS__
initPinOutTrigger(); // pinout use USART Rx / Tx pins, reconfigure it
#endif
// Reset I/O queue over USB (for USB need also connect/disconnect)
if (usb_IsActive()){
if (config._mode & _MODE_SERIAL)
@ -2642,6 +2645,7 @@ static void shell_init_connection(void) {
* Set I/O stream (SDU1 or SD1) for shell
*/
PREPARE_STREAM;
shell_reset_console();
}
#else

@ -114,6 +114,7 @@
#define __NOISE_FIGURE__
#define __VBW__
#define __SWEEP_RESTART__
#define __TRIGGER_PINS__ // Set output pins in HIGH state on trigger event (depend from band trigger different pins)
// #define DIRECT_CORRECTION // Not enough space for config in one flash page.
#define DB_PER_DEGREE_BELOW 0.056
#define DB_PER_DEGREE_ABOVE 0.069
@ -1337,7 +1338,9 @@ typedef struct setting
systime_t measure_sweep_time_us;
systime_t actual_sweep_time_us;
systime_t additional_step_delay_us;
#ifdef __TRIGGER_PINS__
systime_t pinout_time_s;
#endif
uint32_t trigger_grid;
// freq_t *correction_frequency;

@ -607,6 +607,9 @@ void reset_settings(int m)
setting.bands[i].level = 0;
}
#endif
#ifdef __TRIGGER_PINS__
setting.pinout_time_s = 30;
#endif
#ifdef __ULTRA__
ultra_start = (config.ultra_start == ULTRA_AUTO ? ULTRA_THRESHOLD : config.ultra_start);
#endif
@ -4978,6 +4981,79 @@ void reset_band(void) {
}
#endif
#ifdef __TRIGGER_PINS__
//=============================================================================================================
// Trigger Pin control
//=============================================================================================================
#define PINOUT_MAX 4 // Pin count
// Active pins (defined in NANOVNA_STM32_F303\board.h)
static const uint32_t pinout_lines[PINOUT_MAX] = {
LINE_PINOUT_1,
LINE_PINOUT_2,
LINE_PINOUT_3,
LINE_PINOUT_4,
//LINE_PINOUT_5,
//LINE_PINOUT_6,
//LINE_PINOUT_7,
//LINE_PINOUT_8,
};
// Active pin delay after trigger (get from config)
#define ACTIVE_PINOUT_TIME_S setting.pinout_time_s
static systime_t pinout_timers[PINOUT_MAX]; // Timers count after trigger
static uint16_t active_pins; // Active pins
void initPinOutTrigger(void) {
active_pins = 0;
for(uint32_t band = 0; band < ARRAY_COUNT(pinout_lines); band++) {
uint32_t pal = pinout_lines[band];
palSetPadMode(PAL_PORT(pal), PAL_PAD(pal), PAL_MODE_OUTPUT_PUSHPULL);
palClearLine(pal);
}
#ifdef __USE_SERIAL_CONSOLE__
if (config._mode & _MODE_SERIAL) { // Setup pads for USART if serial connection active
palSetPadMode(GPIO_UART_TX_PORT, GPIO_UART_TX, PAL_MODE_ALTERNATE(7));
palSetPadMode(GPIO_UART_RX_PORT, GPIO_UART_RX, PAL_MODE_ALTERNATE(7));
}
#endif
}
// Trigger activate in band (in multi band mode) or in 0
static void startPinout(uint16_t band) {
if (band >= ARRAY_COUNT(pinout_lines)) return;
systime_t r_time = chVTGetSystemTimeX(); // get system time
if (!(active_pins & (1<<band))) { // Pin not active
active_pins|= (1<<band); // Set pin as active
pinout_timers[band] = r_time; // Stup activation time
palSetLine(pinout_lines[band]); // Set pin state as HIGH
}
#if 0 // Debug
ili9341_set_foreground(LCD_FG_COLOR);
ili9341_set_background(LCD_BG_COLOR);
lcd_printf(180, 310, "%02x ", active_pins);
#endif
}
// Check pin activation end time
static void updatePinout(void) {
systime_t r_time = chVTGetSystemTimeX(), t; // get system time
for(uint16_t band = 0; band < ARRAY_COUNT(pinout_lines) && active_pins != 0; band++) {
if (!(active_pins & (1<<band))) continue; // not active
t = r_time - pinout_timers[band]; // check active time
if (t < S2ST(ACTIVE_PINOUT_TIME_S)) continue; // not complete
active_pins&=~(1<<band); // timeout, deactivate
palClearLine(pinout_lines[band]); // Set pin state as LOW
}
#if 0 // Debug
ili9341_set_foreground(LCD_FG_COLOR);
ili9341_set_background(LCD_BG_COLOR);
lcd_printf(180, 310, "%02x ", active_pins);
#endif
}
#else // Empty functions
#define updatePinout()
#define startPinout(band)
#endif
// main loop for measurement
static bool sweep(bool break_on_operation)
{
@ -5022,7 +5098,7 @@ static bool sweep(bool break_on_operation)
config.cor_wfm = -14;
}
#endif
updatePinout();
if (dirty) { // Calculate new scanning solution
#ifdef __BANDS__
if (setting.multi_band && ! setting.multi_trace) {
@ -5446,6 +5522,7 @@ static volatile int dummy;
)
{
triggered = true;
startPinout(current_band);
#ifdef __BEEP__
if (setting.trigger_beep) pwm_start(4000);
#endif

22
ui.c

@ -1414,6 +1414,9 @@ enum {
KM_FILENAME,
#endif
KM_TRIGGER_GRID,
#ifdef __TRIGGER_PINS__
KM_PIN_TRIGGER_TIME,
#endif
KM_NONE // always at enum end
};
@ -1506,6 +1509,9 @@ static const struct {
[KM_FILENAME] = {keypads_text , "NAME"}, // filename
#endif
[KM_TRIGGER_GRID] = {keypads_time , "INTERVAL"}, // KM_CODE
#ifdef __TRIGGER_PINS__
[KM_PIN_TRIGGER_TIME] = {keypads_time , "OUT PIN\nTIME"}, // Pin hold time
#endif
};
#if 0 // Not used
@ -5214,6 +5220,9 @@ static const menuitem_t menu_trigger[] = {
#endif
{ MT_ADV_CALLBACK, T_MODE, "TRIGGER\n\b%s", menu_trigger_acb},
{ MT_KEYPAD, KM_TRIGGER_GRID, "INTERVAL\n\b%ss", NULL},
#ifdef __TRIGGER_PINS__
{ MT_KEYPAD, KM_PIN_TRIGGER_TIME, "PIN OUT\nTIME \b%ss", NULL},
#endif
#ifdef __BEEP__
{ MT_ADV_CALLBACK, T_BEEP, "BEEP", menu_trigger_acb},
#endif
@ -5595,7 +5604,12 @@ static void fetch_numeric_target(uint8_t mode)
uistat.value = ((float)setting.trigger_grid) / CH_CFG_ST_FREQUENCY; // ((float)ST2US(setting.trigger_grid))/1000000.0;
plot_printf(uistat.text, sizeof uistat.text, "%.3F", uistat.value);
break;
#ifdef __TRIGGER_PINS__
case KM_PIN_TRIGGER_TIME:
uistat.value = setting.pinout_time_s;
plot_printf(uistat.text, sizeof uistat.text, "%.3F", uistat.value);
break;
#endif
case KM_MARKER:
if (active_marker >=0) {
uistat.freq_value = markers[active_marker].frequency;
@ -5886,6 +5900,12 @@ set_numeric_value(void)
setting.trigger_grid = (uistat.value + 0.5/(float)CH_CFG_ST_FREQUENCY)* CH_CFG_ST_FREQUENCY; // US2ST(uistat.value*1000000.0) ;
completed = true;
break;
#ifdef __TRIGGER_PINS__
case KM_PIN_TRIGGER_TIME:
setting.pinout_time_s = uistat.value;
completed = true;
break;
#endif
case KM_GRIDLINES:
set_gridlines(uistat.value);
break;

Loading…
Cancel
Save

Powered by TurnKey Linux.