打印
[MM32硬件]

MM32F3277 MicroPython 的定时器功能

[复制链接]
796|3
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
磨砂|  楼主 | 2021-12-27 12:12 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

一、测试基本功能1、测试代码

#!/usr/local/bin/python
# -*- coding: gbk -*-
#============================================================
# TEST1.PY                     -- by Dr. ZhuoQing 2021-11-29
#
# Note:
#============================================================
from machine                import Pin,Timer
import utime
led0 = Pin('PB2', mode=Pin.OUT_PUSHPULL)
print("Test Timer.")
def t0_callback(self):
    led0(1-led0())
t0 = Timer(0, mode=Timer.PERIODIC, callback=t0_callback, period=100)
while True:
    pass
#------------------------------------------------------------
#        END OF FILE : TEST1.PY
#============================================================



2、测试结果
>> Reset MicroPython...
>> Wait for MicroPython coming back...
>> Download MicroPython : 27 lines/657 characters.
>> -------------------------------------------------------------------------

Test Timer.


使用特权

评论回复
沙发
磨砂|  楼主 | 2021-12-27 12:13 | 只看该作者

二、两个Timer1、Timer个数
在现在的版本中,只有两个Timer可以用。
machine_timer_conf_t timer_conf[MACHINE_TIMER_NUM];

const machine_timer_obj_t timer0 = {.base = {&machine_timer_type}, .timer_port = TIM6, .timer_irqn = TIM6_IRQn, .timer_id = 0u, .conf = &timer_conf[0]};
const machine_timer_obj_t timer1 = {.base = {&machine_timer_type}, .timer_port = TIM7, .timer_irqn = TIM7_IRQn, .timer_id = 1u, .conf = &timer_conf[1]};

const machine_timer_obj_t * machine_timer_objs[] =
{
    &timer0 ,
    &timer1 ,
};


在MM32F3277上共有八个TIM模块,其中两个给了Timer, 四个给了PWM,两个给Encoder。


2、测试两个Timer
from machine                import Pin,Timer
import utime
import math


led0 = Pin('PB2', mode=Pin.OUT_PUSHPULL)


print("Test Timer.")


def t0_callback(self):
    led0(1-led0())


count = 1
def t1_callback(self):
    global count
    print(math.sin(count*math.pi/100))
    count += 1


t0 = Timer(0, mode=Timer.PERIODIC, callback=t0_callback, period=100)
t1 = Timer(1, mode=Timer.PERIODIC, callback=t1_callback, period=500)
while True:
    pass


3、测试结果


 可以看到两个不同频率间隔的Timer可以独自完成输出文字,闪烁LED等。


使用特权

评论回复
板凳
七毛钱| | 2021-12-27 14:30 | 只看该作者
过来了解一下测试过程

使用特权

评论回复
地板
asmine| | 2021-12-27 14:43 | 只看该作者
能讲详细点么?给小白点机会

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

85

主题

3886

帖子

2

粉丝