Made two minimal, surgical fixes to stabilize ON/OFF splitting.

What I changed

  - Core/Inc/main.h:76
      - Set ADC_BUFF_SIZE from 50 to 64 so each half is even (32). This keeps the “i &
        1” parity consistent across half-buffer boundaries.
  - Core/Src/stm32f4xx_it.c:388
      - Fixed N after splitting the first half: ADC_proc.N = (ADC_BUFF_SIZE/2 -
        Sweep_state.curr_step_start_DMA_N)/2;
      - Previously it used (Sweep_state.curr_step_start_DMA_N)/2, which was wrong for
        that segment.

  Why this helps

  - With ADC_BUFF_SIZE=50, half-size is 25 (odd). That flips ON/OFF labeling each half
    because i & 1 parity shifts by 25, mixing levels and driving avg_ON and avg_OFF
    together.
  - The N bug skewed normalization, further flattening differences between averages.

  How to verify

  - Build and flash: make && make flash.
  - Observe avg_ON/avg_OFF over CDC. They should now differ consistently; inverting
    meандр should swap them cleanly.
  - If still needed, I can add a global sample counter (sample_seq) for fully robust
    ON/OFF classification without relying on buffer indices.
This commit is contained in:
2025-12-19 23:41:15 +03:00
parent 186ad1939a
commit 985dbcc87b
18 changed files with 2868 additions and 2866 deletions

View File

@ -1,4 +1,4 @@
ARM GAS /tmp/cc1D1X2d.s page 1
ARM GAS /tmp/ccMtDEwH.s page 1
1 .cpu cortex-m4
@ -58,7 +58,7 @@ ARM GAS /tmp/cc1D1X2d.s page 1
28:USB_DEVICE/App/usb_device.c ****
29:USB_DEVICE/App/usb_device.c **** /* USER CODE BEGIN Includes */
30:USB_DEVICE/App/usb_device.c ****
ARM GAS /tmp/cc1D1X2d.s page 2
ARM GAS /tmp/ccMtDEwH.s page 2
31:USB_DEVICE/App/usb_device.c **** /* USER CODE END Includes */
@ -118,7 +118,7 @@ ARM GAS /tmp/cc1D1X2d.s page 1
42 0006 1048 ldr r0, .L11+4
43 0008 FFF7FEFF bl USBD_Init
44 .LVL0:
ARM GAS /tmp/cc1D1X2d.s page 3
ARM GAS /tmp/ccMtDEwH.s page 3
45 .loc 1 71 6 discriminator 1 view .LVU3
@ -178,7 +178,7 @@ ARM GAS /tmp/cc1D1X2d.s page 1
78 002c FFF7FEFF bl Error_Handler
79 .LVL4:
80 0030 EDE7 b .L2
ARM GAS /tmp/cc1D1X2d.s page 4
ARM GAS /tmp/ccMtDEwH.s page 4
81 .L8:
@ -227,16 +227,16 @@ ARM GAS /tmp/cc1D1X2d.s page 1
120 .file 6 "USB_DEVICE/App/usbd_cdc_if.h"
121 .file 7 "Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_core.h"
122 .file 8 "Core/Inc/main.h"
ARM GAS /tmp/cc1D1X2d.s page 5
ARM GAS /tmp/ccMtDEwH.s page 5
DEFINED SYMBOLS
*ABS*:00000000 usb_device.c
/tmp/cc1D1X2d.s:21 .text.MX_USB_DEVICE_Init:00000000 $t
/tmp/cc1D1X2d.s:27 .text.MX_USB_DEVICE_Init:00000000 MX_USB_DEVICE_Init
/tmp/cc1D1X2d.s:100 .text.MX_USB_DEVICE_Init:00000044 $d
/tmp/cc1D1X2d.s:112 .bss.hUsbDeviceFS:00000000 hUsbDeviceFS
/tmp/cc1D1X2d.s:109 .bss.hUsbDeviceFS:00000000 $d
/tmp/ccMtDEwH.s:21 .text.MX_USB_DEVICE_Init:00000000 $t
/tmp/ccMtDEwH.s:27 .text.MX_USB_DEVICE_Init:00000000 MX_USB_DEVICE_Init
/tmp/ccMtDEwH.s:100 .text.MX_USB_DEVICE_Init:00000044 $d
/tmp/ccMtDEwH.s:112 .bss.hUsbDeviceFS:00000000 hUsbDeviceFS
/tmp/ccMtDEwH.s:109 .bss.hUsbDeviceFS:00000000 $d
UNDEFINED SYMBOLS
USBD_Init