Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 5244

General • Re: Help Needed: Achieving Long Delays with PIO for Pump Control on Raspberry Pi Pico

$
0
0
Or, as I would interpret it -

1) Don't do anything until the sensor has read only as full for a period of time
2) Turn the pump on to remove water
3) Keep pumping until the sensor has read only as not full for a period of time
4) Turn the pump off
5) Repeat from 1

You can implement (1) by starting a 'timeout' counter, decrementing that in a loop, and exiting when it hits zero. In (1) you can restart the timeout if the sensor shows not full. For (4) it's the same except you restart the timeout if the sensor shows full.

Using my PIO Assembler that can be coded as -

Code:

def PumpControl():  # Set a timeout period  mov(y, invert(null))  wrap_target()  # Wait until sensor reads full for some time  mov(x, y)             # x = TIMEOUT;  repeat()              # repeat {  dec(x)                #  x = x - 1;  if_(NOT_PIN)          #  if (sensorPinValue() == 0) {  mov(x, y)             #    x = TIMEOUT;  endif()               #  }  until(X_EQ_ZERO)      # } until (x == 0);  # Turn pump on  set(PINS, 1)          # SetPump(1);  # Wait until sensor reads not full for some time  mov(x, y)             # x = TIMEOUT;  repeat()              # repeat {  dec(x)                #  x = x - 1;  if_(PIN)              #  if (sensorPinValue() == 1) {  mov(x, y)             #    x = TIMEOUT;  endif()               #  }  until(X_EQ_ZERO)      # } until (x == 0);  # Turn pump off  set(PINS, 0)          # SetPump(0);  # Repeat forever  wrap()
Which I believe would be the following using the default RP2 PIO Assembler -

Code:

def PumpControl():  mov(y, invert(null))  wrap_target()  mov(x, y)  label("0x02")  jmp(x_dec, "0x03")  label("0x03")  jmp(pin, "0x05")  mov(x, y)  label("0x05")  jmp(not_x, "0x07")  jmp("0x02")  label("0x07")  set(pins, 1)  mov(x, y)  label("0x09")  jmp(x_dec, "0x0A")  label("0x0A")  jmp(pin, "0x0C")  jmp("0x0D")  label("0x0C")  mov(x, y)  label("0x0D")  jmp(not_x, "0x0F")  jmp("0x09")  label("0x0F")  set(pins, 0)  wrap()

Statistics: Posted by hippy — Mon Aug 05, 2024 1:09 pm



Viewing all articles
Browse latest Browse all 5244

Trending Articles