Try to increase NCO phase precision
This commit is contained in:
parent
f10f8d5ceb
commit
758488c054
12
src/main.c
12
src/main.c
|
@ -132,13 +132,23 @@ static void init_lo()
|
||||||
pio_sm_exec_wait_blocking(PIO, SM_LO, pio_encode_set(pio_pins, 0));
|
pio_sm_exec_wait_blocking(PIO, SM_LO, pio_encode_set(pio_pins, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline static uint32_t phase_bit(uint32_t phase, uint32_t step)
|
||||||
|
{
|
||||||
|
uint32_t next = phase + step;
|
||||||
|
|
||||||
|
if ((next & 0x7fffffff) > (step >> 1))
|
||||||
|
return next >> 31;
|
||||||
|
|
||||||
|
return phase >> 31;
|
||||||
|
}
|
||||||
|
|
||||||
static void nco_generate_phase(uint32_t *buf, size_t len, uint32_t step, uint32_t phase)
|
static void nco_generate_phase(uint32_t *buf, size_t len, uint32_t step, uint32_t phase)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < len; i++) {
|
for (size_t i = 0; i < len; i++) {
|
||||||
uint32_t bits = 0;
|
uint32_t bits = 0;
|
||||||
|
|
||||||
for (int j = 0; j < 32; j++) {
|
for (int j = 0; j < 32; j++) {
|
||||||
bits |= phase >> 31;
|
bits |= phase_bit(phase, step);
|
||||||
bits <<= 1;
|
bits <<= 1;
|
||||||
phase += step;
|
phase += step;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue