I assume this must be a software problem so I tried a few different releases of micropython but I have the same behavior with each.
Perhaps someone could shed some light on this or perhaps test it in their environment?
I've added the print() and disable/enable_irq calls while debugging this and they seem to make no difference.
Thanks -Bob
apologies, code formatting doesn't seem to be working. code is indented as expected.
Code: Select all
from time import sleep_us
from machine import Pin
from machine import disable_irq, enable_irq
def up_swcb(p):
irq_state = disable_irq()
global direction, trigger
trigger = 0
direction = 1
print('up switch callback')
enable_irq(irq_state)
def down_swcb(p):
irq_state = disable_irq()
global direction, trigger
trigger = 0
direction = -1
print('down switch callback')
enable_irq(irq_state)
up_sw = Pin(2, Pin.IN, Pin.PULL_UP)
down_sw = Pin(0, Pin.IN, Pin.PULL_UP)
up_sw.irq(trigger=Pin.IRQ_FALLING, handler=up_swcb)
down_sw.irq(trigger=Pin.IRQ_FALLING, handler=down_swcb)
while True:
sleep_us(1000)
Code: Select all
MicroPython v1.8.3-dirty on 2016-11-06; ESP module with ESP8266
Type "help()" for more information.
>>>
paste mode; Ctrl-C to cancel, Ctrl-D to finish
=== from time import sleep_us
=== from machine import Pin
=== from machine import disable_irq, enable_irq
===
=== def up_swcb(p):
=== irq_state = disable_irq()
=== global direction, trigger
=== trigger = 0
=== direction = 1
=== print('up switch callback')
=== enable_irq(irq_state)
===
=== def down_swcb(p):
=== irq_state = disable_irq()
=== global direction, trigger
=== trigger = 0
=== direction = -1
=== print('down switch callback')
=== enable_irq(irq_state)
===
=== up_sw = Pin(2, Pin.IN, Pin.PULL_UP)
=== down_sw = Pin(0, Pin.IN, Pin.PULL_UP)
===
=== up_sw.irq(trigger=Pin.IRQ_FALLING, handler=up_swcb)
=== down_sw.irq(trigger=Pin.IRQ_FALLING, handler=down_swcb)
===
=== while True:
=== sleep_us(1000)
===
<IRQ>
<IRQ>
up switch callback
up switch callback
down switch callback
up switch callback
down switch callback
up switch callback
down switch callback
up switch callback
down switch callback
up switch callback
down switch callback
up switch callback
MicroPython v1.8.4 on 2016-11-06; ESP module with ESP8266
Type "help()" for more information.
>>>
paste mode; Ctrl-C to cancel, Ctrl-D to finish
=== from time import sleep_us
=== from machine import Pin
=== from machine import disable_irq, enable_irq
===
=== def up_swcb(p):
=== irq_state = disable_irq()
=== global direction, trigger
=== trigger = 0
=== direction = 1
=== print('up switch callback')
=== enable_irq(irq_state)
===
=== def down_swcb(p):
=== irq_state = disable_irq()
=== global direction, trigger
=== trigger = 0
=== direction = -1
=== print('down switch callback')
=== enable_irq(irq_state)
===
=== up_sw = Pin(2, Pin.IN, Pin.PULL_UP)
=== down_sw = Pin(0, Pin.IN, Pin.PULL_UP)
===
=== up_sw.irq(trigger=Pin.IRQ_FALLING, handler=up_swcb)
=== down_sw.irq(trigger=Pin.IRQ_FALLING, handler=down_swcb)
===
=== while True:
=== sleep_us(1000)
===
<IRQ>
<IRQ>
down switch callback
up switch callback
down switch callback
up switch callback
up switch callback
down switch callback
up switch callback
down switch callback
up switch callback
down switch callback
up switch callback
down switch callback
up switch callback
down switch callback
up switch callback
MicroPython v1.8.5 on 2016-11-06; ESP module with ESP8266
Type "help()" for more information.
>>>
paste mode; Ctrl-C to cancel, Ctrl-D to finish
=== from time import sleep_us
=== from machine import Pin
=== from machine import disable_irq, enable_irq
===
=== def up_swcb(p):
=== irq_state = disable_irq()
=== global direction, trigger
=== trigger = 0
=== direction = 1
=== print('up switch callback')
=== enable_irq(irq_state)
===
=== def down_swcb(p):
=== irq_state = disable_irq()
=== global direction, trigger
=== trigger = 0
=== direction = -1
=== print('down switch callback')
=== enable_irq(irq_state)
===
=== up_sw = Pin(2, Pin.IN, Pin.PULL_UP)
=== down_sw = Pin(0, Pin.IN, Pin.PULL_UP)
===
=== up_sw.irq(trigger=Pin.IRQ_FALLING, handler=up_swcb)
=== down_sw.irq(trigger=Pin.IRQ_FALLING, handler=down_swcb)
===
=== while True:
=== sleep_us(1000)
===
<IRQ>
<IRQ>
down switch callback
up switch callback
up switch callback
down switch callback
up switch callback
down switch callback
up switch callback
up switch callback
up switch callback
up switch callback
down switch callback
up switch callback
down switch callback
up switch callback
with sdk 2.0
MicroPython v1.8.5-122-g8f068e8 on 2016-11-06; ESP module with ESP8266
Type "help()" for more information.
>>>
paste mode; Ctrl-C to cancel, Ctrl-D to finish
=== from time import sleep_us
=== from machine import Pin
=== from machine import disable_irq, enable_irq
===
=== def up_swcb(p):
=== irq_state = disable_irq()
=== global direction, trigger
=== trigger = 0
=== direction = 1
=== print('up switch callback')
=== enable_irq(irq_state)
===
=== def down_swcb(p):
=== irq_state = disable_irq()
=== global direction, trigger
=== trigger = 0
=== direction = -1
=== print('down switch callback')
=== enable_irq(irq_state)
===
=== up_sw = Pin(2, Pin.IN, Pin.PULL_UP)
=== down_sw = Pin(0, Pin.IN, Pin.PULL_UP)
===
=== up_sw.irq(trigger=Pin.IRQ_FALLING, handler=up_swcb)
=== down_sw.irq(trigger=Pin.IRQ_FALLING, handler=down_swcb)
===
=== while True:
=== sleep_us(1000)
===
<IRQ>
<IRQ>
up switch callback
down switch callback
up switch callback
down switch callback
up switch callback
up switch callback
down switch callback
up switch callback
down switch callback
up switch callback
down switch callback