motion: increased signal stability for motion module.
This commit is contained in:
@@ -10,15 +10,19 @@
|
|||||||
|
|
||||||
.equ MOTION_SEND_1_AFTER = 1 ; send motion message after 100ms
|
.equ MOTION_SEND_1_AFTER = 1 ; send motion message after 100ms
|
||||||
.equ MOTION_SEND_2_AFTER = 11 ; send motion message after 1100ms
|
.equ MOTION_SEND_2_AFTER = 11 ; send motion message after 1100ms
|
||||||
.equ MOTION_SEND_3_AFTER = 50 ; repeat motion message after 5s
|
;.equ MOTION_SEND_3_AFTER = 50 ; repeat motion message after 5s
|
||||||
.equ MOTION_RESTART_AFTER = 150 ; restart motion report counter after 15s
|
.equ MOTION_RESTART_AFTER = 100 ; restart motion report counter after 10s
|
||||||
|
|
||||||
|
|
||||||
|
.equ MOTION_UPCOUNTER_VALUE = 50
|
||||||
|
|
||||||
|
|
||||||
.dseg
|
.dseg
|
||||||
|
|
||||||
motionDataBegin:
|
motionDataBegin:
|
||||||
motionCurrentState: .byte 1
|
;motionCurrentState: .byte 1
|
||||||
motionStateCounter: .byte 1
|
motionStateCounter: .byte 1
|
||||||
|
motionUpCounter: .byte 1
|
||||||
motionDataEnd:
|
motionDataEnd:
|
||||||
|
|
||||||
|
|
||||||
@@ -60,38 +64,41 @@ Motion_Every100ms:
|
|||||||
clr r16
|
clr r16
|
||||||
sbic MOTION_INPUT, MOTION_PIN
|
sbic MOTION_INPUT, MOTION_PIN
|
||||||
inc r16
|
inc r16
|
||||||
; check against stored state
|
|
||||||
lds r17, motionCurrentState
|
|
||||||
cp r16, r17
|
|
||||||
brne Motion_Every100ms_stateChanged
|
|
||||||
; state not changed
|
|
||||||
tst r16
|
tst r16
|
||||||
|
brne Motion_Every100ms_up
|
||||||
|
; motion pin is inactive, decrement counter
|
||||||
|
lds r17, motionUpCounter
|
||||||
|
tst r17
|
||||||
breq Motion_Every100ms_end
|
breq Motion_Every100ms_end
|
||||||
; state unchanged, active motion
|
dec r17
|
||||||
lds r16, motionStateCounter
|
sts motionUpCounter, r17
|
||||||
inc r16
|
brne Motion_Every100ms_handleStateCounter
|
||||||
sts motionStateCounter, r16
|
; reached 0, virtual state is now NO_MOTION
|
||||||
cpi r16, MOTION_SEND_1_AFTER
|
sts motionStateCounter, r17
|
||||||
breq Motion_Every100ms_send
|
ret
|
||||||
cpi r16, MOTION_SEND_2_AFTER
|
|
||||||
breq Motion_Every100ms_send
|
Motion_Every100ms_up:
|
||||||
; cpi r16, MOTION_SEND_3_AFTER
|
; motion is active, keep uptimer up
|
||||||
; breq Motion_Every100ms_send
|
ldi r17, MOTION_UPCOUNTER_VALUE
|
||||||
cpi r16, MOTION_RESTART_AFTER
|
sts motionUpCounter, r17
|
||||||
brne Motion_Every100ms_end
|
|
||||||
clr r16
|
Motion_Every100ms_handleStateCounter:
|
||||||
sts motionStateCounter, r16 ; restart motion state counter (thus report again on motion)
|
tst r17 ; motionUpCounter?
|
||||||
|
breq Motion_Every100ms_end ; 0, jmp
|
||||||
|
lds r17, motionStateCounter
|
||||||
|
inc r17
|
||||||
|
sts motionStateCounter, r17
|
||||||
|
cpi r17, MOTION_SEND_1_AFTER
|
||||||
|
breq Motion_Every100ms_send
|
||||||
|
cpi r17, MOTION_SEND_2_AFTER
|
||||||
|
breq Motion_Every100ms_send
|
||||||
|
cpi r17, MOTION_RESTART_AFTER
|
||||||
|
brne Motion_Every100ms_end
|
||||||
|
clr r17 ; restart counter
|
||||||
|
sts motionStateCounter, r17
|
||||||
ret
|
ret
|
||||||
Motion_Every100ms_stateChanged:
|
|
||||||
sts motionCurrentState, r16
|
|
||||||
clr r16
|
|
||||||
sts motionStateCounter, r16
|
|
||||||
ret ; only send according to timers above
|
|
||||||
Motion_Every100ms_send:
|
Motion_Every100ms_send:
|
||||||
lds r18, motionCurrentState
|
ldi r18, 1
|
||||||
; only send if state is != 0
|
|
||||||
tst r18
|
|
||||||
breq Motion_Every100ms_end
|
|
||||||
rjmp Motion_SendReport
|
rjmp Motion_SendReport
|
||||||
Motion_Every100ms_end:
|
Motion_Every100ms_end:
|
||||||
ret
|
ret
|
||||||
|
|||||||
Reference in New Issue
Block a user