Code:
Observing the side-set pin 17 on an oscope reveals that it remains low always. Here the C program and the associated PIO program.program custom_signal.side_set 1 opt ; Declare 1 side-set pin and enable OPT.wrap_targetstart: set y, 31 ; Initialize loop counter and set sideset pin LOW pull ; Wait for data, keep sideset Low bitloop: out x, 1 ; Shift out one bit from OSR jmp !x bit0 ; If x is 0, jump to bit0 set pins, 1 side 1 [2] ; bit is a '1' so short high for 3 cycles; clock goes high set pins, 0 [4] ; low for 5 cycles jmp y--, bitloop side 0 ; loop: get another bit, low for 1 cycle; clock goes low jmp start ; Go to start: pull another word bit0: set pins, 1 side 1 [5] ; bit 0 so long high for 6 cycles set pins, 0 [1] ; short low for 3 cyles jmp y--, bitloop side 0 ; Go back to start after bitloop, set sideset LOW .wrap-------- c program ---- below#include "pico/stdlib.h"#include "hardware/pio.h"#include "hardware/gpio.h"#include "custom_signal.pio.h"// Define the pins and hardware configuration#define SET_PIN 16 // SET pin for data output#define SIDE_PIN 17 // Side-set pin#define PIO_BLOCK pio0 #define SM 0 #define CLK_DIV 25000.0fvoid setup_pio_pins(PIO pio, uint sm) { // Disable state machine before configuration pio_sm_set_enabled(pio, sm, false); // Load the PIO program uint offset = pio_add_program(pio, &custom_signal_program); // Get default configuration pio_sm_config config = custom_signal_program_get_default_config(offset); // Configure clock divider sm_config_set_clkdiv(&config, CLK_DIV); // Join FIFOs to increase TX size sm_config_set_fifo_join(&config, PIO_FIFO_JOIN_TX); // Initialize GPIO pins for PIO function gpio_init(SET_PIN); gpio_init(SIDE_PIN); // Set GPIO function to PIO0 - CRITICAL FOR PROPER OPERATION gpio_set_function(SET_PIN, GPIO_FUNC_PIO0); gpio_set_function(SIDE_PIN, GPIO_FUNC_PIO0); // Configure SET pin sm_config_set_set_pins(&config, SET_PIN, 1); // Configure side-set pin - THIS IS THE CRITICAL PART FOR PIN 17 sm_config_set_sideset_pins(&config, SIDE_PIN); sm_config_set_sideset(&config, 1, true, false); // 1 pin, optional, no pindirs control // Set pins as outputs pio_sm_set_consecutive_pindirs(pio, sm, SET_PIN, 1, true); pio_sm_set_consecutive_pindirs(pio, sm, SIDE_PIN, 1, true); // Initialize state machine with configuration pio_sm_init(pio, sm, offset, &config); // Set initial pin states pio_sm_set_pins_with_mask(pio, sm, 0, (1u << SET_PIN)); pio_sm_set_pins_with_mask(pio, sm, 0, (1u << SIDE_PIN)); // Enable the state machine pio_sm_set_enabled(pio, sm, true); // For debugging: printf("PIO pins configured - SET: %d, SIDE: %d\n", SET_PIN, SIDE_PIN);}int main() { // Initialize standard library stdio_init_all(); sleep_ms(500); // Allow time for USB serial to initialize printf("Initializing PIO side-set example\n"); // Setup PIO with correct pins setup_pio_pins(PIO_BLOCK, SM); uint32_t count = 0; // Main loop - send alternating patterns while (true) { // Alternate between all 0s and all 1s uint32_t data = (count++ % 2) ? 0xFFFFFFFF : 0x00000000; // Send data to PIO if (!pio_sm_is_tx_fifo_full(PIO_BLOCK, SM)) { pio_sm_put_blocking(PIO_BLOCK, SM, data); // Debug output occasionally if (count % 1000 == 0) { printf("Sent data: 0x%08lx (count: %lu)\n", (unsigned long)data, (unsigned long)count); } } sleep_ms(5); // Small delay to prevent overwhelming CPU } return 0;}
Statistics: Posted by hendersonh — Wed Mar 12, 2025 1:50 am — Replies 0 — Views 5