kopia lustrzana https://github.com/RPiks/pico-hf-oscillator
rodzic
d7f92d412a
commit
0e5f208661
|
@ -20,38 +20,38 @@ if (PICO_SDK_VERSION_STRING VERSION_LESS "1.4.0")
|
|||
message(FATAL_ERROR "Raspberry Pi Pico SDK version 1.4.0 (or later) required. Your version is ${PICO_SDK_VERSION_STRING}")
|
||||
endif()
|
||||
|
||||
project(pico-DCO-test C CXX ASM)
|
||||
project(pico-hf-oscillator-test C CXX ASM)
|
||||
|
||||
# Initialise the Raspberry Pi Pico SDK
|
||||
pico_sdk_init()
|
||||
|
||||
# Add executable. Default name is the project name, version 0.1
|
||||
|
||||
add_executable(pico-DCO-test)
|
||||
add_executable(pico-hf-oscillator-test)
|
||||
|
||||
pico_generate_pio_header(pico-DCO-test ${CMAKE_CURRENT_LIST_DIR}/piodco/dco.pio)
|
||||
pico_generate_pio_header(pico-hf-oscillator-test ${CMAKE_CURRENT_LIST_DIR}/piodco/dco.pio)
|
||||
|
||||
target_sources(pico-DCO-test PUBLIC
|
||||
target_sources(pico-hf-oscillator-test PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}/lib/assert.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/piodco/piodco.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/test.c
|
||||
)
|
||||
|
||||
pico_set_program_name(pico-DCO-test "pico-DCO-test")
|
||||
pico_set_program_version(pico-DCO-test "0.9")
|
||||
pico_set_program_name(pico-hf-oscillator-test "pico-hf-oscillator-test")
|
||||
pico_set_program_version(pico-hf-oscillator-test "0.9")
|
||||
|
||||
pico_enable_stdio_uart(pico-DCO-test 1)
|
||||
pico_enable_stdio_usb(pico-DCO-test 0)
|
||||
pico_enable_stdio_uart(pico-hf-oscillator-test 1)
|
||||
pico_enable_stdio_usb(pico-hf-oscillator-test 0)
|
||||
|
||||
# Add the standard include files to the build
|
||||
target_include_directories(pico-DCO-test PRIVATE
|
||||
target_include_directories(pico-hf-oscillator-test PRIVATE
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
${CMAKE_CURRENT_LIST_DIR}/.. # for our common lwipopts or any other standard includes, if required
|
||||
)
|
||||
|
||||
# Add any user requested libraries
|
||||
target_link_libraries(
|
||||
pico-DCO-test
|
||||
pico-hf-oscillator-test
|
||||
pico_stdlib
|
||||
pico_sync
|
||||
pico_multicore
|
||||
|
@ -61,4 +61,4 @@ target_link_libraries(
|
|||
hardware_vreg
|
||||
)
|
||||
|
||||
pico_add_extra_outputs(pico-DCO-test)
|
||||
pico_add_extra_outputs(pico-hf-oscillator-test)
|
||||
|
|
|
@ -97,22 +97,25 @@ int PioDCOInit(PioDco *pdco, int gpio, int cpuclkhz)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/// @brief Sets DCO working frequency in Hz.
|
||||
/// @brief Sets DCO working frequency in Hz: Fout = ui32_frq_hz + ui32_frq_millihz * 1e-3.
|
||||
/// @param pdco Ptr to DCO context.
|
||||
/// @param ui32_frq_hz The frequency [Hz].
|
||||
/// @param ui32_frq_hz The `coarse` part of frequency [Hz].
|
||||
/// @param ui32_frq_millihz The `fine` part of frequency [Hz].
|
||||
/// @return 0 if OK. -1 invalid freq.
|
||||
/// @attention The func can be called while DCO running.
|
||||
int PioDCOSetFreq(PioDco *pdco, uint32_t ui32_frq_hz)
|
||||
int PioDCOSetFreq(PioDco *pdco, uint32_t ui32_frq_hz, uint32_t ui32_frq_millihz)
|
||||
{
|
||||
assert_(pdco);
|
||||
assert(pdco->_clkfreq_hz);
|
||||
|
||||
ui32_frq_hz <<= 1;
|
||||
|
||||
/* RPix: Calculate an accurate value of phase increment of the freq
|
||||
per 1 tick of CPU clock, here 2^24 is scaling coefficient. */
|
||||
pdco->_frq_cycles_per_pi = (int32_t)(((int64_t)pdco->_clkfreq_hz * (int64_t)(1<<24)
|
||||
+ (ui32_frq_hz>>1)) / (int64_t)ui32_frq_hz);
|
||||
const int64_t i64denominator = 2000LL * (int64_t)ui32_frq_hz + (int64_t)ui32_frq_millihz;
|
||||
pdco->_frq_cycles_per_pi = (int32_t)(((int64_t)pdco->_clkfreq_hz * (int64_t)(1<<24) * 1000LL
|
||||
+(i64denominator>>1)) / i64denominator);
|
||||
|
||||
//pdco->_frq_cycles_per_pi = (int32_t)(((int64_t)pdco->_clkfreq_hz * (int64_t)(1<<24)
|
||||
//+ (ui32_frq_hz>>1)) / (int64_t)ui32_frq_hz);
|
||||
|
||||
si32precise_cycles = pdco->_frq_cycles_per_pi;
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
// REVISION HISTORY
|
||||
//
|
||||
// Rev 0.1 05 Nov 2023
|
||||
// Rev 0.2 18 Nov 2023
|
||||
// Initial release.
|
||||
//
|
||||
// LICENCE
|
||||
|
@ -87,7 +88,7 @@ typedef struct
|
|||
} PioDco;
|
||||
|
||||
int PioDCOInit(PioDco *pdco, int gpio, int cpuclkhz);
|
||||
int PioDCOSetFreq(PioDco *pdco, uint32_t ui32_frq_hz);
|
||||
int PioDCOSetFreq(PioDco *pdco, uint32_t ui32_frq_hz, uint32_t ui32_frq_millihz);
|
||||
|
||||
void PioDCOStart(PioDco *pdco);
|
||||
void PioDCOStop(PioDco *pdco);
|
||||
|
|
56
test.c
56
test.c
|
@ -95,7 +95,7 @@ void core1_entry()
|
|||
PioDCOStart(&DCO);
|
||||
|
||||
/* Set initial freq. */
|
||||
assert_(0 == PioDCOSetFreq(&DCO, freq_hz));
|
||||
assert_(0 == PioDCOSetFreq(&DCO, freq_hz, 0u));
|
||||
|
||||
/* Run the main DCO algorithm. It spins forever. */
|
||||
PioDCOWorker(&DCO);
|
||||
|
@ -103,14 +103,13 @@ void core1_entry()
|
|||
|
||||
void RAM (SpinnerMFSKTest)(void)
|
||||
{
|
||||
int i = 0;
|
||||
uint32_t rndval = 77777777;
|
||||
for(;;)
|
||||
{
|
||||
/* This example sets new RND frequency every ~250 ms.
|
||||
Frequency shift is 5 Hz for each step.
|
||||
*/
|
||||
PioDCOSetFreq(&DCO, GEN_FRQ_HZ - 5*(rndval & 7));
|
||||
PioDCOSetFreq(&DCO, GEN_FRQ_HZ - 5*(rndval & 7), 0u);
|
||||
|
||||
/* LED signal */
|
||||
gpio_put(PICO_DEFAULT_LED_PIN, 1);
|
||||
|
@ -130,7 +129,7 @@ void RAM (SpinnerSweepTest)(void)
|
|||
/* This example sets new frequency every ~250 ms.
|
||||
Frequency shift is 5 Hz for each step.
|
||||
*/
|
||||
PioDCOSetFreq(&DCO, GEN_FRQ_HZ - 5*i);
|
||||
PioDCOSetFreq(&DCO, GEN_FRQ_HZ - 5*i, 0u);
|
||||
|
||||
/* LED signal */
|
||||
gpio_put(PICO_DEFAULT_LED_PIN, 1);
|
||||
|
@ -146,7 +145,6 @@ void RAM (SpinnerSweepTest)(void)
|
|||
|
||||
void RAM (SpinnerRTTYTest)(void)
|
||||
{
|
||||
int i = 0;
|
||||
int32_t df = 170; /* 170 Hz freq diff. */
|
||||
uint32_t rndval = 77777777;
|
||||
for(;;)
|
||||
|
@ -154,8 +152,7 @@ void RAM (SpinnerRTTYTest)(void)
|
|||
/* This example sets new PRN frequency every ~22 ms.
|
||||
Note: You should use precise timing while building a real transmitter.
|
||||
*/
|
||||
|
||||
PioDCOSetFreq(&DCO, GEN_FRQ_HZ - df*(rndval & 1));
|
||||
PioDCOSetFreq(&DCO, GEN_FRQ_HZ - df*(rndval & 1), 0u);
|
||||
|
||||
/* LED signal */
|
||||
gpio_put(PICO_DEFAULT_LED_PIN, 1);
|
||||
|
@ -167,6 +164,45 @@ void RAM (SpinnerRTTYTest)(void)
|
|||
}
|
||||
}
|
||||
|
||||
void RAM (SpinnerMilliHertzTest)(void)
|
||||
{
|
||||
int i = 0;
|
||||
for(;;)
|
||||
{
|
||||
/* This example sets new frequency every ~1s.
|
||||
Frequency shift is 0.99 Hz for each step.
|
||||
*/
|
||||
PioDCOSetFreq(&DCO, GEN_FRQ_HZ, 990*(++i&1));
|
||||
|
||||
/* LED signal */
|
||||
gpio_put(PICO_DEFAULT_LED_PIN, 1);
|
||||
sleep_ms(1000);
|
||||
gpio_put(PICO_DEFAULT_LED_PIN, 0);
|
||||
sleep_ms(1000);
|
||||
}
|
||||
}
|
||||
|
||||
void RAM (SpinnerWide4FSKTest)(void)
|
||||
{
|
||||
int32_t df = 100; /* 100 Hz freq diff * 4 = 400 Hz. */
|
||||
uint32_t rndval = 77777777;
|
||||
for(;;)
|
||||
{
|
||||
/* This example sets new PRN frequency every ~20 ms.
|
||||
Note: You should use precise timing while building a real transmitter.
|
||||
*/
|
||||
PioDCOSetFreq(&DCO, GEN_FRQ_HZ - df*(rndval & 3), 0u);
|
||||
|
||||
/* LED signal */
|
||||
gpio_put(PICO_DEFAULT_LED_PIN, 1);
|
||||
sleep_ms(20);
|
||||
gpio_put(PICO_DEFAULT_LED_PIN, 0);
|
||||
sleep_ms(20);
|
||||
|
||||
PRN32(&rndval);
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
const uint32_t clkhz = PLL_SYS_MHZ * 1000000L;
|
||||
|
@ -178,8 +214,10 @@ int main()
|
|||
multicore_launch_core1(core1_entry);
|
||||
|
||||
//SpinnerSweepTest();
|
||||
//SpinnerMFSKTest();
|
||||
SpinnerRTTYTest();
|
||||
SpinnerMFSKTest();
|
||||
//SpinnerRTTYTest();
|
||||
//SpinnerMilliHertzTest();
|
||||
//SpinnerWide4FSKTest();
|
||||
}
|
||||
|
||||
void PRN32(uint32_t *val)
|
||||
|
|
Plik binarny nie jest wyświetlany.
Plik binarny nie jest wyświetlany.
Plik binarny nie jest wyświetlany.
Plik binarny nie jest wyświetlany.
Plik binarny nie jest wyświetlany.
Ładowanie…
Reference in New Issue