• Calculate frequencey and pulse width?

    From Samson@jansencomplex@gmail.com to comp.sys.raspberry-pi on Fri Nov 1 07:19:07 2024
    From Newsgroup: comp.sys.raspberry-pi

    Hi, i have this code hos do i calculate the frquency and pulse width?

    from machine import Pin
    from rp2 import PIO, StateMachine, asm_pio
    import time

    led = Pin("LED", Pin.OUT, value=0)

    @asm_pio(set_init=PIO.OUT_LOW)
    def square():
    # Cycles: 1 + 1 + 6 + 32 * (30 + 1) = 1000
    irq(rel(0))
    set(pins, 1)
    set(x, 31) [5]
    label("delay_high")
    nop() [5]
    jmp(x_dec, "delay_high")

    # Cycles: 1 + 7 + 32 * (30 + 1) = 1000
    set(pins, 0)
    set(x, 31) [5]
    label("delay_low")
    nop() [1]
    jmp(x_dec, "delay_low")

    sm = StateMachine(0, square, freq=2000, set_base=Pin(0))

    sm.irq(lambda p: led.toggle())

    sm.active(1)


    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From Lawrence D'Oliveiro@ldo@nz.invalid to comp.sys.raspberry-pi on Fri Nov 1 21:03:03 2024
    From Newsgroup: comp.sys.raspberry-pi

    On Fri, 1 Nov 2024 07:19:07 +0100, Samson wrote:

    [how] do i calculate the frquency and pulse width?

    Let’s see, cycle duration = 1 ÷ frequency, so pulse width must be duty cycle × cycle duration.

    What do I win?
    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From Samson@jansencomplex@gmail.com to comp.sys.raspberry-pi on Sat Nov 2 07:53:23 2024
    From Newsgroup: comp.sys.raspberry-pi

    Den 01-11-2024 kl. 22:03 skrev Lawrence D'Oliveiro:
    On Fri, 1 Nov 2024 07:19:07 +0100, Samson wrote:

    [how] do i calculate the frquency and pulse width?

    Let’s see, cycle duration = 1 ÷ frequency, so pulse width must be duty cycle × cycle duration.

    What do I win?

    Sorry here are more info. The pico limits PWM 8 Hz and up pulse width 1 - 100 % .
    I have this program and i works i understand how it works.


    my problem was understanding >> dup[delay] ?

    =====
    # Example using PIO to blink an LED and raise an IRQ at 1Hz.

    import time
    from machine import Pin
    import rp2


    @rp2.asm_pio(set_init=rp2.PIO.OUT_LOW)
    def blink_1hz():
    # Cycles: 1 + 1 + 6 + 32 * (30 + 1) = 1000
    irq(rel(0))
    set(pins, 1)
    set(x, 31) [5]
    label("delay_high")
    nop() [29]
    jmp(x_dec, "delay_high")

    # Cycles: 1 + 7 + 32 * (30 + 1) = 1000
    set(pins, 0)
    set(x, 31) [6]
    label("delay_low")
    nop() [29]
    jmp(x_dec, "delay_low")


    # Create the StateMachine with the blink_1hz program, outputting on Pin(25).
    sm = rp2.StateMachine(0, blink_1hz, freq=2000, set_base=Pin(25))

    # Set the IRQ handler to print the millisecond timestamp.
    sm.irq(lambda p: print(time.ticks_ms()))

    # Start the StateMachine.
    sm.active(1)

    --- Synchronet 3.20a-Linux NewsLink 1.114