pulse modulation added
This commit is contained in:
+8
-5
@@ -195,7 +195,7 @@ static bool app_activate_profile(const profile_t *profile, uint16_t index, bool
|
||||
static bool app_handle_profile_boot(void);
|
||||
static bool app_apply_waveform_config(const waveform_config_t *waveform);
|
||||
static void app_apply_profile_auxiliary_outputs(const profile_t *profile);
|
||||
static bool app_load_custom_waveform_from_file(const char *path);
|
||||
static bool app_load_custom_waveform_from_file(const char *path, uint16_t pat_period_us);
|
||||
static void app_handle_packet(const app_packet_t *packet);
|
||||
static void app_handle_work_config_packet(const app_packet_t *packet);
|
||||
static void app_handle_profile_save_control_packet(const app_packet_t *packet);
|
||||
@@ -724,7 +724,7 @@ static void app_decode_work_packet(const uint16_t *packet_words)
|
||||
g_app.laser_config[1].current_raw = packet_words[12];
|
||||
}
|
||||
|
||||
static bool app_load_custom_waveform_from_file(const char *path)
|
||||
static bool app_load_custom_waveform_from_file(const char *path, uint16_t pat_period_us)
|
||||
{
|
||||
char buffer[APP_CUSTOM_WAVE_BUFFER_SIZE];
|
||||
UINT bytes_read = 0u;
|
||||
@@ -769,7 +769,7 @@ static bool app_load_custom_waveform_from_file(const char *path)
|
||||
cursor = end_ptr;
|
||||
}
|
||||
|
||||
if ((sample_count < 2u) || !ad9102_begin_custom_upload(sample_count))
|
||||
if ((sample_count < 2u) || !ad9102_begin_custom_upload(sample_count, pat_period_us))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -858,7 +858,8 @@ static bool app_apply_waveform_config(const waveform_config_t *waveform)
|
||||
ad9102_stop_output();
|
||||
return true;
|
||||
}
|
||||
return app_load_custom_waveform_from_file(waveform->source_path);
|
||||
return app_load_custom_waveform_from_file(waveform->source_path,
|
||||
waveform->custom_pat_period_us);
|
||||
|
||||
default:
|
||||
return false;
|
||||
@@ -1352,7 +1353,9 @@ static void app_handle_ad9102_wave_control_packet(const app_packet_t *packet)
|
||||
switch (opcode)
|
||||
{
|
||||
case APP_AD9102_WAVE_OPCODE_BEGIN:
|
||||
if ((param1 != 0u) || !ad9102_begin_custom_upload(param0))
|
||||
/* param1 = pattern repetition period in microseconds; 0 keeps
|
||||
* the legacy back-to-back playback. */
|
||||
if (!ad9102_begin_custom_upload(param0, param1))
|
||||
{
|
||||
ad9102_cancel_custom_upload();
|
||||
app_set_error(APP_STATUS_FLAG_AD9102_ERROR);
|
||||
|
||||
@@ -44,6 +44,9 @@
|
||||
#define AD9102_EX2_SAW_CONFIG 0x0200u
|
||||
#define AD9102_SRAM_PAT_PERIOD_BASE_DEFAULT 0x1u
|
||||
#define AD9102_SRAM_START_DELAY_BASE_DEFAULT 0x1u
|
||||
|
||||
/* Board-level oscillator on the AD9102 CLKIN pin. */
|
||||
#define AD9102_DAC_CLOCK_MHZ 150u
|
||||
#define AD9102_SRAM_START_DLY_DEFAULT 0x0000u
|
||||
#define AD9102_SRAM_RAMP_MIN (-8192)
|
||||
#define AD9102_SRAM_RAMP_MAX (8191)
|
||||
@@ -207,10 +210,13 @@ static void ad9102_start_output(void)
|
||||
HAL_GPIO_WritePin(AD9102_TRIG_GPIO_Port, AD9102_TRIG_Pin, GPIO_PIN_RESET);
|
||||
}
|
||||
|
||||
static void ad9102_configure_sram_playback(uint16_t sample_count, uint8_t hold_cycles)
|
||||
static void ad9102_configure_sram_playback(uint16_t sample_count,
|
||||
uint8_t hold_cycles,
|
||||
uint16_t pat_period_us)
|
||||
{
|
||||
uint16_t pat_timebase;
|
||||
uint32_t pat_period;
|
||||
uint32_t pat_period_base = AD9102_SRAM_PAT_PERIOD_BASE_DEFAULT;
|
||||
|
||||
if (sample_count < 2u)
|
||||
{
|
||||
@@ -229,9 +235,6 @@ static void ad9102_configure_sram_playback(uint16_t sample_count, uint8_t hold_c
|
||||
hold_cycles = 0x0Fu;
|
||||
}
|
||||
|
||||
pat_timebase = (uint16_t)(((uint16_t)(hold_cycles & 0x0Fu) << 8) |
|
||||
((AD9102_SRAM_PAT_PERIOD_BASE_DEFAULT & 0x0Fu) << 4) |
|
||||
(AD9102_SRAM_START_DELAY_BASE_DEFAULT & 0x0Fu));
|
||||
pat_period = (uint32_t)sample_count * (uint32_t)(hold_cycles & 0x0Fu);
|
||||
if (pat_period == 0u)
|
||||
{
|
||||
@@ -242,6 +245,37 @@ static void ad9102_configure_sram_playback(uint16_t sample_count, uint8_t hold_c
|
||||
pat_period = 0xFFFFu;
|
||||
}
|
||||
|
||||
if (pat_period_us != 0u)
|
||||
{
|
||||
/* Repetition period requested in microseconds (0 = back-to-back).
|
||||
* PAT_PERIOD counts in units of PATTERN_PERIOD_BASE DAC clocks, so
|
||||
* spread the tick count over the smallest base that fits 16 bits. */
|
||||
uint32_t period_clocks = (uint32_t)pat_period_us * AD9102_DAC_CLOCK_MHZ;
|
||||
uint32_t pattern_clocks = (uint32_t)sample_count * (uint32_t)(hold_cycles & 0x0Fu);
|
||||
|
||||
if (period_clocks < pattern_clocks)
|
||||
{
|
||||
/* Shorter than the pattern itself would truncate it and raise a
|
||||
* configuration error; fall back to back-to-back playback. */
|
||||
period_clocks = pattern_clocks;
|
||||
}
|
||||
|
||||
pat_period_base = 1u + ((period_clocks - 1u) / 0xFFFFu);
|
||||
if (pat_period_base > 0x0Fu)
|
||||
{
|
||||
pat_period_base = 0x0Fu;
|
||||
}
|
||||
pat_period = (period_clocks + (pat_period_base / 2u)) / pat_period_base;
|
||||
if (pat_period > 0xFFFFu)
|
||||
{
|
||||
pat_period = 0xFFFFu;
|
||||
}
|
||||
}
|
||||
|
||||
pat_timebase = (uint16_t)(((uint16_t)(hold_cycles & 0x0Fu) << 8) |
|
||||
((uint16_t)(pat_period_base & 0x0Fu) << 4) |
|
||||
(AD9102_SRAM_START_DELAY_BASE_DEFAULT & 0x0Fu));
|
||||
|
||||
ad9102_write_reg_table(g_ad9102_example2_regval, AD9102_REG_COUNT);
|
||||
ad9102_stop_output();
|
||||
ad9102_write_reg(AD9102_REG_WAV_CONFIG, AD9102_EX2_WAV_CONFIG);
|
||||
@@ -426,7 +460,7 @@ uint16_t ad9102_apply_generated_sram(uint8_t enabled,
|
||||
amplitude = AD9102_SRAM_DEFAULT_AMPLITUDE;
|
||||
}
|
||||
|
||||
ad9102_configure_sram_playback(sample_count, hold_cycles);
|
||||
ad9102_configure_sram_playback(sample_count, hold_cycles, 0u);
|
||||
ad9102_load_sram_ramp(sample_count, triangle_mode, amplitude);
|
||||
|
||||
if (enabled != 0u)
|
||||
@@ -441,7 +475,7 @@ uint16_t ad9102_apply_generated_sram(uint8_t enabled,
|
||||
return ad9102_read_reg(AD9102_REG_PAT_STATUS);
|
||||
}
|
||||
|
||||
bool ad9102_begin_custom_upload(uint16_t sample_count)
|
||||
bool ad9102_begin_custom_upload(uint16_t sample_count, uint16_t pat_period_us)
|
||||
{
|
||||
if ((sample_count < 2u) || (sample_count > AD9102_SRAM_MAX_SAMPLE_COUNT))
|
||||
{
|
||||
@@ -450,7 +484,7 @@ bool ad9102_begin_custom_upload(uint16_t sample_count)
|
||||
|
||||
ad9102_stop_output();
|
||||
ad9102_reset_upload_state();
|
||||
ad9102_configure_sram_playback(sample_count, AD9102_SRAM_DEFAULT_HOLD);
|
||||
ad9102_configure_sram_playback(sample_count, AD9102_SRAM_DEFAULT_HOLD, pat_period_us);
|
||||
ad9102_write_reg(AD9102_REG_PAT_STATUS, 0x0004u);
|
||||
|
||||
g_upload_state.expected_samples = sample_count;
|
||||
|
||||
@@ -34,7 +34,8 @@ uint16_t ad9102_apply_generated_sram(uint8_t enabled,
|
||||
uint8_t hold_cycles,
|
||||
uint8_t triangle_mode,
|
||||
uint16_t amplitude);
|
||||
bool ad9102_begin_custom_upload(uint16_t sample_count);
|
||||
/* pat_period_us: pattern repetition period in microseconds (0 = back-to-back). */
|
||||
bool ad9102_begin_custom_upload(uint16_t sample_count, uint16_t pat_period_us);
|
||||
bool ad9102_write_custom_chunk(const uint16_t *samples, uint16_t chunk_count);
|
||||
uint16_t ad9102_commit_custom_upload(bool *out_ok);
|
||||
void ad9102_cancel_custom_upload(void);
|
||||
|
||||
@@ -305,6 +305,10 @@ typedef struct waveform_config_t {
|
||||
uint8_t saw_step;
|
||||
uint8_t pat_period_base;
|
||||
uint16_t pat_period;
|
||||
/* Repetition period for custom SRAM patterns in microseconds;
|
||||
* 0 keeps the legacy back-to-back playback. Kept separate from
|
||||
* pat_period because that field carries the SAW-mode default (0xFFFF). */
|
||||
uint16_t custom_pat_period_us;
|
||||
uint16_t sample_count;
|
||||
uint8_t hold_cycles;
|
||||
uint16_t amplitude;
|
||||
|
||||
@@ -103,6 +103,7 @@ static void profile_repository_reset_profile(profile_t *profile)
|
||||
profile->waveform.saw_step = 1u;
|
||||
profile->waveform.pat_period_base = 2u;
|
||||
profile->waveform.pat_period = 0xFFFFu;
|
||||
profile->waveform.custom_pat_period_us = 0u;
|
||||
profile->waveform.sample_count = AD9102_SRAM_DEFAULT_SAMPLE_COUNT;
|
||||
profile->waveform.hold_cycles = AD9102_SRAM_DEFAULT_HOLD;
|
||||
profile->waveform.amplitude = AD9102_SRAM_DEFAULT_AMPLITUDE;
|
||||
@@ -267,6 +268,10 @@ static void profile_repository_apply_key_value(profile_t *profile, const char *k
|
||||
{
|
||||
profile->waveform.pat_period = profile_repository_parse_u16(value);
|
||||
}
|
||||
else if (strcmp(key, "waveform_custom_period_us") == 0)
|
||||
{
|
||||
profile->waveform.custom_pat_period_us = profile_repository_parse_u16(value);
|
||||
}
|
||||
else if (strcmp(key, "waveform_sample_count") == 0)
|
||||
{
|
||||
profile->waveform.sample_count = profile_repository_parse_u16(value);
|
||||
|
||||
Reference in New Issue
Block a user