Skip to content

Commit

Permalink
fix: Make inverted comparator output work on BB1
Browse files Browse the repository at this point in the history
This bug made the O-L-* ESC layouts not work
  • Loading branch information
mathiasvr committed Aug 21, 2021
1 parent 0f54d76 commit 3ffc6b4
Show file tree
Hide file tree
Showing 24 changed files with 29 additions and 14 deletions.
1 change: 1 addition & 0 deletions Layouts/A.inc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ PWM_ACTIVE_HIGH EQU 1 ; Pwm non-inverted
COM_ACTIVE_HIGH EQU 1 ; Damping inverted

COMPARATOR_PORT EQU 0 ; All comparator (mux) pins must be on the same port
COMPARATOR_INVERT EQU 0 ; Comparator output non-inverted

IF DEADTIME == 0
PCA0CPM_POWER EQU PCA0CPM0
Expand Down
1 change: 1 addition & 0 deletions Layouts/B.inc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ PWM_ACTIVE_HIGH EQU 1 ; Pwm non-inverted
COM_ACTIVE_HIGH EQU 1 ; Damping inverted

COMPARATOR_PORT EQU 0 ; All comparator (mux) pins must be on the same port
COMPARATOR_INVERT EQU 0 ; Comparator output non-inverted

IF DEADTIME == 0
PCA0CPM_POWER EQU PCA0CPM0
Expand Down
10 changes: 6 additions & 4 deletions Layouts/Base.inc
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,19 @@ CMP_MD EQU CMP1MD
CMP_MX EQU CMP1MX
ENDIF

$if NOT CUSTOM_COMPARATOR_SETUP

Initialize_Comparator MACRO
mov CMP_CN0, #80h ;; Comparator enabled, no hysteresis
mov CMP_MD, #00h ;; Comparator response time 100ns
IF COMPARATOR_INVERT == 1 AND MCU_48MHZ == 1
mov CMP_MD, #40h ;; Output polarity inverted (Only supported on BB2)
ENDIF
ENDM

$endif

Read_Comparator_Output MACRO
mov A, CMP_CN0 ;; Read comparator output
IF COMPARATOR_INVERT == 1 AND MCU_48MHZ == 0
cpl A ;; Invert output polarity manually on BB1
ENDIF
ENDM

; Set comparator multiplexer to phase A
Expand Down
1 change: 1 addition & 0 deletions Layouts/C.inc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ PWM_ACTIVE_HIGH EQU 1 ; Pwm non-inverted
COM_ACTIVE_HIGH EQU 1 ; Damping inverted

COMPARATOR_PORT EQU 0 ; All comparator (mux) pins must be on the same port
COMPARATOR_INVERT EQU 0 ; Comparator output non-inverted

IF DEADTIME == 0
PCA0CPM_POWER EQU PCA0CPM0
Expand Down
1 change: 1 addition & 0 deletions Layouts/D.inc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ PWM_ACTIVE_HIGH EQU 1 ; Pwm non-inverted
COM_ACTIVE_HIGH EQU 0 ; Damping non-inverted

COMPARATOR_PORT EQU 0 ; All comparator (mux) pins must be on the same port
COMPARATOR_INVERT EQU 0 ; Comparator output non-inverted

IF DEADTIME == 0
PCA0CPM_POWER EQU PCA0CPM0
Expand Down
1 change: 1 addition & 0 deletions Layouts/E.inc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ PWM_ACTIVE_HIGH EQU 1 ; Pwm non-inverted
COM_ACTIVE_HIGH EQU 1 ; Damping inverted

COMPARATOR_PORT EQU 0 ; All comparator (mux) pins must be on the same port
COMPARATOR_INVERT EQU 0 ; Comparator output non-inverted

IF DEADTIME == 0
PCA0CPM_POWER EQU PCA0CPM0
Expand Down
1 change: 1 addition & 0 deletions Layouts/F.inc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ PWM_ACTIVE_HIGH EQU 1 ; Pwm non-inverted
COM_ACTIVE_HIGH EQU 1 ; Damping inverted

COMPARATOR_PORT EQU 0 ; All comparator (mux) pins must be on the same port
COMPARATOR_INVERT EQU 0 ; Comparator output non-inverted

IF DEADTIME == 0
PCA0CPM_POWER EQU PCA0CPM0
Expand Down
1 change: 1 addition & 0 deletions Layouts/G.inc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ PWM_ACTIVE_HIGH EQU 1 ; Pwm non-inverted
COM_ACTIVE_HIGH EQU 1 ; Damping inverted

COMPARATOR_PORT EQU 0 ; All comparator (mux) pins must be on the same port
COMPARATOR_INVERT EQU 0 ; Comparator output non-inverted

IF DEADTIME == 0
PCA0CPM_POWER EQU PCA0CPM0
Expand Down
1 change: 1 addition & 0 deletions Layouts/H.inc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ PWM_ACTIVE_HIGH EQU 1 ; Pwm non-inverted
COM_ACTIVE_HIGH EQU 1 ; Damping inverted

COMPARATOR_PORT EQU 0 ; All comparator (mux) pins must be on the same port
COMPARATOR_INVERT EQU 0 ; Comparator output non-inverted

IF DEADTIME == 0
PCA0CPM_POWER EQU PCA0CPM0
Expand Down
1 change: 1 addition & 0 deletions Layouts/I.inc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ PWM_ACTIVE_HIGH EQU 1 ; Pwm non-inverted
COM_ACTIVE_HIGH EQU 1 ; Damping inverted

COMPARATOR_PORT EQU 0 ; All comparator (mux) pins must be on the same port
COMPARATOR_INVERT EQU 0 ; Comparator output non-inverted

IF DEADTIME == 0
PCA0CPM_POWER EQU PCA0CPM0
Expand Down
1 change: 1 addition & 0 deletions Layouts/J.inc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ PWM_ACTIVE_HIGH EQU 1 ; Pwm non-inverted
COM_ACTIVE_HIGH EQU 1 ; Damping inverted

COMPARATOR_PORT EQU 0 ; All comparator (mux) pins must be on the same port
COMPARATOR_INVERT EQU 0 ; Comparator output non-inverted

IF DEADTIME == 0
PCA0CPM_POWER EQU PCA0CPM0
Expand Down
1 change: 1 addition & 0 deletions Layouts/K.inc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ PWM_ACTIVE_HIGH EQU 1 ; Pwm non-inverted
COM_ACTIVE_HIGH EQU 0 ; Damping non-inverted

COMPARATOR_PORT EQU 0 ; All comparator (mux) pins must be on the same port
COMPARATOR_INVERT EQU 0 ; Comparator output non-inverted

IF DEADTIME == 0
PCA0CPM_POWER EQU PCA0CPM0
Expand Down
1 change: 1 addition & 0 deletions Layouts/L.inc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ PWM_ACTIVE_HIGH EQU 1 ; Pwm non-inverted
COM_ACTIVE_HIGH EQU 1 ; Damping inverted

COMPARATOR_PORT EQU 0 ; All comparator (mux) pins must be on the same port
COMPARATOR_INVERT EQU 0 ; Comparator output non-inverted

IF DEADTIME == 0
PCA0CPM_POWER EQU PCA0CPM0
Expand Down
1 change: 1 addition & 0 deletions Layouts/M.inc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ PWM_ACTIVE_HIGH EQU 1 ; Pwm non-inverted
COM_ACTIVE_HIGH EQU 1 ; Damping inverted

COMPARATOR_PORT EQU 0 ; All comparator (mux) pins must be on the same port
COMPARATOR_INVERT EQU 0 ; Comparator output non-inverted

IF DEADTIME == 0
PCA0CPM_POWER EQU PCA0CPM0
Expand Down
1 change: 1 addition & 0 deletions Layouts/N.inc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ PWM_ACTIVE_HIGH EQU 1 ; Pwm non-inverted
COM_ACTIVE_HIGH EQU 1 ; Damping inverted

COMPARATOR_PORT EQU 0 ; All comparator (mux) pins must be on the same port
COMPARATOR_INVERT EQU 0 ; Comparator output non-inverted

IF DEADTIME == 0
PCA0CPM_POWER EQU PCA0CPM0
Expand Down
11 changes: 1 addition & 10 deletions Layouts/O.inc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ PWM_ACTIVE_HIGH EQU 1 ; Pwm non-inverted
COM_ACTIVE_HIGH EQU 0 ; Damping non-inverted

COMPARATOR_PORT EQU 0 ; All comparator (mux) pins must be on the same port
COMPARATOR_INVERT EQU 1 ; Comparator output inverted

IF DEADTIME == 0
PCA0CPM_POWER EQU PCA0CPM0
Expand Down Expand Up @@ -97,17 +98,7 @@ P2_PUSHPULL EQU (1 SHL DebugPin)
P2_SKIP EQU (1 SHL DebugPin)


;**** **** **** **** ****
; Comparator setup
;**** **** **** **** ****
Initialize_Comparator MACRO
mov CMP_CN0, #80h ;; Comparator enabled, no hysteresis
mov CMP_MD, #40h ;; Comparator response time 100ns, Output polarity inverted
ENDM


;**** **** **** **** ****
; Inherit base layout
;**** **** **** **** ****
$set(CUSTOM_COMPARATOR_SETUP)
$include (Base.inc)
1 change: 1 addition & 0 deletions Layouts/P.inc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ PWM_ACTIVE_HIGH EQU 1 ; Pwm non-inverted
COM_ACTIVE_HIGH EQU 1 ; Damping inverted

COMPARATOR_PORT EQU 0 ; All comparator (mux) pins must be on the same port
COMPARATOR_INVERT EQU 0 ; Comparator output non-inverted

IF DEADTIME == 0
PCA0CPM_POWER EQU PCA0CPM0
Expand Down
1 change: 1 addition & 0 deletions Layouts/R.inc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ PWM_ACTIVE_HIGH EQU 1 ; Pwm non-inverted
COM_ACTIVE_HIGH EQU 1 ; Damping inverted

COMPARATOR_PORT EQU 0 ; All comparator (mux) pins must be on the same port
COMPARATOR_INVERT EQU 0 ; Comparator output non-inverted

IF DEADTIME == 0
PCA0CPM_POWER EQU PCA0CPM0
Expand Down
1 change: 1 addition & 0 deletions Layouts/S.inc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ PWM_ACTIVE_HIGH EQU 1 ; Pwm non-inverted
COM_ACTIVE_HIGH EQU 1 ; Damping inverted

COMPARATOR_PORT EQU 0 ; All comparator (mux) pins must be on the same port
COMPARATOR_INVERT EQU 0 ; Comparator output non-inverted

IF DEADTIME == 0
PCA0CPM_POWER EQU PCA0CPM0
Expand Down
1 change: 1 addition & 0 deletions Layouts/T.inc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ PWM_ACTIVE_HIGH EQU 1 ; Pwm non-inverted
COM_ACTIVE_HIGH EQU 1 ; Damping inverted

COMPARATOR_PORT EQU 0 ; All comparator (mux) pins must be on the same port
COMPARATOR_INVERT EQU 0 ; Comparator output non-inverted

IF DEADTIME == 0
PCA0CPM_POWER EQU PCA0CPM0
Expand Down
1 change: 1 addition & 0 deletions Layouts/U.inc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ PWM_ACTIVE_HIGH EQU 1 ; Pwm non-inverted
COM_ACTIVE_HIGH EQU 1 ; Damping inverted

COMPARATOR_PORT EQU 0 ; All comparator (mux) pins must be on the same port
COMPARATOR_INVERT EQU 0 ; Comparator output non-inverted

IF DEADTIME == 0
PCA0CPM_POWER EQU PCA0CPM0
Expand Down
1 change: 1 addition & 0 deletions Layouts/V.inc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ PWM_ACTIVE_HIGH EQU 1 ; Pwm non-inverted
COM_ACTIVE_HIGH EQU 1 ; Damping inverted

COMPARATOR_PORT EQU 0 ; All comparator (mux) pins must be on the same port
COMPARATOR_INVERT EQU 0 ; Comparator output non-inverted

IF DEADTIME == 0
PCA0CPM_POWER EQU PCA0CPM0
Expand Down
1 change: 1 addition & 0 deletions Layouts/W.inc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ PWM_ACTIVE_HIGH EQU 1 ; Pwm non-inverted
COM_ACTIVE_HIGH EQU 1 ; Damping inverted

COMPARATOR_PORT EQU 0 ; All comparator (mux) pins must be on the same port
COMPARATOR_INVERT EQU 0 ; Comparator output non-inverted

IF DEADTIME == 0
PCA0CPM_POWER EQU PCA0CPM0
Expand Down
1 change: 1 addition & 0 deletions Layouts/Z.inc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ PWM_ACTIVE_HIGH EQU 0 ; Pwm inverted
COM_ACTIVE_HIGH EQU 1 ; Damping inverted

COMPARATOR_PORT EQU 0 ; All comparator (mux) pins must be on the same port
COMPARATOR_INVERT EQU 0 ; Comparator output non-inverted

IF DEADTIME == 0
PCA0CPM_POWER EQU PCA0CPM0
Expand Down

0 comments on commit 3ffc6b4

Please sign in to comment.