2016-12-02 6 views
0

홀 효과 센서와 유사한 센서를 사용하여 인터럽트 수를 계산합니다. 임의의 시간이 지나면 일반적으로 1-2 시간 동안 켜진 후 재설정되고 임의의 간격으로 무작위로 재설정됩니다. Nodemcu/ESP 8266을 재설정하는 원인은 무엇입니까?

counter = 0; 
sampletime = 0; 
lastrisetime = tmr.now() 
pin = 2 

do 
    gpio.mode(pin, gpio.INT) 

    local function rising(level) 
    -- to eliminate multiple counts during a short period (.5 second) difference is taken 
     if ((tmr.now() - lastrisetime) > 500000) then 
     lastrisetime = tmr.now(); 
    end 
    -- when tmr.now() resets to zero this takes into account that particular count 
    if ((tmr.now() - lastrisetime) < 0) then 
     lastrisetime = tmr.now(); 
    end 
    end 

    local function falling(level) 
    if ((tmr.now() - lastrisetime) > 500000) then 
     -- Only counted when the pin is on falling 
     -- It is like a sine curve so either the peak or trough is counted 
      counter = counter + 1; 
     print(counter) 
     lastrisetime = tmr.now(); 
     sampletime = lastrisetime; 
    end 
    -- when tmr.now() resets to zero this takes into account that particular count 
    if ((tmr.now() - lastrisetime) < 0) then 
     lastrisetime = tmr.now(); 
      counter = counter + 1; 
     print(counter) 
    end 
    end 

    gpio.trig(pin, "up", rising) 
    gpio.trig(pin, "down", falling) 
end 

또한 내가 메모리 시간의 각 한 쌍을 확인하고이 결과를 볼 수 있습니다, 내가 CoolTerm에서 얻을 오류입니다.

NodeMCU 0.9.6 build 20150704 powered by Lua 5.1.4 
> Connecting... 
connected 
print(node.heap()) 
22920 
> print(node.heap()) 
22904 
> print(node.heap()) 
22944 
> print(node.heap()) 
22944 
> 2. .print(node.heap()) 
22944 
> print(node.heap()) 
22944 
> ∆.)ç˛.䂸 ã ¸@H7.àåË‘ 

NodeMCU 0.9.6 build 20150704 powered by Lua 5.1.4 
> Connecting... 
connected 
print(node.heap()) 
21216 
> F.)ç˛.¶Ùå¶[email protected]  .ÊÍ 

NodeMCU 0.9.6 build 20150704 powered by Lua 5.1.4 
> Connecting... 
connected 
H!໩.ä‚D.ã ¸å¶H.åb‘ 

NodeMCU 0.9.6 build 20150704 powered by Lua 5.1.4 
> Connecting... 
connected 
print(node.heap()) 
22904 
> print(node.heap()) 
21216 
> 

시간을내어 읽어 주셔서 감사합니다. 귀하의 의견을 감사하십시오.

+0

이 문제가 해결 되었습니까? 그렇다면 [upvoting/accepting] (https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work) 답을 고려하십시오. –

답변

0

가능한 감시 타이머 문제입니다.

인터럽트 서비스 루틴이 너무 오래 기다리는 것처럼 보입니다.

거기에서 타이밍 작업을 제거하는 것이 플래그를 설정하고 다른 루프에서 플래그 상태를 확인하고 타이밍 작업을 완료하는 것이 좋습니다.

0

NodeMCU 0.9.6 빌드 20150704 첫 번째 것은 정말 NodeMCU 펌웨어의 최신 버전을 사용하는 것입니다 루아 5.1.4

에 의해 구동. 0.9.x는 고대이고 많은 버그가 포함되어 더 이상 지원되지 않습니다. 여기를 참조하십시오 https://github.com/nodemcu/nodemcu-firmware/#releases

lastrisetime = tmr.now()

진짜 문제는 tmr.now() 롤 이상 2,147초에 내가 믿는 것입니다. 내가 proper debounce function에서 일했던 I learned about this.

-- inspired by https://github.com/hackhitchin/esp8266-co-uk/blob/master/tutorials/introduction-to-gpio-api.md 
-- and http://www.esp8266.com/viewtopic.php?f=24&t=4833&start=5#p29127 
local pin = 4 --> GPIO2 

function debounce (func) 
    local last = 0 
    local delay = 50000 -- 50ms * 1000 as tmr.now() has μs resolution 

    return function (...) 
     local now = tmr.now() 
     local delta = now - last 
     if delta < 0 then delta = delta + 2147483647 end; -- proposed because of delta rolling over, https://github.com/hackhitchin/esp8266-co-uk/issues/2 
     if delta < delay then return end; 

     last = now 
     return func(...) 
    end 
end 

function onChange() 
    print('The pin value has changed to '..gpio.read(pin)) 
end 

gpio.mode(pin, gpio.INT, gpio.PULLUP) -- see https://github.com/hackhitchin/esp8266-co-uk/pull/1 
gpio.trig(pin, 'both', debounce(onChange)) 
+0

답변 해 주셔서 감사합니다. 최신 NodeMCU 펌웨어를 판매하는 신뢰할 수있는 소스가 설치되어 있습니까? 나는 플래시를 시도했지만 작동하지 않았고 오래된 Lolin 버전을 판매했다. –

+0

"플래시를 시도했지만 작동하지 않았다"- 그런 다음이를 수정해야합니다. 최신 펌웨어가 필요할 때마다 새로운 dev 키트를 주문하는 것은 지속되지 않습니다. http://nodemcu.readthedocs.io/en/latest/en/flash/ –