Mercurial > ~darius > hgwebdir.cgi > modulator
changeset 2:0d653f60dec8
Actually get data moving out.
Previous shape info caused a hard fault.
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Mon, 29 Mar 2021 17:39:00 +1030 |
parents | b9ec45077bff |
children | b10097c3383d |
files | CMakeLists.txt dac.pio modulator.c |
diffstat | 3 files changed, 48 insertions(+), 45 deletions(-) [+] |
line wrap: on
line diff
--- a/CMakeLists.txt Mon Mar 29 13:54:55 2021 +1030 +++ b/CMakeLists.txt Mon Mar 29 17:39:00 2021 +1030 @@ -25,8 +25,8 @@ hardware_pio ) -bin2elf(${NAME} shaped-trap.dat) -bin2elf(${NAME} sgauss.dat) +#bin2elf(${NAME} shaped-trap.dat) +#bin2elf(${NAME} sgauss.dat) # create map/bin/hex file etc. pico_add_extra_outputs(${NAME})
--- a/dac.pio Mon Mar 29 13:54:55 2021 +1030 +++ b/dac.pio Mon Mar 29 17:39:00 2021 +1030 @@ -1,48 +1,50 @@ ; -; Copyright (c) 2021 Raspberry Pi (Trading) Ltd. -; -; SPDX-License-Identifier: BSD-3-Clause +; Copyright (c) 2021 Daniel O'Connor ; .program dac -; Sample bits using an external clock, and push groups of bits into the RX FIFO. -; - IN pin 0 is the data pin -; - IN pin 1 is the clock pin -; - Autopush is enabled, threshold 8 -; -; This program samples data with each rising clock edge (like mode 0 or mode 3 -; SPI). The data is actually sampled one system clock cycle after the rising -; edge is observed, so a clock ratio of at least input_clk < clk_sys / 6 is -; recommended for good sampling alignment. +.side_set 1 +; Clock DAC and write data from the FIFO - wait 0 pin 1 - wait 1 pin 1 - in pins, 1 +.wrap_target + pull side 1 + out pins 8 side 0 + nop side 1 + out pins 8 side 0 + nop side 1 + out pins 8 side 0 + nop side 1 + out pins 8 side 0 +.wrap % c-sdk { static inline void dac_program_init(PIO pio, uint sm, uint offset, uint pin) { pio_sm_config c = dac_program_get_default_config(offset); - // Set the IN base pin to the provided `pin` parameter. This is the data - // pin, and the next-numbered GPIO is used as the clock pin. - sm_config_set_in_pins(&c, pin); - // Set the pin directions to input at the PIO - pio_sm_set_consecutive_pindirs(pio, sm, pin, 2, false); + // Set the OUT base pin to the provided `pin` parameter. + // First 8 pins are data, last is clock + sm_config_set_out_pins(&c, pin, 9); + // Set the pin directions to output at the PIO + pio_sm_set_consecutive_pindirs(pio, sm, pin, 9, true); // Connect these GPIOs to this PIO block - pio_gpio_init(pio, pin); - pio_gpio_init(pio, pin + 1); + for (int i = 0; i < 9; i++) + pio_gpio_init(pio, pin + i); - // Shifting to left matches the customary MSB-first ordering of SPI. - sm_config_set_in_shift( + sm_config_set_out_shift( &c, - false, // Shift-to-right = false (i.e. shift to left) - true, // Autopush enabled - 8 // Autopush threshold = 8 + true, // Shift-to-right + false, // Autopull enabled + 8 // Autopull threshold (bits!) ); - // We only receive, so disable the TX FIFO to make the RX FIFO deeper. - sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_RX); + // Configure clock as sideset pin + sm_config_set_sideset_pins(&c, pin + 7); + + // We only send, so disable the RX FIFO to make the TX FIFO deeper. + sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_TX); + +// sm_config_set_clkdiv(&c, 100); // Load our configuration, and start the program from the beginning pio_sm_init(pio, sm, offset, &c);
--- a/modulator.c Mon Mar 29 13:54:55 2021 +1030 +++ b/modulator.c Mon Mar 29 17:39:00 2021 +1030 @@ -23,11 +23,16 @@ #include "dac.pio.h" +#if 0 extern void* shaped_trap_dat_size; extern void* shaped_trap_dat_start; extern void* sgauss_dat_size; extern void* sgauss_dat_start; +#endif + +uint8_t shaped_trap_dat_start[] = { 0, 1, 2, 4, 8, 16, 32, 64, 128, 0, 0, 0, 0, 0, 0, 0 }; +//uint8_t shaped_trap_dat_start[] = { 0, 1, 2, 3, 1, 2, 0, 3, 1, 1, 2, 3, 0, 1, 2, 3 }; int main() { @@ -44,22 +49,18 @@ PIO pio = pio0; uint offset = pio_add_program(pio, &dac_program); uint sm = pio_claim_unused_sm(pio, true); - dac_program_init(pio, sm, offset, 4); + // XXX: I would prefer starting at GPIO16 but in that case the top 2 + // bits don't seem to work + dac_program_init(pio, sm, offset, 14); while (true) { - for (i = 0; i < (int)&shaped_trap_dat_size; i++) { - if (*(uint8_t *)shaped_trap_dat_start) - gpio_put(LED_PIN, 1); - else - gpio_put(LED_PIN, 0); - sleep_ms(250); + for (int i = 0; i < sizeof(shaped_trap_dat_start) / 4; i++) { + pio_sm_put_blocking(pio, sm, ((uint32_t *)shaped_trap_dat_start)[i]); } - for (i = 0; i < (int)&sgauss_dat_size; i++) { - if (*(uint8_t *)sgauss_dat_start) - gpio_put(LED_PIN, 1); - else - gpio_put(LED_PIN, 0); - sleep_ms(250); - } +#if 0 + gpio_put(LED_PIN, 1); + sleep_ms(100); + gpio_put(LED_PIN, 0); +#endif } }