Skip to content

Commit

Permalink
Implement deadtime pwm correction.
Browse files Browse the repository at this point in the history
The correction will be made with a LUT.
Previously this correction had to be made in timer1 interrupt that was stuffed, so it penalized commutation. Now the load is moved to a new state machine the like of dshot_tlm_create_packet.
dshot_tlm_create_packet has been demistified removing obstructing macros.
  • Loading branch information
damosvil committed Feb 24, 2023
1 parent e3b0bae commit 03bd9ce
Show file tree
Hide file tree
Showing 6 changed files with 647 additions and 461 deletions.
14 changes: 10 additions & 4 deletions Bluejay.asm
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,14 @@
;
; Bluejay is a fork of BLHeli_S <https://github.com/bitdump/BLHeli> by Steffen Skaug.
;
; The input signal can be DShot with rates: DShot150, DShot300 and DShot600.
; The input signal can be DShot with rates: DShot300 and DShot600.
;
; This file is best viewed with tab width set to 5.
;
;**** **** **** **** ****
; Master clock is internal 24MHz oscillator (or 48MHz, for which the times below are halved)
; Although 24/48 are used in the code, the exact clock frequencies are 24.5MHz or 49.0 MHz
; Timer0 (41.67ns counts) always counts up and is used for
; - RC pulse measurement
; - DShot telemetry pulse timing
; Timer1 (41.67ns counts) always counts up and is used for
; - DShot frame sync detection
Expand Down Expand Up @@ -290,6 +289,12 @@ Ext_Telemetry_H: DS 1
Scheduler_Counter: DS 1 ; Scheduler Heartbeat
PwmBitsCount: DS 1 ; 0 = 8 bit pwm, 1 = 9 bit pwm, 2 = 10 bit pwm, 3 = 11 bit pwm

DShot_rcpulse_stm_state: DS 1 ; RC pulse state machine state or step
DShot_rcpulse_stm_pwm_t2: DS 1 ; RC pulse state machine temp2
DShot_rcpulse_stm_pwm_t3: DS 1 ; RC pulse state machine temp3
DShot_rcpulse_stm_pwm_t4: DS 1 ; RC pulse state machine temp4
DShot_rcpulse_stm_pwm_t5: DS 1 ; RC pulse state machine temp5

;**** **** **** **** ****
; Indirect addressing data segments
ISEG AT 080h ; The variables below must be in this sequence
Expand Down Expand Up @@ -336,10 +341,10 @@ Pgm_Var_PWM_lo_thres: DS 1 ; Variable PWM low rcpulse threshold
Pgm_Var_PWM_hi_thres: DS 1 ; Variable PWM high rcpulse threshold

ISEG AT 0B0h
Stack: DS 16 ; Reserved stack space
Stack: DS 16 ; Reserved stack space

ISEG AT 0C0h
Dithering_Patterns: DS 16 ; Bit patterns for pwm dithering
Dithering_Patterns: DS 8 ; Unified bit patterns for pwm dithering

ISEG AT 0D0h
Temp_Storage: DS 48 ; Temporary storage (internal memory)
Expand Down Expand Up @@ -426,6 +431,7 @@ Interrupt_Table_Definition ; SiLabs interrupts
CSEG AT 80h ; Code segment after interrupt vectors where Bluejay beggins

; Submodule includes
$include (Bluejay_DtLut.asm)
$include (Bluejay_Isrs.asm)
$include (Bluejay_Fx.asm)
$include (Bluejay_PowerCtl.asm)
Expand Down
24 changes: 4 additions & 20 deletions Bluejay_Common.asm
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,11 @@ ENDM
; Prepare telemetry packet while waiting for Timer3 to wrap
Wait_For_Timer3 MACRO
LOCAL wait_for_t3 done_waiting
jb Flag_Telemetry_Pending, wait_for_t3

jnb Flag_Timer3_Pending, done_waiting
call dshot_rcpulse_stm

jb Flag_Telemetry_Pending, wait_for_t3
jnb Flag_Timer3_Pending, done_waiting
call dshot_tlm_create_packet

Expand All @@ -283,25 +286,6 @@ wait_for_t3:
done_waiting:
ENDM

; Used for subdividing the DShot telemetry routine into chunks,
; that will return if Timer3 has wrapped
Early_Return_Packet_Stage MACRO num
Early_Return_Packet_Stage_ num, %(num + 1)
ENDM

Early_Return_Packet_Stage_ MACRO num next
IF num > 0
inc Temp7 ;; Increment current packet stage
jb Flag_Timer3_Pending, dshot_packet_stage_&num ;; Return early if Timer3 has wrapped
pop PSW
ret
dshot_packet_stage_&num:
ENDIF
IF num < 5
cjne Temp7, #(num), dshot_packet_stage_&next ;; If this is not current stage, skip to next
ENDIF
ENDM

Decode_DShot_2Bit MACRO dest, decode_fail
movx A, @Temp1
mov Temp7, A
Expand Down
Loading

0 comments on commit 03bd9ce

Please sign in to comment.