Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add rctimer nfs esc support #125

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
*.hex
*.obj

*.cof
45 changes: 45 additions & 0 deletions MakeHexFiles.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
REM build script v2.0 by Chris Osgood 2013-09-07 http://lunarflow.com/

@echo off
SETLOCAL enabledelayedexpansion

IF "%1"=="" (
FOR /F "tokens=1,2,*" %%i in (Makefile) DO (
IF "%%i"=="ALL_TARGETS" (
FOR %%F IN (%%k) DO (
call :DoCompile %%~nF
IF !errorlevel! NEQ 0 goto error
)
goto exit
)
)
) else (
FOR %%F IN (%*) DO (
call :DoCompile %%~nF
IF !errorlevel! NEQ 0 goto error
)
)

:exit
pause
goto :eof

:error
echo ********** ERROR **********
pause
goto :eof

:DoCompile
echo.
echo ========== BUILD "%1" ==========
echo.
IF NOT EXIST %1.asm (
COPY tgy.asm %1.asm
avra -fI -o %1.inc.hex -D %1_esc -e %1.eeprom -d %1.obj %1.asm
SET err=!errorlevel!
DEL %1.asm
) else (
avra -fI -o %1.inc.hex -D %1_esc -e %1.eeprom -d %1.obj %1.asm
SET err=!errorlevel!
)
exit /B !err!
Binary file added avra.exe
Binary file not shown.
77 changes: 77 additions & 0 deletions rct30nfs.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
;***************************************************************
;* For RCTimer NFS 30A all n-Channel FETs *
;* Original fuses are -U lfuse:w:0x2f:m -U hfuse:w:0xCA:m *
;* By Nils Högberg *
;* *
;* https://github.com/sim-/tgy *
;***************************************************************

.equ F_CPU = 16000000
.equ USE_INT0 = 0 ; used by channel C
.equ USE_I2C = 0 ; We could, no FETs are on the I2C ports
.equ USE_UART = 1
.equ USE_ICP = 1


;*********************
; PORT D definitions *
;*********************

.equ ApFET = 4
.equ AnFET = 5
.equ BpFET = 3
.equ BnFET = 7
.equ CpFET = 2

.equ txd = 1
.equ rxd = 0

.equ INIT_PD = (1<<ApFET)+(1<<BpFET)+(1<<CpFET)
.equ DIR_PD = (1<<AnFET)+(1<<ApFET)+(1<<BnFET)+(1<<BpFET)+(1<<CpFET)

.equ ApFET_port = PORTD
.equ AnFET_port = PORTD
.equ BpFET_port = PORTD
.equ BnFET_port = PORTD
.equ CpFET_port = PORTD

;*********************
; PORT C definitions *
;*********************
;.equ i2c_clk = 5 ; ADC5/SCL
;.equ i2c_data = 4 ; ADC4/SDA

.equ mux_a = 6 ; ADC6
.equ mux_b = 7 ; ADC7
.equ mux_c = 0 ; ADC0

.equ mux_voltage = 2 ; ADC2 voltage input (220 from Vbat, 39 to gnd, ?V -> ?V at ADC2)
.equ mux_temperature = 1 ; ADC1 temperature input (100 from +5V, ?k NTC to gnd at ADC1)


.equ O_POWER = 220
.equ O_GROUND = 39

.equ INIT_PC = 0 ;(1<<i2c_clk)+(1<<i2c_data)
.equ DIR_PC = 0

;*********************
; PORT B definitions *
;*********************
.equ CnFET = 1

.equ rcp_in = 0 ; r/c pulse input

.equ INIT_PB = 0
.equ DIR_PB = (1<<CnFET)

.equ CnFET_port = PORTB

.MACRO RED_on
.ENDMACRO
.MACRO RED_off
.ENDMACRO
.MACRO GRN_on
.ENDMACRO
.MACRO GRN_off
.ENDMACRO
80 changes: 80 additions & 0 deletions rct45nfs.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
;***************************************************************
;* For RCTimer NFS 45A all n-Channel FETs *
;* Original fuses are -U lfuse:w:0x2F:m -U hfuse:w:0xCA:m *
;* By Nils Högberg *
;* *
;* https://github.com/sim-/tgy *
;***************************************************************

.equ F_CPU = 16000000
.equ USE_INT0 = 1
.equ USE_I2C = 0
.equ USE_UART = 0
.equ USE_ICP = 0
.equ MOTOR_ADVANCE = 18 ; Degrees of timing advance (0 - 30, 30 meaning no delay)
.equ TIMING_OFFSET = 0

;*********************
; PORT D definitions *
;*********************
;.equ = 7 ; AIN1
.equ c_comp = 6 ; AIN0
.equ ApFET = 5
.equ BpFET = 4
.equ CpFET = 3
.equ rcp_in = 2 ; r/c pulse input
;.equ txd = 1
;.equ rxd = 0

.equ INIT_PD = 0
.equ DIR_PD = (1<<ApFET)+(1<<BpFET)+(1<<CpFET)

.equ ApFET_port = PORTD
.equ BpFET_port = PORTD
.equ CpFET_port = PORTD

;*********************
; PORT C definitions *
;*********************
;.equ = 7 ; ADC7
;.equ = 6 ; RESET
.equ mux_a = 5 ; ADC5
.equ mux_b = 4 ; ADC4
;.equ = 3 ; ADC3
;.equ = 2 ; ADC2
.equ mux_temperature = 1 ; ADC1 temperature input (897 from +5V, ?k NTC to gnd at ADC1)
.equ mux_voltage = 0 ; ADC0 voltage input (220 from Vbat, 39 to gnd, ?V -> ?V at ADC2)



.equ O_POWER = 10
.equ O_GROUND = 1

.equ INIT_PC = 0
.equ DIR_PC = 0

;*********************
; PORT B definitions *
;*********************
;.equ = 5 ; SCK
;.equ = 4 ; MISO
;.equ = 3 ; MOSI
.equ AnFET = 2
.equ BnFET = 1
.equ CnFET = 0

.equ INIT_PB = 0
.equ DIR_PB = (1<<AnFET)+(1<<BnFET)+(1<<CnFET)

.equ AnFET_port = PORTB
.equ BnFET_port = PORTB
.equ CnFET_port = PORTB

.MACRO RED_on
.ENDMACRO
.MACRO RED_off
.ENDMACRO
.MACRO GRN_on
.ENDMACRO
.MACRO GRN_off
.ENDMACRO
36 changes: 20 additions & 16 deletions tgy.asm
Original file line number Diff line number Diff line change
Expand Up @@ -154,22 +154,26 @@
#include "tgy_8mhz.inc" ; TowerPro/Turnigy Basic/Plush "type 2" w/8MHz oscillator (INT0 PWM)
#elif defined(tgy_esc)
#include "tgy.inc" ; TowerPro/Turnigy Basic/Plush "type 2" (INT0 PWM)
#elif defined(rct30nfs_esc)
#include "rct30nfs.inc" ; RCTimer NFS 30A (INT0 PWM)
#elif defined(rct45nfs_esc)
#include "rct45nfs.inc"
#else
#error "Unrecognized board type."
#endif

.equ CPU_MHZ = F_CPU / 1000000

.equ BOOT_LOADER = 1 ; Include Turnigy USB linker STK500v2 boot loader on PWM input pin
.equ BOOT_LOADER = 0 ; Include Turnigy USB linker STK500v2 boot loader on PWM input pin
.equ BOOT_JUMP = 1 ; Jump to any boot loader when PWM input stays high
.equ BOOT_START = THIRDBOOTSTART

.if !defined(COMP_PWM)
.equ COMP_PWM = 0 ; During PWM off, switch high side on (unsafe on some boards!)
.endif
.if !defined(DEAD_LOW_NS)
.equ DEAD_LOW_NS = 300 ; Low-side dead time w/COMP_PWM (62.5ns steps @ 16MHz, max 2437ns)
.equ DEAD_HIGH_NS = 300 ; High-side dead time w/COMP_PWM (62.5ns steps @ 16MHz, max roughly PWM period)
.equ DEAD_LOW_NS = 100 ; Low-side dead time w/COMP_PWM (62.5ns steps @ 16MHz, max 2437ns)
.equ DEAD_HIGH_NS = 100 ; High-side dead time w/COMP_PWM (62.5ns steps @ 16MHz, max roughly PWM period)
.endif
.equ DEAD_TIME_LOW = DEAD_LOW_NS * CPU_MHZ / 1000
.equ DEAD_TIME_HIGH = DEAD_HIGH_NS * CPU_MHZ / 1000
Expand All @@ -180,21 +184,21 @@
.if !defined(TIMING_OFFSET)
.equ TIMING_OFFSET = 0 ; Motor timing offset in microseconds
.endif
.equ MOTOR_BRAKE = 0 ; Enable brake during neutral/idle ("motor drag" brake)
.equ MOTOR_BRAKE = 1 ; Enable brake during neutral/idle ("motor drag" brake)
.equ LOW_BRAKE = 0 ; Enable brake on very short RC pulse ("thumb" brake like on Airtronics XL2P)
.if !defined(MOTOR_REVERSE)
.equ MOTOR_REVERSE = 0 ; Reverse normal commutation direction
.endif
.equ RC_PULS_REVERSE = 0 ; Enable RC-car style forward/reverse throttle
.equ RC_CALIBRATION = 1 ; Support run-time calibration of min/max pulse lengths
.equ RC_CALIBRATION = 0 ; Support run-time calibration of min/max pulse lengths
.equ SLOW_THROTTLE = 0 ; Limit maximum throttle jump to try to prevent overcurrent
.equ BEACON = 1 ; Beep periodically when RC signal is lost
.equ BEACON_IDLE = 0 ; Beep periodically if idle for a long period
.if !defined(CHECK_HARDWARE)
.equ CHECK_HARDWARE = 0 ; Check for correct pin configuration, sense inputs, and functioning MOSFETs
.endif
.equ CELL_MAX_DV = 43 ; Maximum battery cell deciV
.equ CELL_MIN_DV = 35 ; Minimum battery cell deciV
.equ CELL_MIN_DV = 0 ; Minimum battery cell deciV
.equ CELL_COUNT = 0 ; 0: auto, >0: hard-coded number of cells (for reliable LVC > ~4S)
.equ BLIP_CELL_COUNT = 0 ; Blip out cell count before arming
.equ DEBUG_ADC_DUMP = 0 ; Output an endless loop of all ADC values (no normal operation)
Expand All @@ -208,10 +212,10 @@
; These are now defaults which can be adjusted via throttle calibration
; (stick high, stick low, (stick neutral) at start).
; These might be a bit wide for most radios, but lines up with POWER_RANGE.
.equ STOP_RC_PULS = 1060 ; Stop motor at or below this pulse length
.equ FULL_RC_PULS = 1860 ; Full speed at or above this pulse length
.equ MAX_RC_PULS = 2400 ; Throw away any pulses longer than this
.equ MIN_RC_PULS = 768 ; Throw away any pulses shorter than this
.equ STOP_RC_PULS = 1000 ; Stop motor at or below this pulse length
.equ FULL_RC_PULS = 2000 ; Full speed at or above this pulse length
.equ MAX_RC_PULS = 2060 ; Throw away any pulses longer than this
.equ MIN_RC_PULS = 940 ; Throw away any pulses shorter than this
.equ MID_RC_PULS = (STOP_RC_PULS + FULL_RC_PULS) / 2 ; Neutral when RC_PULS_REVERSE = 1
.equ RCP_ALIAS_SHIFT = 3 ; Enable 1/8th PWM input alias ("oneshot125")
.equ BEEP_RCP_ERROR = 0 ; Beep at stop if invalid PWM pulses were received
Expand All @@ -237,18 +241,18 @@

; Number of PWM steps (too high and PWM frequency drops into audible range)
.if !defined(POWER_RANGE)
.equ POWER_RANGE = 800 * CPU_MHZ / 16 + MIN_DUTY
.equ POWER_RANGE = 1000 * CPU_MHZ / 16 + MIN_DUTY
.endif

.equ MAX_POWER = (POWER_RANGE-1)
.equ PWR_COOL_START = (POWER_RANGE/24) ; Power limit while starting to reduce heating
.equ PWR_MIN_START = (POWER_RANGE/6) ; Power limit while starting (to start)
.equ PWR_MAX_START = (POWER_RANGE/4) ; Power limit while starting (if still not running)
.equ PWR_MIN_START = (POWER_RANGE/3) ; Power limit while starting (to start)
.equ PWR_MAX_START = (POWER_RANGE/2) ; Power limit while starting (if still not running)
.equ PWR_MAX_RPM1 = (POWER_RANGE/4) ; Power limit when running slower than TIMING_RANGE1
.equ PWR_MAX_RPM2 = (POWER_RANGE/2) ; Power limit when running slower than TIMING_RANGE2

.equ BRAKE_POWER = MAX_POWER*2/3 ; Brake force is exponential, so start fairly high
.equ BRAKE_SPEED = 3 ; Speed to reach MAX_POWER, 0 (slowest) - 8 (fastest)
.equ BRAKE_SPEED = 6 ; Speed to reach MAX_POWER, 0 (slowest) - 8 (fastest)
.equ LOW_BRAKE_POWER = MAX_POWER*2/3
.equ LOW_BRAKE_SPEED = 5

Expand All @@ -262,8 +266,8 @@
.if !defined(START_DELAY_US)
.equ START_DELAY_US = 0 ; Initial post-commutation wait during starting
.endif
.equ START_DSTEP_US = 8 ; Microseconds per start delay step
.equ START_DELAY_INC = 15 ; Wait step count increase (wraps in a byte)
.equ START_DSTEP_US = 6 ; Microseconds per start delay step
.equ START_DELAY_INC = 12 ; Wait step count increase (wraps in a byte)
.equ START_MOD_INC = 4 ; Start power modulation step count increase (wraps in a byte)
.equ START_MOD_LIMIT = 48 ; Value at which power is reduced to avoid overheating
.equ START_FAIL_INC = 16 ; start_tries step count increase (wraps in a byte, upon which we disarm)
Expand Down