From a78e354c28634e6c5b7c156c147f013c43014275 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Sun, 15 Dec 2024 22:14:45 +0100 Subject: [PATCH] motion: increased signal stability for motion module. --- avr/modules/motion/main.asm | 69 ++++++++++++++++++++----------------- 1 file changed, 38 insertions(+), 31 deletions(-) diff --git a/avr/modules/motion/main.asm b/avr/modules/motion/main.asm index 8920692..5318f2d 100644 --- a/avr/modules/motion/main.asm +++ b/avr/modules/motion/main.asm @@ -10,15 +10,19 @@ .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_3_AFTER = 50 ; repeat motion message after 5s -.equ MOTION_RESTART_AFTER = 150 ; restart motion report counter after 15s +;.equ MOTION_SEND_3_AFTER = 50 ; repeat motion message after 5s +.equ MOTION_RESTART_AFTER = 100 ; restart motion report counter after 10s + + +.equ MOTION_UPCOUNTER_VALUE = 50 .dseg motionDataBegin: -motionCurrentState: .byte 1 +;motionCurrentState: .byte 1 motionStateCounter: .byte 1 +motionUpCounter: .byte 1 motionDataEnd: @@ -60,38 +64,41 @@ Motion_Every100ms: clr r16 sbic MOTION_INPUT, MOTION_PIN inc r16 - ; check against stored state - lds r17, motionCurrentState - cp r16, r17 - brne Motion_Every100ms_stateChanged - ; state not changed tst r16 + brne Motion_Every100ms_up + ; motion pin is inactive, decrement counter + lds r17, motionUpCounter + tst r17 breq Motion_Every100ms_end - ; state unchanged, active motion - lds r16, motionStateCounter - inc r16 - sts motionStateCounter, r16 - cpi r16, MOTION_SEND_1_AFTER - breq Motion_Every100ms_send - cpi r16, MOTION_SEND_2_AFTER - breq Motion_Every100ms_send -; cpi r16, MOTION_SEND_3_AFTER -; breq Motion_Every100ms_send - cpi r16, MOTION_RESTART_AFTER - brne Motion_Every100ms_end - clr r16 - sts motionStateCounter, r16 ; restart motion state counter (thus report again on motion) + dec r17 + sts motionUpCounter, r17 + brne Motion_Every100ms_handleStateCounter + ; reached 0, virtual state is now NO_MOTION + sts motionStateCounter, r17 + ret + +Motion_Every100ms_up: + ; motion is active, keep uptimer up + ldi r17, MOTION_UPCOUNTER_VALUE + sts motionUpCounter, r17 + +Motion_Every100ms_handleStateCounter: + 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 -Motion_Every100ms_stateChanged: - sts motionCurrentState, r16 - clr r16 - sts motionStateCounter, r16 - ret ; only send according to timers above Motion_Every100ms_send: - lds r18, motionCurrentState - ; only send if state is != 0 - tst r18 - breq Motion_Every100ms_end + ldi r18, 1 rjmp Motion_SendReport Motion_Every100ms_end: ret