comparison dac.pio @ 9:3acdebd7eec7

Make it actually work
author Daniel O'Connor <darius@dons.net.au>
date Fri, 21 Feb 2025 17:27:22 +1030
parents 2db42eaba3c8
children 98880b18bcc1
comparison
equal deleted inserted replaced
8:0249d0cecac4 9:3acdebd7eec7
1 ; 1 ;
2 ; Copyright (c) 2021 Daniel O'Connor 2 ; Copyright (c) 2025 Daniel O'Connor
3 ; 3 ;
4 4
5 .program dac 5 .program dac
6 .define TRIGGER_IRQ 0
7 ; Need 1 side set pin, the clock
8 .side_set 1
9 ; Force load at address 0 so DMA handler can force a jump
10 ; presumably we could calculate the address but this is easier.
11 .origin 0
6 12
7 .side_set 1 13 ; Clock in a 0 byte
14 ; mov pins, null side 0
15 ; nop side 1
16 ; Wait for start trigger
17 ; wait 1 irq TRIGGER_IRQ side 0
8 ; Clock DAC and write data from the FIFO 18 ; Clock DAC and write data from the FIFO
9 19 ; DAC clocks data in on the rising clock edge
20 ; Autopull is enabled so no need to pull
10 .wrap_target 21 .wrap_target
11 pull side 1
12 out pins 8 side 0 22 out pins 8 side 0
13 nop side 1 23 nop side 1
14 out pins 8 side 0 24 out pins 8 side 0
15 nop side 1 25 nop side 1
16 out pins 8 side 0 26 out pins 8 side 0
17 nop side 1 27 nop side 1
18 out pins 8 side 0 28 out pins 8 side 0
29 nop side 1
19 .wrap 30 .wrap
20 31
21 % c-sdk { 32 % c-sdk {
22 static inline void dac_program_init(PIO pio, uint sm, uint offset, uint pin, uint clkdiv) { 33 static inline void dac_program_init(PIO pio, uint sm, uint offset, uint pin, uint clkdiv) {
23 pio_sm_config c = dac_program_get_default_config(offset); 34 pio_sm_config c = dac_program_get_default_config(offset);
32 pio_gpio_init(pio, pin + i); 43 pio_gpio_init(pio, pin + i);
33 44
34 sm_config_set_out_shift( 45 sm_config_set_out_shift(
35 &c, 46 &c,
36 true, // Shift-to-right 47 true, // Shift-to-right
37 false, // Autopull enabled 48 true, // Autopull enabled
38 32 // Autopull threshold (bits!) 49 32 // Autopull threshold (bits!)
39 ); 50 );
40 51
41 // Configure clock as sideset pin 52 // Configure sideset pin to use for clock
42 sm_config_set_sideset_pins(&c, pin + 7); 53 sm_config_set_sideset_pins(&c, pin + 8);
43 54
44 // We only send, so disable the RX FIFO to make the TX FIFO deeper. 55 // We only send, so disable the RX FIFO to make the TX FIFO deeper.
45 sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_TX); 56 sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_TX);
46 57
47 sm_config_set_clkdiv(&c, clkdiv); 58 sm_config_set_clkdiv(&c, clkdiv);