MM32F3277 MicroPython 的定时器功能
        【摘要】 
                    
                        
                    
                     
 
 简 介: 对于SuYong发送过来的带有Timer功能版本的MicroPython进行了测试。在新版的MicroPython中,可以最多定义两个不同频率的定时器中断,完成对于周期时间的控制和输出...
    
    
    
    
简 介: 对于SuYong发送过来的带有Timer功能版本的MicroPython进行了测试。在新版的MicroPython中,可以最多定义两个不同频率的定时器中断,完成对于周期时间的控制和输出。这一点在很多数字控制系统中应用比较重要。
关键词: MM32,Timer,MicroPython
 
  §01 MM32F3277 
    MicroPython 
  
MicroPython
今天收到 MindMotion SuYong发送过来的MM32F3277 带有Timer的MicroPython的版本。下面对于这个版本进行测试。
一、测试基本功能
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
#============================================================
  
 - 1
 - 2
 - 3
 - 4
 - 5
 - 6
 - 7
 - 8
 - 9
 - 10
 - 11
 - 12
 - 13
 - 14
 - 15
 - 16
 - 17
 - 18
 - 19
 
2、测试结果
>> Reset MicroPython...
>> Wait for MicroPython coming back...
>> Download MicroPython : 27 lines/657 characters.
>> -------------------------------------------------------------------------
Test Timer.
  
 - 1
 - 2
 - 3
 - 4
 - 5
 - 6
 
二、两个Timer
1、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 ,
};
  
 - 1
 - 2
 - 3
 - 4
 - 5
 - 6
 - 7
 - 8
 - 9
 - 10
 
在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
  
 - 1
 - 2
 - 3
 - 4
 - 5
 - 6
 - 7
 - 8
 - 9
 - 10
 - 11
 - 12
 - 13
 - 14
 - 15
 - 16
 - 17
 - 18
 - 19
 - 20
 - 21
 
3、测试结果
可以看到两个不同频率间隔的Timer可以独自完成输出文字,闪烁LED等。
 
  ※ 测试总结 ※ 
  
对于SuYong发送过来的带有Timer功能版本的MicroPython进行了测试。在新版的MicroPython中,可以最多定义两个不同频率的定时器中断,完成对于周期时间的控制和输出。这一点在很多数字控制系统中应用比较重要。
文章来源: zhuoqing.blog.csdn.net,作者:卓晴,版权归原作者所有,如需转载,请联系作者。
原文链接:zhuoqing.blog.csdn.net/article/details/121616248
        【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
            cloudbbs@huaweicloud.com
        
        
        
        
        
        
        - 点赞
 - 收藏
 - 关注作者
 
            
           
评论(0)