Pyboard basic functions --- Timer

Timer

Timer is one of the most basic functions of an embedded system, a timer may be implemented in addition to its function, but also to achieve a delay, PWM outputs, waveform generator, servo control, metronome, wake-up period, automatic data collection, etc. Features. In MicroPython, many functions are also dependent on the function of the timer.

1. Get Timer class which method:

>>> help(pyb.Timer)
object <class 'Timer'> is of type type
  init -- <function>
  deinit -- <function>
  channel -- <function>
  counter -- <function>
  source_freq -- <function>
  freq -- <function>
  prescaler -- <function>
  period -- <function>
  callback -- <function>
  UP -- 0
  DOWN -- 16
  CENTER -- 32
  PWM -- 0
  PWM_INVERTED -- 1
  OC_TIMING -- 2
  OC_ACTIVE -- 3
  OC_INACTIVE -- 4
  OC_TOGGLE -- 5
  OC_FORCED_ACTIVE -- 6
  OC_FORCED_INACTIVE -- 7
  IC -- 8
  ENC_A -- 9
  ENC_B -- 10
  ENC_AB -- 11
  HIGH -- 0
  LOW -- 2
  RISING -- 0
  FALLING -- 2
  BOTH -- 10
  BRK_OFF -- 0
  BRK_LOW -- 1
  BRK_HIGH -- 2

 The method is used to import Timer timer module, then the parameters defined timer, set the timer ID, frequency, etc. callback function. Such as:

>>> from PYB Import the Timer
 >>> Tim = the Timer (1, FREQ = 100 ) using the timer # 1, the frequency of 100Hz
 >>> Tim = the Timer (. 4, FREQ = 200 is, the callback = Print ( ' Yes ' )) # 4 using the timer, frequency 200hz, and set a callback function 
yes
 >>>

 Insert knowledge points: on-board LED (3) and the LED (4) are light orange and blue light, both of them can be adjusted brightness, the other two (LED (1), LED (2)) is not adaptive brightness difference is that the LED (3) and the LED (4) using the PWM timer to adjust brightness. LED (3) using the timer 2, LED (4) using a timer 3, it can no longer use these two timers when using two light brightness adjustment function, and the program will otherwise expected out of tune.

 LED_YELLOW -- Pin(Pin.cpu.A15, mode=Pin.ALT, af=Pin.AF1_TIM2)
 LED_BLUE -- Pin(Pin.cpu.B4, mode=Pin.ALT, af=Pin.AF2_TIM3)

 (1) Timer (n)

Defined Timer, n = 1 ~ 14.

 

Guess you like

Origin www.cnblogs.com/iBoundary/p/11514209.html