I generate a frame on the pin X9/PB6 :
- During 3000 ms, X9 = 1b
- During 500 ms, X9 = 0b
- During 1500 ms, X9 = 1b
- During 500 ms, X9 = 0b
- During 1500 ms, X9 = 1b
...
I tried :
- with pin.value([True|False]) : it's OK
- with pin.[high|low]() : it's OK
- with assembly code asm_[set|clear]_x9() : it's KO !!!
---> The functions pyb.delay(500) and pyb.delay(1500) are swapped during the execution of the code.
Is it an error from me?
Best Regards.
Code: Select all
#*******************************************************************************
# IMPORT ***********************************************************************
#*******************************************************************************
import pyb
import machine
import stm
#*******************************************************************************
# GLOBAL ***********************************************************************
#*******************************************************************************
# pin X9/PB6
g_pin_x9 = pyb.Pin.board.X9
g_pin_x9.init(pyb.Pin.OUT_PP, pull = pyb.Pin.PULL_UP, af = -1)
# standby value = 1b
g_pin_x9.value(True)
#*******************************************************************************
# DEF ******************************************************************-*******
#*******************************************************************************
# -- asm_set_x9 ----------------------------------------------------------------
#
# Description : pin X9/PB6 = 1b
#
# Parameters :
#
# Return :
#
# Notes :
#
@micropython.asm_thumb
def asm_set_x9() :
movw(r0, 1 << 6)
movwt(r1, stm.GPIOB)
strh(r0, [r1, stm.GPIO_BSRRH])
# -- asm_clear_x9 --------------------------------------------------------------
#
# Description : pin X9/PB6 = 0b
#
# Parameters :
#
# Return :
#
# Notes :
#
@micropython.asm_thumb
def asm_clear_x9() :
movw(r0, 1 << 6)
movwt(r1, stm.GPIOB)
strh(r0, [r1, stm.GPIO_BSRRL])
#*******************************************************************************
# MAIN *************************************************************************
#*******************************************************************************
# test with pin.value(True) / pin.value(False) : OK
#
# ! ! ! ! ! ! ! ! ! ! ! ! ! !
# ......_________ ________ ________
# ...... |__| |__| |....
# in ms: 3000 500 1500 500 1500 500
#
if 0 :
pyb.delay(3000)
for i in range(30) :
# X9/PB6 = False
g_pin_x9.value(False)
pyb.delay(500)
# X9/PB6 = True
g_pin_x9.value(True)
pyb.delay(1500)
# test with pin.high() / pin.low() : OK
#
# ! ! ! ! ! ! ! ! ! ! ! ! ! !
# ......_________ ________ ________
# ...... |__| |__| |....
# in ms: 3000 500 1500 500 1500 500
#
if 0 :
pyb.delay(3000)
for i in range(30) :
# X9/PB6 = low
g_pin_x9.low()
pyb.delay(500)
# X9/PB6 = high
g_pin_x9.high()
pyb.delay(1500)
# test with asm_set_x9() and asm_clear_x9() : KO
#
# ! ! ! ! ! ! ! ! ! ! ! ! ! !
# ......_________ __ __
# ...... |________| |________| |....
# in ms: 3000 1500 500 1500 500
#
if 1 :
pyb.delay(3000)
for i in range(30) :
# X9/PB6 = 0b
asm_clear_x9()
pyb.delay(500)
# X9/PB6 = 1b
asm_set_x9()
pyb.delay(1500)