https://imgur.com/wkKE4e2
I want to experiment with PIO and pin direction. What I am trying to do is simulate what would happen on an 8-bit computer data bus. In theory, SW1 is supposed to give me an input of high or low depending upon whether SW1 is closed or not and I'm feeding that voltage into GPIO6.
In my PIO program, I (think I) am setting the pin direction of GPIO6 to output. The program currently toggles the value of GPIO6 from low to high. LED2 is flashing on and off which confirms this behaviour.
When I close SW1, I then see LED1 toggling as well. My assumption is that when GPIO6 is low, LED1 drains through GPIO6 and switches on. When GPIO6 is high, there voltage across both sides of LED1 is 3V, (0V difference) so LED1 switches off.
If I'm correct about LED1 draining through GPIO6, is this safe? Is there an internal resistor within the Pico or will I fry something?
What do I need to do to ensure that LED1 stays on? If I change the pin direction of GPIO6 to Input, will GPIO6 then become high impedance giving me what I want?
Here's my PIO code for reference:And main.c
I want to experiment with PIO and pin direction. What I am trying to do is simulate what would happen on an 8-bit computer data bus. In theory, SW1 is supposed to give me an input of high or low depending upon whether SW1 is closed or not and I'm feeding that voltage into GPIO6.
In my PIO program, I (think I) am setting the pin direction of GPIO6 to output. The program currently toggles the value of GPIO6 from low to high. LED2 is flashing on and off which confirms this behaviour.
When I close SW1, I then see LED1 toggling as well. My assumption is that when GPIO6 is low, LED1 drains through GPIO6 and switches on. When GPIO6 is high, there voltage across both sides of LED1 is 3V, (0V difference) so LED1 switches off.
If I'm correct about LED1 draining through GPIO6, is this safe? Is there an internal resistor within the Pico or will I fry something?
What do I need to do to ensure that LED1 stays on? If I change the pin direction of GPIO6 to Input, will GPIO6 then become high impedance giving me what I want?
Here's my PIO code for reference:
Code:
.program romstart:.wrap_target set pindirs 1 set pins 1 ; Wait for byte from C program pull block set pins 0 ; Wait for byte from C program pull block .wrap% c-sdk {#include "hardware/clocks.h"static inline void rom_program_init(PIO pio, uint sm, uint offset, uint pinIn, uint pinOut, uint pinJmp) { pio_sm_config c = rom_program_get_default_config( offset ); for( int i = 2; i < 29; i ++ ) { // Start after the UART pins pio_gpio_init( pio, i ); } //sm_config_set_out_pins( &c, pinOut, 1 ); sm_config_set_set_pins( &c, pinOut, 1 ); sm_config_set_jmp_pin( &c, pinJmp ); sm_config_set_in_pins( &c, pinIn ); sm_config_set_in_shift(&c, false, true, 0); // Push left pio_sm_set_consecutive_pindirs( pio, sm, pinIn, 1, false ); // Leaving 2 pins for UART pio_sm_init( pio, sm, offset, &c ); pio_sm_set_enabled( pio, sm, true );}%}
Code:
#include <stdio.h>#include <string.h>#include "pico/stdlib.h"#include "hardware/pio.h"// Include our assembled PIO program.. (appears in the build folder)#include "rom.pio.h"int main() { stdio_init_all(); printf( "\nStarted..\n\n"); PIO pio = pio0; uint offset = pio_add_program( pio, &rom_program ); uint BASE_IN_PIN = 2; uint BASE_OUT_PIN = 6; uint BASE_JMP_PIN = 16; uint sm = pio_claim_unused_sm( pio, true ); rom_program_init( pio, sm, offset, BASE_IN_PIN, BASE_OUT_PIN, BASE_JMP_PIN ); while (true) { printf( "Push blocking (A)..\n"); pio_sm_put_blocking( pio, sm, 0xFFFF ); sleep_ms( 1000 ); printf( "Push blocking (B)..\n"); pio_sm_put_blocking( pio, sm, 0xFFFF ); sleep_ms( 1000 ); }}
Statistics: Posted by SparkyNZ — Thu Oct 10, 2024 5:46 am