Download Print this page

Pwm - Raspberry Pi Pico Python SDK Manual

A micropython environment for rp2040 microcontrollers

Advertisement

Raspberry Pi Pico Python SDK
 
programmable frame size
18
in_(pins, 1)
19
jmp(not_osre, "bitloop") .side(0x1)
20
21
nop()
22
wrap()
23
24
25
class
26
27
def
=1000000):
28
29
pin_sck), out_base=Pin(pin_mosi), in_base=Pin(pin_sck))
30
31
32
# Note this code will die spectacularly cause we're not draining the RX FIFO
33
def
34
35
36
37
def
38
39
40
41
42
43
def
44
45
46
47
48
NOTE
This SPI program supports programmable frame sizes (by holding the reload value for X counter in the Y register) but
currently this can't be used, because the autopull threshold is associated with the program, instead of the SM
instantiation.

3.9.5. PWM

A PWM example,
Pico MicroPython Examples:
 1
# Example of using PIO for PWM, and fading the brightness of an LED
 2
 3
from
 4
from
 5
from
 6
 7
 8 @asm_pio(sideset_init=PIO.OUT_LOW)
 9
def
pwm_prog():
10
pull(noblock) .side(0)
11
mov(x, osr)
12
mov(y, isr)
3.9. PIO Support
.side(0x1)
.side(0x0)
PIOSPI:
__init__(self, sm_id, pin_mosi, pin_miso, pin_sck, cpha=False, cpol=False, freq
assert(not(cpol or cpha))
self._sm = rp2.StateMachine(sm_id, spi_cpha0, freq=4*freq, sideset_base=Pin(
self._sm.active(1)
write_blocking(wdata):
for
b in wdata:
self._sm.put(b << 24)
read_blocking(n):
data = []
for
i in range(n):
data.append(self._sm.get() & 0xff)
return
data
write_read_blocking(wdata):
rdata = []
for
b in wdata:
self._sm.put(b << 24)
rdata.append(self._sm.get() & 0xff)
return
rdata
https://github.com/raspberrypi/pico-micropython-examples/tree/master/pio/pio_pwm.py
machine
import
Pin
rp2
import
PIO, StateMachine, asm_pio
time
import
sleep
# Keep most recent pull data stashed in X, for recycling by noblock
# ISR must be preloaded with PWM count max
# Fallthru if TXF empties
[1]
# CSn back porch
Lines 1 - 43
24

Advertisement

loading
Need help?

Need help?

Do you have a question about the Pico Python SDK and is the answer not in the manual?

Subscribe to Our Youtube Channel

This manual is also suitable for:

Pico seriesPico 2