pico-hf-oscillator/piodco/dco2.pio

134 wiersze
4.6 KiB
Plaintext

///////////////////////////////////////////////////////////////////////////////
//
// Roman Piksaykin [piksaykin@gmail.com], R2BDY
// https://www.qrz.com/db/r2bdy
//
///////////////////////////////////////////////////////////////////////////////
//
//
// dco2.pio - Digital controlled radio freq oscillator based on PIO.
//
//
// DESCRIPTION
//
// The oscillator provides precise generation of any frequency ranging
// from 1 Hz to 33.333 MHz with tenth's of millihertz resolution (please note that
// this is relative resolution owing to the fact that the absolute accuracy of
// onboard crystal of pi pico is limited; the absoulte accuracy can be provided
// when using GPS reference option included).
// The DCO uses phase locked loop principle programmed in C and PIO asm.
// The DCO does *NOT* use any floating point operations - all time-critical
// instructions run in 1 CPU cycle.
// Currently the upper freq. limit is about 33.333 MHz and it is achieved only
// using pi pico overclocking to 270 MHz.
// Owing to the meager frequency step, it is possible to use 3, 5, or 7th
// harmonics of generated frequency. Such solution completely cover all HF and
// a portion of VHF band up to about 233 MHz.
// Unfortunately due to pure digital freq.synthesis principle the jitter may
// be a problem on higher frequencies. You should assess the quality of generated
// signal if you want to emit a noticeable power.
// This is an experimental project of amateur radio class and it is devised
// by me on the free will base in order to experiment with QRP narrowband
// digital modes.
// I appreciate any thoughts or comments on that matter.
//
// PLATFORM
// Raspberry Pi pico.
//
// REVISION HISTORY
//
// Rev 0.1 05 Nov 2023 Initial release
// Rev 0.2 18 Nov 2023
// Rev 1.0 10 Dec 2023 Improved frequency range (to ~33.333 MHz).
//
// PROJECT PAGE
// https://github.com/RPiks/pico-hf-oscillator
//
// LICENCE
// MIT License (http://www.opensource.org/licenses/mit-license.php)
//
// Copyright (c) 2023 by Roman Piksaykin
//
// Permission is hereby granted, free of charge,to any person obtaining a copy
// of this software and associated documentation files (the Software), to deal
// in the Software without restriction,including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY,WHETHER IN AN ACTION OF CONTRACT,TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
///////////////////////////////////////////////////////////////////////////////
.program dco
.wrap_target
out y, 32
mov x, y
LOOP0:
jmp x-- LOOP0
set pins, 1
mov x, y [1]
LOOP1:
jmp x-- LOOP1
set pins, 0
mov x, y [1]
LOOP2:
jmp x-- LOOP2
set pins, 1
mov x, y [1]
LOOP3:
jmp x-- LOOP3
set pins, 0
.wrap
% c-sdk {
#define PIOASM_DELAY_CYCLES 4
static inline void dco_program_init(PIO pio, uint sm, uint offset, uint pin)
{
pio_sm_config c = dco_program_get_default_config(offset);
sm_config_set_out_shift(&c, true, true, 32); // Autopull.
sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_TX);
sm_config_set_out_pins(&c, pin, 1);
pio_gpio_init(pio, pin);
pio_sm_set_consecutive_pindirs(pio, sm, pin, 1, true);
sm_config_set_clkdiv_int_frac(&c, 1u, 0u);
pio_sm_init(pio, sm, offset, &c);
pio_sm_set_enabled(pio, sm, true);
}
//
static inline void dco_program_puts(PIO pio, uint sm, const uint32_t *s)
{
pio_sm_put_blocking(pio, sm, s[0]);
pio_sm_put_blocking(pio, sm, s[1]);
pio_sm_put_blocking(pio, sm, s[2]);
pio_sm_put_blocking(pio, sm, s[3]);
pio_sm_put_blocking(pio, sm, s[4]);
pio_sm_put_blocking(pio, sm, s[5]);
pio_sm_put_blocking(pio, sm, s[6]);
pio_sm_put_blocking(pio, sm, s[7]);
}
static inline void dco_program_puts1w(PIO pio, uint sm, const uint32_t val)
{
pio_sm_put_blocking(pio, sm, val);
}
%}