diff --git a/src/main.c b/src/main.c index 3360a13..6c67be0 100644 --- a/src/main.c +++ b/src/main.c @@ -947,10 +947,21 @@ static void command(const char *cmd) actual = rx_lo_init(actual - step_hz); printf("Frequency: %.0f\n", actual); } else if ((c >= '1') && (c <= '9')) { - for (int i = 0; i < 1000; i++) { - phase = !phase; + uint32_t t0 = time_us_32(); + uint32_t tmax = 1000000 / (c - '0'); + uint32_t step = 1000 / (c - '0') / 2; + + while (true) { + uint32_t t1 = time_us_32(); + uint32_t te = t1 - t0; + + if (te >= tmax) + break; + + phase = (te / step) & 1; + gpio_set_outover(n, phase); - sleep_us(1000 / (c - '0')); + sleep_us(1); } } }