pwm
erikkaashoek 3 years ago
parent 80adee7144
commit 748a680fd8

@ -226,7 +226,7 @@
PIN_ODR_HIGH(1) | \ PIN_ODR_HIGH(1) | \
PIN_ODR_HIGH(2) | \ PIN_ODR_HIGH(2) | \
PIN_ODR_HIGH(3) | \ PIN_ODR_HIGH(3) | \
PIN_ODR_HIGH(GPIO_SD_DAT2) | \ PIN_ODR_LOW(GPIO_SD_DAT2) | \
PIN_ODR_LOW(5) | \ PIN_ODR_LOW(5) | \
PIN_ODR_HIGH(6) | \ PIN_ODR_HIGH(6) | \
PIN_ODR_HIGH(7) | \ PIN_ODR_HIGH(7) | \

@ -2582,6 +2582,22 @@ void pwm_stop(void)
#endif #endif
static uint16_t audio_mode = A_DAC;
void set_audio_mode(uint16_t new_mode)
{
if (new_mode == audio_mode)
return;
if (new_mode == A_PWM) {
DAC->CR&= ~DAC_CR_EN1; // Disable DAC CH1
pwm_init();
} else {
palSetPadMode(GPIOA, 4, PAL_MODE_INPUT); // Back to DAC mode
DAC->CR|= DAC_CR_EN1 | DAC_CR_EN2; // Use DAC: CH1 and CH2
}
audio_mode = new_mode;
}
static const GPTConfig gpt4cfg = { static const GPTConfig gpt4cfg = {
8000000, // 8 MHz timer clock. 8000000, // 8 MHz timer clock.
NULL, // No callback NULL, // No callback
@ -2699,19 +2715,18 @@ int main(void)
spi_init(); spi_init();
PULSE PULSE
#ifdef __PWM__ //#ifdef __PWM__
pwm_init(); // pwm_init();
pwm_start(2000); // pwm_start(2000);
pwm_stop(); // pwm_stop();
#endif //#endif
/* /*
* Set LCD display brightness (use DAC2 for control) * Set LCD display brightness (use DAC2 for control)
* Starting DAC1 driver, setting up the output pin as analog as suggested by the Reference Manual. * Starting DAC1 driver, setting up the output pin as analog as suggested by the Reference Manual.
*/ */
dac_init(); dac_init();
PULSE PULSE
// DAC->CR|= DAC_CR_EN1 | DAC_CR_EN2; // Use DAC: CH1 and CH2 DAC->CR|= DAC_CR_EN1 | DAC_CR_EN2; // Use DAC: CH1 and CH2
DAC->CR|= DAC_CR_EN2; // Use DAC: CH1 and CH2
#ifdef __LCD_BRIGHTNESS__ #ifdef __LCD_BRIGHTNESS__
lcd_setBrightness(DEFAULT_BRIGHTNESS); lcd_setBrightness(DEFAULT_BRIGHTNESS);
#endif #endif

@ -344,6 +344,14 @@ extern const char * const info_about[];
#ifdef TINYSA4 #ifdef TINYSA4
void toggle_extra_lna(void); void toggle_extra_lna(void);
void set_extra_lna(int t); void set_extra_lna(int t);
enum { A_DAC, A_PWM };
void set_audio_mode(uint16_t new_mode);
void pwm_start(int f);
void pwm_stop(void);
#ifdef __GUARD__
void reset_guard(void);
#endif
#endif #endif
// ------------------------------- sa_core.c ---------------------------------- // ------------------------------- sa_core.c ----------------------------------
@ -1747,8 +1755,9 @@ void interpolate_maximum(int m);
void calibrate_modulation(int modulation, int8_t *correction); void calibrate_modulation(int modulation, int8_t *correction);
enum { enum {
M_OFF, M_IMD, M_OIP3, M_PHASE_NOISE, M_SNR, M_PASS_BAND, M_LINEARITY, M_AM, M_FM, M_THD, M_CP, M_NF_TINYSA, M_NF_STORE, M_NF_VALIDATE, M_NF_AMPLIFIER, M_GUARD, M_DECONV M_OFF, M_IMD, M_OIP3, M_PHASE_NOISE, M_SNR, M_PASS_BAND, M_LINEARITY, M_AM, M_FM, M_THD, M_CP, M_NF_TINYSA, M_NF_STORE, M_NF_VALIDATE, M_NF_AMPLIFIER, M_GUARD, M_DECONV,M_MAX
}; };
#define MEASUREMENT_TEXT "OFF","IMD","OIP3","PN","SNR","PASS","LIN","AM","FM","THD","CP","NF T","NF S","NF V","NF A","GUARD","DECONF"
enum { enum {
T_AUTO, T_NORMAL, T_SINGLE, T_DONE, T_UP, T_DOWN, T_MODE, T_PRE, T_POST, T_MID T_AUTO, T_NORMAL, T_SINGLE, T_DONE, T_UP, T_DOWN, T_MODE, T_PRE, T_POST, T_MID

@ -4787,6 +4787,13 @@ again: // Spur redu
static uint8_t low_count = 0; static uint8_t low_count = 0;
static uint8_t sweep_counter = 0; // Only used for HW refresh static uint8_t sweep_counter = 0; // Only used for HW refresh
#ifdef __GUARD__
static int last_guard = -1;
void reset_guard(void) {
last_guard = -1;
}
#endif
// main loop for measurement // main loop for measurement
static bool sweep(bool break_on_operation) static bool sweep(bool break_on_operation)
@ -4873,17 +4880,19 @@ static bool sweep(bool break_on_operation)
current_guard = 0; current_guard = 0;
} }
while(!(setting.guards[current_guard].enabled)); while(!(setting.guards[current_guard].enabled));
if (setting.guards[current_guard].end > setting.guards[current_guard].start) { if (setting.guards[current_guard].end > setting.guards[current_guard].start && last_guard != current_guard) {
last_guard = current_guard;
set_sweep_frequency(ST_START, setting.guards[current_guard].start); set_sweep_frequency(ST_START, setting.guards[current_guard].start);
set_sweep_frequency(ST_STOP, setting.guards[current_guard].end); set_sweep_frequency(ST_STOP, setting.guards[current_guard].end);
set_rbw(8000); set_rbw(8000);
set_sweep_points((setting.guards[current_guard].end - setting.guards[current_guard].start) / 800000); set_sweep_points((setting.guards[current_guard].end - setting.guards[current_guard].start) / 800000);
} }
pwm_init(); set_audio_mode(A_PWM);
pwm_stop(); pwm_stop();
} else {
last_guard = -1;
set_audio_mode(A_DAC);
} }
else
palSetPadMode(GPIOA, 4, PAL_MODE_INPUT); // Back to DAC mode
#endif #endif
setting.measure_sweep_time_us = 0; // start measure sweep time setting.measure_sweep_time_us = 0; // start measure sweep time

12
ui.c

@ -1497,6 +1497,9 @@ static const menuitem_t menu_settings2[];
static const menuitem_t menu_lowoutput_settings[]; static const menuitem_t menu_lowoutput_settings[];
extern bool dirty; extern bool dirty;
char range_text[20]; char range_text[20];
#ifdef TINYSA4
const char * const measurement_text[] = {MEASUREMENT_TEXT};
#endif
#ifdef TINYSA4 #ifdef TINYSA4
int input_is_calibrated(void) int input_is_calibrated(void)
@ -3190,6 +3193,7 @@ static UI_FUNCTION_ADV_CALLBACK(menu_guard_select_acb)
if (count == 0) setting.guards[0].enabled = true; if (count == 0) setting.guards[0].enabled = true;
b->icon = (setting.guards[data].enabled?BUTTON_ICON_CHECK:BUTTON_ICON_NOCHECK) ; b->icon = (setting.guards[data].enabled?BUTTON_ICON_CHECK:BUTTON_ICON_NOCHECK) ;
plot_printf(b->text, sizeof(b->text), "%.6FHz\n%.6FHz", (float)setting.guards[data].start, (float)setting.guards[data].end); plot_printf(b->text, sizeof(b->text), "%.6FHz\n%.6FHz", (float)setting.guards[data].start, (float)setting.guards[data].end);
reset_guard();
return; return;
} }
active_guard = data; active_guard = data;
@ -5540,6 +5544,14 @@ redraw_cal_status:
quick_menu_y[max_quick_menu] = y; quick_menu_y[max_quick_menu] = y;
quick_menu[max_quick_menu++] = (menuitem_t *)NULL; quick_menu[max_quick_menu++] = (menuitem_t *)NULL;
#ifdef TINYSA4
if (setting.measurement != M_OFF){
ili9341_set_foreground(LCD_BRIGHT_COLOR_GREEN);
lcd_printf(x, y, measurement_text[setting.measurement]);
y += 2*YSTEP + YSTEP/2;
}
#endif
// if (setting.mode == M_LOW) { // if (setting.mode == M_LOW) {
// Attenuation // Attenuation
ili9341_set_foreground(setting.auto_attenuation ? LCD_FG_COLOR : LCD_BRIGHT_COLOR_GREEN); ili9341_set_foreground(setting.auto_attenuation ? LCD_FG_COLOR : LCD_BRIGHT_COLOR_GREEN);

Loading…
Cancel
Save

Powered by TurnKey Linux.