Skip to content

Commit 362f676

Browse files
Fix quadrature_encoder examples on rp2350 (#551)
Have to initialise the gpio function for rp2350. Stop the quadrature_encoder example spamming sdio if nothing has changed. Change the pins used for quadrature_encoder_substep so they match the other example. Fixes #550
1 parent 40d2476 commit 362f676

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

pio/quadrature_encoder/quadrature_encoder.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,14 @@
3434

3535
int main() {
3636
int new_value, delta, old_value = 0;
37+
int last_value = -1, last_delta = -1;
3738

3839
// Base pin to connect the A phase of the encoder.
3940
// The B phase must be connected to the next pin
4041
const uint PIN_AB = 10;
4142

4243
stdio_init_all();
44+
printf("Hello from quadrature encoder\n");
4345

4446
PIO pio = pio0;
4547
const uint sm = 0;
@@ -56,7 +58,11 @@ int main() {
5658
delta = new_value - old_value;
5759
old_value = new_value;
5860

59-
printf("position %8d, delta %6d\n", new_value, delta);
61+
if (new_value != last_value || delta != last_delta ) {
62+
printf("position %8d, delta %6d\n", new_value, delta);
63+
last_value = new_value;
64+
last_delta = delta;
65+
}
6066
sleep_ms(100);
6167
}
6268
}

pio/quadrature_encoder/quadrature_encoder.pio

+3
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ increment_cont:
9999
static inline void quadrature_encoder_program_init(PIO pio, uint sm, uint pin, int max_step_rate)
100100
{
101101
pio_sm_set_consecutive_pindirs(pio, sm, pin, 2, false);
102+
pio_gpio_init(pio, pin);
103+
pio_gpio_init(pio, pin + 1);
104+
102105
gpio_pull_up(pin);
103106
gpio_pull_up(pin + 1);
104107

pio/quadrature_encoder_substep/quadrature_encoder_substep.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -368,9 +368,10 @@ int main(void)
368368

369369
// base pin to connect the A phase of the encoder. the B phase must be
370370
// connected to the next pin
371-
const uint PIN_A = 2;
371+
const uint PIN_A = 10;
372372

373373
stdio_init_all();
374+
printf("Hello from quadrature encoder substep\n");
374375

375376
PIO pio = pio0;
376377
const uint sm = 0;

pio/quadrature_encoder_substep/quadrature_encoder_substep.pio

+2
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ invalid:
133133
static inline void quadrature_encoder_substep_program_init(PIO pio, uint sm, uint pin_A)
134134
{
135135
uint pin_state, position, ints;
136+
pio_gpio_init(pio, pin_A);
137+
pio_gpio_init(pio, pin_A + 1);
136138

137139
pio_sm_set_consecutive_pindirs(pio, sm, pin_A, 2, false);
138140
gpio_pull_up(pin_A);

0 commit comments

Comments
 (0)