Quantcast
Viewing all articles
Browse latest Browse all 5127

General • Re: Pull-ups or pull-downs?

But the simple circuit with just the two LEDs (and their resistors), no switch, is better in some ways as it shows you the three possible states of the Pico pin - high low or undriven. There's a fundamental conflict between wanting to know that the pin is in the undriven state, vs wanting to use it as a useful input and making sure that the undriven state is a valid logic level - you have to pick which is important to you.
I forgot I bought a logic probe some time ago! I gave the probe a try with an Arduino first of all using the following sketch:

Code:

void loop() {  pinMode(D2, OUTPUT);  digitalWrite(D2, HIGH);  delay(2000);  digitalWrite(D2, LOW);  delay(2000);  pinMode(D2, INPUT);  delay(2000);}
This worked really well with the logic probe - I got an LED for 1, LED for 0 and then no LEDs for the floating phase.

I thought I'd try the same thing on the Pico using the below PIO code:

Code:

#include <stdio.h>#include <string.h>#include "pico/stdlib.h"#include "hardware/pio.h"#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( "Output HI\n");        pio_sm_put_blocking( pio, sm, 0xFFFF );        sleep_ms( 1000 );        printf( "Output LO\n");        pio_sm_put_blocking( pio, sm, 0xFFFF );        sleep_ms( 1000 );        printf( "HiZ..\n\n");        pio_sm_put_blocking( pio, sm, 0xFFFF );        sleep_ms( 1000 );    }}// PIO file.program romstart:.wrap_target    ; Wait for byte from C program    pull block    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    ; Wait for byte from C program    set pindirs 0.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 );}%}
Unfortunately I'm only seeing the LEDs for HI and LO light up on the logic probe. When I enter the third state (set pindirs 0), the LO LED still remains lit.

Shouldn't I see the floating state on the logic probe, same as I would on the Arduino? I'm just wondering if I'm struggling with the API here and I've made a mistake in the code somewhere?

Statistics: Posted by SparkyNZ — Sun Oct 13, 2024 1:53 am



Viewing all articles
Browse latest Browse all 5127

Trending Articles