home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.sys.raspberry-pi      Raspberry Pi computers & related hardwar      26,127 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 25,137 of 26,127   
   Samson to All   
   Calculate frequencey and pulse width?   
   01 Nov 24 07:19:07   
   
   From: jansencomplex@gmail.com   
      
   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)   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca