logo

关于定时器中断函数内产生MemoryError的问题

2019-07-30 17:29
0
z25g

OpenMV4在定时器中断中调用一些简单的函数或者使能其他的定时器中断就会报错(MemoryError),请问这个问题怎么解决。

如图,我在定时器2里面使能了定时器7,然后程序跑到使能定时器7的这段代码里就会报错(MemoryError)。

请问这种问题怎么才能解决,难道中断里面稍微写两句话都会使内存溢出吗?

a991c83b-f007-4361-ae90-6d2ac89cf651.png
f86fd9ce-99fa-48c3-b0b2-9500aad8a261.png
2019-07-30 17:37
0
z25g
import image, math,pyb, sensor, struct, time
from pyb import UART

global interrupt7_land
interrupt7_land = 0

def timer_interrupt2(timer):
    if (work_mode == 0x00) :
        pyb.LED(1).toggle()
    else :
        pyb.LED(1).off()
        #print(2)
        if (work_mode == 0x41):
            #print(1)
            tim7 = pyb.Timer(7 ,freq = 1)
            tim7.callback(timer_interrupt7)

def timer_interrupt7(timer):
    global interrupt7_land
    interrupt7_land = 1
    print("ZPJ_COOL")

tim2 = pyb.Timer(2 ,freq = 300)
tim2.callback(timer_interrupt2)
work_mode = 0x41
2019-07-31 15:25
I
网红小智智 星瞳科技

中断服务函数里面,不能有局部变量。

I
网红小智智 星瞳科技

你的work_mode, pyb, tim7都要加global