You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

7888 lines
237 KiB

12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
9 years ago
12 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
9 years ago
12 years ago
9 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
9 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
  1. $NOMOD51
  2. ;**** **** **** **** ****
  3. ;
  4. ; BLHeli program for controlling brushless motors in helicopters and multirotors
  5. ;
  6. ; Copyright 2011, 2012 Steffen Skaug
  7. ; This program is distributed under the terms of the GNU General Public License
  8. ;
  9. ; This file is part of BLHeli.
  10. ;
  11. ; BLHeli is free software: you can redistribute it and/or modify
  12. ; it under the terms of the GNU General Public License as published by
  13. ; the Free Software Foundation, either version 3 of the License, or
  14. ; (at your option) any later version.
  15. ;
  16. ; BLHeli is distributed in the hope that it will be useful,
  17. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. ; GNU General Public License for more details.
  20. ;
  21. ; You should have received a copy of the GNU General Public License
  22. ; along with BLHeli. If not, see <http://www.gnu.org/licenses/>.
  23. ;
  24. ;**** **** **** **** ****
  25. ;
  26. ; The software was initially designed for use with Eflite mCP X, but is now adapted to copters/planes in general
  27. ;
  28. ; The software was inspired by and started from from Bernard Konze's BLMC: http://home.versanet.de/~bkonze/blc_6a/blc_6a.htm
  29. ; And also Simon Kirby's TGY: https://github.com/sim-/tgy
  30. ;
  31. ; This file is best viewed with tab width set to 5
  32. ;
  33. ; The input signal can be positive 1kHz, 2kHz, 4kHz, 8kHz or 12kHz PWM (e.g. taken from the "resistor tap" on mCPx)
  34. ; And the input signal can be PPM (1-2ms) or OneShot125 (125-250us) at rates up to several hundred Hz.
  35. ; The code autodetects the various input modes/frequencies
  36. ; The code can also be programmed to accept inverted input signal.
  37. ;
  38. ; The first lines of the software must be modified according to the chosen environment:
  39. ; Uncomment the selected ESC and main/tail/multi mode
  40. ; BESCNO EQU "ESC"_"mode"
  41. ;
  42. ;**** **** **** **** ****
  43. ; Revision history:
  44. ; - Rev1.0: Initial revision based upon BLHeli for AVR controllers
  45. ; - Rev2.0: Changed "Eeprom" initialization, layout and defaults
  46. ; Various changes and improvements to comparator reading. Now using timer1 for time from pwm on/off
  47. ; Beeps are made louder
  48. ; Added programmable low voltage limit
  49. ; Added programmable damped tail mode (only for 1S ESCs)
  50. ; Added programmable motor rotation direction
  51. ; - Rev2.1: (minor changes by 4712)
  52. ; Added Disable TX Programming by PC Setup Application
  53. ; therfore changed EEPROM_LAYOUT_REVISION = 8
  54. ; Added Vdd Monitor as reset source when writing to "EEProm"
  55. ; Changed for use of batch file to assemble, link and make hex files
  56. ; - Rev2.2: (minor changes by 4712)
  57. ; Added Disable Throttle Re-Arming every motor start by PC Setup Application
  58. ; - Rev2.3: (minor changes by 4712)
  59. ; Added bugfixed (2x CLR C before j(n)c operations)thx Steffen!
  60. ; - Rev2.4: Revisions 2.1 to 2.3 integrated
  61. ; - Rev3.0: Added PPM (1050us-1866us) as accepted input signal
  62. ; Added startup rpm as a programming parameter
  63. ; Added startup acceleration as a programming parameter
  64. ; Added option for using voltage measurements to compensate motor power
  65. ; Added governor target by setup as a governor mode option
  66. ; Governor is kept active regardless of rpm
  67. ; Smooth governor spoolup/down in arm and setup modes
  68. ; Increased governor P and I gain programming ranges
  69. ; Increased and changed low voltage limit programming range
  70. ; Disabled tx programming entry for all but the first arming sequence after power on
  71. ; Made it possible to skip parameters in tx programming by setting throttle midstick
  72. ; Made it default not to rearm for every restart
  73. ; - Rev3.1: Fixed bug that prevented chosen parameter to be set in tx programming
  74. ; - Rev3.2: ...also updated the EEPROM revision parameter
  75. ; - Rev3.3: Fixed negative number bug in voltage compensation
  76. ; Fixed bug in startup power calculation for non-default power
  77. ; Prevented possibility for voltage compensation fighting low voltage limiting
  78. ; Applied overall spoolup control to ensure soft spoolup in any mode
  79. ; Added a delay of 3 seconds from initiation of main motor stop until new startup is allowed
  80. ; Reduced beep power to reduce power consumption for very strong motors/ESCs
  81. ; - Rev3.4: Fixed bug that prevented full power in governor arm and setup modes
  82. ; Increased NFETON_DELAY for XP_7A and XP_12A to allow for more powerful fets
  83. ; Increased initial spoolup power, and linked to startup power
  84. ; - Rev4.0: Fixed bug that made tail tx program beeps very weak
  85. ; Added thermal protection feature
  86. ; Governor P and I gain ranges are extended up to 8.0x gain
  87. ; Startup sequence is aborted upon zero throttle
  88. ; Avoided voltage compensation function induced latency for tail when voltage compensation is not enabled
  89. ; Improved input signal frequency detection robustness
  90. ; - Rev4.1: Increased thermal protection temperature limits
  91. ; - Rev5.0: Added multi(copter) operating mode. TAIL define changed to MODE with three modes: MAIN, TAIL and MULTI
  92. ; Added programmable commutation timing
  93. ; Added a damped light mode that has less damping, but that can be used with all escs
  94. ; Added programmable damping force
  95. ; Added thermal protection for startup too
  96. ; Added wait beeps when waiting more than 30 sec for throttle above zero (after having been armed)
  97. ; Modified tail idling to provide option for very low speeds
  98. ; Changed PPM range to 1150-1830us
  99. ; Arming sequence is dropped for PPM input, unless it is governor arm mode
  100. ; Loss of input signal will immediately stop the motor for PPM input
  101. ; Bug corrected in Turnigy Plush 6A voltage measurement setup
  102. ; FET switching delays are set for original fets. Stronger/doubled/tripled etc fets may require faster pfet off switching
  103. ; Miscellaneous other changes
  104. ; - Rev6.0: Reverted comparator reading routine to rev5.0 equivalent, in order to avoid tail motor stops
  105. ; Added governor range programmability
  106. ; Implemented startup retry sequence with varying startup power for multi mode
  107. ; In damped light mode, damping is now applied to the active nfet phase for fully damped capable ESCs
  108. ; - Rev6.1: Added input signal qualification criteria for PPM, to avoid triggering on noise spikes (fix for plush hardware)
  109. ; Changed main and multi mode stop criteria. Will now be in run mode, even if RC pulse input is zero
  110. ; Fixed bug in commutation that caused rough running in damped light mode
  111. ; Miscellaneous other changes
  112. ; - Rev7.0 Added direct startup mode programmability
  113. ; Added throttle calibration. Min>=1000us and Max<=2000us. Difference must be >520us, otherwise max is shifted so that difference=520us
  114. ; Added programmable throttle change rate
  115. ; Added programmable beep strength, beacon strength and beacon delay
  116. ; Reduced power step to full power significantly
  117. ; Miscellaneous other changes
  118. ; - Rev8.0 Added a 2 second delay after power up, to wait for receiver initialization
  119. ; Added a programming option for disabling low voltage limit, and made it default for MULTI
  120. ; Added programable demag compensation, using the concept of SimonK
  121. ; Improved robustness against noisy input signal
  122. ; Refined direct startup
  123. ; Removed voltage compensation
  124. ; Miscellaneous other changes
  125. ; - Rev9.0 Increased programming range for startup power, and made its default ESC dependent
  126. ; Made default startup method ESC dependent
  127. ; Even more smooth and gentle spoolup for MAIN, to suit larger helis
  128. ; Improved transition from stepped startup to run
  129. ; Refined direct startup
  130. ; - Rev9.1 Fixed bug that changed FW revision after throttle calibration or TX programming
  131. ; - Rev9.2 Altered timing of throttle calibration in order to work with MultiWii calibration firmware
  132. ; Reduced main spoolup time to around 5 seconds
  133. ; Changed default beacon delay to 3 minutes
  134. ; - Rev9.3 Fixed bug in Plush 60/80A temperature reading, that caused failure in operation above 4S
  135. ; Corrected temperature limit for HiModel cool 22/33/41A, RCTimer 6A, Skywalker 20/40A, Turnigy AE45A, Plush 40/60/80A. Limit was previously set too high
  136. ; - Rev9.4 Improved timing for increased maximum rpm limit
  137. ; - Rev10.0 Added closed loop mode for multi
  138. ; Added high/low BEC voltage option (for the ESCs where HW supports it)
  139. ; Added method of resetting all programmed parameter values to defaults by TX programming
  140. ; Added Turnigy K-force 40A and Turnigy K-force 120A HV ESCs
  141. ; Enabled fully damped mode for several ESCs
  142. ; Extended startup power range downwards to enable very smooth start for large heli main motors
  143. ; Extended damping force with a highest setting
  144. ; Corrected temperature limits for F310 chips (Plush 40A and AE 45A)
  145. ; Implemented temperature reading average in order to avoid problems with ADC noise on Skywalkers
  146. ; Increased switching delays for XP 7A fast, in order to avoid cross conduction of N and P fets
  147. ; Miscellaneous other changes
  148. ; - Rev10.1 Relaxed RC signal jitter requirement during frequency measurement
  149. ; Corrected bug that prevented using governor low
  150. ; Enabled vdd monitor always, in order to reduce likelihood of accidental overwriting of adjustments
  151. ; Fixed bug that caused stop for PPM input above 2048us, and moved upper accepted limit to 2160us
  152. ; - Rev10.2 Corrected temperature limit for AE20-30/XP7-25, where limit was too high
  153. ; Corrected temperature limit for 120HV, where limit was too low
  154. ; Fixed bug that caused AE20/25/30A not to run in reverse
  155. ; - Rev10.3 Removed vdd monitor for 1S capable ESCs, in order to avoid brownouts/resets
  156. ; Made auto bailout spoolup for main more smooth
  157. ; - Rev10.4 Ensured that main spoolup and governor activation will always be smooth, regardless of throttle input
  158. ; Added capability to operate on 12kHz input signal too
  159. ; - Rev11.0 Fixed bug of programming default values for governor in MULTI mode
  160. ; Disabled interrupts explicitly some places, to avoid possibilities for unintentional fet switching
  161. ; Changed interrupt disable strategy, to always allow pwm interrupts, to avoid noise when running at low rpms
  162. ; Added governor middle range for MAIN mode
  163. ; Added bidirectional mode for TAIL and MULTI mode with PPM input
  164. ; Changed and improved demag compensation
  165. ; Miscellaneous other changes
  166. ; - Rev11.1 Fixed bug of slow acceleration response for MAIN mode running without governor
  167. ; Fixed bug with PWM input, where throttle remains high even when zeroing throttle (seen on V922 tail)
  168. ; Fixed bug in bidirectional operation, where direction change could cause reset
  169. ; Improved autorotation bailout for MAIN
  170. ; Reduced min speed back to 1220 erpm
  171. ; Misc code cleanups
  172. ; - Rev11.2 Fixed throttle calibration bug
  173. ; Added high side driver precharge for all-nfet ESCs
  174. ; Optimized timing in general and for demag compensation in particular
  175. ; Auto bailout functionality modified
  176. ; Governor is deactivated for throttle inputs below 10%
  177. ; Increased beacon delay times
  178. ; - Rev12.0 Added programmable main spoolup time
  179. ; Added programmable temperature protection enable
  180. ; Bidirectional mode stop/start improved. Motor is now stopped before starting
  181. ; Power is limited for very low rpms (when BEMF is low), in order to avoid sync loss
  182. ; Damped light mode is made more smooth and quiet, particularly at low and high rpms
  183. ; Comparator signal qualification scheme is changed
  184. ; Demag compensation scheme is significantly changed
  185. ; Increased jitter tolerance for PPM frequency measurement
  186. ; Fully damped mode removed, and damped light only supported on damped capable ESCs
  187. ; Default tail mode changed to damped light
  188. ; Miscellaneous other changes
  189. ; - Rev12.1 Fixed bug in tail code
  190. ; Improved startup for Atmel
  191. ; Added support for multiple high BEC voltages
  192. ; Added support for RPM output
  193. ; - Rev12.2 Improved running smoothness, particularly for damped light
  194. ; Avoiding lockup at full throttle when input signal is noisy
  195. ; Avoiding detection of 1-wire programming signal as valid throttle signal
  196. ; - Rev13.0 Removed stepped start
  197. ; Removed throttle change rate and damping force parameters
  198. ; Added support for OneShot125
  199. ; Improved commutation timing accuracy
  200. ; - Rev13.1 Removed startup ramp for MULTI
  201. ; Improved startup for some odd ESCs
  202. ; - Rev13.2 Still tweaking startup to make it more reliable and faster for all ESC/motor combos
  203. ; Increased deadband for bidirectional operation
  204. ; Relaxed signal detection criteria
  205. ; Added support for running 48MHz capable SiLabs MCUs at 48MHz
  206. ; Added bootlader to SiLabs code
  207. ; Miscellaneous other changes
  208. ; - Rev14.0 Improved running at high timing
  209. ; Improved running at high RPMs and increased max RPM limit
  210. ; Avoid being locked in bootloader (implemented in Suite 13202)
  211. ; Improved reliability of 3D (bidirectional) mode and startup
  212. ; Smoother running and greatly reduced step to full power in damped light mode
  213. ; Removed low voltage limiting for MULTI
  214. ; Added pwm dither parameter
  215. ; Added setting for enable/disable of low RPM power protection
  216. ; Added setting for enable/disable of PWM input
  217. ; Better AFW and damping for some ESCs (that have a slow high side driver)
  218. ; Miscellaneous other changes
  219. ; - Rev14.1 Fixed max throttle calibration bug (for non-oneshot)
  220. ; Fixed some closed loop mode bugs
  221. ; Relaxed signal jitter requirement for looptimes below 1000
  222. ; Added skipping of damping fet switching near max power, for improved high end throttle linearity, using the concept of SimonK
  223. ; Improved sync hold at high rpms
  224. ; - Rev14.2 Added stalled motor shutoff after about 10 seconds (for tail and multi code with PPM input)
  225. ; Greatly increased maximum rpm limit, and added rpm limiting at 250k erpm (48MHz MCUs at 400k erpm)
  226. ; Improved bidirectional operation
  227. ; - Rev14.3 Moved reset vector to be just before the settings segment, in order to better recover from partially failed flashing operation
  228. ; Added 100ms intialization delay for the Graupner Ultra 20A ESC
  229. ; Shortened stall detect time to about 5sec, and prevented going into tx programming after a stall
  230. ; Optimizations of software timing and running reliability
  231. ; - Rev14.4 Improved startup, particularly for larger motors
  232. ; Improved running at very high rpms
  233. ; Made damped light default for MULTI on ESCs that support it
  234. ; Miscellaneous other changes
  235. ;
  236. ;
  237. ;**** **** **** **** ****
  238. ; Up to 8K Bytes of In-System Self-Programmable Flash
  239. ; Up to 768 Bytes Internal SRAM
  240. ;
  241. ;**** **** **** **** ****
  242. ; Master clock is internal 24MHz oscillator (or 48MHz, for which the times below are halved)
  243. ; Timer 0 (167/500ns counts) always counts up and is used for
  244. ; - PWM generation
  245. ; Timer 1 (167/500ns counts) always counts up and is used for
  246. ; - Time from pwm on/off event
  247. ; Timer 2 (500ns counts) always counts up and is used for
  248. ; - RC pulse timeout/skip counts and commutation times
  249. ; Timer 3 (500ns counts) always counts up and is used for
  250. ; - Commutation timeouts
  251. ; PCA0 (500ns counts) always counts up and is used for
  252. ; - RC pulse measurement
  253. ;
  254. ;**** **** **** **** ****
  255. ; Interrupt handling
  256. ; The C8051 does not disable interrupts when entering an interrupt routine.
  257. ; Also some interrupt flags need to be cleared by software
  258. ; The code disables interrupts in interrupt routines, in order to avoid too nested interrupts
  259. ; - Interrupts are disabled during beeps, to avoid audible interference from interrupts
  260. ; - RC pulse interrupts are periodically disabled in order to reduce interference with pwm interrupts.
  261. ;
  262. ;**** **** **** **** ****
  263. ; Motor control:
  264. ; - Brushless motor control with 6 states for each electrical 360 degrees
  265. ; - An advance timing of 0deg has zero cross 30deg after one commutation and 30deg before the next
  266. ; - Timing advance in this implementation is set to 15deg nominally
  267. ; - "Damped" commutation schemes are available, where more than one pfet is on when pwm is off. This will absorb energy from bemf and make step settling more damped.
  268. ; Motor sequence starting from zero crossing:
  269. ; - Timer wait: Wt_Comm 15deg ; Time to wait from zero cross to actual commutation
  270. ; - Timer wait: Wt_Advance 15deg ; Time to wait for timing advance. Nominal commutation point is after this
  271. ; - Timer wait: Wt_Zc_Scan 7.5deg ; Time to wait before looking for zero cross
  272. ; - Scan for zero cross 22.5deg , Nominal, with some motor variations
  273. ;
  274. ; Motor startup:
  275. ; There is a startup phase and an initial run phase, before normal bemf commutation run begins.
  276. ;
  277. ;**** **** **** **** ****
  278. ; List of enumerated supported ESCs and modes (main, tail or multi)
  279. XP_3A_Main EQU 1
  280. XP_3A_Tail EQU 2
  281. XP_3A_Multi EQU 3
  282. XP_7A_Main EQU 4
  283. XP_7A_Tail EQU 5
  284. XP_7A_Multi EQU 6
  285. XP_7A_Fast_Main EQU 7
  286. XP_7A_Fast_Tail EQU 8
  287. XP_7A_Fast_Multi EQU 9
  288. XP_12A_Main EQU 10
  289. XP_12A_Tail EQU 11
  290. XP_12A_Multi EQU 12
  291. XP_18A_Main EQU 13
  292. XP_18A_Tail EQU 14
  293. XP_18A_Multi EQU 15
  294. XP_25A_Main EQU 16
  295. XP_25A_Tail EQU 17
  296. XP_25A_Multi EQU 18
  297. XP_35A_SW_Main EQU 19
  298. XP_35A_SW_Tail EQU 20
  299. XP_35A_SW_Multi EQU 21
  300. DP_3A_Main EQU 22
  301. DP_3A_Tail EQU 23
  302. DP_3A_Multi EQU 24
  303. Supermicro_3p5A_Main EQU 25
  304. Supermicro_3p5A_Tail EQU 26
  305. Supermicro_3p5A_Multi EQU 27
  306. Turnigy_Plush_6A_Main EQU 28
  307. Turnigy_Plush_6A_Tail EQU 29
  308. Turnigy_Plush_6A_Multi EQU 30
  309. Turnigy_Plush_10A_Main EQU 31
  310. Turnigy_Plush_10A_Tail EQU 32
  311. Turnigy_Plush_10A_Multi EQU 33
  312. Turnigy_Plush_12A_Main EQU 34
  313. Turnigy_Plush_12A_Tail EQU 35
  314. Turnigy_Plush_12A_Multi EQU 36
  315. Turnigy_Plush_18A_Main EQU 37
  316. Turnigy_Plush_18A_Tail EQU 38
  317. Turnigy_Plush_18A_Multi EQU 39
  318. Turnigy_Plush_25A_Main EQU 40
  319. Turnigy_Plush_25A_Tail EQU 41
  320. Turnigy_Plush_25A_Multi EQU 42
  321. Turnigy_Plush_30A_Main EQU 43
  322. Turnigy_Plush_30A_Tail EQU 44
  323. Turnigy_Plush_30A_Multi EQU 45
  324. Turnigy_Plush_40A_Main EQU 46
  325. Turnigy_Plush_40A_Tail EQU 47
  326. Turnigy_Plush_40A_Multi EQU 48
  327. Turnigy_Plush_60A_Main EQU 49
  328. Turnigy_Plush_60A_Tail EQU 50
  329. Turnigy_Plush_60A_Multi EQU 51
  330. Turnigy_Plush_80A_Main EQU 52
  331. Turnigy_Plush_80A_Tail EQU 53
  332. Turnigy_Plush_80A_Multi EQU 54
  333. Turnigy_Plush_Nfet_18A_Main EQU 55
  334. Turnigy_Plush_Nfet_18A_Tail EQU 56
  335. Turnigy_Plush_Nfet_18A_Multi EQU 57
  336. Turnigy_Plush_Nfet_25A_Main EQU 58
  337. Turnigy_Plush_Nfet_25A_Tail EQU 59
  338. Turnigy_Plush_Nfet_25A_Multi EQU 60
  339. Turnigy_Plush_Nfet_30A_Main EQU 61
  340. Turnigy_Plush_Nfet_30A_Tail EQU 62
  341. Turnigy_Plush_Nfet_30A_Multi EQU 63
  342. Turnigy_AE_20A_Main EQU 64
  343. Turnigy_AE_20A_Tail EQU 65
  344. Turnigy_AE_20A_Multi EQU 66
  345. Turnigy_AE_25A_Main EQU 67
  346. Turnigy_AE_25A_Tail EQU 68
  347. Turnigy_AE_25A_Multi EQU 69
  348. Turnigy_AE_30A_Main EQU 70
  349. Turnigy_AE_30A_Tail EQU 71
  350. Turnigy_AE_30A_Multi EQU 72
  351. Turnigy_AE_45A_Main EQU 73
  352. Turnigy_AE_45A_Tail EQU 74
  353. Turnigy_AE_45A_Multi EQU 75
  354. Turnigy_KForce_40A_Main EQU 76
  355. Turnigy_KForce_40A_Tail EQU 77
  356. Turnigy_KForce_40A_Multi EQU 78
  357. Turnigy_KForce_70A_HV_Main EQU 79
  358. Turnigy_KForce_70A_HV_Tail EQU 80
  359. Turnigy_KForce_70A_HV_Multi EQU 81
  360. Turnigy_KForce_120A_HV_Main EQU 82
  361. Turnigy_KForce_120A_HV_Tail EQU 83
  362. Turnigy_KForce_120A_HV_Multi EQU 84
  363. Turnigy_KForce_120A_HV_v2_Main EQU 85
  364. Turnigy_KForce_120A_HV_v2_Tail EQU 86
  365. Turnigy_KForce_120A_HV_v2_Multi EQU 87
  366. Skywalker_20A_Main EQU 88
  367. Skywalker_20A_Tail EQU 89
  368. Skywalker_20A_Multi EQU 90
  369. Skywalker_40A_Main EQU 91
  370. Skywalker_40A_Tail EQU 92
  371. Skywalker_40A_Multi EQU 93
  372. HiModel_Cool_22A_Main EQU 94
  373. HiModel_Cool_22A_Tail EQU 95
  374. HiModel_Cool_22A_Multi EQU 96
  375. HiModel_Cool_33A_Main EQU 97
  376. HiModel_Cool_33A_Tail EQU 98
  377. HiModel_Cool_33A_Multi EQU 99
  378. HiModel_Cool_41A_Main EQU 100
  379. HiModel_Cool_41A_Tail EQU 101
  380. HiModel_Cool_41A_Multi EQU 102
  381. RCTimer_6A_Main EQU 103
  382. RCTimer_6A_Tail EQU 104
  383. RCTimer_6A_Multi EQU 105
  384. Align_RCE_BL15X_Main EQU 106
  385. Align_RCE_BL15X_Tail EQU 107
  386. Align_RCE_BL15X_Multi EQU 108
  387. Align_RCE_BL15P_Main EQU 109
  388. Align_RCE_BL15P_Tail EQU 110
  389. Align_RCE_BL15P_Multi EQU 111
  390. Align_RCE_BL35X_Main EQU 112
  391. Align_RCE_BL35X_Tail EQU 113
  392. Align_RCE_BL35X_Multi EQU 114
  393. Align_RCE_BL35P_Main EQU 115
  394. Align_RCE_BL35P_Tail EQU 116
  395. Align_RCE_BL35P_Multi EQU 117
  396. Gaui_GE_183_18A_Main EQU 118
  397. Gaui_GE_183_18A_Tail EQU 119
  398. Gaui_GE_183_18A_Multi EQU 120
  399. H_King_10A_Main EQU 121
  400. H_King_10A_Tail EQU 122
  401. H_King_10A_Multi EQU 123
  402. H_King_20A_Main EQU 124
  403. H_King_20A_Tail EQU 125
  404. H_King_20A_Multi EQU 126
  405. H_King_35A_Main EQU 127
  406. H_King_35A_Tail EQU 128
  407. H_King_35A_Multi EQU 129
  408. H_King_50A_Main EQU 130
  409. H_King_50A_Tail EQU 131
  410. H_King_50A_Multi EQU 132
  411. Polaris_Thunder_12A_Main EQU 133
  412. Polaris_Thunder_12A_Tail EQU 134
  413. Polaris_Thunder_12A_Multi EQU 135
  414. Polaris_Thunder_20A_Main EQU 136
  415. Polaris_Thunder_20A_Tail EQU 137
  416. Polaris_Thunder_20A_Multi EQU 138
  417. Polaris_Thunder_30A_Main EQU 139
  418. Polaris_Thunder_30A_Tail EQU 140
  419. Polaris_Thunder_30A_Multi EQU 141
  420. Polaris_Thunder_40A_Main EQU 142
  421. Polaris_Thunder_40A_Tail EQU 143
  422. Polaris_Thunder_40A_Multi EQU 144
  423. Polaris_Thunder_60A_Main EQU 145
  424. Polaris_Thunder_60A_Tail EQU 146
  425. Polaris_Thunder_60A_Multi EQU 147
  426. Polaris_Thunder_80A_Main EQU 148
  427. Polaris_Thunder_80A_Tail EQU 149
  428. Polaris_Thunder_80A_Multi EQU 150
  429. Polaris_Thunder_100A_Main EQU 151
  430. Polaris_Thunder_100A_Tail EQU 152
  431. Polaris_Thunder_100A_Multi EQU 153
  432. Platinum_Pro_30A_Main EQU 154
  433. Platinum_Pro_30A_Tail EQU 155
  434. Platinum_Pro_30A_Multi EQU 156
  435. Platinum_Pro_150A_Main EQU 157
  436. Platinum_Pro_150A_Tail EQU 158
  437. Platinum_Pro_150A_Multi EQU 159
  438. Platinum_50Av3_Main EQU 160
  439. Platinum_50Av3_Tail EQU 161
  440. Platinum_50Av3_Multi EQU 162
  441. EAZY_3Av2_Main EQU 163
  442. EAZY_3Av2_Tail EQU 164
  443. EAZY_3Av2_Multi EQU 165
  444. Tarot_30A_Main EQU 166
  445. Tarot_30A_Tail EQU 167
  446. Tarot_30A_Multi EQU 168
  447. SkyIII_30A_Main EQU 169
  448. SkyIII_30A_Tail EQU 170
  449. SkyIII_30A_Multi EQU 171
  450. EMAX_20A_Main EQU 172
  451. EMAX_20A_Tail EQU 173
  452. EMAX_20A_Multi EQU 174
  453. EMAX_40A_Main EQU 175
  454. EMAX_40A_Tail EQU 176
  455. EMAX_40A_Multi EQU 177
  456. EMAX_Nano_20A_Main EQU 178
  457. EMAX_Nano_20A_Tail EQU 179
  458. EMAX_Nano_20A_Multi EQU 180
  459. XRotor_10A_Main EQU 181
  460. XRotor_10A_Tail EQU 182
  461. XRotor_10A_Multi EQU 183
  462. XRotor_20A_Main EQU 184
  463. XRotor_20A_Tail EQU 185
  464. XRotor_20A_Multi EQU 186
  465. XRotor_40A_Main EQU 187
  466. XRotor_40A_Tail EQU 188
  467. XRotor_40A_Multi EQU 189
  468. MDRX62H_Main EQU 190
  469. MDRX62H_Tail EQU 191
  470. MDRX62H_Multi EQU 192
  471. RotorGeeks_20A_Main EQU 193
  472. RotorGeeks_20A_Tail EQU 194
  473. RotorGeeks_20A_Multi EQU 195
  474. Flycolor_Fairy_6A_Main EQU 196
  475. Flycolor_Fairy_6A_Tail EQU 197
  476. Flycolor_Fairy_6A_Multi EQU 198
  477. Flycolor_Fairy_30A_Main EQU 199
  478. Flycolor_Fairy_30A_Tail EQU 200
  479. Flycolor_Fairy_30A_Multi EQU 201
  480. Flycolor_Raptor_20A_Main EQU 202
  481. Flycolor_Raptor_20A_Tail EQU 203
  482. Flycolor_Raptor_20A_Multi EQU 204
  483. Flycolor_Raptor_390_20A_Main EQU 205
  484. Flycolor_Raptor_390_20A_Tail EQU 206
  485. Flycolor_Raptor_390_20A_Multi EQU 207
  486. FVT_Littlebee_20A_Main EQU 208
  487. FVT_Littlebee_20A_Tail EQU 209
  488. FVT_Littlebee_20A_Multi EQU 210
  489. FVT_Littlebee_20A_Pro_Main EQU 211
  490. FVT_Littlebee_20A_Pro_Tail EQU 212
  491. FVT_Littlebee_20A_Pro_Multi EQU 213
  492. FVT_Littlebee_30A_Main EQU 214
  493. FVT_Littlebee_30A_Tail EQU 215
  494. FVT_Littlebee_30A_Multi EQU 216
  495. Graupner_Ultra_20A_Main EQU 217
  496. Graupner_Ultra_20A_Tail EQU 218
  497. Graupner_Ultra_20A_Multi EQU 219
  498. F85_3A_Main EQU 220
  499. F85_3A_Tail EQU 221
  500. F85_3A_Multi EQU 222
  501. ZTW_Spider_Pro_20A_Main EQU 223
  502. ZTW_Spider_Pro_20A_Tail EQU 224
  503. ZTW_Spider_Pro_20A_Multi EQU 225
  504. ZTW_Spider_Pro_20A_Premium_Main EQU 226
  505. ZTW_Spider_Pro_20A_Premium_Tail EQU 227
  506. ZTW_Spider_Pro_20A_Premium_Multi EQU 228
  507. ZTW_Spider_Pro_20A_HV_Main EQU 229
  508. ZTW_Spider_Pro_20A_HV_Tail EQU 230
  509. ZTW_Spider_Pro_20A_HV_Multi EQU 231
  510. ZTW_Spider_Pro_30A_HV_Main EQU 232
  511. ZTW_Spider_Pro_30A_HV_Tail EQU 233
  512. ZTW_Spider_Pro_30A_HV_Multi EQU 234
  513. DYS_XM20A_Main EQU 235
  514. DYS_XM20A_Tail EQU 236
  515. DYS_XM20A_Multi EQU 237
  516. Oversky_MR_20A_Pro_Main EQU 238
  517. Oversky_MR_20A_Pro_Tail EQU 239
  518. Oversky_MR_20A_Pro_Multi EQU 240
  519. TBS_Cube_12A_Main EQU 241
  520. TBS_Cube_12A_Tail EQU 242
  521. TBS_Cube_12A_Multi EQU 243
  522. DALRC_XR20A_Main EQU 244
  523. DALRC_XR20A_Tail EQU 245
  524. DALRC_XR20A_Multi EQU 246
  525. ;**** **** **** **** ****
  526. ; Select the ESC and mode to use (or unselect all for use with external batch compile file)
  527. ;BESCNO EQU XP_3A_Main
  528. ;BESCNO EQU XP_3A_Tail
  529. ;BESCNO EQU XP_3A_Multi
  530. ;BESCNO EQU XP_7A_Main
  531. ;BESCNO EQU XP_7A_Tail
  532. ;BESCNO EQU XP_7A_Multi
  533. ;BESCNO EQU XP_7A_Fast_Main
  534. ;BESCNO EQU XP_7A_Fast_Tail
  535. ;BESCNO EQU XP_7A_Fast_Multi
  536. ;BESCNO EQU XP_12A_Main
  537. ;BESCNO EQU XP_12A_Tail
  538. ;BESCNO EQU XP_12A_Multi
  539. ;BESCNO EQU XP_18A_Main
  540. ;BESCNO EQU XP_18A_Tail
  541. ;BESCNO EQU XP_18A_Multi
  542. ;BESCNO EQU XP_25A_Main
  543. ;BESCNO EQU XP_25A_Tail
  544. ;BESCNO EQU XP_25A_Multi
  545. ;BESCNO EQU XP_35A_SW_Main
  546. ;BESCNO EQU XP_35A_SW_Tail
  547. ;BESCNO EQU XP_35A_SW_Multi
  548. ;BESCNO EQU DP_3A_Main
  549. ;BESCNO EQU DP_3A_Tail
  550. ;BESCNO EQU DP_3A_Multi
  551. ;BESCNO EQU Supermicro_3p5A_Main
  552. ;BESCNO EQU Supermicro_3p5A_Tail
  553. ;BESCNO EQU Supermicro_3p5A_Multi
  554. ;BESCNO EQU Turnigy_Plush_6A_Main
  555. ;BESCNO EQU Turnigy_Plush_6A_Tail
  556. ;BESCNO EQU Turnigy_Plush_6A_Multi
  557. ;BESCNO EQU Turnigy_Plush_10A_Main
  558. ;BESCNO EQU Turnigy_Plush_10A_Tail
  559. ;BESCNO EQU Turnigy_Plush_10A_Multi
  560. ;BESCNO EQU Turnigy_Plush_12A_Main
  561. ;BESCNO EQU Turnigy_Plush_12A_Tail
  562. ;BESCNO EQU Turnigy_Plush_12A_Multi
  563. ;BESCNO EQU Turnigy_Plush_18A_Main
  564. ;BESCNO EQU Turnigy_Plush_18A_Tail
  565. ;BESCNO EQU Turnigy_Plush_18A_Multi
  566. ;BESCNO EQU Turnigy_Plush_25A_Main
  567. ;BESCNO EQU Turnigy_Plush_25A_Tail
  568. ;BESCNO EQU Turnigy_Plush_25A_Multi
  569. ;BESCNO EQU Turnigy_Plush_30A_Main
  570. ;BESCNO EQU Turnigy_Plush_30A_Tail
  571. ;BESCNO EQU Turnigy_Plush_30A_Multi
  572. ;BESCNO EQU Turnigy_Plush_40A_Main
  573. ;BESCNO EQU Turnigy_Plush_40A_Tail
  574. ;BESCNO EQU Turnigy_Plush_40A_Multi
  575. ;BESCNO EQU Turnigy_Plush_60A_Main
  576. ;BESCNO EQU Turnigy_Plush_60A_Tail
  577. ;BESCNO EQU Turnigy_Plush_60A_Multi
  578. ;BESCNO EQU Turnigy_Plush_80A_Main
  579. ;BESCNO EQU Turnigy_Plush_80A_Tail
  580. ;BESCNO EQU Turnigy_Plush_80A_Multi
  581. ;BESCNO EQU Turnigy_Plush_Nfet_18A_Main
  582. ;BESCNO EQU Turnigy_Plush_Nfet_18A_Tail
  583. ;BESCNO EQU Turnigy_Plush_Nfet_18A_Multi
  584. ;BESCNO EQU Turnigy_Plush_Nfet_25A_Main
  585. ;BESCNO EQU Turnigy_Plush_Nfet_25A_Tail
  586. ;BESCNO EQU Turnigy_Plush_Nfet_25A_Multi
  587. ;BESCNO EQU Turnigy_Plush_Nfet_30A_Main
  588. ;BESCNO EQU Turnigy_Plush_Nfet_30A_Tail
  589. ;BESCNO EQU Turnigy_Plush_Nfet_30A_Multi
  590. ;BESCNO EQU Turnigy_AE_20A_Main
  591. ;BESCNO EQU Turnigy_AE_20A_Tail
  592. ;BESCNO EQU Turnigy_AE_20A_Multi
  593. ;BESCNO EQU Turnigy_AE_25A_Main
  594. ;BESCNO EQU Turnigy_AE_25A_Tail
  595. ;BESCNO EQU Turnigy_AE_25A_Multi
  596. ;BESCNO EQU Turnigy_AE_30A_Main
  597. ;BESCNO EQU Turnigy_AE_30A_Tail
  598. ;BESCNO EQU Turnigy_AE_30A_Multi
  599. ;BESCNO EQU Turnigy_AE_45A_Main
  600. ;BESCNO EQU Turnigy_AE_45A_Tail
  601. ;BESCNO EQU Turnigy_AE_45A_Multi
  602. ;BESCNO EQU Turnigy_KForce_40A_Main
  603. ;BESCNO EQU Turnigy_KForce_40A_Tail
  604. ;BESCNO EQU Turnigy_KForce_40A_Multi
  605. ;BESCNO EQU Turnigy_KForce_70A_HV_Main
  606. ;BESCNO EQU Turnigy_KForce_70A_HV_Tail
  607. ;BESCNO EQU Turnigy_KForce_70A_HV_Multi
  608. ;BESCNO EQU Turnigy_KForce_120A_HV_Main
  609. ;BESCNO EQU Turnigy_KForce_120A_HV_Tail
  610. ;BESCNO EQU Turnigy_KForce_120A_HV_Multi
  611. ;BESCNO EQU Turnigy_KForce_120A_HV_v2_Main
  612. ;BESCNO EQU Turnigy_KForce_120A_HV_v2_Tail
  613. ;BESCNO EQU Turnigy_KForce_120A_HV_v2_Multi
  614. ;BESCNO EQU Skywalker_20A_Main
  615. ;BESCNO EQU Skywalker_20A_Tail
  616. ;BESCNO EQU Skywalker_20A_Multi
  617. ;BESCNO EQU Skywalker_40A_Main
  618. ;BESCNO EQU Skywalker_40A_Tail
  619. ;BESCNO EQU Skywalker_40A_Multi
  620. ;BESCNO EQU HiModel_Cool_22A_Main
  621. ;BESCNO EQU HiModel_Cool_22A_Tail
  622. ;BESCNO EQU HiModel_Cool_22A_Multi
  623. ;BESCNO EQU HiModel_Cool_33A_Main
  624. ;BESCNO EQU HiModel_Cool_33A_Tail
  625. ;BESCNO EQU HiModel_Cool_33A_Multi
  626. ;BESCNO EQU HiModel_Cool_41A_Main
  627. ;BESCNO EQU HiModel_Cool_41A_Tail
  628. ;BESCNO EQU HiModel_Cool_41A_Multi
  629. ;BESCNO EQU RCTimer_6A_Main
  630. ;BESCNO EQU RCTimer_6A_Tail
  631. ;BESCNO EQU RCTimer_6A_Multi
  632. ;BESCNO EQU Align_RCE_BL15X_Main
  633. ;BESCNO EQU Align_RCE_BL15X_Tail
  634. ;BESCNO EQU Align_RCE_BL15X_Multi
  635. ;BESCNO EQU Align_RCE_BL15P_Main
  636. ;BESCNO EQU Align_RCE_BL15P_Tail
  637. ;BESCNO EQU Align_RCE_BL15P_Multi
  638. ;BESCNO EQU Align_RCE_BL35X_Main
  639. ;BESCNO EQU Align_RCE_BL35X_Tail
  640. ;BESCNO EQU Align_RCE_BL35X_Multi
  641. ;BESCNO EQU Align_RCE_BL35P_Main
  642. ;BESCNO EQU Align_RCE_BL35P_Tail
  643. ;BESCNO EQU Align_RCE_BL35P_Multi
  644. ;BESCNO EQU Gaui_GE_183_18A_Main
  645. ;BESCNO EQU Gaui_GE_183_18A_Tail
  646. ;BESCNO EQU Gaui_GE_183_18A_Multi
  647. ;BESCNO EQU H_King_10A_Main
  648. ;BESCNO EQU H_King_10A_Tail
  649. ;BESCNO EQU H_King_10A_Multi
  650. ;BESCNO EQU H_King_20A_Main
  651. ;BESCNO EQU H_King_20A_Tail
  652. ;BESCNO EQU H_King_20A_Multi
  653. ;BESCNO EQU H_King_35A_Main
  654. ;BESCNO EQU H_King_35A_Tail
  655. ;BESCNO EQU H_King_35A_Multi
  656. ;BESCNO EQU H_King_50A_Main
  657. ;BESCNO EQU H_King_50A_Tail
  658. ;BESCNO EQU H_King_50A_Multi
  659. ;BESCNO EQU Polaris_Thunder_12A_Main
  660. ;BESCNO EQU Polaris_Thunder_12A_Tail
  661. ;BESCNO EQU Polaris_Thunder_12A_Multi
  662. ;BESCNO EQU Polaris_Thunder_20A_Main
  663. ;BESCNO EQU Polaris_Thunder_20A_Tail
  664. ;BESCNO EQU Polaris_Thunder_20A_Multi
  665. ;BESCNO EQU Polaris_Thunder_30A_Main
  666. ;BESCNO EQU Polaris_Thunder_30A_Tail
  667. ;BESCNO EQU Polaris_Thunder_30A_Multi
  668. ;BESCNO EQU Polaris_Thunder_40A_Main
  669. ;BESCNO EQU Polaris_Thunder_40A_Tail
  670. ;BESCNO EQU Polaris_Thunder_40A_Multi
  671. ;BESCNO EQU Polaris_Thunder_60A_Main
  672. ;BESCNO EQU Polaris_Thunder_60A_Tail
  673. ;BESCNO EQU Polaris_Thunder_60A_Multi
  674. ;BESCNO EQU Polaris_Thunder_80A_Main
  675. ;BESCNO EQU Polaris_Thunder_80A_Tail
  676. ;BESCNO EQU Polaris_Thunder_80A_Multi
  677. ;BESCNO EQU Polaris_Thunder_100A_Main
  678. ;BESCNO EQU Polaris_Thunder_100A_Tail
  679. ;BESCNO EQU Polaris_Thunder_100A_Multi
  680. ;BESCNO EQU Platinum_Pro_30A_Main
  681. ;BESCNO EQU Platinum_Pro_30A_Tail
  682. ;BESCNO EQU Platinum_Pro_30A_Multi
  683. ;BESCNO EQU Platinum_Pro_150A_Main
  684. ;BESCNO EQU Platinum_Pro_150A_Tail
  685. ;BESCNO EQU Platinum_Pro_150A_Multi
  686. ;BESCNO EQU Platinum_50Av3_Main
  687. ;BESCNO EQU Platinum_50Av3_Tail
  688. ;BESCNO EQU Platinum_50Av3_Multi
  689. ;BESCNO EQU EAZY_3Av2_Main
  690. ;BESCNO EQU EAZY_3Av2_Tail
  691. ;BESCNO EQU EAZY_3Av2_Multi
  692. ;BESCNO EQU Tarot_30A_Main
  693. ;BESCNO EQU Tarot_30A_Tail
  694. ;BESCNO EQU Tarot_30A_Multi
  695. ;BESCNO EQU SkyIII_30A_Main
  696. ;BESCNO EQU SkyIII_30A_Tail
  697. ;BESCNO EQU SkyIII_30A_Multi
  698. ;BESCNO EQU EMAX_20A_Main
  699. ;BESCNO EQU EMAX_20A_Tail
  700. ;BESCNO EQU EMAX_20A_Multi
  701. ;BESCNO EQU EMAX_40A_Main
  702. ;BESCNO EQU EMAX_40A_Tail
  703. ;BESCNO EQU EMAX_40A_Multi
  704. ;BESCNO EQU EMAX_Nano_20A_Main
  705. ;BESCNO EQU EMAX_Nano_20A_Tail
  706. ;BESCNO EQU EMAX_Nano_20A_Multi
  707. ;BESCNO EQU XRotor_10A_Main
  708. ;BESCNO EQU XRotor_10A_Tail
  709. ;BESCNO EQU XRotor_10A_Multi
  710. ;BESCNO EQU XRotor_20A_Main
  711. ;BESCNO EQU XRotor_20A_Tail
  712. ;BESCNO EQU XRotor_20A_Multi
  713. ;BESCNO EQU XRotor_40A_Main
  714. ;BESCNO EQU XRotor_40A_Tail
  715. ;BESCNO EQU XRotor_40A_Multi
  716. ;BESCNO EQU MDRX62H_Main
  717. ;BESCNO EQU MDRX62H_Tail
  718. ;BESCNO EQU MDRX62H_Multi
  719. ;BESCNO EQU RotorGeeks_20A_Main
  720. ;BESCNO EQU RotorGeeks_20A_Tail
  721. ;BESCNO EQU RotorGeeks_20A_Multi
  722. ;BESCNO EQU Flycolor_Fairy_6A_Main
  723. ;BESCNO EQU Flycolor_Fairy_6A_Tail
  724. ;BESCNO EQU Flycolor_Fairy_6A_Multi
  725. ;BESCNO EQU Flycolor_Fairy_30A_Main
  726. ;BESCNO EQU Flycolor_Fairy_30A_Tail
  727. ;BESCNO EQU Flycolor_Fairy_30A_Multi
  728. ;BESCNO EQU Flycolor_Raptor_20A_Main
  729. ;BESCNO EQU Flycolor_Raptor_20A_Tail
  730. ;BESCNO EQU Flycolor_Raptor_20A_Multi
  731. ;BESCNO EQU Flycolor_Raptor_390_20A_Main
  732. ;BESCNO EQU Flycolor_Raptor_390_20A_Tail
  733. ;BESCNO EQU Flycolor_Raptor_390_20A_Multi
  734. ;BESCNO EQU FVT_Littlebee_20A_Main
  735. ;BESCNO EQU FVT_Littlebee_20A_Tail
  736. ;BESCNO EQU FVT_Littlebee_20A_Multi
  737. ;BESCNO EQU FVT_Littlebee_20A_Pro_Main
  738. ;BESCNO EQU FVT_Littlebee_20A_Pro_Tail
  739. ;BESCNO EQU FVT_Littlebee_20A_Pro_Multi
  740. ;BESCNO EQU FVT_Littlebee_30A_Main
  741. ;BESCNO EQU FVT_Littlebee_30A_Tail
  742. ;BESCNO EQU FVT_Littlebee_30A_Multi
  743. ;BESCNO EQU Graupner_Ultra_20A_Main
  744. ;BESCNO EQU Graupner_Ultra_20A_Tail
  745. ;BESCNO EQU Graupner_Ultra_20A_Multi
  746. ;BESCNO EQU F85_3A_Main
  747. ;BESCNO EQU F85_3A_Tail
  748. ;BESCNO EQU F85_3A_Multi
  749. ;BESCNO EQU ZTW_Spider_Pro_20A_Main
  750. ;BESCNO EQU ZTW_Spider_Pro_20A_Tail
  751. ;BESCNO EQU ZTW_Spider_Pro_20A_Multi
  752. ;BESCNO EQU ZTW_Spider_Pro_20A_Premium_Main
  753. ;BESCNO EQU ZTW_Spider_Pro_20A_Premium_Tail
  754. ;BESCNO EQU ZTW_Spider_Pro_20A_Premium_Multi
  755. ;BESCNO EQU ZTW_Spider_Pro_20A_HV_Main
  756. ;BESCNO EQU ZTW_Spider_Pro_20A_HV_Tail
  757. ;BESCNO EQU ZTW_Spider_Pro_20A_HV_Multi
  758. ;BESCNO EQU ZTW_Spider_Pro_30A_HV_Main
  759. ;BESCNO EQU ZTW_Spider_Pro_30A_HV_Tail
  760. ;BESCNO EQU ZTW_Spider_Pro_30A_HV_Multi
  761. ;BESCNO EQU DYS_XM20A_Main
  762. ;BESCNO EQU DYS_XM20A_Tail
  763. ;BESCNO EQU DYS_XM20A_Multi
  764. ;BESCNO EQU Oversky_MR_20A_Pro_Main
  765. ;BESCNO EQU Oversky_MR_20A_Pro_Tail
  766. ;BESCNO EQU Oversky_MR_20A_Pro_Multi
  767. ;BESCNO EQU TBS_Cube_12A_Main
  768. ;BESCNO EQU TBS_Cube_12A_Tail
  769. ;BESCNO EQU TBS_Cube_12A_Multi
  770. ;BESCNO EQU DALRC_XR20A_Main
  771. ;BESCNO EQU DALRC_XR20A_Tail
  772. ;BESCNO EQU DALRC_XR20A_Multi
  773. ;**** **** **** **** ****
  774. ; ESC selection statements
  775. IF BESCNO == XP_3A_Main
  776. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  777. $include (XP_3A.inc) ; Select XP 3A pinout
  778. ENDIF
  779. IF BESCNO == XP_3A_Tail
  780. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  781. $include (XP_3A.inc) ; Select XP 3A pinout
  782. ENDIF
  783. IF BESCNO == XP_3A_Multi
  784. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  785. $include (XP_3A.inc) ; Select XP 3A pinout
  786. ENDIF
  787. IF BESCNO == XP_7A_Main
  788. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  789. $include (XP_7A.inc) ; Select XP 7A pinout
  790. ENDIF
  791. IF BESCNO == XP_7A_Tail
  792. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  793. $include (XP_7A.inc) ; Select XP 7A pinout
  794. ENDIF
  795. IF BESCNO == XP_7A_Multi
  796. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  797. $include (XP_7A.inc) ; Select XP 7A pinout
  798. ENDIF
  799. IF BESCNO == XP_7A_Fast_Main
  800. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  801. $include (XP_7A_Fast.inc) ; Select XP 7A Fast pinout
  802. ENDIF
  803. IF BESCNO == XP_7A_Fast_Tail
  804. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  805. $include (XP_7A_Fast.inc) ; Select XP 7A Fast pinout
  806. ENDIF
  807. IF BESCNO == XP_7A_Fast_Multi
  808. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  809. $include (XP_7A_Fast.inc) ; Select XP 7A Fast pinout
  810. ENDIF
  811. IF BESCNO == XP_12A_Main
  812. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  813. $include (XP_12A.inc) ; Select XP 12A pinout
  814. ENDIF
  815. IF BESCNO == XP_12A_Tail
  816. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  817. $include (XP_12A.inc) ; Select XP 12A pinout
  818. ENDIF
  819. IF BESCNO == XP_12A_Multi
  820. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  821. $include (XP_12A.inc) ; Select XP 12A pinout
  822. ENDIF
  823. IF BESCNO == XP_18A_Main
  824. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  825. $include (XP_18A.inc) ; Select XP 18A pinout
  826. ENDIF
  827. IF BESCNO == XP_18A_Tail
  828. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  829. $include (XP_18A.inc) ; Select XP 18A pinout
  830. ENDIF
  831. IF BESCNO == XP_18A_Multi
  832. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  833. $include (XP_18A.inc) ; Select XP 18A pinout
  834. ENDIF
  835. IF BESCNO == XP_25A_Main
  836. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  837. $include (XP_25A.inc) ; Select XP 25A pinout
  838. ENDIF
  839. IF BESCNO == XP_25A_Tail
  840. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  841. $include (XP_25A.inc) ; Select XP 25A pinout
  842. ENDIF
  843. IF BESCNO == XP_25A_Multi
  844. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  845. $include (XP_25A.inc) ; Select XP 25A pinout
  846. ENDIF
  847. IF BESCNO == XP_35A_SW_Main
  848. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  849. $include (XP_35A_SW.inc) ; Select XP 35A SW pinout
  850. ENDIF
  851. IF BESCNO == XP_35A_SW_Tail
  852. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  853. $include (XP_35A_SW.inc) ; Select XP 35A SW pinout
  854. ENDIF
  855. IF BESCNO == XP_35A_SW_Multi
  856. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  857. $include (XP_35A_SW.inc) ; Select XP 35A SW pinout
  858. ENDIF
  859. IF BESCNO == DP_3A_Main
  860. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  861. $include (DP_3A.inc) ; Select DP 3A pinout
  862. ENDIF
  863. IF BESCNO == DP_3A_Tail
  864. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  865. $include (DP_3A.inc) ; Select DP 3A pinout
  866. ENDIF
  867. IF BESCNO == DP_3A_Multi
  868. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  869. $include (DP_3A.inc) ; Select DP 3A pinout
  870. ENDIF
  871. IF BESCNO == Supermicro_3p5A_Main
  872. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  873. $include (Supermicro_3p5A.inc) ; Select Supermicro 3.5A pinout
  874. ENDIF
  875. IF BESCNO == Supermicro_3p5A_Tail
  876. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  877. $include (Supermicro_3p5A.inc) ; Select Supermicro 3.5A pinout
  878. ENDIF
  879. IF BESCNO == Supermicro_3p5A_Multi
  880. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  881. $include (Supermicro_3p5A.inc) ; Select Supermicro 3.5A pinout
  882. ENDIF
  883. IF BESCNO == Turnigy_Plush_6A_Main
  884. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  885. $include (Turnigy_Plush_6A.inc) ; Select Turnigy Plush 6A pinout
  886. ENDIF
  887. IF BESCNO == Turnigy_Plush_6A_Tail
  888. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  889. $include (Turnigy_Plush_6A.inc) ; Select Turnigy Plush 6A pinout
  890. ENDIF
  891. IF BESCNO == Turnigy_Plush_6A_Multi
  892. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  893. $include (Turnigy_Plush_6A.inc) ; Select Turnigy Plush 6A pinout
  894. ENDIF
  895. IF BESCNO == Turnigy_Plush_10A_Main
  896. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  897. $include (Turnigy_Plush_10A.inc) ; Select Turnigy Plush 10A pinout
  898. ENDIF
  899. IF BESCNO == Turnigy_Plush_10A_Tail
  900. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  901. $include (Turnigy_Plush_10A.inc) ; Select Turnigy Plush 10A pinout
  902. ENDIF
  903. IF BESCNO == Turnigy_Plush_10A_Multi
  904. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  905. $include (Turnigy_Plush_10A.inc) ; Select Turnigy Plush 10A pinout
  906. ENDIF
  907. IF BESCNO == Turnigy_Plush_12A_Main
  908. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  909. $include (Turnigy_Plush_12A.inc) ; Select Turnigy Plush 12A pinout
  910. ENDIF
  911. IF BESCNO == Turnigy_Plush_12A_Tail
  912. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  913. $include (Turnigy_Plush_12A.inc) ; Select Turnigy Plush 12A pinout
  914. ENDIF
  915. IF BESCNO == Turnigy_Plush_12A_Multi
  916. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  917. $include (Turnigy_Plush_12A.inc) ; Select Turnigy Plush 12A pinout
  918. ENDIF
  919. IF BESCNO == Turnigy_Plush_18A_Main
  920. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  921. $include (Turnigy_Plush_18A.inc) ; Select Turnigy Plush 18A pinout
  922. ENDIF
  923. IF BESCNO == Turnigy_Plush_18A_Tail
  924. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  925. $include (Turnigy_Plush_18A.inc) ; Select Turnigy Plush 18A pinout
  926. ENDIF
  927. IF BESCNO == Turnigy_Plush_18A_Multi
  928. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  929. $include (Turnigy_Plush_18A.inc) ; Select Turnigy Plush 18A pinout
  930. ENDIF
  931. IF BESCNO == Turnigy_Plush_25A_Main
  932. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  933. $include (Turnigy_Plush_25A.inc) ; Select Turnigy Plush 25A pinout
  934. ENDIF
  935. IF BESCNO == Turnigy_Plush_25A_Tail
  936. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  937. $include (Turnigy_Plush_25A.inc) ; Select Turnigy Plush 25A pinout
  938. ENDIF
  939. IF BESCNO == Turnigy_Plush_25A_Multi
  940. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  941. $include (Turnigy_Plush_25A.inc) ; Select Turnigy Plush 25A pinout
  942. ENDIF
  943. IF BESCNO == Turnigy_Plush_30A_Main
  944. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  945. $include (Turnigy_Plush_30A.inc) ; Select Turnigy Plush 30A pinout
  946. ENDIF
  947. IF BESCNO == Turnigy_Plush_30A_Tail
  948. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  949. $include (Turnigy_Plush_30A.inc) ; Select Turnigy Plush 30A pinout
  950. ENDIF
  951. IF BESCNO == Turnigy_Plush_30A_Multi
  952. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  953. $include (Turnigy_Plush_30A.inc) ; Select Turnigy Plush 30A pinout
  954. ENDIF
  955. IF BESCNO == Turnigy_Plush_40A_Main
  956. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  957. $include (Turnigy_Plush_40A.inc) ; Select Turnigy Plush 40A pinout
  958. ENDIF
  959. IF BESCNO == Turnigy_Plush_40A_Tail
  960. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  961. $include (Turnigy_Plush_40A.inc) ; Select Turnigy Plush 40A pinout
  962. ENDIF
  963. IF BESCNO == Turnigy_Plush_40A_Multi
  964. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  965. $include (Turnigy_Plush_40A.inc) ; Select Turnigy Plush 40A pinout
  966. ENDIF
  967. IF BESCNO == Turnigy_Plush_60A_Main
  968. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  969. $include (Turnigy_Plush_60A.inc) ; Select Turnigy Plush 60A pinout
  970. ENDIF
  971. IF BESCNO == Turnigy_Plush_60A_Tail
  972. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  973. $include (Turnigy_Plush_60A.inc) ; Select Turnigy Plush 60A pinout
  974. ENDIF
  975. IF BESCNO == Turnigy_Plush_60A_Multi
  976. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  977. $include (Turnigy_Plush_60A.inc) ; Select Turnigy Plush 60A pinout
  978. ENDIF
  979. IF BESCNO == Turnigy_Plush_80A_Main
  980. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  981. $include (Turnigy_Plush_80A.inc) ; Select Turnigy Plush 80A pinout
  982. ENDIF
  983. IF BESCNO == Turnigy_Plush_80A_Tail
  984. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  985. $include (Turnigy_Plush_80A.inc) ; Select Turnigy Plush 80A pinout
  986. ENDIF
  987. IF BESCNO == Turnigy_Plush_80A_Multi
  988. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  989. $include (Turnigy_Plush_80A.inc) ; Select Turnigy Plush 80A pinout
  990. ENDIF
  991. IF BESCNO == Turnigy_Plush_Nfet_18A_Main
  992. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  993. $include (Turnigy_Plush_Nfet_18A.inc) ; Select Turnigy Plush Nfet 18A pinout
  994. ENDIF
  995. IF BESCNO == Turnigy_Plush_Nfet_18A_Tail
  996. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  997. $include (Turnigy_Plush_Nfet_18A.inc) ; Select Turnigy Plush Nfet 18A pinout
  998. ENDIF
  999. IF BESCNO == Turnigy_Plush_Nfet_18A_Multi
  1000. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1001. $include (Turnigy_Plush_Nfet_18A.inc) ; Select Turnigy Plush Nfet 18A pinout
  1002. ENDIF
  1003. IF BESCNO == Turnigy_Plush_Nfet_25A_Main
  1004. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1005. $include (Turnigy_Plush_Nfet_25A.inc) ; Select Turnigy Plush Nfet 25A pinout
  1006. ENDIF
  1007. IF BESCNO == Turnigy_Plush_Nfet_25A_Tail
  1008. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1009. $include (Turnigy_Plush_Nfet_25A.inc) ; Select Turnigy Plush Nfet 25A pinout
  1010. ENDIF
  1011. IF BESCNO == Turnigy_Plush_Nfet_25A_Multi
  1012. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1013. $include (Turnigy_Plush_Nfet_25A.inc) ; Select Turnigy Plush Nfet 25A pinout
  1014. ENDIF
  1015. IF BESCNO == Turnigy_Plush_Nfet_30A_Main
  1016. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1017. $include (Turnigy_Plush_Nfet_30A.inc) ; Select Turnigy Plush Nfet 30A pinout
  1018. ENDIF
  1019. IF BESCNO == Turnigy_Plush_Nfet_30A_Tail
  1020. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1021. $include (Turnigy_Plush_Nfet_30A.inc) ; Select Turnigy Plush Nfet 30A pinout
  1022. ENDIF
  1023. IF BESCNO == Turnigy_Plush_Nfet_30A_Multi
  1024. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1025. $include (Turnigy_Plush_Nfet_30A.inc) ; Select Turnigy Plush Nfet 30A pinout
  1026. ENDIF
  1027. IF BESCNO == Turnigy_AE_20A_Main
  1028. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1029. $include (Turnigy_AE_20A.inc) ; Select Turnigy AE-20A pinout
  1030. ENDIF
  1031. IF BESCNO == Turnigy_AE_20A_Tail
  1032. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1033. $include (Turnigy_AE_20A.inc) ; Select Turnigy AE-20A pinout
  1034. ENDIF
  1035. IF BESCNO == Turnigy_AE_20A_Multi
  1036. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1037. $include (Turnigy_AE_20A.inc) ; Select Turnigy AE-20A pinout
  1038. ENDIF
  1039. IF BESCNO == Turnigy_AE_25A_Main
  1040. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1041. $include (Turnigy_AE_25A.inc) ; Select Turnigy AE-25A pinout
  1042. ENDIF
  1043. IF BESCNO == Turnigy_AE_25A_Tail
  1044. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1045. $include (Turnigy_AE_25A.inc) ; Select Turnigy AE-25A pinout
  1046. ENDIF
  1047. IF BESCNO == Turnigy_AE_25A_Multi
  1048. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1049. $include (Turnigy_AE_25A.inc) ; Select Turnigy AE-25A pinout
  1050. ENDIF
  1051. IF BESCNO == Turnigy_AE_30A_Main
  1052. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1053. $include (Turnigy_AE_30A.inc) ; Select Turnigy AE-30A pinout
  1054. ENDIF
  1055. IF BESCNO == Turnigy_AE_30A_Tail
  1056. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1057. $include (Turnigy_AE_30A.inc) ; Select Turnigy AE-30A pinout
  1058. ENDIF
  1059. IF BESCNO == Turnigy_AE_30A_Multi
  1060. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1061. $include (Turnigy_AE_30A.inc) ; Select Turnigy AE-30A pinout
  1062. ENDIF
  1063. IF BESCNO == Turnigy_AE_45A_Main
  1064. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1065. $include (Turnigy_AE_45A.inc) ; Select Turnigy AE-45A pinout
  1066. ENDIF
  1067. IF BESCNO == Turnigy_AE_45A_Tail
  1068. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1069. $include (Turnigy_AE_45A.inc) ; Select Turnigy AE-45A pinout
  1070. ENDIF
  1071. IF BESCNO == Turnigy_AE_45A_Multi
  1072. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1073. $include (Turnigy_AE_45A.inc) ; Select Turnigy AE-45A pinout
  1074. ENDIF
  1075. IF BESCNO == Turnigy_KForce_40A_Main
  1076. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1077. $include (Turnigy_KForce_40A.inc) ; Select Turnigy KForce 40A pinout
  1078. ENDIF
  1079. IF BESCNO == Turnigy_KForce_40A_Tail
  1080. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1081. $include (Turnigy_KForce_40A.inc) ; Select Turnigy KForce 40A pinout
  1082. ENDIF
  1083. IF BESCNO == Turnigy_KForce_40A_Multi
  1084. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1085. $include (Turnigy_KForce_40A.inc) ; Select Turnigy KForce 40A pinout
  1086. ENDIF
  1087. IF BESCNO == Turnigy_KForce_70A_HV_Main
  1088. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1089. $include (Turnigy_KForce_70A_HV.inc) ; Select Turnigy KForce 70A HV pinout
  1090. ENDIF
  1091. IF BESCNO == Turnigy_KForce_70A_HV_Tail
  1092. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1093. $include (Turnigy_KForce_70A_HV.inc) ; Select Turnigy KForce 70A HV pinout
  1094. ENDIF
  1095. IF BESCNO == Turnigy_KForce_70A_HV_Multi
  1096. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1097. $include (Turnigy_KForce_70A_HV.inc) ; Select Turnigy KForce 70A HV pinout
  1098. ENDIF
  1099. IF BESCNO == Turnigy_KForce_120A_HV_Main
  1100. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1101. $include (Turnigy_KForce_120A_HV.inc) ; Select Turnigy KForce 120A HV pinout
  1102. ENDIF
  1103. IF BESCNO == Turnigy_KForce_120A_HV_Tail
  1104. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1105. $include (Turnigy_KForce_120A_HV.inc) ; Select Turnigy KForce 120A HV pinout
  1106. ENDIF
  1107. IF BESCNO == Turnigy_KForce_120A_HV_Multi
  1108. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1109. $include (Turnigy_KForce_120A_HV.inc) ; Select Turnigy KForce 120A HV pinout
  1110. ENDIF
  1111. IF BESCNO == Turnigy_KForce_120A_HV_v2_Main
  1112. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1113. $include (Turnigy_KForce_120A_HV_v2.inc); Select Turnigy KForce 120A HV v2 pinout
  1114. ENDIF
  1115. IF BESCNO == Turnigy_KForce_120A_HV_v2_Tail
  1116. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1117. $include (Turnigy_KForce_120A_HV_v2.inc); Select Turnigy KForce 120A HV v2 pinout
  1118. ENDIF
  1119. IF BESCNO == Turnigy_KForce_120A_HV_v2_Multi
  1120. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1121. $include (Turnigy_KForce_120A_HV_v2.inc); Select Turnigy KForce 120A HV v2 pinout
  1122. ENDIF
  1123. IF BESCNO == Skywalker_20A_Main
  1124. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1125. $include (Skywalker_20A.inc) ; Select Skywalker 20A pinout
  1126. ENDIF
  1127. IF BESCNO == Skywalker_20A_Tail
  1128. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1129. $include (Skywalker_20A.inc) ; Select Skywalker 20A pinout
  1130. ENDIF
  1131. IF BESCNO == Skywalker_20A_Multi
  1132. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1133. $include (Skywalker_20A.inc) ; Select Skywalker 20A pinout
  1134. ENDIF
  1135. IF BESCNO == Skywalker_40A_Main
  1136. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1137. $include (Skywalker_40A.inc) ; Select Skywalker 40A pinout
  1138. ENDIF
  1139. IF BESCNO == Skywalker_40A_Tail
  1140. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1141. $include (Skywalker_40A.inc) ; Select Skywalker 40A pinout
  1142. ENDIF
  1143. IF BESCNO == Skywalker_40A_Multi
  1144. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1145. $include (Skywalker_40A.inc) ; Select Skywalker 40A pinout
  1146. ENDIF
  1147. IF BESCNO == HiModel_Cool_22A_Main
  1148. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1149. $include (HiModel_Cool_22A.inc) ; Select HiModel Cool 22A pinout
  1150. ENDIF
  1151. IF BESCNO == HiModel_Cool_22A_Tail
  1152. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1153. $include (HiModel_Cool_22A.inc) ; Select HiModel Cool 22A pinout
  1154. ENDIF
  1155. IF BESCNO == HiModel_Cool_22A_Multi
  1156. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1157. $include (HiModel_Cool_22A.inc) ; Select HiModel Cool 22A pinout
  1158. ENDIF
  1159. IF BESCNO == HiModel_Cool_33A_Main
  1160. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1161. $include (HiModel_Cool_33A.inc) ; Select HiModel Cool 33A pinout
  1162. ENDIF
  1163. IF BESCNO == HiModel_Cool_33A_Tail
  1164. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1165. $include (HiModel_Cool_33A.inc) ; Select HiModel Cool 33A pinout
  1166. ENDIF
  1167. IF BESCNO == HiModel_Cool_33A_Multi
  1168. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1169. $include (HiModel_Cool_33A.inc) ; Select HiModel Cool 33A pinout
  1170. ENDIF
  1171. IF BESCNO == HiModel_Cool_41A_Main
  1172. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1173. $include (HiModel_Cool_41A.inc) ; Select HiModel Cool 41A pinout
  1174. ENDIF
  1175. IF BESCNO == HiModel_Cool_41A_Tail
  1176. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1177. $include (HiModel_Cool_41A.inc) ; Select HiModel Cool 41A pinout
  1178. ENDIF
  1179. IF BESCNO == HiModel_Cool_41A_Multi
  1180. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1181. $include (HiModel_Cool_41A.inc) ; Select HiModel Cool 41A pinout
  1182. ENDIF
  1183. IF BESCNO == RCTimer_6A_Main
  1184. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1185. $include (RCTimer_6A.inc) ; Select RC Timer 6A pinout
  1186. ENDIF
  1187. IF BESCNO == RCTimer_6A_Tail
  1188. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1189. $include (RCTimer_6A.inc) ; Select RC Timer 6A pinout
  1190. ENDIF
  1191. IF BESCNO == RCTimer_6A_Multi
  1192. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1193. $include (RCTimer_6A.inc) ; Select RC Timer 6A pinout
  1194. ENDIF
  1195. IF BESCNO == Align_RCE_BL15X_Main
  1196. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1197. $include (Align_RCE_BL15X.inc) ; Select Align RCE-BL15X pinout
  1198. ENDIF
  1199. IF BESCNO == Align_RCE_BL15X_Tail
  1200. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1201. $include (Align_RCE_BL15X.inc) ; Select Align RCE-BL15X pinout
  1202. ENDIF
  1203. IF BESCNO == Align_RCE_BL15X_Multi
  1204. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1205. $include (Align_RCE_BL15X.inc) ; Select Align RCE-BL15X pinout
  1206. ENDIF
  1207. IF BESCNO == Align_RCE_BL15P_Main
  1208. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1209. $include (Align_RCE_BL15P.inc) ; Select Align RCE-BL15P pinout
  1210. ENDIF
  1211. IF BESCNO == Align_RCE_BL15P_Tail
  1212. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1213. $include (Align_RCE_BL15P.inc) ; Select Align RCE-BL15P pinout
  1214. ENDIF
  1215. IF BESCNO == Align_RCE_BL15P_Multi
  1216. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1217. $include (Align_RCE_BL15P.inc) ; Select Align RCE-BL15P pinout
  1218. ENDIF
  1219. IF BESCNO == Align_RCE_BL35X_Main
  1220. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1221. $include (Align_RCE_BL35X.inc) ; Select Align RCE-BL35X pinout
  1222. ENDIF
  1223. IF BESCNO == Align_RCE_BL35X_Tail
  1224. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1225. $include (Align_RCE_BL35X.inc) ; Select Align RCE-BL35X pinout
  1226. ENDIF
  1227. IF BESCNO == Align_RCE_BL35X_Multi
  1228. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1229. $include (Align_RCE_BL35X.inc) ; Select Align RCE-BL35X pinout
  1230. ENDIF
  1231. IF BESCNO == Align_RCE_BL35P_Main
  1232. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1233. $include (Align_RCE_BL35P.inc) ; Select Align RCE-BL35P pinout
  1234. ENDIF
  1235. IF BESCNO == Align_RCE_BL35P_Tail
  1236. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1237. $include (Align_RCE_BL35P.inc) ; Select Align RCE-BL35P pinout
  1238. ENDIF
  1239. IF BESCNO == Align_RCE_BL35P_Multi
  1240. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1241. $include (Align_RCE_BL35P.inc) ; Select Align RCE-BL35P pinout
  1242. ENDIF
  1243. IF BESCNO == Gaui_GE_183_18A_Main
  1244. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1245. $include (Gaui_GE_183_18A.inc) ; Select Gaui GE-183 18A pinout
  1246. ENDIF
  1247. IF BESCNO == Gaui_GE_183_18A_Tail
  1248. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1249. $include (Gaui_GE_183_18A.inc) ; Select Gaui GE-183 18A pinout
  1250. ENDIF
  1251. IF BESCNO == Gaui_GE_183_18A_Multi
  1252. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1253. $include (Gaui_GE_183_18A.inc) ; Select Gaui GE-183 18A pinout
  1254. ENDIF
  1255. IF BESCNO == H_King_10A_Main
  1256. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1257. $include (H_King_10A.inc) ; Select H-King 10A pinout
  1258. ENDIF
  1259. IF BESCNO == H_King_10A_Tail
  1260. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1261. $include (H_King_10A.inc) ; Select H-King 10A pinout
  1262. ENDIF
  1263. IF BESCNO == H_King_10A_Multi
  1264. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1265. $include (H_King_10A.inc) ; Select H-King 10A pinout
  1266. ENDIF
  1267. IF BESCNO == H_King_20A_Main
  1268. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1269. $include (H_King_20A.inc) ; Select H-King 20A pinout
  1270. ENDIF
  1271. IF BESCNO == H_King_20A_Tail
  1272. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1273. $include (H_King_20A.inc) ; Select H-King 20A pinout
  1274. ENDIF
  1275. IF BESCNO == H_King_20A_Multi
  1276. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1277. $include (H_King_20A.inc) ; Select H-King 20A pinout
  1278. ENDIF
  1279. IF BESCNO == H_King_35A_Main
  1280. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1281. $include (H_King_35A.inc) ; Select H-King 35A pinout
  1282. ENDIF
  1283. IF BESCNO == H_King_35A_Tail
  1284. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1285. $include (H_King_35A.inc) ; Select H-King 35A pinout
  1286. ENDIF
  1287. IF BESCNO == H_King_35A_Multi
  1288. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1289. $include (H_King_35A.inc) ; Select H-King 35A pinout
  1290. ENDIF
  1291. IF BESCNO == H_King_50A_Main
  1292. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1293. $include (H_King_50A.inc) ; Select H-King 50A pinout
  1294. ENDIF
  1295. IF BESCNO == H_King_50A_Tail
  1296. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1297. $include (H_King_50A.inc) ; Select H-King 50A pinout
  1298. ENDIF
  1299. IF BESCNO == H_King_50A_Multi
  1300. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1301. $include (H_King_50A.inc) ; Select H-King 50A pinout
  1302. ENDIF
  1303. IF BESCNO == Polaris_Thunder_12A_Main
  1304. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1305. $include (Polaris_Thunder_12A.inc) ; Select Polaris Thunder 12A pinout
  1306. ENDIF
  1307. IF BESCNO == Polaris_Thunder_12A_Tail
  1308. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1309. $include (Polaris_Thunder_12A.inc) ; Select Polaris Thunder 12A pinout
  1310. ENDIF
  1311. IF BESCNO == Polaris_Thunder_12A_Multi
  1312. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1313. $include (Polaris_Thunder_12A.inc) ; Select Polaris Thunder 12A pinout
  1314. ENDIF
  1315. IF BESCNO == Polaris_Thunder_20A_Main
  1316. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1317. $include (Polaris_Thunder_20A.inc) ; Select Polaris Thunder 20A pinout
  1318. ENDIF
  1319. IF BESCNO == Polaris_Thunder_20A_Tail
  1320. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1321. $include (Polaris_Thunder_20A.inc) ; Select Polaris Thunder 20A pinout
  1322. ENDIF
  1323. IF BESCNO == Polaris_Thunder_20A_Multi
  1324. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1325. $include (Polaris_Thunder_20A.inc) ; Select Polaris Thunder 20A pinout
  1326. ENDIF
  1327. IF BESCNO == Polaris_Thunder_30A_Main
  1328. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1329. $include (Polaris_Thunder_30A.inc) ; Select Polaris Thunder 30A pinout
  1330. ENDIF
  1331. IF BESCNO == Polaris_Thunder_30A_Tail
  1332. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1333. $include (Polaris_Thunder_30A.inc) ; Select Polaris Thunder 30A pinout
  1334. ENDIF
  1335. IF BESCNO == Polaris_Thunder_30A_Multi
  1336. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1337. $include (Polaris_Thunder_30A.inc) ; Select Polaris Thunder 30A pinout
  1338. ENDIF
  1339. IF BESCNO == Polaris_Thunder_40A_Main
  1340. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1341. $include (Polaris_Thunder_40A.inc) ; Select Polaris Thunder 40A pinout
  1342. ENDIF
  1343. IF BESCNO == Polaris_Thunder_40A_Tail
  1344. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1345. $include (Polaris_Thunder_40A.inc) ; Select Polaris Thunder 40A pinout
  1346. ENDIF
  1347. IF BESCNO == Polaris_Thunder_40A_Multi
  1348. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1349. $include (Polaris_Thunder_40A.inc) ; Select Polaris Thunder 40A pinout
  1350. ENDIF
  1351. IF BESCNO == Polaris_Thunder_60A_Main
  1352. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1353. $include (Polaris_Thunder_60A.inc) ; Select Polaris Thunder 60A pinout
  1354. ENDIF
  1355. IF BESCNO == Polaris_Thunder_60A_Tail
  1356. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1357. $include (Polaris_Thunder_60A.inc) ; Select Polaris Thunder 60A pinout
  1358. ENDIF
  1359. IF BESCNO == Polaris_Thunder_60A_Multi
  1360. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1361. $include (Polaris_Thunder_60A.inc) ; Select Polaris Thunder 60A pinout
  1362. ENDIF
  1363. IF BESCNO == Polaris_Thunder_80A_Main
  1364. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1365. $include (Polaris_Thunder_80A.inc) ; Select Polaris Thunder 80A pinout
  1366. ENDIF
  1367. IF BESCNO == Polaris_Thunder_80A_Tail
  1368. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1369. $include (Polaris_Thunder_80A.inc) ; Select Polaris Thunder 80A pinout
  1370. ENDIF
  1371. IF BESCNO == Polaris_Thunder_80A_Multi
  1372. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1373. $include (Polaris_Thunder_80A.inc) ; Select Polaris Thunder 80A pinout
  1374. ENDIF
  1375. IF BESCNO == Polaris_Thunder_100A_Main
  1376. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1377. $include (Polaris_Thunder_100A.inc); Select Polaris Thunder 100A pinout
  1378. ENDIF
  1379. IF BESCNO == Polaris_Thunder_100A_Tail
  1380. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1381. $include (Polaris_Thunder_100A.inc); Select Polaris Thunder 100A pinout
  1382. ENDIF
  1383. IF BESCNO == Polaris_Thunder_100A_Multi
  1384. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1385. $include (Polaris_Thunder_100A.inc); Select Polaris Thunder 100A pinout
  1386. ENDIF
  1387. IF BESCNO == Platinum_Pro_30A_Main
  1388. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1389. $include (Platinum_Pro_30A.inc) ; Select Platinum Pro 30A pinout
  1390. ENDIF
  1391. IF BESCNO == Platinum_Pro_30A_Tail
  1392. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1393. $include (Platinum_Pro_30A.inc) ; Select Platinum Pro 30A pinout
  1394. ENDIF
  1395. IF BESCNO == Platinum_Pro_30A_Multi
  1396. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1397. $include (Platinum_Pro_30A.inc) ; Select Platinum Pro 30A pinout
  1398. ENDIF
  1399. IF BESCNO == Platinum_Pro_150A_Main
  1400. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1401. $include (Platinum_Pro_150A.inc) ; Select Platinum Pro 150A pinout
  1402. ENDIF
  1403. IF BESCNO == Platinum_Pro_150A_Tail
  1404. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1405. $include (Platinum_Pro_150A.inc) ; Select Platinum Pro 150A pinout
  1406. ENDIF
  1407. IF BESCNO == Platinum_Pro_150A_Multi
  1408. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1409. $include (Platinum_Pro_150A.inc) ; Select Platinum Pro 150A pinout
  1410. ENDIF
  1411. IF BESCNO == Platinum_50Av3_Main
  1412. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1413. $include (Platinum_50Av3.inc) ; Select Platinum 50A v3 pinout
  1414. ENDIF
  1415. IF BESCNO == Platinum_50Av3_Tail
  1416. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1417. $include (Platinum_50Av3.inc) ; Select Platinum 50A v3 pinout
  1418. ENDIF
  1419. IF BESCNO == Platinum_50Av3_Multi
  1420. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1421. $include (Platinum_50Av3.inc) ; Select Platinum 50A v3 pinout
  1422. ENDIF
  1423. IF BESCNO == EAZY_3Av2_Main
  1424. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1425. $include (EAZY_3Av2.inc) ; Select Eazy 3A v2 pinout
  1426. ENDIF
  1427. IF BESCNO == EAZY_3Av2_Tail
  1428. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1429. $include (EAZY_3Av2.inc) ; Select Eazy 3A v2 pinout
  1430. ENDIF
  1431. IF BESCNO == EAZY_3Av2_Multi
  1432. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1433. $include (EAZY_3Av2.inc) ; Select Eazy 3A v2 pinout
  1434. ENDIF
  1435. IF BESCNO == Tarot_30A_Main
  1436. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1437. $include (Tarot_30A.inc) ; Select Tarot 30A pinout
  1438. ENDIF
  1439. IF BESCNO == Tarot_30A_Tail
  1440. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1441. $include (Tarot_30A.inc) ; Select Tarot 30A pinout
  1442. ENDIF
  1443. IF BESCNO == Tarot_30A_Multi
  1444. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1445. $include (Tarot_30A.inc) ; Select Tarot 30A pinout
  1446. ENDIF
  1447. IF BESCNO == SkyIII_30A_Main
  1448. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1449. $include (SkyIII_30A.inc) ; Select SkyIII 30A pinout
  1450. ENDIF
  1451. IF BESCNO == SkyIII_30A_Tail
  1452. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1453. $include (SkyIII_30A.inc) ; Select SkyIII 30A pinout
  1454. ENDIF
  1455. IF BESCNO == SkyIII_30A_Multi
  1456. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1457. $include (SkyIII_30A.inc) ; Select SkyIII 30A pinout
  1458. ENDIF
  1459. IF BESCNO == EMAX_20A_Main
  1460. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1461. $include (EMAX_20A.inc) ; Select EMAX 20A pinout
  1462. ENDIF
  1463. IF BESCNO == EMAX_20A_Tail
  1464. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1465. $include (EMAX_20A.inc) ; Select EMAX 20A pinout
  1466. ENDIF
  1467. IF BESCNO == EMAX_20A_Multi
  1468. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1469. $include (EMAX_20A.inc) ; Select EMAX 20A pinout
  1470. ENDIF
  1471. IF BESCNO == EMAX_40A_Main
  1472. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1473. $include (EMAX_40A.inc) ; Select EMAX 40A pinout
  1474. ENDIF
  1475. IF BESCNO == EMAX_40A_Tail
  1476. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1477. $include (EMAX_40A.inc) ; Select EMAX 40A pinout
  1478. ENDIF
  1479. IF BESCNO == EMAX_40A_Multi
  1480. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1481. $include (EMAX_40A.inc) ; Select EMAX 40A pinout
  1482. ENDIF
  1483. IF BESCNO == EMAX_Nano_20A_Main
  1484. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1485. $include (EMAX_Nano_20A.inc) ; Select EMAX Nano 20A pinout
  1486. ENDIF
  1487. IF BESCNO == EMAX_Nano_20A_Tail
  1488. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1489. $include (EMAX_Nano_20A.inc) ; Select EMAX Nano 20A pinout
  1490. ENDIF
  1491. IF BESCNO == EMAX_Nano_20A_Multi
  1492. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1493. $include (EMAX_Nano_20A.inc) ; Select EMAX Nano 20A pinout
  1494. ENDIF
  1495. IF BESCNO == XRotor_10A_Main
  1496. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1497. $include (XRotor_10A.inc) ; Select XRotor 10A pinout
  1498. ENDIF
  1499. IF BESCNO == XRotor_10A_Tail
  1500. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1501. $include (XRotor_10A.inc) ; Select XRotor 10A pinout
  1502. ENDIF
  1503. IF BESCNO == XRotor_10A_Multi
  1504. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1505. $include (XRotor_10A.inc) ; Select XRotor 10A pinout
  1506. ENDIF
  1507. IF BESCNO == XRotor_20A_Main
  1508. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1509. $include (XRotor_20A.inc) ; Select XRotor 20A pinout
  1510. ENDIF
  1511. IF BESCNO == XRotor_20A_Tail
  1512. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1513. $include (XRotor_20A.inc) ; Select XRotor 20A pinout
  1514. ENDIF
  1515. IF BESCNO == XRotor_20A_Multi
  1516. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1517. $include (XRotor_20A.inc) ; Select XRotor 20A pinout
  1518. ENDIF
  1519. IF BESCNO == XRotor_40A_Main
  1520. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1521. $include (XRotor_40A.inc) ; Select XRotor 40A pinout
  1522. ENDIF
  1523. IF BESCNO == XRotor_40A_Tail
  1524. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1525. $include (XRotor_40A.inc) ; Select XRotor 40A pinout
  1526. ENDIF
  1527. IF BESCNO == XRotor_40A_Multi
  1528. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1529. $include (XRotor_40A.inc) ; Select XRotor 40A pinout
  1530. ENDIF
  1531. IF BESCNO == MDRX62H_Main
  1532. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1533. $include (MDRX62H.inc) ; Select MDRX62H pinout
  1534. ENDIF
  1535. IF BESCNO == MDRX62H_Tail
  1536. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1537. $include (MDRX62H.inc) ; Select MDRX62H pinout
  1538. ENDIF
  1539. IF BESCNO == MDRX62H_Multi
  1540. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1541. $include (MDRX62H.inc) ; Select MDRX62H pinout
  1542. ENDIF
  1543. IF BESCNO == RotorGeeks_20A_Main
  1544. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1545. $include (RotorGeeks_20A.inc) ; Select RotorGeeks 20A pinout
  1546. ENDIF
  1547. IF BESCNO == RotorGeeks_20A_Tail
  1548. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1549. $include (RotorGeeks_20A.inc) ; Select RotorGeeks 20A pinout
  1550. ENDIF
  1551. IF BESCNO == RotorGeeks_20A_Multi
  1552. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1553. $include (RotorGeeks_20A.inc) ; Select RotorGeeks 20A pinout
  1554. ENDIF
  1555. IF BESCNO == Flycolor_Fairy_6A_Main
  1556. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1557. $include (Flycolor_Fairy_6A.inc) ; Select Flycolor Fairy 6A pinout
  1558. ENDIF
  1559. IF BESCNO == Flycolor_Fairy_6A_Tail
  1560. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1561. $include (Flycolor_Fairy_6A.inc) ; Select Flycolor Fairy 6A pinout
  1562. ENDIF
  1563. IF BESCNO == Flycolor_Fairy_6A_Multi
  1564. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1565. $include (Flycolor_Fairy_6A.inc) ; Select Flycolor Fairy 6A pinout
  1566. ENDIF
  1567. IF BESCNO == Flycolor_Fairy_30A_Main
  1568. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1569. $include (Flycolor_Fairy_30A.inc) ; Select Flycolor Fairy 30A pinout
  1570. ENDIF
  1571. IF BESCNO == Flycolor_Fairy_30A_Tail
  1572. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1573. $include (Flycolor_Fairy_30A.inc) ; Select Flycolor Fairy 30A pinout
  1574. ENDIF
  1575. IF BESCNO == Flycolor_Fairy_30A_Multi
  1576. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1577. $include (Flycolor_Fairy_30A.inc) ; Select Flycolor Fairy 30A pinout
  1578. ENDIF
  1579. IF BESCNO == Flycolor_Raptor_20A_Main
  1580. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1581. $include (Flycolor_Raptor_20A.inc) ; Select Flycolor Raptor 20A pinout
  1582. ENDIF
  1583. IF BESCNO == Flycolor_Raptor_20A_Tail
  1584. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1585. $include (Flycolor_Raptor_20A.inc) ; Select Flycolor Raptor 20A pinout
  1586. ENDIF
  1587. IF BESCNO == Flycolor_Raptor_20A_Multi
  1588. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1589. $include (Flycolor_Raptor_20A.inc) ; Select Flycolor Raptor 20A pinout
  1590. ENDIF
  1591. IF BESCNO == Flycolor_Raptor_390_20A_Main
  1592. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1593. $include (Flycolor_Raptor_390_20A.inc) ; Select Flycolor Raptor 390 20A pinout
  1594. ENDIF
  1595. IF BESCNO == Flycolor_Raptor_390_20A_Tail
  1596. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1597. $include (Flycolor_Raptor_390_20A.inc) ; Select Flycolor Raptor 390 20A pinout
  1598. ENDIF
  1599. IF BESCNO == Flycolor_Raptor_390_20A_Multi
  1600. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1601. $include (Flycolor_Raptor_390_20A.inc) ; Select Flycolor Raptor 390 20A pinout
  1602. ENDIF
  1603. IF BESCNO == FVT_Littlebee_20A_Main
  1604. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1605. $include (FVT_Littlebee_20A.inc) ; Select Favourite Littlebee 20A pinout
  1606. ENDIF
  1607. IF BESCNO == FVT_Littlebee_20A_Tail
  1608. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1609. $include (FVT_Littlebee_20A.inc) ; Select Favourite Littlebee 20A pinout
  1610. ENDIF
  1611. IF BESCNO == FVT_Littlebee_20A_Multi
  1612. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1613. $include (FVT_Littlebee_20A.inc) ; Select Favourite Littlebee 20A pinout
  1614. ENDIF
  1615. IF BESCNO == FVT_Littlebee_20A_Pro_Main
  1616. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1617. $include (FVT_Littlebee_20A_Pro.inc) ; Select Favourite Littlebee 20A Pro pinout
  1618. ENDIF
  1619. IF BESCNO == FVT_Littlebee_20A_Pro_Tail
  1620. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1621. $include (FVT_Littlebee_20A_Pro.inc) ; Select Favourite Littlebee 20A Pro pinout
  1622. ENDIF
  1623. IF BESCNO == FVT_Littlebee_20A_Pro_Multi
  1624. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1625. $include (FVT_Littlebee_20A_Pro.inc) ; Select Favourite Littlebee 20A Pro pinout
  1626. ENDIF
  1627. IF BESCNO == FVT_Littlebee_30A_Main
  1628. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1629. $include (FVT_Littlebee_30A.inc) ; Select Favourite Littlebee 30A pinout
  1630. ENDIF
  1631. IF BESCNO == FVT_Littlebee_30A_Tail
  1632. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1633. $include (FVT_Littlebee_30A.inc) ; Select Favourite Littlebee 30A pinout
  1634. ENDIF
  1635. IF BESCNO == FVT_Littlebee_30A_Multi
  1636. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1637. $include (FVT_Littlebee_30A.inc) ; Select Favourite Littlebee 30A pinout
  1638. ENDIF
  1639. IF BESCNO == Graupner_Ultra_20A_Main
  1640. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1641. $include (Graupner_Ultra_20A.inc) ; Select Graupner Ultra 20A pinout
  1642. ENDIF
  1643. IF BESCNO == Graupner_Ultra_20A_Tail
  1644. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1645. $include (Graupner_Ultra_20A.inc) ; Select Graupner Ultra 20A pinout
  1646. ENDIF
  1647. IF BESCNO == Graupner_Ultra_20A_Multi
  1648. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1649. $include (Graupner_Ultra_20A.inc) ; Select Graupner Ultra 20A pinout
  1650. ENDIF
  1651. IF BESCNO == F85_3A_Main
  1652. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1653. $include (F85_3A.inc) ; Select F85 3A pinout
  1654. ENDIF
  1655. IF BESCNO == F85_3A_Tail
  1656. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1657. $include (F85_3A.inc) ; Select F85 3A pinout
  1658. ENDIF
  1659. IF BESCNO == F85_3A_Multi
  1660. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1661. $include (F85_3A.inc) ; Select F85 3A pinout
  1662. ENDIF
  1663. IF BESCNO == ZTW_Spider_Pro_20A_Main
  1664. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1665. $include (ZTW_Spider_Pro_20A.inc) ; Select ZTW Spider Pro 20A pinout
  1666. ENDIF
  1667. IF BESCNO == ZTW_Spider_Pro_20A_Tail
  1668. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1669. $include (ZTW_Spider_Pro_20A.inc) ; Select ZTW Spider Pro 20A pinout
  1670. ENDIF
  1671. IF BESCNO == ZTW_Spider_Pro_20A_Multi
  1672. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1673. $include (ZTW_Spider_Pro_20A.inc) ; Select ZTW Spider Pro 20A pinout
  1674. ENDIF
  1675. IF BESCNO == ZTW_Spider_Pro_20A_Premium_Main
  1676. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1677. $include (ZTW_Spider_Pro_20A_Premium.inc) ; Select ZTW Spider Pro 20A Premium pinout
  1678. ENDIF
  1679. IF BESCNO == ZTW_Spider_Pro_20A_Premium_Tail
  1680. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1681. $include (ZTW_Spider_Pro_20A_Premium.inc) ; Select ZTW Spider Pro 20A Premium pinout
  1682. ENDIF
  1683. IF BESCNO == ZTW_Spider_Pro_20A_Premium_Multi
  1684. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1685. $include (ZTW_Spider_Pro_20A_Premium.inc) ; Select ZTW Spider Pro 20A Premium pinout
  1686. ENDIF
  1687. IF BESCNO == ZTW_Spider_Pro_20A_HV_Main
  1688. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1689. $include (ZTW_Spider_Pro_20A_HV.inc) ; Select ZTW Spider Pro 20A HV pinout
  1690. ENDIF
  1691. IF BESCNO == ZTW_Spider_Pro_20A_HV_Tail
  1692. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1693. $include (ZTW_Spider_Pro_20A_HV.inc) ; Select ZTW Spider Pro 20A HV pinout
  1694. ENDIF
  1695. IF BESCNO == ZTW_Spider_Pro_20A_HV_Multi
  1696. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1697. $include (ZTW_Spider_Pro_20A_HV.inc) ; Select ZTW Spider Pro 20A HV pinout
  1698. ENDIF
  1699. IF BESCNO == ZTW_Spider_Pro_30A_HV_Main
  1700. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1701. $include (ZTW_Spider_Pro_30A_HV.inc) ; Select ZTW Spider Pro 30A HV pinout
  1702. ENDIF
  1703. IF BESCNO == ZTW_Spider_Pro_30A_HV_Tail
  1704. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1705. $include (ZTW_Spider_Pro_30A_HV.inc) ; Select ZTW Spider Pro 30A HV pinout
  1706. ENDIF
  1707. IF BESCNO == ZTW_Spider_Pro_30A_HV_Multi
  1708. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1709. $include (ZTW_Spider_Pro_30A_HV.inc) ; Select ZTW Spider Pro 30A HV pinout
  1710. ENDIF
  1711. IF BESCNO == DYS_XM20A_Main
  1712. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1713. $include (DYS_XM20A.inc) ; Select DYS XM20A pinout
  1714. ENDIF
  1715. IF BESCNO == DYS_XM20A_Tail
  1716. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1717. $include (DYS_XM20A.inc) ; Select DYS XM20A pinout
  1718. ENDIF
  1719. IF BESCNO == DYS_XM20A_Multi
  1720. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1721. $include (DYS_XM20A.inc) ; Select DYS XM20A pinout
  1722. ENDIF
  1723. IF BESCNO == Oversky_MR_20A_Pro_Main
  1724. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1725. $include (Oversky_MR_20A_Pro.inc) ; Select Oversky MR-20A Pro pinout
  1726. ENDIF
  1727. IF BESCNO == Oversky_MR_20A_Pro_Tail
  1728. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1729. $include (Oversky_MR_20A_Pro.inc) ; Select Oversky MR-20A Pro pinout
  1730. ENDIF
  1731. IF BESCNO == Oversky_MR_20A_Pro_Multi
  1732. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1733. $include (Oversky_MR_20A_Pro.inc) ; Select Oversky MR-20A Pro pinout
  1734. ENDIF
  1735. IF BESCNO == TBS_Cube_12A_Main
  1736. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1737. $include (TBS_Cube_12A.inc) ; Select TBS Cube 12A pinout
  1738. ENDIF
  1739. IF BESCNO == TBS_Cube_12A_Tail
  1740. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1741. $include (TBS_Cube_12A.inc) ; Select TBS Cube 12A pinout
  1742. ENDIF
  1743. IF BESCNO == TBS_Cube_12A_Multi
  1744. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1745. $include (TBS_Cube_12A.inc) ; Select TBS Cube 12A pinout
  1746. ENDIF
  1747. IF BESCNO == DALRC_XR20A_Main
  1748. MODE EQU 0 ; Choose mode. Set to 0 for main motor
  1749. $include (DALRC_XR20A.inc) ; Select DALRC 20A pinout
  1750. ENDIF
  1751. IF BESCNO == DALRC_XR20A_Tail
  1752. MODE EQU 1 ; Choose mode. Set to 1 for tail motor
  1753. $include (DALRC_XR20A.inc) ; Select DALRC 20A pinout
  1754. ENDIF
  1755. IF BESCNO == DALRC_XR20A_Multi
  1756. MODE EQU 2 ; Choose mode. Set to 2 for multirotor
  1757. $include (DALRC_XR20A.inc) ; Select DALRC 20A pinout
  1758. ENDIF
  1759. ;**** **** **** **** ****
  1760. ; TX programming defaults
  1761. ;
  1762. ; Parameter dependencies:
  1763. ; - Governor P gain, I gain and Range is only used if one of the three governor modes is selected
  1764. ; - Governor setup target is only used if Setup governor mode is selected (or closed loop mode is on for multi)
  1765. ;
  1766. ; MAIN
  1767. DEFAULT_PGM_MAIN_P_GAIN EQU 7 ; 1=0.13 2=0.17 3=0.25 4=0.38 5=0.50 6=0.75 7=1.00 8=1.5 9=2.0 10=3.0 11=4.0 12=6.0 13=8.0
  1768. DEFAULT_PGM_MAIN_I_GAIN EQU 7 ; 1=0.13 2=0.17 3=0.25 4=0.38 5=0.50 6=0.75 7=1.00 8=1.5 9=2.0 10=3.0 11=4.0 12=6.0 13=8.0
  1769. DEFAULT_PGM_MAIN_GOVERNOR_MODE EQU 1 ; 1=Tx 2=Arm 3=Setup 4=Off
  1770. DEFAULT_PGM_MAIN_GOVERNOR_RANGE EQU 1 ; 1=High 2=Middle 3=Low
  1771. DEFAULT_PGM_MAIN_LOW_VOLTAGE_LIM EQU 4 ; 1=Off 2=3.0V/c 3=3.1V/c 4=3.2V/c 5=3.3V/c 6=3.4V/c
  1772. DEFAULT_PGM_MAIN_COMM_TIMING EQU 3 ; 1=Low 2=MediumLow 3=Medium 4=MediumHigh 5=High
  1773. IF DAMPED_MODE_ENABLE == 1
  1774. DEFAULT_PGM_MAIN_PWM_FREQ EQU 2 ; 1=High 2=Low 3=DampedLight
  1775. ELSE
  1776. DEFAULT_PGM_MAIN_PWM_FREQ EQU 2 ; 1=High 2=Low
  1777. ENDIF
  1778. DEFAULT_PGM_MAIN_DEMAG_COMP EQU 1 ; 1=Disabled 2=Low 3=High
  1779. DEFAULT_PGM_MAIN_DIRECTION EQU 1 ; 1=Normal 2=Reversed
  1780. DEFAULT_PGM_MAIN_RCP_PWM_POL EQU 1 ; 1=Positive 2=Negative
  1781. DEFAULT_PGM_MAIN_GOV_SETUP_TARGET EQU 180 ; Target for governor in setup mode. Corresponds to 70% throttle
  1782. DEFAULT_PGM_MAIN_REARM_START EQU 0 ; 1=Enabled 0=Disabled
  1783. DEFAULT_PGM_MAIN_BEEP_STRENGTH EQU 120 ; Beep strength
  1784. DEFAULT_PGM_MAIN_BEACON_STRENGTH EQU 200 ; Beacon strength
  1785. DEFAULT_PGM_MAIN_BEACON_DELAY EQU 4 ; 1=1m 2=2m 3=5m 4=10m 5=Infinite
  1786. ; TAIL
  1787. DEFAULT_PGM_TAIL_GAIN EQU 3 ; 1=0.75 2=0.88 3=1.00 4=1.12 5=1.25
  1788. DEFAULT_PGM_TAIL_IDLE_SPEED EQU 4 ; 1=Low 2=MediumLow 3=Medium 4=MediumHigh 5=High
  1789. DEFAULT_PGM_TAIL_COMM_TIMING EQU 3 ; 1=Low 2=MediumLow 3=Medium 4=MediumHigh 5=High
  1790. IF DAMPED_MODE_ENABLE == 1
  1791. DEFAULT_PGM_TAIL_PWM_FREQ EQU 3 ; 1=High 2=Low 3=DampedLight
  1792. ELSE
  1793. DEFAULT_PGM_TAIL_PWM_FREQ EQU 1 ; 1=High 2=Low
  1794. ENDIF
  1795. DEFAULT_PGM_TAIL_DEMAG_COMP EQU 1 ; 1=Disabled 2=Low 3=High
  1796. DEFAULT_PGM_TAIL_DIRECTION EQU 1 ; 1=Normal 2=Reversed 3=Bidirectional
  1797. DEFAULT_PGM_TAIL_RCP_PWM_POL EQU 1 ; 1=Positive 2=Negative
  1798. DEFAULT_PGM_TAIL_BEEP_STRENGTH EQU 250 ; Beep strength
  1799. DEFAULT_PGM_TAIL_BEACON_STRENGTH EQU 250 ; Beacon strength
  1800. DEFAULT_PGM_TAIL_BEACON_DELAY EQU 4 ; 1=1m 2=2m 3=5m 4=10m 5=Infinite
  1801. DEFAULT_PGM_TAIL_PWM_DITHER EQU 3 ; 1=Off 2=7 3=15 4=31 5=63
  1802. ; MULTI
  1803. DEFAULT_PGM_MULTI_P_GAIN EQU 9 ; 1=0.13 2=0.17 3=0.25 4=0.38 5=0.50 6=0.75 7=1.00 8=1.5 9=2.0 10=3.0 11=4.0 12=6.0 13=8.0
  1804. DEFAULT_PGM_MULTI_I_GAIN EQU 9 ; 1=0.13 2=0.17 3=0.25 4=0.38 5=0.50 6=0.75 7=1.00 8=1.5 9=2.0 10=3.0 11=4.0 12=6.0 13=8.0
  1805. DEFAULT_PGM_MULTI_GOVERNOR_MODE EQU 4 ; 1=HiRange 2=MidRange 3=LoRange 4=Off
  1806. DEFAULT_PGM_MULTI_GAIN EQU 3 ; 1=0.75 2=0.88 3=1.00 4=1.12 5=1.25
  1807. DEFAULT_PGM_MULTI_COMM_TIMING EQU 3 ; 1=Low 2=MediumLow 3=Medium 4=MediumHigh 5=High
  1808. IF DAMPED_MODE_ENABLE == 1
  1809. DEFAULT_PGM_MULTI_PWM_FREQ EQU 3 ; 1=High 2=Low 3=DampedLight
  1810. ELSE
  1811. DEFAULT_PGM_MULTI_PWM_FREQ EQU 1 ; 1=High 2=Low
  1812. ENDIF
  1813. DEFAULT_PGM_MULTI_DEMAG_COMP EQU 2 ; 1=Disabled 2=Low 3=High
  1814. DEFAULT_PGM_MULTI_DIRECTION EQU 1 ; 1=Normal 2=Reversed 3=Bidirectional
  1815. DEFAULT_PGM_MULTI_RCP_PWM_POL EQU 1 ; 1=Positive 2=Negative
  1816. DEFAULT_PGM_MULTI_BEEP_STRENGTH EQU 40 ; Beep strength
  1817. DEFAULT_PGM_MULTI_BEACON_STRENGTH EQU 80 ; Beacon strength
  1818. DEFAULT_PGM_MULTI_BEACON_DELAY EQU 4 ; 1=1m 2=2m 3=5m 4=10m 5=Infinite
  1819. DEFAULT_PGM_MULTI_PWM_DITHER EQU 3 ; 1=Off 2=7 3=15 4=31 5=63
  1820. ; COMMON
  1821. DEFAULT_PGM_ENABLE_TX_PROGRAM EQU 1 ; 1=Enabled 0=Disabled
  1822. DEFAULT_PGM_PPM_MIN_THROTTLE EQU 37 ; 4*37+1000=1148
  1823. DEFAULT_PGM_PPM_MAX_THROTTLE EQU 208 ; 4*208+1000=1832
  1824. DEFAULT_PGM_PPM_CENTER_THROTTLE EQU 122 ; 4*122+1000=1488 (used in bidirectional mode)
  1825. DEFAULT_PGM_BEC_VOLTAGE_HIGH EQU 0 ; 0=Low 1+= High or higher
  1826. DEFAULT_PGM_ENABLE_TEMP_PROT EQU 1 ; 1=Enabled 0=Disabled
  1827. DEFAULT_PGM_ENABLE_POWER_PROT EQU 1 ; 1=Enabled 0=Disabled
  1828. DEFAULT_PGM_ENABLE_PWM_INPUT EQU 0 ; 1=Enabled 0=Disabled
  1829. ;**** **** **** **** ****
  1830. ; Constant definitions for main
  1831. IF MODE == 0
  1832. GOV_SPOOLRATE EQU 2 ; Number of steps for governor requested pwm per 32ms
  1833. RCP_TIMEOUT_PPM EQU 10 ; Number of timer2H overflows (about 32ms) before considering rc pulse lost
  1834. RCP_TIMEOUT EQU 64 ; Number of timer2L overflows (about 128us) before considering rc pulse lost
  1835. RCP_SKIP_RATE EQU 32 ; Number of timer2L overflows (about 128us) before reenabling rc pulse detection
  1836. RCP_MIN EQU 0 ; This is minimum RC pulse length
  1837. RCP_MAX EQU 255 ; This is maximum RC pulse length
  1838. RCP_VALIDATE EQU 2 ; Require minimum this pulse length to validate RC pulse
  1839. RCP_STOP EQU 1 ; Stop motor at or below this pulse length
  1840. RCP_STOP_LIMIT EQU 250 ; Stop motor if this many timer2H overflows (~32ms) are below stop limit
  1841. PWM_START EQU 50 ; PWM used as max power during start
  1842. COMM_TIME_MIN EQU 1 ; Minimum time (in us) for commutation wait
  1843. TEMP_CHECK_RATE EQU 8 ; Number of adc conversions for each check of temperature (the other conversions are used for voltage)
  1844. ENDIF
  1845. ; Constant definitions for tail
  1846. IF MODE == 1
  1847. GOV_SPOOLRATE EQU 1 ; Number of steps for governor requested pwm per 32ms
  1848. RCP_TIMEOUT_PPM EQU 10 ; Number of timer2H overflows (about 32ms) before considering rc pulse lost
  1849. RCP_TIMEOUT EQU 24 ; Number of timer2L overflows (about 128us) before considering rc pulse lost
  1850. RCP_SKIP_RATE EQU 6 ; Number of timer2L overflows (about 128us) before reenabling rc pulse detection
  1851. RCP_MIN EQU 0 ; This is minimum RC pulse length
  1852. RCP_MAX EQU 255 ; This is maximum RC pulse length
  1853. RCP_VALIDATE EQU 2 ; Require minimum this pulse length to validate RC pulse
  1854. RCP_STOP EQU 1 ; Stop motor at or below this pulse length
  1855. RCP_STOP_LIMIT EQU 130 ; Stop motor if this many timer2H overflows (~32ms) are below stop limit
  1856. PWM_START EQU 50 ; PWM used as max power during start
  1857. COMM_TIME_MIN EQU 1 ; Minimum time (in us) for commutation wait
  1858. TEMP_CHECK_RATE EQU 8 ; Number of adc conversions for each check of temperature (the other conversions are used for voltage)
  1859. ENDIF
  1860. ; Constant definitions for multi
  1861. IF MODE == 2
  1862. GOV_SPOOLRATE EQU 1 ; Number of steps for governor requested pwm per 32ms
  1863. RCP_TIMEOUT_PPM EQU 10 ; Number of timer2H overflows (about 32ms) before considering rc pulse lost
  1864. RCP_TIMEOUT EQU 24 ; Number of timer2L overflows (about 128us) before considering rc pulse lost
  1865. RCP_SKIP_RATE EQU 6 ; Number of timer2L overflows (about 128us) before reenabling rc pulse detection
  1866. RCP_MIN EQU 0 ; This is minimum RC pulse length
  1867. RCP_MAX EQU 255 ; This is maximum RC pulse length
  1868. RCP_VALIDATE EQU 2 ; Require minimum this pulse length to validate RC pulse
  1869. RCP_STOP EQU 1 ; Stop motor at or below this pulse length
  1870. RCP_STOP_LIMIT EQU 250 ; Stop motor if this many timer2H overflows (~32ms) are below stop limit
  1871. PWM_START EQU 50 ; PWM used as max power during start
  1872. COMM_TIME_MIN EQU 1 ; Minimum time (in us) for commutation wait
  1873. TEMP_CHECK_RATE EQU 8 ; Number of adc conversions for each check of temperature (the other conversions are used for voltage)
  1874. ENDIF
  1875. ;**** **** **** **** ****
  1876. ; Temporary register definitions
  1877. Temp1 EQU R0
  1878. Temp2 EQU R1
  1879. Temp3 EQU R2
  1880. Temp4 EQU R3
  1881. Temp5 EQU R4
  1882. Temp6 EQU R5
  1883. Temp7 EQU R6
  1884. Temp8 EQU R7
  1885. ;**** **** **** **** ****
  1886. ; Register definitions
  1887. DSEG AT 20h ; Variables segment
  1888. Bit_Access: DS 1 ; MUST BE AT THIS ADDRESS. Variable at bit accessible address (for non interrupt routines)
  1889. Bit_Access_Int: DS 1 ; Variable at bit accessible address (for interrupts)
  1890. Requested_Pwm: DS 1 ; Requested pwm (from RC pulse value)
  1891. Governor_Req_Pwm: DS 1 ; Governor requested pwm (sets governor target)
  1892. Current_Pwm: DS 1 ; Current pwm
  1893. Current_Pwm_Limited: DS 1 ; Current pwm that is limited
  1894. Current_Pwm_Lim_Dith: DS 1 ; Current pwm that is limited and dithered (applied to the motor output)
  1895. Rcp_Prev_Edge_L: DS 1 ; RC pulse previous edge timer3 timestamp (lo byte)
  1896. Rcp_Prev_Edge_H: DS 1 ; RC pulse previous edge timer3 timestamp (hi byte)
  1897. Rcp_Outside_Range_Cnt: DS 1 ; RC pulse outside range counter (incrementing)
  1898. Rcp_Timeout_Cntd: DS 1 ; RC pulse timeout counter (decrementing)
  1899. Rcp_Skip_Cntd: DS 1 ; RC pulse skip counter (decrementing)
  1900. Flags0: DS 1 ; State flags. Reset upon init_start
  1901. T3_PENDING EQU 0 ; Timer3 pending flag
  1902. RCP_MEAS_PWM_FREQ EQU 1 ; Measure RC pulse pwm frequency
  1903. PWM_ON EQU 2 ; Set in on part of pwm cycle
  1904. PWM_TIMER0_OVERFLOW EQU 3 ; Set for 48MHz MCUs when PWM timer 0 overflows
  1905. DEMAG_ENABLED EQU 4 ; Set when demag compensation is enabled (above a min speed and throttle)
  1906. DEMAG_DETECTED EQU 5 ; Set when excessive demag time is detected
  1907. DEMAG_CUT_POWER EQU 6 ; Set when demag compensation cuts power
  1908. HIGH_RPM EQU 7 ; Set when motor rpm is high (Comm_Period4x_H less than 2)
  1909. Flags1: DS 1 ; State flags. Reset upon init_start
  1910. MOTOR_SPINNING EQU 0 ; Set when in motor is spinning
  1911. STARTUP_PHASE EQU 1 ; Set when in startup phase
  1912. INITIAL_RUN_PHASE EQU 2 ; Set when in initial run phase, before synchronized run is achieved
  1913. DIR_CHANGE_BRAKE EQU 3 ; Set when braking before direction change
  1914. COMP_TIMED_OUT EQU 4 ; Set when comparator reading timed out
  1915. GOV_ACTIVE EQU 5 ; Set when governor is active (enabled when speed is above minimum)
  1916. SKIP_DAMP_ON EQU 6 ; Set when turning damping fet on is skipped
  1917. ; EQU 7
  1918. Flags2: DS 1 ; State flags. NOT reset upon init_start
  1919. RCP_UPDATED EQU 0 ; New RC pulse length value available
  1920. RCP_EDGE_NO EQU 1 ; RC pulse edge no. 0=rising, 1=falling
  1921. PGM_PWMOFF_DAMPED EQU 2 ; Programmed pwm off damped mode
  1922. PGM_PWM_HIGH_FREQ EQU 3 ; Progremmed pwm high frequency
  1923. RCP_PPM EQU 4 ; RC pulse ppm type input (set also when oneshot is set)
  1924. RCP_PPM_ONESHOT125 EQU 5 ; RC pulse ppm type input is OneShot125
  1925. RCP_DIR_REV EQU 6 ; RC pulse direction in bidirectional mode
  1926. ; EQU 7
  1927. Flags3: DS 1 ; State flags. NOT reset upon init_start
  1928. RCP_PWM_FREQ_1KHZ EQU 0 ; RC pulse pwm frequency is 1kHz
  1929. RCP_PWM_FREQ_2KHZ EQU 1 ; RC pulse pwm frequency is 2kHz
  1930. RCP_PWM_FREQ_4KHZ EQU 2 ; RC pulse pwm frequency is 4kHz
  1931. RCP_PWM_FREQ_8KHZ EQU 3 ; RC pulse pwm frequency is 8kHz
  1932. RCP_PWM_FREQ_12KHZ EQU 4 ; RC pulse pwm frequency is 12kHz
  1933. PGM_DIR_REV EQU 5 ; Programmed direction. 0=normal, 1=reversed
  1934. PGM_RCP_PWM_POL EQU 6 ; Programmed RC pulse pwm polarity. 0=positive, 1=negative
  1935. FULL_THROTTLE_RANGE EQU 7 ; When set full throttle range is used (1000-2000us) and stored calibration values are ignored
  1936. ;**** **** **** **** ****
  1937. ; RAM definitions
  1938. DSEG AT 30h ; Ram data segment, direct addressing
  1939. Initial_Arm: DS 1 ; Variable that is set during the first arm sequence after power on
  1940. Power_On_Wait_Cnt_L: DS 1 ; Power on wait counter (lo byte)
  1941. Power_On_Wait_Cnt_H: DS 1 ; Power on wait counter (hi byte)
  1942. Startup_Cnt: DS 1 ; Startup phase commutations counter (incrementing)
  1943. Startup_Zc_Timeout_Cntd: DS 1 ; Startup zero cross timeout counter (decrementing)
  1944. Initial_Run_Rot_Cnt: DS 1 ; Initial run rotations counter (incrementing)
  1945. Stall_Cnt: DS 1 ; Counts start/run attempts that resulted in stall. Reset upon a proper stop
  1946. Demag_Detected_Metric: DS 1 ; Metric used to gauge demag event frequency
  1947. Demag_Pwr_Off_Thresh: DS 1 ; Metric threshold above which power is cut
  1948. Low_Rpm_Pwr_Slope: DS 1 ; Sets the slope of power increase for low rpms
  1949. Timer2_X: DS 1 ; Timer 2 extended byte
  1950. Prev_Comm_L: DS 1 ; Previous commutation timer3 timestamp (lo byte)
  1951. Prev_Comm_H: DS 1 ; Previous commutation timer3 timestamp (hi byte)
  1952. Prev_Comm_X: DS 1 ; Previous commutation timer3 timestamp (ext byte)
  1953. Prev_Prev_Comm_L: DS 1 ; Pre-previous commutation timer3 timestamp (lo byte)
  1954. Prev_Prev_Comm_H: DS 1 ; Pre-previous commutation timer3 timestamp (hi byte)
  1955. Comm_Period4x_L: DS 1 ; Timer3 counts between the last 4 commutations (lo byte)
  1956. Comm_Period4x_H: DS 1 ; Timer3 counts between the last 4 commutations (hi byte)
  1957. Comm_Diff: DS 1 ; Timer3 count difference between the last two commutations
  1958. Comm_Phase: DS 1 ; Current commutation phase
  1959. Comparator_Read_Cnt: DS 1 ; Number of comparator reads done
  1960. Gov_Target_L: DS 1 ; Governor target (lo byte)
  1961. Gov_Target_H: DS 1 ; Governor target (hi byte)
  1962. Gov_Integral_L: DS 1 ; Governor integral error (lo byte)
  1963. Gov_Integral_H: DS 1 ; Governor integral error (hi byte)
  1964. Gov_Integral_X: DS 1 ; Governor integral error (ex byte)
  1965. Gov_Proportional_L: DS 1 ; Governor proportional error (lo byte)
  1966. Gov_Proportional_H: DS 1 ; Governor proportional error (hi byte)
  1967. Gov_Prop_Pwm: DS 1 ; Governor calculated new pwm based upon proportional error
  1968. Gov_Arm_Target: DS 1 ; Governor arm target value
  1969. Wt_Adv_Start_L: DS 1 ; Timer3 start point for commutation advance timing (lo byte)
  1970. Wt_Adv_Start_H: DS 1 ; Timer3 start point for commutation advance timing (hi byte)
  1971. Wt_Zc_Scan_Start_L: DS 1 ; Timer3 start point from commutation to zero cross scan (lo byte)
  1972. Wt_Zc_Scan_Start_H: DS 1 ; Timer3 start point from commutation to zero cross scan (hi byte)
  1973. Wt_Zc_Tout_Start_L: DS 1 ; Timer3 start point for zero cross scan timeout (lo byte)
  1974. Wt_Zc_Tout_Start_H: DS 1 ; Timer3 start point for zero cross scan timeout (hi byte)
  1975. Wt_Comm_Start_L: DS 1 ; Timer3 start point from zero cross to commutation (lo byte)
  1976. Wt_Comm_Start_H: DS 1 ; Timer3 start point from zero cross to commutation (hi byte)
  1977. Next_Wt_Start_L: DS 1 ; Timer3 start point for next wait period (lo byte)
  1978. Next_Wt_Start_H: DS 1 ; Timer3 start point for next wait period (hi byte)
  1979. Rcp_PrePrev_Edge_L: DS 1 ; RC pulse pre previous edge pca timestamp (lo byte)
  1980. Rcp_PrePrev_Edge_H: DS 1 ; RC pulse pre previous edge pca timestamp (hi byte)
  1981. Rcp_Edge_L: DS 1 ; RC pulse edge pca timestamp (lo byte)
  1982. Rcp_Edge_H: DS 1 ; RC pulse edge pca timestamp (hi byte)
  1983. Rcp_Prev_Period_L: DS 1 ; RC pulse previous period (lo byte)
  1984. Rcp_Prev_Period_H: DS 1 ; RC pulse previous period (hi byte)
  1985. Rcp_Period_Diff_Accepted: DS 1 ; RC pulse period difference acceptable
  1986. New_Rcp: DS 1 ; New RC pulse value in pca counts
  1987. Prev_Rcp_Pwm_Freq: DS 1 ; Previous RC pulse pwm frequency (used during pwm frequency measurement)
  1988. Curr_Rcp_Pwm_Freq: DS 1 ; Current RC pulse pwm frequency (used during pwm frequency measurement)
  1989. Rcp_Stop_Cnt: DS 1 ; Counter for RC pulses below stop value
  1990. Auto_Bailout_Armed: DS 1 ; Set when auto rotation bailout is armed
  1991. Pwm_Limit: DS 1 ; Maximum allowed pwm
  1992. Pwm_Limit_Spoolup: DS 1 ; Maximum allowed pwm during spoolup
  1993. Pwm_Limit_By_Rpm: DS 1 ; Maximum allowed pwm for low or high rpms
  1994. Pwm_Spoolup_Beg: DS 1 ; Pwm to begin main spoolup with
  1995. Pwm_Motor_Idle: DS 1 ; Motor idle speed pwm
  1996. Pwm_Dither_Decoded: DS 1 ; Decoded pwm dither value
  1997. Pwm_Dither_Excess_Power: DS 1 ; Excess power (above max) from pwm dither
  1998. Random: DS 1 ; Random number from LFSR
  1999. Spoolup_Limit_Cnt: DS 1 ; Interrupt count for spoolup limit
  2000. Spoolup_Limit_Skip: DS 1 ; Interrupt skips for spoolup limit increment (1=no skips, 2=skip one etc)
  2001. Main_Spoolup_Time_3x: DS 1 ; Main spoolup time x3
  2002. Main_Spoolup_Time_10x: DS 1 ; Main spoolup time x10
  2003. Main_Spoolup_Time_15x: DS 1 ; Main spoolup time x15
  2004. Lipo_Adc_Limit_L: DS 1 ; Low voltage limit adc value (lo byte)
  2005. Lipo_Adc_Limit_H: DS 1 ; Low voltage limit adc value (hi byte)
  2006. Adc_Conversion_Cnt: DS 1 ; Adc conversion counter
  2007. Current_Average_Temp: DS 1 ; Current average temperature (lo byte ADC reading, assuming hi byte is 1)
  2008. Ppm_Throttle_Gain: DS 1 ; Gain to be applied to RCP value for PPM input
  2009. Beep_Strength: DS 1 ; Strength of beeps
  2010. Tx_Pgm_Func_No: DS 1 ; Function number when doing programming by tx
  2011. Tx_Pgm_Paraval_No: DS 1 ; Parameter value number when doing programming by tx
  2012. Tx_Pgm_Beep_No: DS 1 ; Beep number when doing programming by tx
  2013. Skip_T2_Int: DS 1 ; Set for 48MHz MCUs when timer 2 interrupt shall be ignored
  2014. Skip_T2h_Int: DS 1 ; Set for 48MHz MCUs when timer 2 high interrupt shall be ignored
  2015. Timer0_Overflow_Value: DS 1 ; Remaining timer 0 wait time used with 48MHz MCUs
  2016. Clock_Set_At_48MHz: DS 1 ; Variable set if 48MHz MCUs run at 48MHz
  2017. DampingFET: DS 1 ; Port position of fet used for damping
  2018. ; Indirect addressing data segment. The variables below must be in this sequence
  2019. ISEG AT 080h
  2020. Pgm_Gov_P_Gain: DS 1 ; Programmed governor P gain
  2021. Pgm_Gov_I_Gain: DS 1 ; Programmed governor I gain
  2022. Pgm_Gov_Mode: DS 1 ; Programmed governor mode
  2023. Pgm_Low_Voltage_Lim: DS 1 ; Programmed low voltage limit
  2024. Pgm_Motor_Gain: DS 1 ; Programmed motor gain
  2025. Pgm_Motor_Idle: DS 1 ; Programmed motor idle speed
  2026. Pgm_Startup_Pwr: DS 1 ; Programmed startup power
  2027. Pgm_Pwm_Freq: DS 1 ; Programmed pwm frequency
  2028. Pgm_Direction: DS 1 ; Programmed rotation direction
  2029. Pgm_Input_Pol: DS 1 ; Programmed input pwm polarity
  2030. Initialized_L_Dummy: DS 1 ; Place holder
  2031. Initialized_H_Dummy: DS 1 ; Place holder
  2032. Pgm_Enable_TX_Program: DS 1 ; Programmed enable/disable value for TX programming
  2033. Pgm_Main_Rearm_Start: DS 1 ; Programmed enable/disable re-arming main every start
  2034. Pgm_Gov_Setup_Target: DS 1 ; Programmed main governor setup target
  2035. _Pgm_Startup_Rpm: DS 1 ; Programmed startup rpm (unused - place holder)
  2036. _Pgm_Startup_Accel: DS 1 ; Programmed startup acceleration (unused - place holder)
  2037. _Pgm_Volt_Comp: DS 1 ; Place holder
  2038. Pgm_Comm_Timing: DS 1 ; Programmed commutation timing
  2039. _Pgm_Damping_Force: DS 1 ; Programmed damping force (unused - place holder)
  2040. Pgm_Gov_Range: DS 1 ; Programmed governor range
  2041. _Pgm_Startup_Method: DS 1 ; Programmed startup method (unused - place holder)
  2042. Pgm_Ppm_Min_Throttle: DS 1 ; Programmed throttle minimum
  2043. Pgm_Ppm_Max_Throttle: DS 1 ; Programmed throttle maximum
  2044. Pgm_Beep_Strength: DS 1 ; Programmed beep strength
  2045. Pgm_Beacon_Strength: DS 1 ; Programmed beacon strength
  2046. Pgm_Beacon_Delay: DS 1 ; Programmed beacon delay
  2047. _Pgm_Throttle_Rate: DS 1 ; Programmed throttle rate (unused - place holder)
  2048. Pgm_Demag_Comp: DS 1 ; Programmed demag compensation
  2049. Pgm_BEC_Voltage_High: DS 1 ; Programmed BEC voltage
  2050. Pgm_Ppm_Center_Throttle: DS 1 ; Programmed throttle center (in bidirectional mode)
  2051. Pgm_Main_Spoolup_Time: DS 1 ; Programmed main spoolup time
  2052. Pgm_Enable_Temp_Prot: DS 1 ; Programmed temperature protection enable
  2053. Pgm_Enable_Power_Prot: DS 1 ; Programmed low rpm power protection enable
  2054. Pgm_Enable_Pwm_Input: DS 1 ; Programmed PWM input signal enable
  2055. Pgm_Pwm_Dither: DS 1 ; Programmed output PWM dither
  2056. ; The sequence of the variables below is no longer of importance
  2057. Pgm_Gov_P_Gain_Decoded: DS 1 ; Programmed governor decoded P gain
  2058. Pgm_Gov_I_Gain_Decoded: DS 1 ; Programmed governor decoded I gain
  2059. Pgm_Startup_Pwr_Decoded: DS 1 ; Programmed startup power decoded
  2060. ; Indirect addressing data segment
  2061. ISEG AT 0D0h
  2062. Tag_Temporary_Storage: DS 48 ; Temporary storage for tags when updating "Eeprom"
  2063. ;**** **** **** **** ****
  2064. CSEG AT 1A00h ; "Eeprom" segment
  2065. EEPROM_FW_MAIN_REVISION EQU 14 ; Main revision of the firmware
  2066. EEPROM_FW_SUB_REVISION EQU 4 ; Sub revision of the firmware
  2067. EEPROM_LAYOUT_REVISION EQU 20 ; Revision of the EEPROM layout
  2068. Eep_FW_Main_Revision: DB EEPROM_FW_MAIN_REVISION ; EEPROM firmware main revision number
  2069. Eep_FW_Sub_Revision: DB EEPROM_FW_SUB_REVISION ; EEPROM firmware sub revision number
  2070. Eep_Layout_Revision: DB EEPROM_LAYOUT_REVISION ; EEPROM layout revision number
  2071. IF MODE == 0
  2072. Eep_Pgm_Gov_P_Gain: DB DEFAULT_PGM_MAIN_P_GAIN ; EEPROM copy of programmed governor P gain
  2073. Eep_Pgm_Gov_I_Gain: DB DEFAULT_PGM_MAIN_I_GAIN ; EEPROM copy of programmed governor I gain
  2074. Eep_Pgm_Gov_Mode: DB DEFAULT_PGM_MAIN_GOVERNOR_MODE ; EEPROM copy of programmed governor mode
  2075. Eep_Pgm_Low_Voltage_Lim: DB DEFAULT_PGM_MAIN_LOW_VOLTAGE_LIM ; EEPROM copy of programmed low voltage limit
  2076. _Eep_Pgm_Motor_Gain: DB 0FFh
  2077. _Eep_Pgm_Motor_Idle: DB 0FFh
  2078. Eep_Pgm_Startup_Pwr: DB DEFAULT_PGM_MAIN_STARTUP_PWR ; EEPROM copy of programmed startup power
  2079. Eep_Pgm_Pwm_Freq: DB DEFAULT_PGM_MAIN_PWM_FREQ ; EEPROM copy of programmed pwm frequency
  2080. Eep_Pgm_Direction: DB DEFAULT_PGM_MAIN_DIRECTION ; EEPROM copy of programmed rotation direction
  2081. Eep_Pgm_Input_Pol: DB DEFAULT_PGM_MAIN_RCP_PWM_POL ; EEPROM copy of programmed input polarity
  2082. Eep_Initialized_L: DB 0A5h ; EEPROM initialized signature low byte
  2083. Eep_Initialized_H: DB 05Ah ; EEPROM initialized signature high byte
  2084. Eep_Enable_TX_Program: DB DEFAULT_PGM_ENABLE_TX_PROGRAM ; EEPROM TX programming enable
  2085. Eep_Main_Rearm_Start: DB DEFAULT_PGM_MAIN_REARM_START ; EEPROM re-arming main enable
  2086. Eep_Pgm_Gov_Setup_Target: DB DEFAULT_PGM_MAIN_GOV_SETUP_TARGET ; EEPROM main governor setup target
  2087. _Eep_Pgm_Startup_Rpm: DB 0FFh
  2088. _Eep_Pgm_Startup_Accel: DB 0FFh
  2089. _Eep_Pgm_Volt_Comp: DB 0FFh
  2090. Eep_Pgm_Comm_Timing: DB DEFAULT_PGM_MAIN_COMM_TIMING ; EEPROM copy of programmed commutation timing
  2091. _Eep_Pgm_Damping_Force: DB 0FFh
  2092. Eep_Pgm_Gov_Range: DB DEFAULT_PGM_MAIN_GOVERNOR_RANGE ; EEPROM copy of programmed governor range
  2093. _Eep_Pgm_Startup_Method: DB 0FFh
  2094. Eep_Pgm_Ppm_Min_Throttle: DB DEFAULT_PGM_PPM_MIN_THROTTLE ; EEPROM copy of programmed minimum throttle (final value is 4x+1000=1148)
  2095. Eep_Pgm_Ppm_Max_Throttle: DB DEFAULT_PGM_PPM_MAX_THROTTLE ; EEPROM copy of programmed minimum throttle (final value is 4x+1000=1832)
  2096. Eep_Pgm_Beep_Strength: DB DEFAULT_PGM_MAIN_BEEP_STRENGTH ; EEPROM copy of programmed beep strength
  2097. Eep_Pgm_Beacon_Strength: DB DEFAULT_PGM_MAIN_BEACON_STRENGTH ; EEPROM copy of programmed beacon strength
  2098. Eep_Pgm_Beacon_Delay: DB DEFAULT_PGM_MAIN_BEACON_DELAY ; EEPROM copy of programmed beacon delay
  2099. _Eep_Pgm_Throttle_Rate: DB 0FFh
  2100. Eep_Pgm_Demag_Comp: DB DEFAULT_PGM_MAIN_DEMAG_COMP ; EEPROM copy of programmed demag compensation
  2101. Eep_Pgm_BEC_Voltage_High: DB DEFAULT_PGM_BEC_VOLTAGE_HIGH ; EEPROM copy of programmed BEC voltage
  2102. _Eep_Pgm_Ppm_Center_Throttle: DB 0FFh
  2103. Eep_Pgm_Main_Spoolup_Time: DB DEFAULT_PGM_MAIN_SPOOLUP_TIME ; EEPROM copy of programmed main spoolup time
  2104. Eep_Pgm_Temp_Prot_Enable: DB DEFAULT_PGM_ENABLE_TEMP_PROT ; EEPROM copy of programmed temperature protection enable
  2105. Eep_Pgm_Enable_Power_Prot: DB DEFAULT_PGM_ENABLE_POWER_PROT ; EEPROM copy of programmed low rpm power protection enable
  2106. Eep_Pgm_Enable_Pwm_Input: DB DEFAULT_PGM_ENABLE_PWM_INPUT ; EEPROM copy of programmed PWM input signal enable
  2107. _Eep_Pgm_Pwm_Dither: DB 0FFh
  2108. ENDIF
  2109. IF MODE == 1
  2110. _Eep_Pgm_Gov_P_Gain: DB 0FFh
  2111. _Eep_Pgm_Gov_I_Gain: DB 0FFh
  2112. _Eep_Pgm_Gov_Mode: DB 0FFh
  2113. _Eep_Pgm_Low_Voltage_Lim: DB 0FFh
  2114. Eep_Pgm_Motor_Gain: DB DEFAULT_PGM_TAIL_GAIN ; EEPROM copy of programmed tail gain
  2115. Eep_Pgm_Motor_Idle: DB DEFAULT_PGM_TAIL_IDLE_SPEED ; EEPROM copy of programmed tail idle speed
  2116. Eep_Pgm_Startup_Pwr: DB DEFAULT_PGM_TAIL_STARTUP_PWR ; EEPROM copy of programmed startup power
  2117. Eep_Pgm_Pwm_Freq: DB DEFAULT_PGM_TAIL_PWM_FREQ ; EEPROM copy of programmed pwm frequency
  2118. Eep_Pgm_Direction: DB DEFAULT_PGM_TAIL_DIRECTION ; EEPROM copy of programmed rotation direction
  2119. Eep_Pgm_Input_Pol: DB DEFAULT_PGM_TAIL_RCP_PWM_POL ; EEPROM copy of programmed input polarity
  2120. Eep_Initialized_L: DB 05Ah ; EEPROM initialized signature low byte
  2121. Eep_Initialized_H: DB 0A5h ; EEPROM initialized signature high byte
  2122. Eep_Enable_TX_Program: DB DEFAULT_PGM_ENABLE_TX_PROGRAM ; EEPROM TX programming enable
  2123. _Eep_Main_Rearm_Start: DB 0FFh
  2124. _Eep_Pgm_Gov_Setup_Target: DB 0FFh
  2125. _Eep_Pgm_Startup_Rpm: DB 0FFh
  2126. _Eep_Pgm_Startup_Accel: DB 0FFh
  2127. _Eep_Pgm_Volt_Comp: DB 0FFh
  2128. Eep_Pgm_Comm_Timing: DB DEFAULT_PGM_TAIL_COMM_TIMING ; EEPROM copy of programmed commutation timing
  2129. _Eep_Pgm_Damping_Force: DB 0FFh
  2130. _Eep_Pgm_Gov_Range: DB 0FFh
  2131. _Eep_Pgm_Startup_Method: DB 0FFh
  2132. Eep_Pgm_Ppm_Min_Throttle: DB DEFAULT_PGM_PPM_MIN_THROTTLE ; EEPROM copy of programmed minimum throttle (final value is 4x+1000=1148)
  2133. Eep_Pgm_Ppm_Max_Throttle: DB DEFAULT_PGM_PPM_MAX_THROTTLE ; EEPROM copy of programmed minimum throttle (final value is 4x+1000=1832)
  2134. Eep_Pgm_Beep_Strength: DB DEFAULT_PGM_TAIL_BEEP_STRENGTH ; EEPROM copy of programmed beep strength
  2135. Eep_Pgm_Beacon_Strength: DB DEFAULT_PGM_TAIL_BEACON_STRENGTH ; EEPROM copy of programmed beacon strength
  2136. Eep_Pgm_Beacon_Delay: DB DEFAULT_PGM_TAIL_BEACON_DELAY ; EEPROM copy of programmed beacon delay
  2137. _Eep_Pgm_Throttle_Rate: DB 0FFh
  2138. Eep_Pgm_Demag_Comp: DB DEFAULT_PGM_TAIL_DEMAG_COMP ; EEPROM copy of programmed demag compensation
  2139. Eep_Pgm_BEC_Voltage_High: DB DEFAULT_PGM_BEC_VOLTAGE_HIGH ; EEPROM copy of programmed BEC voltage
  2140. Eep_Pgm_Ppm_Center_Throttle: DB DEFAULT_PGM_PPM_CENTER_THROTTLE ; EEPROM copy of programmed center throttle (final value is 4x+1000=1488)
  2141. _Eep_Pgm_Main_Spoolup_Time: DB 0FFh
  2142. Eep_Pgm_Temp_Prot_Enable: DB DEFAULT_PGM_ENABLE_TEMP_PROT ; EEPROM copy of programmed temperature protection enable
  2143. Eep_Pgm_Enable_Power_Prot: DB DEFAULT_PGM_ENABLE_POWER_PROT ; EEPROM copy of programmed low rpm power protection enable
  2144. Eep_Pgm_Enable_Pwm_Input: DB DEFAULT_PGM_ENABLE_PWM_INPUT ; EEPROM copy of programmed PWM input signal enable
  2145. Eep_Pgm_Pwm_Dither: DB DEFAULT_PGM_TAIL_PWM_DITHER ; EEPROM copy of programmed output PWM dither
  2146. ENDIF
  2147. IF MODE == 2
  2148. Eep_Pgm_Gov_P_Gain: DB DEFAULT_PGM_MULTI_P_GAIN ; EEPROM copy of programmed closed loop P gain
  2149. Eep_Pgm_Gov_I_Gain: DB DEFAULT_PGM_MULTI_I_GAIN ; EEPROM copy of programmed closed loop I gain
  2150. Eep_Pgm_Gov_Mode: DB DEFAULT_PGM_MULTI_GOVERNOR_MODE ; EEPROM copy of programmed closed loop mode
  2151. _Eep_Pgm_Low_Voltage_Lim: DB 0FFh
  2152. Eep_Pgm_Motor_Gain: DB DEFAULT_PGM_MULTI_GAIN ; EEPROM copy of programmed tail gain
  2153. _Eep_Pgm_Motor_Idle: DB 0FFh ; EEPROM copy of programmed tail idle speed
  2154. Eep_Pgm_Startup_Pwr: DB DEFAULT_PGM_MULTI_STARTUP_PWR ; EEPROM copy of programmed startup power
  2155. Eep_Pgm_Pwm_Freq: DB DEFAULT_PGM_MULTI_PWM_FREQ ; EEPROM copy of programmed pwm frequency
  2156. Eep_Pgm_Direction: DB DEFAULT_PGM_MULTI_DIRECTION ; EEPROM copy of programmed rotation direction
  2157. Eep_Pgm_Input_Pol: DB DEFAULT_PGM_MULTI_RCP_PWM_POL ; EEPROM copy of programmed input polarity
  2158. Eep_Initialized_L: DB 055h ; EEPROM initialized signature low byte
  2159. Eep_Initialized_H: DB 0AAh ; EEPROM initialized signature high byte
  2160. Eep_Enable_TX_Program: DB DEFAULT_PGM_ENABLE_TX_PROGRAM ; EEPROM TX programming enable
  2161. _Eep_Main_Rearm_Start: DB 0FFh
  2162. _Eep_Pgm_Gov_Setup_Target: DB 0FFh
  2163. _Eep_Pgm_Startup_Rpm: DB 0FFh
  2164. _Eep_Pgm_Startup_Accel: DB 0FFh
  2165. _Eep_Pgm_Volt_Comp: DB 0FFh
  2166. Eep_Pgm_Comm_Timing: DB DEFAULT_PGM_MULTI_COMM_TIMING ; EEPROM copy of programmed commutation timing
  2167. _Eep_Pgm_Damping_Force: DB 0FFh
  2168. _Eep_Pgm_Gov_Range: DB 0FFh
  2169. _Eep_Pgm_Startup_Method: DB 0FFh
  2170. Eep_Pgm_Ppm_Min_Throttle: DB DEFAULT_PGM_PPM_MIN_THROTTLE ; EEPROM copy of programmed minimum throttle (final value is 4x+1000=1148)
  2171. Eep_Pgm_Ppm_Max_Throttle: DB DEFAULT_PGM_PPM_MAX_THROTTLE ; EEPROM copy of programmed minimum throttle (final value is 4x+1000=1832)
  2172. Eep_Pgm_Beep_Strength: DB DEFAULT_PGM_MULTI_BEEP_STRENGTH ; EEPROM copy of programmed beep strength
  2173. Eep_Pgm_Beacon_Strength: DB DEFAULT_PGM_MULTI_BEACON_STRENGTH ; EEPROM copy of programmed beacon strength
  2174. Eep_Pgm_Beacon_Delay: DB DEFAULT_PGM_MULTI_BEACON_DELAY ; EEPROM copy of programmed beacon delay
  2175. _Eep_Pgm_Throttle_Rate: DB 0FFh
  2176. Eep_Pgm_Demag_Comp: DB DEFAULT_PGM_MULTI_DEMAG_COMP ; EEPROM copy of programmed demag compensation
  2177. Eep_Pgm_BEC_Voltage_High: DB DEFAULT_PGM_BEC_VOLTAGE_HIGH ; EEPROM copy of programmed BEC voltage
  2178. Eep_Pgm_Ppm_Center_Throttle: DB DEFAULT_PGM_PPM_CENTER_THROTTLE ; EEPROM copy of programmed center throttle (final value is 4x+1000=1488)
  2179. _Eep_Pgm_Main_Spoolup_Time: DB 0FFh
  2180. Eep_Pgm_Temp_Prot_Enable: DB DEFAULT_PGM_ENABLE_TEMP_PROT ; EEPROM copy of programmed temperature protection enable
  2181. Eep_Pgm_Enable_Power_Prot: DB DEFAULT_PGM_ENABLE_POWER_PROT ; EEPROM copy of programmed low rpm power protection enable
  2182. Eep_Pgm_Enable_Pwm_Input: DB DEFAULT_PGM_ENABLE_PWM_INPUT ; EEPROM copy of programmed PWM input signal enable
  2183. Eep_Pgm_Pwm_Dither: DB DEFAULT_PGM_MULTI_PWM_DITHER ; EEPROM copy of programmed output PWM dither
  2184. ENDIF
  2185. Eep_Dummy: DB 0FFh ; EEPROM address for safety reason
  2186. CSEG AT 1A60h
  2187. Eep_Name: DB " " ; Name tag (16 Bytes)
  2188. ;**** **** **** **** ****
  2189. Interrupt_Table_Definition ; SiLabs interrupts
  2190. CSEG AT 80h ; Code segment after interrupt vectors
  2191. ;**** **** **** **** ****
  2192. ; Table definitions
  2193. GOV_GAIN_TABLE: DB 02h, 03h, 04h, 06h, 08h, 0Ch, 10h, 18h, 20h, 30h, 40h, 60h, 80h
  2194. STARTUP_POWER_TABLE: DB 04h, 06h, 08h, 0Ch, 10h, 18h, 20h, 30h, 40h, 60h, 80h, 0A0h, 0C0h
  2195. PWM_DITHER_TABLE: DB 00h, 07h, 0Fh, 1Fh, 3Fh
  2196. IF MODE == 0
  2197. IF DAMPED_MODE_ENABLE == 1
  2198. TX_PGM_PARAMS_MAIN: DB 13, 13, 4, 3, 6, 13, 5, 3, 3, 2, 2
  2199. ENDIF
  2200. IF DAMPED_MODE_ENABLE == 0
  2201. TX_PGM_PARAMS_MAIN: DB 13, 13, 4, 3, 6, 13, 5, 2, 3, 2, 2
  2202. ENDIF
  2203. ENDIF
  2204. IF MODE == 1
  2205. IF DAMPED_MODE_ENABLE == 1
  2206. TX_PGM_PARAMS_TAIL: DB 5, 5, 13, 5, 3, 5, 3, 3, 2
  2207. ENDIF
  2208. IF DAMPED_MODE_ENABLE == 0
  2209. TX_PGM_PARAMS_TAIL: DB 5, 5, 13, 5, 2, 5, 3, 3, 2
  2210. ENDIF
  2211. ENDIF
  2212. IF MODE == 2
  2213. IF DAMPED_MODE_ENABLE == 1
  2214. TX_PGM_PARAMS_MULTI: DB 13, 13, 4, 5, 13, 5, 3, 5, 3, 3, 2
  2215. ENDIF
  2216. IF DAMPED_MODE_ENABLE == 0
  2217. TX_PGM_PARAMS_MULTI: DB 13, 13, 4, 5, 13, 5, 2, 5, 3, 3, 2
  2218. ENDIF
  2219. ENDIF
  2220. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  2221. ;
  2222. ; Timer0 interrupt routine
  2223. ;
  2224. ; Assumptions: DPTR register must be set to desired pwm_nfet_on label
  2225. ; Requirements: Temp variables can NOT be used since PSW.3 is not set
  2226. ;
  2227. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  2228. t0_int: ; Used for pwm control
  2229. clr EA ; Disable all interrupts
  2230. IF MCU_48MHZ == 1
  2231. ; Check overflow flag
  2232. jnb Flags0.PWM_TIMER0_OVERFLOW, t0_int_start; Execute this interrupt
  2233. clr Flags0.PWM_TIMER0_OVERFLOW
  2234. mov TL0, Timer0_Overflow_Value ; Set timer
  2235. setb EA ; Enable all interrupts
  2236. reti
  2237. t0_int_start:
  2238. ENDIF
  2239. push PSW ; Preserve registers through interrupt
  2240. push ACC
  2241. ; Check if pwm is on
  2242. jb Flags0.PWM_ON, t0_int_pwm_off ; Is pwm on?
  2243. ; Pwm on cycle
  2244. mov A, Current_Pwm_Limited
  2245. jz t0_int_pwm_on_exit
  2246. clr A
  2247. jmp @A+DPTR ; Jump to pwm on routines. DPTR should be set to one of the pwm_nfet_on labels
  2248. t0_int_pwm_on_exit:
  2249. ; Set timer for coming on cycle length
  2250. mov A, Current_Pwm_Limited ; Load current pwm
  2251. cpl A ; cpl is 255-x
  2252. IF MCU_48MHZ == 0
  2253. mov TL0, A ; Write start point for timer
  2254. ELSE
  2255. clr C
  2256. rlc A
  2257. jc t0_int_pwm_on_set_timer
  2258. mov TL0, #0
  2259. setb Flags0.PWM_TIMER0_OVERFLOW
  2260. mov Timer0_Overflow_Value, A
  2261. ajmp t0_int_pwm_on_timer_set
  2262. t0_int_pwm_on_set_timer:
  2263. mov TL0, A
  2264. t0_int_pwm_on_timer_set:
  2265. ENDIF
  2266. ; Set other variables
  2267. mov TL1, #0 ; Reset timer1
  2268. IF MCU_48MHZ == 1
  2269. mov TH1, #0
  2270. ENDIF
  2271. setb Flags0.PWM_ON ; Set pwm on flag
  2272. ; Exit interrupt
  2273. pop ACC ; Restore preserved registers
  2274. pop PSW
  2275. setb EA ; Enable all interrupts
  2276. reti
  2277. ; Pwm off cycle
  2278. t0_int_pwm_off:
  2279. IF MCU_48MHZ == 0
  2280. mov TL0, Current_Pwm_Lim_Dith ; Load new timer setting
  2281. ELSE
  2282. clr C
  2283. mov A, Current_Pwm_Lim_Dith
  2284. rlc A
  2285. jc t0_int_pwm_off_set_timer
  2286. mov TL0, #0
  2287. setb Flags0.PWM_TIMER0_OVERFLOW
  2288. mov Timer0_Overflow_Value, A
  2289. ajmp t0_int_pwm_off_timer_set
  2290. t0_int_pwm_off_set_timer:
  2291. mov TL0, A
  2292. t0_int_pwm_off_timer_set:
  2293. ENDIF
  2294. ; Clear pwm on flag
  2295. clr Flags0.PWM_ON
  2296. ; Set full PWM (on all the time) if current PWM near max. This will give full power, but at the cost of a small "jump" in power
  2297. mov A, Current_Pwm_Lim_Dith ; Load current pwm
  2298. cpl A ; Full pwm?
  2299. jz t0_int_pwm_off_fullpower_exit ; Yes - exit
  2300. IF DAMPED_MODE_ENABLE == 1
  2301. ; Do not execute damped pwm when stopped
  2302. jnb Flags1.MOTOR_SPINNING, t0_int_pwm_off_exit_nfets_off
  2303. ; If damped operation, set pFETs on in pwm_off
  2304. jb Flags2.PGM_PWMOFF_DAMPED, t0_int_pwm_off_damped ; Damped operation?
  2305. ENDIF
  2306. t0_int_pwm_off_exit_nfets_off:
  2307. ; Separate exit commands here for minimum delay
  2308. mov TL1, #0 ; Reset timer1
  2309. IF MCU_48MHZ == 1
  2310. mov TH1, #0
  2311. ENDIF
  2312. pop ACC ; Restore preserved registers
  2313. pop PSW
  2314. All_nFETs_Off ; Switch off all nfets
  2315. setb EA ; Enable all interrupts
  2316. reti
  2317. t0_int_pwm_off_damped:
  2318. IF PFETON_DELAY < 128
  2319. All_nFETs_Off ; Switch off all nfets
  2320. jb Flags1.SKIP_DAMP_ON, t0_int_pwm_off_damp_done
  2321. jb Flags0.DEMAG_CUT_POWER, t0_int_pwm_off_damp_done
  2322. IF PFETON_DELAY NE 0
  2323. mov A, #PFETON_DELAY
  2324. djnz ACC, $
  2325. ENDIF
  2326. Damping_FET_on
  2327. t0_int_pwm_off_damp_done:
  2328. ENDIF
  2329. IF PFETON_DELAY >= 128 ; "Negative", 1's complement
  2330. jb Flags1.SKIP_DAMP_ON, t0_int_pwm_off_damp_done
  2331. jb Flags0.DEMAG_CUT_POWER, t0_int_pwm_off_damp_done
  2332. Damping_FET_on ; Damping fet on
  2333. mov A, #PFETON_DELAY
  2334. cpl A
  2335. djnz ACC, $
  2336. t0_int_pwm_off_damp_done:
  2337. All_nFETs_Off ; Switch off all nfets
  2338. ENDIF
  2339. t0_int_pwm_off_exit:
  2340. mov TL1, #0 ; Reset timer1
  2341. IF MCU_48MHZ == 1
  2342. mov TH1, #0
  2343. ENDIF
  2344. pop ACC ; Restore preserved registers
  2345. pop PSW
  2346. setb EA ; Enable all interrupts
  2347. reti
  2348. t0_int_pwm_off_fullpower_exit:
  2349. mov TL0, #0 ; Set long time till next interrupt
  2350. IF MCU_48MHZ == 1
  2351. setb Flags0.PWM_TIMER0_OVERFLOW
  2352. mov Timer0_Overflow_Value, #0
  2353. ENDIF
  2354. clr TF0 ; Clear interrupt flag
  2355. setb Flags0.PWM_ON
  2356. ajmp t0_int_pwm_off_exit
  2357. pwm_nofet: ; Dummy pwm on cycle
  2358. ajmp t0_int_pwm_on_exit
  2359. pwm_afet: ; Pwm on cycle afet on
  2360. jnb Flags1.MOTOR_SPINNING, pwm_afet_exit
  2361. jb Flags0.DEMAG_CUT_POWER, pwm_afet_exit
  2362. AnFET_on
  2363. pwm_afet_exit:
  2364. ajmp t0_int_pwm_on_exit
  2365. pwm_bfet: ; Pwm on cycle bfet on
  2366. jnb Flags1.MOTOR_SPINNING, pwm_bfet_exit
  2367. jb Flags0.DEMAG_CUT_POWER, pwm_bfet_exit
  2368. BnFET_on
  2369. pwm_bfet_exit:
  2370. ajmp t0_int_pwm_on_exit
  2371. pwm_cfet: ; Pwm on cycle cfet on
  2372. jnb Flags1.MOTOR_SPINNING, pwm_cfet_exit
  2373. jb Flags0.DEMAG_CUT_POWER, pwm_cfet_exit
  2374. CnFET_on
  2375. pwm_cfet_exit:
  2376. ajmp t0_int_pwm_on_exit
  2377. pwm_afet_damped:
  2378. ApFET_off
  2379. jnb Flags1.MOTOR_SPINNING, pwm_afet_damped_exit
  2380. jb Flags0.DEMAG_CUT_POWER, pwm_afet_damped_exit
  2381. IF NFETON_DELAY NE 0
  2382. mov A, #NFETON_DELAY ; Set delay
  2383. djnz ACC, $
  2384. ENDIF
  2385. pwm_afet_damped_done:
  2386. AnFET_on ; Switch nFET
  2387. pwm_afet_damped_exit:
  2388. ajmp t0_int_pwm_on_exit
  2389. pwm_bfet_damped:
  2390. BpFET_off
  2391. jnb Flags1.MOTOR_SPINNING, pwm_bfet_damped_exit
  2392. jb Flags0.DEMAG_CUT_POWER, pwm_bfet_damped_exit
  2393. IF NFETON_DELAY NE 0
  2394. mov A, #NFETON_DELAY ; Set delay
  2395. djnz ACC, $
  2396. ENDIF
  2397. pwm_bfet_damped_done:
  2398. BnFET_on ; Switch nFET
  2399. pwm_bfet_damped_exit:
  2400. ajmp t0_int_pwm_on_exit
  2401. pwm_cfet_damped:
  2402. CpFET_off
  2403. jnb Flags1.MOTOR_SPINNING, pwm_cfet_damped_exit
  2404. jb Flags0.DEMAG_CUT_POWER, pwm_cfet_damped_exit
  2405. IF NFETON_DELAY NE 0
  2406. mov A, #NFETON_DELAY ; Set delay
  2407. djnz ACC, $
  2408. ENDIF
  2409. pwm_cfet_damped_done:
  2410. CnFET_on ; Switch nFET
  2411. pwm_cfet_damped_exit:
  2412. ajmp t0_int_pwm_on_exit
  2413. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  2414. ;
  2415. ; Timer2 interrupt routine
  2416. ;
  2417. ; No assumptions
  2418. ;
  2419. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  2420. t2_int: ; Happens every 128us for low byte and every 32ms for high byte
  2421. clr EA
  2422. clr ET2 ; Disable timer2 interrupts
  2423. anl EIE1, #0EFh ; Disable PCA0 interrupts
  2424. push PSW ; Preserve registers through interrupt
  2425. push ACC
  2426. setb PSW.3 ; Select register bank 1 for interrupt routines
  2427. setb EA
  2428. IF MCU_48MHZ == 1
  2429. mov A, Clock_Set_At_48MHz
  2430. jz t2_int_start
  2431. ; Check skip variable
  2432. mov A, Skip_T2_Int
  2433. jz t2_int_start ; Execute this interrupt
  2434. mov Skip_T2_Int, #0
  2435. ajmp t2_int_exit
  2436. t2_int_start:
  2437. mov Skip_T2_Int, #1 ; Skip next interrupt
  2438. ENDIF
  2439. ; Clear low byte interrupt flag
  2440. clr TF2L ; Clear interrupt flag
  2441. ; Check RC pulse timeout counter
  2442. mov A, Rcp_Timeout_Cntd ; RC pulse timeout count zero?
  2443. jz t2_int_pulses_absent ; Yes - pulses are absent
  2444. ; Decrement timeout counter (if PWM)
  2445. jb Flags2.RCP_PPM, t2_int_skip_start ; If flag is set (PPM) - branch
  2446. dec Rcp_Timeout_Cntd ; No - decrement
  2447. ajmp t2_int_skip_start
  2448. t2_int_pulses_absent:
  2449. ; Timeout counter has reached zero, pulses are absent
  2450. mov Temp1, #RCP_MIN ; RCP_MIN as default
  2451. mov Temp2, #RCP_MIN
  2452. jb Flags2.RCP_PPM, t2_int_pulses_absent_no_max ; If flag is set (PPM) - branch
  2453. Read_Rcp_Int ; Look at value of Rcp_In
  2454. jnb ACC.Rcp_In, ($+5) ; Is it high?
  2455. mov Temp1, #RCP_MAX ; Yes - set RCP_MAX
  2456. Rcp_Int_First ; Set interrupt trig to first again
  2457. Rcp_Clear_Int_Flag ; Clear interrupt flag
  2458. clr Flags2.RCP_EDGE_NO ; Set first edge flag
  2459. Read_Rcp_Int ; Look once more at value of Rcp_In
  2460. jnb ACC.Rcp_In, ($+5) ; Is it high?
  2461. mov Temp2, #RCP_MAX ; Yes - set RCP_MAX
  2462. clr C
  2463. mov A, Temp1
  2464. subb A, Temp2 ; Compare the two readings of Rcp_In
  2465. jnz t2_int_pulses_absent ; Go back if they are not equal
  2466. t2_int_pulses_absent_no_max:
  2467. jnb Flags0.RCP_MEAS_PWM_FREQ, ($+6) ; Is measure RCP pwm frequency flag set?
  2468. mov Rcp_Timeout_Cntd, #RCP_TIMEOUT ; Yes - set timeout count to start value
  2469. jb Flags2.RCP_PPM, t2_int_ppm_timeout_set ; If flag is set (PPM) - branch
  2470. mov Rcp_Timeout_Cntd, #RCP_TIMEOUT ; For PWM, set timeout count to start value
  2471. t2_int_ppm_timeout_set:
  2472. mov New_Rcp, Temp1 ; Store new pulse length
  2473. setb Flags2.RCP_UPDATED ; Set updated flag
  2474. t2_int_skip_start:
  2475. jb Flags2.RCP_PPM, t2_int_rcp_update_start ; If flag is set (PPM) - branch
  2476. ; Check RC pulse skip counter
  2477. mov A, Rcp_Skip_Cntd
  2478. jz t2_int_skip_end ; If RC pulse skip count is zero - end skipping RC pulse detection
  2479. ; Decrement skip counter (only if edge counter is zero)
  2480. dec Rcp_Skip_Cntd ; Decrement
  2481. ajmp t2_int_rcp_update_start
  2482. t2_int_skip_end:
  2483. ; Skip counter has reached zero, start looking for RC pulses again
  2484. Rcp_Int_Enable ; Enable RC pulse interrupt
  2485. Rcp_Clear_Int_Flag ; Clear interrupt flag
  2486. t2_int_rcp_update_start:
  2487. ; Process updated RC pulse
  2488. jb Flags2.RCP_UPDATED, ($+5) ; Is there an updated RC pulse available?
  2489. ajmp t2_int_current_pwm_update ; No - update pwm limits and exit
  2490. mov Temp1, New_Rcp ; Load new pulse value
  2491. jb Flags0.RCP_MEAS_PWM_FREQ, ($+5) ; If measure RCP pwm frequency flag set - do not clear flag
  2492. clr Flags2.RCP_UPDATED ; Flag that pulse has been evaluated
  2493. ; Use a gain of 1.0625x for pwm input if not governor mode
  2494. jb Flags2.RCP_PPM, t2_int_pwm_min_run ; If flag is set (PPM) - branch
  2495. IF MODE == 0 ; Main - do not adjust gain
  2496. ajmp t2_int_pwm_min_run
  2497. ELSE
  2498. IF MODE == 2 ; Multi
  2499. mov Temp2, #Pgm_Gov_Mode ; Closed loop mode?
  2500. cjne @Temp2, #4, t2_int_pwm_min_run; Yes - branch
  2501. ENDIF
  2502. ; Limit the maximum value to avoid wrap when scaled to pwm range
  2503. clr C
  2504. mov A, Temp1
  2505. subb A, #240 ; 240 = (255/1.0625) Needs to be updated according to multiplication factor below
  2506. jc t2_int_rcp_update_mult
  2507. mov A, #240 ; Set requested pwm to max
  2508. mov Temp1, A
  2509. t2_int_rcp_update_mult:
  2510. ; Multiply by 1.0625 (optional adjustment gyro gain)
  2511. mov A, Temp1
  2512. swap A ; After this "0.0625"
  2513. anl A, #0Fh
  2514. add A, Temp1
  2515. mov Temp1, A
  2516. ; Adjust tail gain
  2517. mov Temp2, #Pgm_Motor_Gain
  2518. cjne @Temp2, #3, ($+5) ; Is gain 1?
  2519. ajmp t2_int_pwm_min_run ; Yes - skip adjustment
  2520. clr C
  2521. rrc A ; After this "0.5"
  2522. clr C
  2523. rrc A ; After this "0.25"
  2524. mov Bit_Access_Int, @Temp2 ; (Temp2 has #Pgm_Motor_Gain)
  2525. jb Bit_Access_Int.0, t2_int_rcp_gain_corr ; Branch if bit 0 in gain is set
  2526. clr C
  2527. rrc A ; After this "0.125"
  2528. t2_int_rcp_gain_corr:
  2529. jb Bit_Access_Int.2, t2_int_rcp_gain_pos ; Branch if bit 2 in gain is set
  2530. clr C
  2531. xch A, Temp1
  2532. subb A, Temp1 ; Apply negative correction
  2533. mov Temp1, A
  2534. ajmp t2_int_pwm_min_run
  2535. t2_int_rcp_gain_pos:
  2536. add A, Temp1 ; Apply positive correction
  2537. mov Temp1, A
  2538. jnc t2_int_pwm_min_run ; Above max?
  2539. mov A, #0FFh ; Yes - limit
  2540. mov Temp1, A
  2541. ENDIF
  2542. t2_int_pwm_min_run:
  2543. IF MODE == 1 ; Tail - limit minimum pwm
  2544. ; Limit minimum pwm
  2545. clr C
  2546. mov A, Temp1
  2547. subb A, Pwm_Motor_Idle ; Is requested pwm lower than minimum?
  2548. jnc t2_int_pwm_update ; No - branch
  2549. mov A, Pwm_Motor_Idle ; Yes - limit pwm to Pwm_Motor_Idle
  2550. mov Temp1, A
  2551. ENDIF
  2552. t2_int_pwm_update:
  2553. ; Update requested_pwm
  2554. mov Requested_Pwm, Temp1 ; Set requested pwm
  2555. IF MODE >= 1 ; Tail or multi
  2556. ; Boost pwm during direct start
  2557. mov A, Flags1
  2558. anl A, #((1 SHL STARTUP_PHASE)+(1 SHL INITIAL_RUN_PHASE))
  2559. jz t2_int_current_pwm_update
  2560. mov A, Startup_Cnt ; Add an extra power boost during start
  2561. clr C
  2562. rrc A
  2563. clr C
  2564. rrc A
  2565. add A, #6
  2566. add A, Requested_Pwm
  2567. mov Requested_Pwm, A
  2568. jnc ($+5)
  2569. mov Requested_Pwm, #0FFh
  2570. ENDIF
  2571. t2_int_current_pwm_update:
  2572. IF MODE == 0 OR MODE == 2 ; Main or multi
  2573. mov Temp1, #Pgm_Gov_Mode ; Governor mode?
  2574. cjne @Temp1, #4, t2_int_pwm_exit ; Yes - branch
  2575. ENDIF
  2576. mov Current_Pwm, Requested_Pwm ; Set equal as default
  2577. IF MODE >= 1 ; Tail or multi
  2578. ; Set current_pwm_limited
  2579. mov Temp1, Current_Pwm ; Default not limited
  2580. clr C
  2581. mov A, Current_Pwm ; Check against limit
  2582. subb A, Pwm_Limit
  2583. jc ($+4) ; If current pwm below limit - branch
  2584. mov Temp1, Pwm_Limit ; Limit pwm
  2585. IF MODE == 2 ; Multi
  2586. ; Limit pwm for low rpms
  2587. clr C
  2588. mov A, Temp1 ; Check against limit
  2589. subb A, Pwm_Limit_By_Rpm
  2590. jc ($+4) ; If current pwm below limit - branch
  2591. mov Temp1, Pwm_Limit_By_Rpm ; Limit pwm
  2592. ENDIF
  2593. mov Current_Pwm_Limited, Temp1
  2594. ; Dither
  2595. mov A, Pwm_Dither_Decoded ; Load pwm dither
  2596. jnz ($+4) ; If active - branch
  2597. ajmp t2_int_current_pwm_no_dither
  2598. clr C
  2599. mov A, Temp1
  2600. mov Temp3, Pwm_Dither_Decoded
  2601. subb A, Temp3 ; Calculate pwm minus dither value
  2602. jnc t2_int_current_pwm_full_dither; If pwm more than dither value, then do full dither
  2603. mov A, Temp1 ; Set dither level to current pwm
  2604. mov Temp3, A
  2605. clr A ; Set pwm minus dither
  2606. t2_int_current_pwm_full_dither:
  2607. mov Temp2, A ; Load pwm minus dither value
  2608. mov A, Temp3 ; Load dither
  2609. clr C
  2610. rlc A ; Shift left once
  2611. mov Temp4, A
  2612. mov A, Random ; Load random number
  2613. cpl A ; Invert to create proper DC bias in random code
  2614. anl A, Temp4 ; And with double dither value
  2615. add A, Temp2 ; Add pwm minus dither
  2616. jc t2_int_current_pwm_dither_max_excess_power ; If dither cause power above max - branch and increase excess
  2617. add A, Pwm_Dither_Excess_Power ; Add excess power from previous cycles
  2618. mov Temp1, A
  2619. mov A, Pwm_Dither_Excess_Power ; Decrement excess power
  2620. jz ($+4)
  2621. dec Pwm_Dither_Excess_Power
  2622. jc t2_int_current_pwm_dither_max_power; If dither cause power above max - branch
  2623. ajmp t2_int_current_pwm_no_dither
  2624. t2_int_current_pwm_dither_max_excess_power:
  2625. inc Temp3 ; Add one to dither in order to always reach max power
  2626. clr C
  2627. mov A, Pwm_Dither_Excess_Power
  2628. subb A, Temp3 ; Limit excess power
  2629. jnc ($+4)
  2630. inc Pwm_Dither_Excess_Power
  2631. t2_int_current_pwm_dither_max_power:
  2632. mov Temp1, #255 ; Set power to max
  2633. t2_int_current_pwm_no_dither:
  2634. mov Current_Pwm_Lim_Dith, Temp1
  2635. IF DAMPED_MODE_ENABLE == 1
  2636. ; Skip damping fet switching for high throttle
  2637. clr Flags1.SKIP_DAMP_ON
  2638. clr C
  2639. mov A, Current_Pwm_Lim_Dith
  2640. subb A, #248
  2641. jc t2_int_pwm_exit
  2642. setb Flags1.SKIP_DAMP_ON
  2643. ENDIF
  2644. ENDIF
  2645. t2_int_pwm_exit:
  2646. ; Set demag enabled if pwm is above limit
  2647. clr C
  2648. mov A, Current_Pwm_Limited
  2649. subb A, #40h ; Set if above 25%
  2650. jc ($+4)
  2651. setb Flags0.DEMAG_ENABLED
  2652. t2_int_exit:
  2653. ; Check if high byte flag is set
  2654. jb TF2H, t2h_int
  2655. pop ACC ; Restore preserved registers
  2656. pop PSW
  2657. orl EIE1, #10h ; Enable PCA0 interrupts
  2658. setb ET2 ; Enable timer2 interrupts
  2659. reti
  2660. t2h_int:
  2661. ; High byte interrupt (happens every 32ms)
  2662. clr TF2H ; Clear interrupt flag
  2663. inc Timer2_X
  2664. IF MCU_48MHZ == 1
  2665. mov A, Clock_Set_At_48MHz
  2666. jz t2h_int_start
  2667. ; Check skip variable
  2668. mov A, Skip_T2h_Int
  2669. jz t2h_int_start ; Execute this interrupt
  2670. mov Skip_T2h_Int, #0
  2671. ajmp t2h_int_exit
  2672. t2h_int_start:
  2673. mov Skip_T2h_Int, #1 ; Skip next interrupt
  2674. ENDIF
  2675. mov Temp1, #GOV_SPOOLRATE ; Load governor spool rate
  2676. ; Check RC pulse timeout counter (used here for PPM only)
  2677. mov A, Rcp_Timeout_Cntd ; RC pulse timeout count zero?
  2678. jz t2h_int_rcp_stop_check ; Yes - do not decrement
  2679. ; Decrement timeout counter (if PPM)
  2680. jnb Flags2.RCP_PPM, t2h_int_rcp_stop_check ; If flag is not set (PWM) - branch
  2681. dec Rcp_Timeout_Cntd ; No flag set (PPM) - decrement
  2682. t2h_int_rcp_stop_check:
  2683. ; Check RC pulse against stop value
  2684. clr C
  2685. mov A, New_Rcp ; Load new pulse value
  2686. subb A, #RCP_STOP ; Check if pulse is below stop value
  2687. jc t2h_int_rcp_stop
  2688. ; RC pulse higher than stop value, reset stop counter
  2689. mov Rcp_Stop_Cnt, #0 ; Reset rcp stop counter
  2690. ajmp t2h_int_rcp_gov_pwm
  2691. t2h_int_rcp_stop:
  2692. ; RC pulse less than stop value
  2693. mov Auto_Bailout_Armed, #0 ; Disarm bailout
  2694. mov Spoolup_Limit_Cnt, #0
  2695. mov A, Rcp_Stop_Cnt ; Increment stop counter
  2696. add A, #1
  2697. mov Rcp_Stop_Cnt, A
  2698. jnc t2h_int_rcp_gov_pwm ; Branch if counter has not wrapped
  2699. mov Rcp_Stop_Cnt, #0FFh ; Set stop counter to max
  2700. t2h_int_rcp_gov_pwm:
  2701. IF MODE == 0 ; Main
  2702. ; Update governor variables
  2703. mov Temp2, #Pgm_Gov_Mode ; Governor target by arm mode?
  2704. cjne @Temp2, #2, t2h_int_rcp_gov_by_setup ; No - branch
  2705. jnb Flags1.GOV_ACTIVE, t2h_int_rcp_gov_by_tx; If governor not active - branch (this ensures soft spoolup by tx)
  2706. clr C
  2707. mov A, Requested_Pwm
  2708. subb A, #50 ; Is requested pwm below 20%?
  2709. jc t2h_int_rcp_gov_by_tx ; Yes - branch (this enables a soft spooldown)
  2710. mov Requested_Pwm, Gov_Arm_Target ; Yes - load arm target
  2711. t2h_int_rcp_gov_by_setup:
  2712. mov Temp2, #Pgm_Gov_Mode ; Governor target by setup mode?
  2713. cjne @Temp2, #3, t2h_int_rcp_gov_by_tx ; No - branch
  2714. jnb Flags1.GOV_ACTIVE, t2h_int_rcp_gov_by_tx; If governor not active - branch (this ensures soft spoolup by tx)
  2715. clr C
  2716. mov A, Requested_Pwm
  2717. subb A, #50 ; Is requested pwm below 20%?
  2718. jc t2h_int_rcp_gov_by_tx ; Yes - branch (this enables a soft spooldown)
  2719. mov Temp2, #Pgm_Gov_Setup_Target ; Gov by setup - load setup target
  2720. mov Requested_Pwm, @Temp2
  2721. t2h_int_rcp_gov_by_tx:
  2722. clr C
  2723. mov A, Governor_Req_Pwm
  2724. subb A, Requested_Pwm ; Is governor requested pwm equal to requested pwm?
  2725. jz t2h_int_rcp_gov_pwm_done ; Yes - branch
  2726. jc t2h_int_rcp_gov_pwm_inc ; No - if lower, then increment
  2727. dec Governor_Req_Pwm ; No - if higher, then decrement
  2728. ajmp t2h_int_rcp_gov_pwm_done
  2729. t2h_int_rcp_gov_pwm_inc:
  2730. inc Governor_Req_Pwm ; Increment
  2731. t2h_int_rcp_gov_pwm_done:
  2732. djnz Temp1, t2h_int_rcp_gov_pwm ; If not number of steps processed - go back
  2733. inc Spoolup_Limit_Cnt ; Increment spoolup count
  2734. mov A, Spoolup_Limit_Cnt
  2735. jnz ($+4) ; Wrapped?
  2736. dec Spoolup_Limit_Cnt ; Yes - decrement
  2737. djnz Spoolup_Limit_Skip, t2h_int_exit ; Jump if skip count is not reached
  2738. mov Spoolup_Limit_Skip, #1 ; Reset skip count. Default is fast spoolup
  2739. mov Temp1, #5 ; Default fast increase
  2740. clr C
  2741. mov A, Spoolup_Limit_Cnt
  2742. subb A, Main_Spoolup_Time_3x ; No spoolup until 3*N*32ms
  2743. jc t2h_int_exit
  2744. clr C
  2745. mov A, Spoolup_Limit_Cnt
  2746. subb A, Main_Spoolup_Time_10x ; Slow spoolup until "100"*N*32ms
  2747. jnc t2h_int_rcp_limit_middle_ramp
  2748. mov Temp1, #1 ; Slow initial spoolup
  2749. mov Spoolup_Limit_Skip, #3
  2750. jmp t2h_int_rcp_set_limit
  2751. t2h_int_rcp_limit_middle_ramp:
  2752. clr C
  2753. mov A, Spoolup_Limit_Cnt
  2754. subb A, Main_Spoolup_Time_15x ; Faster spoolup until "150"*N*32ms
  2755. jnc t2h_int_rcp_set_limit
  2756. mov Temp1, #1 ; Faster middle spoolup
  2757. mov Spoolup_Limit_Skip, #1
  2758. t2h_int_rcp_set_limit:
  2759. ; Do not increment spoolup limit if higher pwm is not requested, unless governor is active
  2760. clr C
  2761. mov A, Pwm_Limit_Spoolup
  2762. subb A, Current_Pwm
  2763. jc t2h_int_rcp_inc_limit ; If Current_Pwm is larger than Pwm_Limit_Spoolup - branch
  2764. mov Temp2, #Pgm_Gov_Mode ; Governor mode?
  2765. cjne @Temp2, #4, ($+5)
  2766. ajmp t2h_int_rcp_bailout_arm ; No - branch
  2767. jb Flags1.GOV_ACTIVE, t2h_int_rcp_inc_limit ; If governor active - branch
  2768. mov Pwm_Limit_Spoolup, Current_Pwm ; Set limit to what current pwm is
  2769. mov A, Spoolup_Limit_Cnt ; Check if spoolup limit count is 255. If it is, then this is a "bailout" ramp
  2770. inc A
  2771. jz ($+5)
  2772. mov Spoolup_Limit_Cnt, Main_Spoolup_Time_3x ; Stay in an early part of the spoolup sequence (unless "bailout" ramp)
  2773. mov Spoolup_Limit_Skip, #1 ; Set skip count
  2774. mov Governor_Req_Pwm, #60 ; Set governor requested speed to ensure that it requests higher speed
  2775. ; 20=Fail on jerk when governor activates
  2776. ; 30=Ok
  2777. ; 100=Fail on small governor settling overshoot on low headspeeds
  2778. ; 200=Fail on governor settling overshoot
  2779. jmp t2h_int_exit ; Exit
  2780. t2h_int_rcp_inc_limit:
  2781. mov A, Pwm_Limit_Spoolup ; Increment spoolup pwm
  2782. add A, Temp1
  2783. jnc t2h_int_rcp_no_limit ; If below 255 - branch
  2784. mov Pwm_Limit_Spoolup, #0FFh
  2785. ajmp t2h_int_rcp_bailout_arm
  2786. t2h_int_rcp_no_limit:
  2787. mov Pwm_Limit_Spoolup, A
  2788. t2h_int_rcp_bailout_arm:
  2789. mov A, Pwm_Limit_Spoolup
  2790. inc A
  2791. jnz t2h_int_exit
  2792. mov Auto_Bailout_Armed, #255 ; Arm bailout
  2793. mov Spoolup_Limit_Cnt, #255
  2794. ENDIF
  2795. t2h_int_exit:
  2796. pop ACC ; Restore preserved registers
  2797. pop PSW
  2798. orl EIE1, #10h ; Enable PCA0 interrupts
  2799. setb ET2 ; Enable timer2 interrupts
  2800. reti
  2801. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  2802. ;
  2803. ; Timer3 interrupt routine
  2804. ;
  2805. ; No assumptions
  2806. ;
  2807. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  2808. t3_int: ; Used for commutation timing
  2809. clr EA ; Disable all interrupts
  2810. push PSW ; Preserve registers through interrupt
  2811. anl EIE1, #7Fh ; Disable timer3 interrupts
  2812. clr Flags0.T3_PENDING ; Flag that timer has wrapped
  2813. ; Set up next wait
  2814. mov TMR3CN, #00h ; Timer3 disabled and interrupt flag cleared
  2815. mov TMR3L, Next_Wt_Start_L ; Set wait value
  2816. mov TMR3H, Next_Wt_Start_H
  2817. mov TMR3CN, #04h ; Timer3 enabled and interrupt flag cleared
  2818. pop PSW
  2819. setb EA ; Enable all interrupts
  2820. reti
  2821. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  2822. ;
  2823. ; PCA interrupt routine
  2824. ;
  2825. ; No assumptions
  2826. ;
  2827. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  2828. pca_int: ; Used for RC pulse timing
  2829. clr EA
  2830. anl EIE1, #0EFh ; Disable PCA0 interrupts
  2831. clr ET2 ; Disable timer2 interrupts
  2832. push PSW ; Preserve registers through interrupt
  2833. push ACC
  2834. push B
  2835. setb PSW.3 ; Select register bank 1 for interrupt routines
  2836. setb EA
  2837. ; Get the PCA counter values
  2838. Get_Rcp_Capture_Values
  2839. ; Clear interrupt flag
  2840. Rcp_Clear_Int_Flag
  2841. ; Check which edge it is
  2842. jnb Flags2.RCP_EDGE_NO, ($+5) ; Is it a first edge trig?
  2843. ajmp pca_int_second_meas_pwm_freq ; No - branch to second
  2844. Rcp_Int_Second ; Yes - set second edge trig
  2845. setb Flags2.RCP_EDGE_NO ; Set second edge flag
  2846. ; Read RC signal level
  2847. Read_Rcp_Int
  2848. ; Test RC signal level
  2849. jb ACC.Rcp_In, ($+5) ; Is it high?
  2850. ajmp pca_int_fail_minimum ; No - jump to fail minimum
  2851. ; RC pulse was high, store RC pulse start timestamp
  2852. mov Rcp_Prev_Edge_L, Temp1
  2853. mov Rcp_Prev_Edge_H, Temp2
  2854. ajmp pca_int_exit ; Exit
  2855. pca_int_fail_minimum:
  2856. ; Prepare for next interrupt
  2857. Rcp_Int_First ; Set interrupt trig to first again
  2858. Rcp_Clear_Int_Flag ; Clear interrupt flag
  2859. clr Flags2.RCP_EDGE_NO ; Set first edge flag
  2860. jnb Flags2.RCP_PPM, ($+5) ; If flag is not set (PWM) - branch
  2861. ajmp pca_int_set_timeout ; If PPM - ignore trig as noise
  2862. mov Temp1, #RCP_MIN ; Set RC pulse value to minimum
  2863. Read_Rcp_Int ; Test RC signal level again
  2864. jnb ACC.Rcp_In, ($+5) ; Is it high?
  2865. ajmp pca_int_set_timeout ; Yes - set new timeout and exit
  2866. mov New_Rcp, Temp1 ; Store new pulse length
  2867. ajmp pca_int_limited ; Set new RC pulse, new timeout and exit
  2868. pca_int_second_meas_pwm_freq:
  2869. ; Prepare for next interrupt
  2870. Rcp_Int_First ; Set first edge trig
  2871. clr Flags2.RCP_EDGE_NO ; Set first edge flag
  2872. ; Check if pwm frequency shall be measured
  2873. jb Flags0.RCP_MEAS_PWM_FREQ, ($+5) ; Is measure RCP pwm frequency flag set?
  2874. ajmp pca_int_fall ; No - skip measurements
  2875. ; Set second edge trig only during pwm frequency measurement
  2876. Rcp_Int_Second ; Set second edge trig
  2877. Rcp_Clear_Int_Flag ; Clear interrupt flag
  2878. setb Flags2.RCP_EDGE_NO ; Set second edge flag
  2879. ; Store edge data to RAM
  2880. mov Rcp_Edge_L, Temp1
  2881. mov Rcp_Edge_H, Temp2
  2882. ; Calculate pwm frequency
  2883. clr C
  2884. mov A, Temp1
  2885. subb A, Rcp_PrePrev_Edge_L
  2886. mov Temp1, A
  2887. mov A, Temp2
  2888. subb A, Rcp_PrePrev_Edge_H
  2889. mov Temp2, A
  2890. mov Temp4, #0
  2891. mov Temp7, #8 ; Set default period tolerance requirement (MSB)
  2892. mov Temp3, #0 ; (LSB)
  2893. ; Check if pulse is too short
  2894. clr C
  2895. mov A, Temp1
  2896. subb A, #low(140) ; If pulse below 70us, not accepted
  2897. mov A, Temp2
  2898. subb A, #high(140)
  2899. jnc pca_int_check_12kHz
  2900. mov Rcp_Period_Diff_Accepted, #0 ; Set not accepted
  2901. ajmp pca_int_store_data
  2902. pca_int_check_12kHz:
  2903. mov Bit_Access_Int, Temp1
  2904. mov Temp1, #Pgm_Enable_PWM_Input ; Check if PWM input is enabled
  2905. mov A, @Temp1
  2906. mov Temp1, Bit_Access_Int
  2907. jz pca_int_restore_edge ; If it is not - branch
  2908. ; Check if pwm frequency is 12kHz
  2909. clr C
  2910. mov A, Temp1
  2911. subb A, #low(200) ; If below 100us, 12kHz pwm is assumed
  2912. mov A, Temp2
  2913. subb A, #high(200)
  2914. jnc pca_int_check_8kHz
  2915. clr A
  2916. setb ACC.RCP_PWM_FREQ_12KHZ
  2917. mov Temp4, A
  2918. mov Temp3, #10 ; Set period tolerance requirement (LSB)
  2919. ajmp pca_int_restore_edge_set_msb
  2920. pca_int_check_8kHz:
  2921. ; Check if pwm frequency is 8kHz
  2922. clr C
  2923. mov A, Temp1
  2924. subb A, #low(360) ; If below 180us, 8kHz pwm is assumed
  2925. mov A, Temp2
  2926. subb A, #high(360)
  2927. jnc pca_int_check_4kHz
  2928. clr A
  2929. setb ACC.RCP_PWM_FREQ_8KHZ
  2930. mov Temp4, A
  2931. mov Temp3, #15 ; Set period tolerance requirement (LSB)
  2932. ajmp pca_int_restore_edge_set_msb
  2933. pca_int_check_4kHz:
  2934. ; Check if pwm frequency is 4kHz
  2935. clr C
  2936. mov A, Temp1
  2937. subb A, #low(720) ; If below 360us, 4kHz pwm is assumed
  2938. mov A, Temp2
  2939. subb A, #high(720)
  2940. jnc pca_int_check_2kHz
  2941. clr A
  2942. setb ACC.RCP_PWM_FREQ_4KHZ
  2943. mov Temp4, A
  2944. mov Temp3, #30 ; Set period tolerance requirement (LSB)
  2945. ajmp pca_int_restore_edge_set_msb
  2946. pca_int_check_2kHz:
  2947. ; Check if pwm frequency is 2kHz
  2948. clr C
  2949. mov A, Temp1
  2950. subb A, #low(1440) ; If below 720us, 2kHz pwm is assumed
  2951. mov A, Temp2
  2952. subb A, #high(1440)
  2953. jnc pca_int_check_1kHz
  2954. clr A
  2955. setb ACC.RCP_PWM_FREQ_2KHZ
  2956. mov Temp4, A
  2957. mov Temp3, #60 ; Set period tolerance requirement (LSB)
  2958. ajmp pca_int_restore_edge_set_msb
  2959. pca_int_check_1kHz:
  2960. ; Check if pwm frequency is 1kHz
  2961. clr C
  2962. mov A, Temp1
  2963. subb A, #low(2200) ; If below 1100us, 1kHz pwm is assumed
  2964. mov A, Temp2
  2965. subb A, #high(2200)
  2966. jnc pca_int_restore_edge
  2967. clr A
  2968. setb ACC.RCP_PWM_FREQ_1KHZ
  2969. mov Temp4, A
  2970. mov Temp3, #120 ; Set period tolerance requirement (LSB)
  2971. pca_int_restore_edge_set_msb:
  2972. mov Temp7, #0 ; Set period tolerance requirement (MSB)
  2973. pca_int_restore_edge:
  2974. ; Calculate difference between this period and previous period
  2975. clr C
  2976. mov A, Temp1
  2977. subb A, Rcp_Prev_Period_L
  2978. mov Temp5, A
  2979. mov A, Temp2
  2980. subb A, Rcp_Prev_Period_H
  2981. mov Temp6, A
  2982. ; Make positive
  2983. jnb ACC.7, pca_int_check_diff
  2984. mov A, Temp5
  2985. cpl A
  2986. add A, #1
  2987. mov Temp5, A
  2988. mov A, Temp6
  2989. cpl A
  2990. addc A, #0
  2991. mov Temp6, A
  2992. pca_int_check_diff:
  2993. ; Check difference
  2994. mov Rcp_Period_Diff_Accepted, #0 ; Set not accepted as default
  2995. clr C
  2996. mov A, Temp5
  2997. subb A, Temp3 ; Check difference
  2998. mov A, Temp6
  2999. subb A, Temp7
  3000. jnc pca_int_store_data
  3001. mov Rcp_Period_Diff_Accepted, #1 ; Set accepted
  3002. pca_int_store_data:
  3003. ; Store previous period
  3004. mov Rcp_Prev_Period_L, Temp1
  3005. mov Rcp_Prev_Period_H, Temp2
  3006. ; Store pre previous edge
  3007. mov Rcp_PrePrev_Edge_L, Rcp_Edge_L
  3008. mov Rcp_PrePrev_Edge_H, Rcp_Edge_H
  3009. mov Temp1, #RCP_VALIDATE
  3010. ajmp pca_int_limited
  3011. pca_int_fall:
  3012. ; RC pulse edge was second, calculate new pulse length
  3013. clr C
  3014. mov A, Temp1
  3015. subb A, Rcp_Prev_Edge_L
  3016. mov Temp1, A
  3017. mov A, Temp2
  3018. subb A, Rcp_Prev_Edge_H
  3019. mov Temp2, A
  3020. jnb Flags3.RCP_PWM_FREQ_12KHZ, ($+5) ; Is RC input pwm frequency 12kHz?
  3021. ajmp pca_int_pwm_divide_done ; Yes - branch forward
  3022. jnb Flags3.RCP_PWM_FREQ_8KHZ, ($+5) ; Is RC input pwm frequency 8kHz?
  3023. ajmp pca_int_pwm_divide_done ; Yes - branch forward
  3024. jnb Flags3.RCP_PWM_FREQ_4KHZ, ($+5) ; Is RC input pwm frequency 4kHz?
  3025. ajmp pca_int_pwm_divide ; Yes - branch forward
  3026. jb Flags2.RCP_PPM_ONESHOT125, ($+5)
  3027. ajmp pca_int_fall_not_oneshot
  3028. mov A, Temp2 ; Oneshot125 - move to I_Temp5/6
  3029. mov Temp6, A
  3030. mov A, Temp1
  3031. mov Temp5, A
  3032. ajmp pca_int_fall_check_range
  3033. pca_int_fall_not_oneshot:
  3034. mov A, Temp2 ; No - 2kHz. Divide by 2
  3035. clr C
  3036. rrc A
  3037. mov Temp2, A
  3038. mov A, Temp1
  3039. rrc A
  3040. mov Temp1, A
  3041. jnb Flags3.RCP_PWM_FREQ_2KHZ, ($+5) ; Is RC input pwm frequency 2kHz?
  3042. ajmp pca_int_pwm_divide ; Yes - branch forward
  3043. mov A, Temp2 ; No - 1kHz. Divide by 2 again
  3044. clr C
  3045. rrc A
  3046. mov Temp2, A
  3047. mov A, Temp1
  3048. rrc A
  3049. mov Temp1, A
  3050. jnb Flags3.RCP_PWM_FREQ_1KHZ, ($+5) ; Is RC input pwm frequency 1kHz?
  3051. ajmp pca_int_pwm_divide ; Yes - branch forward
  3052. mov A, Temp2 ; No - PPM. Divide by 2 (to bring range to 256) and move to Temp5/6
  3053. clr C
  3054. rrc A
  3055. mov Temp6, A
  3056. mov A, Temp1
  3057. rrc A
  3058. mov Temp5, A
  3059. pca_int_fall_check_range:
  3060. ; Skip range limitation if pwm frequency measurement
  3061. jb Flags0.RCP_MEAS_PWM_FREQ, pca_int_ppm_check_full_range
  3062. ; Check if 2160us or above (in order to ignore false pulses)
  3063. clr C
  3064. mov A, Temp5 ; Is pulse 2160us or higher?
  3065. subb A, #28
  3066. mov A, Temp6
  3067. subb A, #2
  3068. jc ($+4) ; No - proceed
  3069. ajmp pca_int_ppm_outside_range ; Yes - ignore pulse
  3070. pca_int_ppm_below_full_range:
  3071. ; Check if below 800us (in order to ignore false pulses)
  3072. mov A, Temp6
  3073. jnz pca_int_ppm_check_full_range
  3074. clr C
  3075. mov A, Temp5 ; Is pulse below 800us?
  3076. subb A, #200
  3077. jnc pca_int_ppm_check_full_range ; No - proceed
  3078. pca_int_ppm_outside_range:
  3079. inc Rcp_Outside_Range_Cnt
  3080. mov A, Rcp_Outside_Range_Cnt
  3081. jnz ($+4)
  3082. dec Rcp_Outside_Range_Cnt
  3083. clr C
  3084. mov A, Rcp_Outside_Range_Cnt
  3085. subb A, #10 ; Allow a given number of outside pulses
  3086. jnc ($+4)
  3087. ajmp pca_int_set_timeout ; If below limit - ignore pulse
  3088. mov New_Rcp, #0 ; Set pulse length to zero
  3089. setb Flags2.RCP_UPDATED ; Set updated flag
  3090. ajmp pca_int_set_timeout
  3091. pca_int_ppm_check_full_range:
  3092. ; Decrement outside range counter
  3093. mov A, Rcp_Outside_Range_Cnt
  3094. jz ($+4)
  3095. dec Rcp_Outside_Range_Cnt
  3096. ; Calculate "1000us" plus throttle minimum
  3097. IF MODE >= 1 ; Tail or multi
  3098. mov Temp1, #Pgm_Direction ; Check if bidirectional operation (store in Temp2)
  3099. mov A, @Temp1
  3100. mov Temp2, A
  3101. ENDIF
  3102. mov A, #0 ; Set 1000us as default minimum
  3103. jb Flags3.FULL_THROTTLE_RANGE, pca_int_ppm_calculate ; Check if full range is chosen
  3104. mov Temp1, #Pgm_Ppm_Min_Throttle ; Min throttle value is in 4us units
  3105. IF MODE >= 1 ; Tail or multi
  3106. cjne Temp2, #3, ($+5)
  3107. mov Temp1, #Pgm_Ppm_Center_Throttle ; Center throttle value is in 4us units
  3108. ENDIF
  3109. mov A, @Temp1
  3110. pca_int_ppm_calculate:
  3111. add A, #250 ; Add 1000us to minimum
  3112. mov Temp7, A
  3113. clr A
  3114. addc A, #0
  3115. mov Temp8, A
  3116. clr C
  3117. mov A, Temp5 ; Subtract minimum
  3118. subb A, Temp7
  3119. mov Temp5, A
  3120. mov A, Temp6
  3121. subb A, Temp8
  3122. mov Temp6, A
  3123. IF MODE >= 1 ; Tail or multi
  3124. mov Bit_Access_Int.0, C
  3125. cjne Temp2, #3, pca_int_ppm_bidir_dir_set; If not bidirectional operation - branch
  3126. mov C, Bit_Access_Int.0
  3127. jnc pca_int_ppm_bidir_fwd ; If result is positive - branch
  3128. pca_int_ppm_bidir_rev:
  3129. jb Flags2.RCP_DIR_REV, pca_int_ppm_bidir_dir_set ; If same direction - branch
  3130. setb Flags2.RCP_DIR_REV
  3131. ajmp pca_int_ppm_bidir_dir_set
  3132. pca_int_ppm_bidir_fwd:
  3133. jnb Flags2.RCP_DIR_REV, pca_int_ppm_bidir_dir_set ; If same direction - branch
  3134. clr Flags2.RCP_DIR_REV
  3135. pca_int_ppm_bidir_dir_set:
  3136. mov C, Bit_Access_Int.0
  3137. ENDIF
  3138. jnc pca_int_ppm_neg_checked ; If result is positive - branch
  3139. IF MODE >= 1 ; Tail or multi
  3140. cjne Temp2, #3, pca_int_ppm_unidir_neg ; If not bidirectional operation - branch
  3141. mov A, Temp5 ; Change sign
  3142. cpl A
  3143. add A, #1
  3144. mov Temp5, A
  3145. mov A, Temp6
  3146. cpl A
  3147. addc A, #0
  3148. mov Temp6, A
  3149. jmp pca_int_ppm_neg_checked
  3150. pca_int_ppm_unidir_neg:
  3151. ENDIF
  3152. mov Temp1, #RCP_MIN ; Yes - set to minimum
  3153. mov Temp2, #0
  3154. ajmp pca_int_pwm_divide_done
  3155. pca_int_ppm_neg_checked:
  3156. IF MODE >= 1 ; Tail or multi
  3157. cjne Temp2, #3, pca_int_ppm_bidir_done ; If not bidirectional operation - branch
  3158. mov A, Temp5 ; Multiply value by 2
  3159. rlc A
  3160. mov Temp5 A
  3161. mov A, Temp6
  3162. rlc A
  3163. mov Temp6 A
  3164. clr C ; Subtract deadband
  3165. mov A, Temp5
  3166. subb A, #10
  3167. mov Temp5, A
  3168. mov A, Temp6
  3169. subb A, #0
  3170. mov Temp6, A
  3171. jnc pca_int_ppm_bidir_done
  3172. mov Temp5, #RCP_MIN
  3173. mov Temp6, #0
  3174. pca_int_ppm_bidir_done:
  3175. ENDIF
  3176. clr C ; Check that RC pulse is within legal range (max 255)
  3177. mov A, Temp5
  3178. subb A, #RCP_MAX
  3179. mov A, Temp6
  3180. subb A, #0
  3181. jc pca_int_ppm_max_checked
  3182. mov Temp1, #RCP_MAX
  3183. mov Temp2, #0
  3184. ajmp pca_int_pwm_divide_done
  3185. pca_int_ppm_max_checked:
  3186. mov A, Temp5 ; Multiply throttle value by gain
  3187. mov B, Ppm_Throttle_Gain
  3188. mul AB
  3189. xch A, B
  3190. mov C, B.7 ; Multiply result by 2 (unity gain is 128)
  3191. rlc A
  3192. mov Temp1, A ; Transfer to Temp1/2
  3193. mov Temp2, #0
  3194. jc pca_int_ppm_limit_after_mult
  3195. jmp pca_int_limited
  3196. pca_int_ppm_limit_after_mult:
  3197. mov Temp1, #RCP_MAX
  3198. mov Temp2, #0
  3199. jmp pca_int_limited
  3200. pca_int_pwm_divide:
  3201. mov A, Temp2 ; Divide by 2
  3202. clr C
  3203. rrc A
  3204. mov Temp2, A
  3205. mov A, Temp1
  3206. rrc A
  3207. mov Temp1, A
  3208. pca_int_pwm_divide_done:
  3209. jnb Flags3.RCP_PWM_FREQ_12KHZ, pca_int_check_legal_range ; Is RC input pwm frequency 12kHz?
  3210. mov A, Temp2 ; Yes - check that value is not more than 255
  3211. jz ($+4)
  3212. mov Temp1, #RCP_MAX
  3213. clr C
  3214. mov A, Temp1 ; Multiply by 1.5
  3215. rrc A
  3216. addc A, Temp1
  3217. mov Temp1, A
  3218. clr A
  3219. addc A, #0
  3220. mov Temp2, A
  3221. pca_int_check_legal_range:
  3222. ; Check that RC pulse is within legal range
  3223. clr C
  3224. mov A, Temp1
  3225. subb A, #RCP_MAX
  3226. mov A, Temp2
  3227. subb A, #0
  3228. jc pca_int_limited
  3229. mov Temp1, #RCP_MAX
  3230. pca_int_limited:
  3231. ; RC pulse value accepted
  3232. mov New_Rcp, Temp1 ; Store new pulse length
  3233. setb Flags2.RCP_UPDATED ; Set updated flag
  3234. jb Flags0.RCP_MEAS_PWM_FREQ, ($+5) ; Is measure RCP pwm frequency flag set?
  3235. ajmp pca_int_set_timeout ; No - skip measurements
  3236. mov A, #((1 SHL RCP_PWM_FREQ_1KHZ)+(1 SHL RCP_PWM_FREQ_2KHZ)+(1 SHL RCP_PWM_FREQ_4KHZ)+(1 SHL RCP_PWM_FREQ_8KHZ)+(1 SHL RCP_PWM_FREQ_12KHZ))
  3237. cpl A
  3238. anl A, Flags3 ; Clear all pwm frequency flags
  3239. orl A, Temp4 ; Store pwm frequency value in flags
  3240. mov Flags3, A
  3241. clr Flags2.RCP_PPM ; Default, flag is not set (PWM)
  3242. mov A, Temp4 ; Check if all flags are cleared
  3243. jnz pca_int_set_timeout
  3244. setb Flags2.RCP_PPM ; Set flag (PPM)
  3245. pca_int_set_timeout:
  3246. mov Rcp_Timeout_Cntd, #RCP_TIMEOUT ; Set timeout count to start value
  3247. jnb Flags2.RCP_PPM, pca_int_ppm_timeout_set ; If flag is not set (PWM) - branch
  3248. mov Rcp_Timeout_Cntd, #RCP_TIMEOUT_PPM ; No flag set means PPM. Set timeout count
  3249. pca_int_ppm_timeout_set:
  3250. jnb Flags0.RCP_MEAS_PWM_FREQ, ($+5) ; Is measure RCP pwm frequency flag set?
  3251. ajmp pca_int_exit ; Yes - exit
  3252. jb Flags2.RCP_PPM, pca_int_exit ; If flag is set (PPM) - branch
  3253. Rcp_Int_Disable ; Disable RC pulse interrupt
  3254. pca_int_exit: ; Exit interrupt routine
  3255. jb Flags2.RCP_PPM, ($+6) ; If flag is set (PPP) - branch
  3256. mov Rcp_Skip_Cntd, #RCP_SKIP_RATE ; Load number of skips
  3257. pop B ; Restore preserved registers
  3258. pop ACC
  3259. pop PSW
  3260. setb ET2 ; Enable timer2 interrupts
  3261. orl EIE1, #10h ; Enable PCA0 interrupts
  3262. reti
  3263. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  3264. ;
  3265. ; Wait xms ~(x*4*250) (Different entry points)
  3266. ;
  3267. ; No assumptions
  3268. ;
  3269. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  3270. wait1ms:
  3271. mov Temp2, #1
  3272. jmp waitxms_o
  3273. wait3ms:
  3274. mov Temp2, #3
  3275. jmp waitxms_o
  3276. wait10ms:
  3277. mov Temp2, #10
  3278. jmp waitxms_o
  3279. wait30ms:
  3280. mov Temp2, #30
  3281. jmp waitxms_o
  3282. wait100ms:
  3283. mov Temp2, #100
  3284. jmp waitxms_o
  3285. wait200ms:
  3286. mov Temp2, #200
  3287. jmp waitxms_o
  3288. waitxms_o: ; Outer loop
  3289. mov Temp1, #23
  3290. waitxms_m: ; Middle loop
  3291. clr A
  3292. djnz ACC, $ ; Inner loop (42.7us - 1024 cycles)
  3293. djnz Temp1, waitxms_m
  3294. djnz Temp2, waitxms_o
  3295. ret
  3296. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  3297. ;
  3298. ; Beeper routines (4 different entry points)
  3299. ;
  3300. ; No assumptions
  3301. ;
  3302. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  3303. beep_f1: ; Entry point 1, load beeper frequency 1 settings
  3304. mov Temp3, #20 ; Off wait loop length
  3305. mov Temp4, #120 ; Number of beep pulses
  3306. jmp beep
  3307. beep_f2: ; Entry point 2, load beeper frequency 2 settings
  3308. mov Temp3, #16
  3309. mov Temp4, #140
  3310. jmp beep
  3311. beep_f3: ; Entry point 3, load beeper frequency 3 settings
  3312. mov Temp3, #13
  3313. mov Temp4, #180
  3314. jmp beep
  3315. beep_f4: ; Entry point 4, load beeper frequency 4 settings
  3316. mov Temp3, #11
  3317. mov Temp4, #200
  3318. jmp beep
  3319. beep: ; Beep loop start
  3320. mov Temp2, #2 ; Must be an even number (or direction will change)
  3321. beep_onoff:
  3322. cpl Flags3.PGM_DIR_REV ; Toggle between using A fet and C fet
  3323. clr A
  3324. BpFET_off ; BpFET off
  3325. djnz ACC, $ ; Allow some time after pfet is turned off
  3326. BnFET_on ; BnFET on (in order to charge the driver of the BpFET)
  3327. djnz ACC, $ ; Let the nfet be turned on a while
  3328. BnFET_off ; BnFET off again
  3329. djnz ACC, $ ; Allow some time after nfet is turned off
  3330. BpFET_on ; BpFET on
  3331. djnz ACC, $ ; Allow some time after pfet is turned on
  3332. ; Turn on nfet
  3333. AnFET_on ; AnFET on
  3334. mov A, Beep_Strength
  3335. djnz ACC, $
  3336. ; Turn off nfet
  3337. AnFET_off ; AnFET off
  3338. mov A, #150 ; 25�s off
  3339. djnz ACC, $
  3340. djnz Temp2, beep_onoff
  3341. ; Copy variable
  3342. mov A, Temp3
  3343. mov Temp1, A
  3344. beep_off: ; Fets off loop
  3345. djnz ACC, $
  3346. djnz Temp1, beep_off
  3347. djnz Temp4, beep
  3348. BpFET_off ; BpFET off
  3349. ret
  3350. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  3351. ;
  3352. ; Division 16bit unsigned by 16bit unsigned
  3353. ;
  3354. ; Dividend shall be in Temp2/Temp1, divisor in Temp4/Temp3
  3355. ; Result will be in Temp2/Temp1
  3356. ;
  3357. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  3358. div_u16_by_u16:
  3359. clr C
  3360. mov Temp5, #0
  3361. mov Temp6, #0
  3362. mov B, #0
  3363. div_u16_by_u16_div1:
  3364. inc B ; Increment counter for each left shift
  3365. mov A, Temp3 ; Shift left the divisor
  3366. rlc A
  3367. mov Temp3, A
  3368. mov A, Temp4
  3369. rlc A
  3370. mov Temp4, A
  3371. jnc div_u16_by_u16_div1 ; Repeat until carry flag is set from high-byte
  3372. div_u16_by_u16_div2:
  3373. mov A, Temp4 ; Shift right the divisor
  3374. rrc A
  3375. mov Temp4, A
  3376. mov A, Temp3
  3377. rrc A
  3378. mov Temp3, A
  3379. clr C
  3380. mov A, Temp2 ; Make a safe copy of the dividend
  3381. mov Temp8, A
  3382. mov A, Temp1
  3383. mov Temp7, A
  3384. mov A, Temp1 ; Move low-byte of dividend into accumulator
  3385. subb A, Temp3 ; Dividend - shifted divisor = result bit (no factor, only 0 or 1)
  3386. mov Temp1, A ; Save updated dividend
  3387. mov A, Temp2 ; Move high-byte of dividend into accumulator
  3388. subb A, Temp4 ; Subtract high-byte of divisor (all together 16-bit substraction)
  3389. mov Temp2, A ; Save updated high-byte back in high-byte of divisor
  3390. jnc div_u16_by_u16_div3 ; If carry flag is NOT set, result is 1
  3391. mov A, Temp8 ; Otherwise result is 0, save copy of divisor to undo subtraction
  3392. mov Temp2, A
  3393. mov A, Temp7
  3394. mov Temp1, A
  3395. div_u16_by_u16_div3:
  3396. cpl C ; Invert carry, so it can be directly copied into result
  3397. mov A, Temp5
  3398. rlc A ; Shift carry flag into temporary result
  3399. mov Temp5, A
  3400. mov A, Temp6
  3401. rlc A
  3402. mov Temp6,A
  3403. djnz B, div_u16_by_u16_div2 ;Now count backwards and repeat until "B" is zero
  3404. mov A, Temp6 ; Move result to Temp2/Temp1
  3405. mov Temp2, A
  3406. mov A, Temp5
  3407. mov Temp1, A
  3408. ret
  3409. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  3410. ;
  3411. ; Multiplication 16bit signed by 8bit unsigned
  3412. ;
  3413. ; Multiplicand shall be in Temp2/Temp1, multiplicator in Temp3
  3414. ; Result will be in Temp2/Temp1. Result will divided by 16
  3415. ;
  3416. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  3417. mult_s16_by_u8_div_16:
  3418. mov A, Temp1 ; Read input to math registers
  3419. mov B, Temp2
  3420. mov Bit_Access, Temp3
  3421. setb PSW.4 ; Select register bank 2 for math routines
  3422. mov Temp1, A ; Store in math registers
  3423. mov Temp2, B
  3424. mov Temp4, #0 ; Set sign in Temp4 and test sign
  3425. jnb B.7, mult_s16_by_u8_positive
  3426. mov Temp4, #0FFh
  3427. cpl A
  3428. add A, #1
  3429. mov Temp1, A
  3430. mov A, Temp2
  3431. cpl A
  3432. addc A, #0
  3433. mov Temp2, A
  3434. mult_s16_by_u8_positive:
  3435. mov A, Temp1 ; Multiply LSB with multiplicator
  3436. mov B, Bit_Access
  3437. mul AB
  3438. mov Temp6, B ; Place MSB in Temp6
  3439. mov Temp1, A ; Place LSB in Temp1 (result)
  3440. mov A, Temp2 ; Multiply MSB with multiplicator
  3441. mov B, Bit_Access
  3442. mul AB
  3443. mov Temp8, B ; Place in Temp8/7
  3444. mov Temp7, A
  3445. mov A, Temp6 ; Add up
  3446. add A, Temp7
  3447. mov Temp2, A
  3448. mov A, #0
  3449. addc A, Temp8
  3450. mov Temp3, A
  3451. mov Temp5, #4 ; Set number of divisions
  3452. mult_s16_by_u8_div_loop:
  3453. clr C ; Rotate right
  3454. mov A, Temp3
  3455. rrc A
  3456. mov Temp3, A
  3457. mov A, Temp2
  3458. rrc A
  3459. mov Temp2, A
  3460. mov A, Temp1
  3461. rrc A
  3462. mov Temp1, A
  3463. djnz Temp5, mult_s16_by_u8_div_loop
  3464. mov B, Temp4 ; Test sign
  3465. jnb B.7, mult_s16_by_u8_exit
  3466. mov A, Temp1
  3467. cpl A
  3468. add A, #1
  3469. mov Temp1, A
  3470. mov A, Temp2
  3471. cpl A
  3472. addc A, #0
  3473. mov Temp2, A
  3474. mult_s16_by_u8_exit:
  3475. mov A, Temp1 ; Store output
  3476. mov B, Temp2
  3477. clr PSW.4 ; Select normal register bank
  3478. mov Temp1, A
  3479. mov Temp2, B
  3480. ret
  3481. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  3482. ;
  3483. ; Calculate governor routines
  3484. ;
  3485. ; No assumptions
  3486. ;
  3487. ; Governs headspeed based upon the Comm_Period4x variable and pwm
  3488. ; The governor task is split into several routines in order to distribute processing time
  3489. ;
  3490. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  3491. ; First governor routine - calculate governor target
  3492. IF MODE == 0 ; Main
  3493. calc_governor_target:
  3494. mov Temp1, #Pgm_Gov_Mode ; Governor mode?
  3495. cjne @Temp1, #4, governor_speed_check ; Yes
  3496. jmp calc_governor_target_exit ; No
  3497. governor_speed_check:
  3498. ; Stop governor for stop RC pulse
  3499. clr C
  3500. mov A, New_Rcp ; Check RC pulse against stop value
  3501. subb A, #(RCP_MAX/10) ; Is pulse below stop value?
  3502. jc governor_deactivate ; Yes - deactivate
  3503. mov A, Flags1
  3504. anl A, #((1 SHL STARTUP_PHASE)+(1 SHL INITIAL_RUN_PHASE))
  3505. jnz governor_deactivate ; Deactivate if any startup phase set
  3506. ; Skip speed check if governor is already active
  3507. jb Flags1.GOV_ACTIVE, governor_target_calc
  3508. ; Check speed (do not run governor for low speeds)
  3509. mov Temp1, #05h ; Default high range activation limit value (~62500 eRPM)
  3510. mov Temp2, #Pgm_Gov_Range
  3511. mov A, @Temp2 ; Check if high range (Temp2 has #Pgm_Gov_Range)
  3512. dec A
  3513. jz governor_act_lim_set ; If high range - branch
  3514. mov Temp1, #0Ah ; Middle range activation limit value (~31250 eRPM)
  3515. dec A
  3516. jz governor_act_lim_set ; If middle range - branch
  3517. mov Temp1, #12h ; Low range activation limit value (~17400 eRPM)
  3518. governor_act_lim_set:
  3519. clr C
  3520. mov A, Comm_Period4x_H
  3521. subb A, Temp1
  3522. jc governor_activate ; If speed above min limit - run governor
  3523. governor_deactivate:
  3524. jnb Flags1.GOV_ACTIVE, governor_first_deactivate_done; This code is executed continuously. Only execute the code below the first time
  3525. mov Pwm_Limit_Spoolup, Pwm_Spoolup_Beg
  3526. mov Spoolup_Limit_Cnt, #255
  3527. mov Spoolup_Limit_Skip, #1
  3528. governor_first_deactivate_done:
  3529. mov Current_Pwm, Requested_Pwm ; Set current pwm to requested
  3530. clr A
  3531. mov Gov_Target_L, A ; Set target to zero
  3532. mov Gov_Target_H, A
  3533. mov Gov_Integral_L, A ; Set integral to zero
  3534. mov Gov_Integral_H, A
  3535. mov Gov_Integral_X, A
  3536. clr Flags1.GOV_ACTIVE
  3537. jmp calc_governor_target_exit
  3538. governor_activate:
  3539. setb Flags1.GOV_ACTIVE
  3540. governor_target_calc:
  3541. ; Governor calculations
  3542. mov Temp2, #Pgm_Gov_Range
  3543. mov A, @Temp2 ; Check high, middle or low range
  3544. dec A
  3545. jnz calc_governor_target_middle
  3546. mov A, Governor_Req_Pwm ; Load governor requested pwm
  3547. cpl A ; Calculate 255-pwm (invert pwm)
  3548. ; Calculate comm period target (1 + 2*((255-Requested_Pwm)/256) - 0.25)
  3549. rlc A ; Msb to carry
  3550. rlc A ; To bit0
  3551. mov Temp2, A ; Now 1 lsb is valid for H
  3552. rrc A
  3553. mov Temp1, A ; Now 7 msbs are valid for L
  3554. mov A, Temp2
  3555. anl A, #01h ; Calculate H byte
  3556. inc A ; Add 1
  3557. mov Temp2, A
  3558. mov A, Temp1
  3559. anl A, #0FEh ; Calculate L byte
  3560. jmp calc_governor_subtract_025
  3561. calc_governor_target_middle:
  3562. mov A, @Temp2 ; Check middle or low range (Temp2 has #Pgm_Gov_Range)
  3563. dec A
  3564. dec A
  3565. jnz calc_governor_target_low
  3566. mov A, Governor_Req_Pwm ; Load governor requested pwm
  3567. cpl A ; Calculate 255-pwm (invert pwm)
  3568. ; Calculate comm period target (1 + 4*((255-Requested_Pwm)/256))
  3569. rlc A ; Msb to carry
  3570. rlc A ; To bit0
  3571. rlc A ; To bit1
  3572. mov Temp2, A ; Now 2 lsbs are valid for H
  3573. rrc A
  3574. mov Temp1, A ; Now 6 msbs are valid for L
  3575. mov A, Temp2
  3576. anl A, #03h ; Calculate H byte
  3577. inc A ; Add 1
  3578. mov Temp2, A
  3579. mov A, Temp1
  3580. anl A, #0FCh ; Calculate L byte
  3581. jmp calc_governor_store_target
  3582. calc_governor_target_low:
  3583. mov A, Governor_Req_Pwm ; Load governor requested pwm
  3584. cpl A ; Calculate 255-pwm (invert pwm)
  3585. ; Calculate comm period target (2 + 8*((255-Requested_Pwm)/256) - 0.25)
  3586. rlc A ; Msb to carry
  3587. rlc A ; To bit0
  3588. rlc A ; To bit1
  3589. rlc A ; To bit2
  3590. mov Temp2, A ; Now 3 lsbs are valid for H
  3591. rrc A
  3592. mov Temp1, A ; Now 5 msbs are valid for L
  3593. mov A, Temp2
  3594. anl A, #07h ; Calculate H byte
  3595. inc A ; Add 1
  3596. inc A ; Add 1 more
  3597. mov Temp2, A
  3598. mov A, Temp1
  3599. anl A, #0F8h ; Calculate L byte
  3600. calc_governor_subtract_025:
  3601. clr C
  3602. subb A, #40h ; Subtract 0.25
  3603. mov Temp1, A
  3604. mov A, Temp2
  3605. subb A, #0
  3606. mov Temp2, A
  3607. calc_governor_store_target:
  3608. ; Store governor target
  3609. mov Gov_Target_L, Temp1
  3610. mov Gov_Target_H, Temp2
  3611. calc_governor_target_exit:
  3612. ret
  3613. ENDIF
  3614. IF MODE == 1 ; Tail
  3615. calc_governor_target:
  3616. ret
  3617. ENDIF
  3618. IF MODE == 2 ; Multi
  3619. calc_governor_target:
  3620. mov Temp1, #Pgm_Gov_Mode ; Closed loop mode?
  3621. cjne @Temp1, #4, governor_target_calc ; Yes - branch
  3622. jmp calc_governor_target_exit ; No
  3623. governor_target_calc:
  3624. ; Stop governor for stop RC pulse
  3625. clr C
  3626. mov A, New_Rcp ; Check RC pulse against stop value
  3627. subb A, #RCP_STOP ; Is pulse below stop value?
  3628. jc governor_deactivate ; Yes - deactivate
  3629. jmp governor_activate ; No - activate
  3630. governor_deactivate:
  3631. mov Current_Pwm, Requested_Pwm ; Set current pwm to requested
  3632. clr A
  3633. mov Gov_Target_L, A ; Set target to zero
  3634. mov Gov_Target_H, A
  3635. mov Gov_Integral_L, A ; Set integral to zero
  3636. mov Gov_Integral_H, A
  3637. mov Gov_Integral_X, A
  3638. clr Flags1.GOV_ACTIVE
  3639. jmp calc_governor_target_exit
  3640. governor_activate:
  3641. mov Temp1, #Pgm_Gov_Mode ; Store gov mode
  3642. mov A, @Temp1
  3643. mov Temp5, A
  3644. setb Flags1.GOV_ACTIVE
  3645. mov A, Requested_Pwm ; Load requested pwm
  3646. mov Governor_Req_Pwm, A ; Set governor requested pwm
  3647. ; Calculate comm period target 2*(51000/Requested_Pwm)
  3648. mov Temp1, #38h ; Load 51000
  3649. mov Temp2, #0C7h
  3650. mov Temp3, Comm_Period4x_L ; Load comm period
  3651. mov Temp4, Comm_Period4x_H
  3652. ; Set speed range
  3653. clr C
  3654. mov A, Temp4
  3655. rrc A
  3656. mov Temp4, A
  3657. mov A, Temp3
  3658. rrc A
  3659. mov Temp3, A ; 200k eRPM range here
  3660. ; Check range
  3661. mov A, Temp5
  3662. dec A
  3663. jz governor_activate_range_set ; 200k eRPM? - branch
  3664. governor_activate_100k:
  3665. clr C
  3666. mov A, Temp4
  3667. rrc A
  3668. mov Temp4, A
  3669. mov A, Temp3
  3670. rrc A
  3671. mov Temp3, A ; 100k eRPM range here
  3672. mov A, Temp5 ; Check range again
  3673. dec A
  3674. dec A
  3675. jz governor_activate_range_set ; 100k eRPM? - branch
  3676. governor_activate_50k:
  3677. clr C
  3678. mov A, Temp4
  3679. rrc A
  3680. mov Temp4, A
  3681. mov A, Temp3
  3682. rrc A
  3683. mov Temp3, A ; 50k eRPM range here
  3684. governor_activate_range_set:
  3685. call div_u16_by_u16
  3686. ; Store governor target
  3687. mov Gov_Target_L, Temp1
  3688. mov Gov_Target_H, Temp2
  3689. calc_governor_target_exit:
  3690. ret
  3691. ENDIF
  3692. ; Second governor routine - calculate governor proportional error
  3693. calc_governor_prop_error:
  3694. IF MODE <= 1 ; Main or tail
  3695. ; Load comm period and divide by 2
  3696. clr C
  3697. mov A, Comm_Period4x_H
  3698. rrc A
  3699. mov Temp2, A
  3700. mov A, Comm_Period4x_L
  3701. rrc A
  3702. mov Temp1, A
  3703. ; Calculate error
  3704. clr C
  3705. mov A, Gov_Target_L
  3706. subb A, Temp1
  3707. mov Temp1, A
  3708. mov A, Gov_Target_H
  3709. subb A, Temp2
  3710. mov Temp2, A
  3711. ENDIF
  3712. IF MODE == 2 ; Multi
  3713. ; Calculate error
  3714. clr C
  3715. mov A, Gov_Target_L
  3716. subb A, Governor_Req_Pwm
  3717. mov Temp1, A
  3718. mov A, Gov_Target_H
  3719. subb A, #0
  3720. mov Temp2, A
  3721. ENDIF
  3722. ; Check error and limit
  3723. jnc governor_check_prop_limit_pos ; Check carry
  3724. clr C
  3725. mov A, Temp1
  3726. subb A, #80h ; Is error too negative?
  3727. mov A, Temp2
  3728. subb A, #0FFh
  3729. jc governor_limit_prop_error_neg ; Yes - limit
  3730. jmp governor_store_prop_error
  3731. governor_check_prop_limit_pos:
  3732. clr C
  3733. mov A, Temp1
  3734. subb A, #7Fh ; Is error too positive?
  3735. mov A, Temp2
  3736. subb A, #00h
  3737. jnc governor_limit_prop_error_pos ; Yes - limit
  3738. jmp governor_store_prop_error
  3739. governor_limit_prop_error_pos:
  3740. mov Temp1, #7Fh ; Limit to max positive (2's complement)
  3741. mov Temp2, #00h
  3742. jmp governor_store_prop_error
  3743. governor_limit_prop_error_neg:
  3744. mov Temp1, #80h ; Limit to max negative (2's complement)
  3745. mov Temp2, #0FFh
  3746. governor_store_prop_error:
  3747. ; Store proportional
  3748. mov Gov_Proportional_L, Temp1
  3749. mov Gov_Proportional_H, Temp2
  3750. calc_governor_prop_error_exit:
  3751. ret
  3752. ; Third governor routine - calculate governor integral error
  3753. calc_governor_int_error:
  3754. ; Add proportional to integral
  3755. mov A, Gov_Proportional_L
  3756. add A, Gov_Integral_L
  3757. mov Temp1, A
  3758. mov A, Gov_Proportional_H
  3759. addc A, Gov_Integral_H
  3760. mov Temp2, A
  3761. mov Bit_Access, Gov_Proportional_H ; Sign extend high byte
  3762. clr A
  3763. jnb Bit_Access.7, ($+4)
  3764. cpl A
  3765. addc A, Gov_Integral_X
  3766. mov Temp3, A
  3767. ; Check integral and limit
  3768. jnb ACC.7, governor_check_int_limit_pos ; Check sign bit
  3769. clr C
  3770. mov A, Temp3
  3771. subb A, #0F0h ; Is error too negative?
  3772. jc governor_limit_int_error_neg ; Yes - limit
  3773. jmp governor_check_pwm
  3774. governor_check_int_limit_pos:
  3775. clr C
  3776. mov A, Temp3
  3777. subb A, #0Fh ; Is error too positive?
  3778. jnc governor_limit_int_error_pos ; Yes - limit
  3779. jmp governor_check_pwm
  3780. governor_limit_int_error_pos:
  3781. mov Temp1, #0FFh ; Limit to max positive (2's complement)
  3782. mov Temp2, #0FFh
  3783. mov Temp3, #0Fh
  3784. jmp governor_check_pwm
  3785. governor_limit_int_error_neg:
  3786. mov Temp1, #00h ; Limit to max negative (2's complement)
  3787. mov Temp2, #00h
  3788. mov Temp3, #0F0h
  3789. governor_check_pwm:
  3790. ; Check current pwm
  3791. clr C
  3792. mov A, Current_Pwm
  3793. subb A, Pwm_Limit ; Is current pwm at or above pwm limit?
  3794. jnc governor_int_max_pwm ; Yes - branch
  3795. clr C
  3796. mov A, #1
  3797. subb A, Current_Pwm ; Is current pwm at minimum?
  3798. jnc governor_int_min_pwm ; Yes - branch
  3799. jmp governor_store_int_error ; No - store integral error
  3800. governor_int_max_pwm:
  3801. mov A, Gov_Proportional_H
  3802. jb ACC.7, calc_governor_int_error_exit ; Is proportional error negative - branch (high byte is always zero)
  3803. jmp governor_store_int_error ; Positive - store integral error
  3804. governor_int_min_pwm:
  3805. mov A, Gov_Proportional_H
  3806. jnb ACC.7, calc_governor_int_error_exit ; Is proportional error positive - branch (high byte is always zero)
  3807. governor_store_int_error:
  3808. ; Store integral
  3809. mov Gov_Integral_L, Temp1
  3810. mov Gov_Integral_H, Temp2
  3811. mov Gov_Integral_X, Temp3
  3812. calc_governor_int_error_exit:
  3813. ret
  3814. ; Fourth governor routine - calculate governor proportional correction
  3815. calc_governor_prop_correction:
  3816. ; Load proportional gain
  3817. mov Temp1, #Pgm_Gov_P_Gain_Decoded; Load proportional gain
  3818. mov A, @Temp1
  3819. mov Temp3, A ; Store in Temp3
  3820. ; Load proportional
  3821. clr C
  3822. mov A, Gov_Proportional_L ; Nominal multiply by 2
  3823. rlc A
  3824. mov Temp1, A
  3825. mov A, Gov_Proportional_H
  3826. rlc A
  3827. mov Temp2, A
  3828. ; Apply gain
  3829. call mult_s16_by_u8_div_16
  3830. ; Check error and limit (to low byte)
  3831. mov A, Temp2
  3832. jnb ACC.7, governor_check_prop_corr_limit_pos ; Check sign bit
  3833. clr C
  3834. mov A, Temp1
  3835. subb A, #80h ; Is error too negative?
  3836. mov A, Temp2
  3837. subb A, #0FFh
  3838. jc governor_limit_prop_corr_neg ; Yes - limit
  3839. ajmp governor_apply_prop_corr
  3840. governor_check_prop_corr_limit_pos:
  3841. clr C
  3842. mov A, Temp1
  3843. subb A, #7Fh ; Is error too positive?
  3844. mov A, Temp2
  3845. subb A, #00h
  3846. jnc governor_limit_prop_corr_pos ; Yes - limit
  3847. ajmp governor_apply_prop_corr
  3848. governor_limit_prop_corr_pos:
  3849. mov Temp1, #7Fh ; Limit to max positive (2's complement)
  3850. mov Temp2, #00h
  3851. ajmp governor_apply_prop_corr
  3852. governor_limit_prop_corr_neg:
  3853. mov Temp1, #80h ; Limit to max negative (2's complement)
  3854. mov Temp2, #0FFh
  3855. governor_apply_prop_corr:
  3856. ; Test proportional sign
  3857. mov A, Temp1
  3858. jb ACC.7, governor_corr_neg_prop ; If proportional negative - go to correct negative
  3859. ; Subtract positive proportional
  3860. clr C
  3861. mov A, Governor_Req_Pwm
  3862. subb A, Temp1
  3863. mov Temp1, A
  3864. ; Check result
  3865. jc governor_corr_prop_min_pwm ; Is result negative?
  3866. clr C
  3867. mov A, Temp1 ; Is result below pwm min?
  3868. subb A, #1
  3869. jc governor_corr_prop_min_pwm ; Yes
  3870. jmp governor_store_prop_corr ; No - store proportional correction
  3871. governor_corr_prop_min_pwm:
  3872. mov Temp1, #1 ; Load minimum pwm
  3873. jmp governor_store_prop_corr
  3874. governor_corr_neg_prop:
  3875. ; Add negative proportional
  3876. mov A, Temp1
  3877. cpl A
  3878. add A, #1
  3879. add A, Governor_Req_Pwm
  3880. mov Temp1, A
  3881. ; Check result
  3882. jc governor_corr_prop_max_pwm ; Is result above max?
  3883. jmp governor_store_prop_corr ; No - store proportional correction
  3884. governor_corr_prop_max_pwm:
  3885. mov Temp1, #255 ; Load maximum pwm
  3886. governor_store_prop_corr:
  3887. ; Store proportional pwm
  3888. mov Gov_Prop_Pwm, Temp1
  3889. calc_governor_prop_corr_exit:
  3890. ret
  3891. ; Fifth governor routine - calculate governor integral correction
  3892. calc_governor_int_correction:
  3893. ; Load integral gain
  3894. mov Temp1, #Pgm_Gov_I_Gain_Decoded; Load integral gain
  3895. mov A, @Temp1
  3896. mov Temp3, A ; Store in Temp3
  3897. ; Load integral
  3898. mov Temp1, Gov_Integral_H
  3899. mov Temp2, Gov_Integral_X
  3900. ; Apply gain
  3901. call mult_s16_by_u8_div_16
  3902. ; Check integral and limit
  3903. mov A, Temp2
  3904. jnb ACC.7, governor_check_int_corr_limit_pos ; Check sign bit
  3905. clr C
  3906. mov A, Temp1
  3907. subb A, #01h ; Is integral too negative?
  3908. mov A, Temp2
  3909. subb A, #0FFh
  3910. jc governor_limit_int_corr_neg ; Yes - limit
  3911. jmp governor_apply_int_corr
  3912. governor_check_int_corr_limit_pos:
  3913. clr C
  3914. mov A, Temp1
  3915. subb A, #0FFh ; Is integral too positive?
  3916. mov A, Temp2
  3917. subb A, #00h
  3918. jnc governor_limit_int_corr_pos ; Yes - limit
  3919. jmp governor_apply_int_corr
  3920. governor_limit_int_corr_pos:
  3921. mov Temp1, #0FFh ; Limit to max positive (2's complement)
  3922. mov Temp2, #00h
  3923. jmp governor_apply_int_corr
  3924. governor_limit_int_corr_neg:
  3925. mov Temp1, #01h ; Limit to max negative (2's complement)
  3926. mov Temp2, #0FFh
  3927. governor_apply_int_corr:
  3928. ; Test integral sign
  3929. mov A, Temp2
  3930. jb ACC.7, governor_corr_neg_int ; If integral negative - go to correct negative
  3931. ; Subtract positive integral
  3932. clr C
  3933. mov A, Gov_Prop_Pwm
  3934. subb A, Temp1
  3935. mov Temp1, A
  3936. ; Check result
  3937. jc governor_corr_int_min_pwm ; Is result negative?
  3938. clr C
  3939. mov A, Temp1 ; Is result below pwm min?
  3940. subb A, #1
  3941. jc governor_corr_int_min_pwm ; Yes
  3942. jmp governor_store_int_corr ; No - store correction
  3943. governor_corr_int_min_pwm:
  3944. mov Temp1, #1 ; Load minimum pwm
  3945. jmp governor_store_int_corr
  3946. governor_corr_neg_int:
  3947. ; Add negative integral
  3948. mov A, Temp1
  3949. cpl A
  3950. add A, #1
  3951. add A, Gov_Prop_Pwm
  3952. mov Temp1, A
  3953. ; Check result
  3954. jc governor_corr_int_max_pwm ; Is result above max?
  3955. jmp governor_store_int_corr ; No - store correction
  3956. governor_corr_int_max_pwm:
  3957. mov Temp1, #255 ; Load maximum pwm
  3958. governor_store_int_corr:
  3959. ; Store current pwm
  3960. mov Current_Pwm, Temp1
  3961. calc_governor_int_corr_exit:
  3962. ret
  3963. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  3964. ;
  3965. ; Set pwm limit low rpm
  3966. ;
  3967. ; No assumptions
  3968. ;
  3969. ; Sets power limit for low rpms and disables demag for low rpms
  3970. ;
  3971. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  3972. set_pwm_limit_low_rpm:
  3973. ; Set pwm limit and demag disable for low rpms
  3974. mov Temp1, #0FFh ; Default full power
  3975. clr Flags0.DEMAG_ENABLED ; Default disabled
  3976. jb Flags1.STARTUP_PHASE, set_pwm_limit_low_rpm_exit ; Exit if startup phase set
  3977. jb Flags1.INITIAL_RUN_PHASE, set_pwm_demag_done ; Skip demag portion if initial run phase set
  3978. setb Flags0.DEMAG_ENABLED ; Enable demag
  3979. clr C
  3980. mov A, Comm_Period4x_H
  3981. subb A, #0Ah ; ~31250 eRPM
  3982. jc set_pwm_demag_done ; If speed above - branch
  3983. clr C
  3984. mov A, Current_Pwm_Limited
  3985. subb A, #40h ; Do not disable if pwm above 25%
  3986. jnc set_pwm_demag_done
  3987. clr Flags0.DEMAG_ENABLED ; Disable demag
  3988. set_pwm_demag_done:
  3989. mov Temp2, #Pgm_Enable_Power_Prot ; Check if low RPM power protection is enabled
  3990. mov A, @Temp2
  3991. jz set_pwm_limit_low_rpm_exit ; Exit if disabled
  3992. mov A, Comm_Period4x_H
  3993. jz set_pwm_limit_low_rpm_exit ; Avoid divide by zero
  3994. mov A, #255 ; Divide 255 by Comm_Period4x_H
  3995. mov B, Comm_Period4x_H
  3996. div AB
  3997. mov B, Low_Rpm_Pwr_Slope ; Multiply by slope
  3998. jnb Flags1.INITIAL_RUN_PHASE, ($+6) ; More protection for initial run phase
  3999. mov B, #5
  4000. mul AB
  4001. mov Temp1, A ; Set new limit
  4002. xch A, B
  4003. jz ($+4) ; Limit to max
  4004. mov Temp1, #0FFh
  4005. clr C
  4006. mov A, Temp1 ; Limit to min
  4007. subb A, Pwm_Spoolup_Beg
  4008. jnc set_pwm_limit_low_rpm_exit
  4009. mov Temp1, Pwm_Spoolup_Beg
  4010. set_pwm_limit_low_rpm_exit:
  4011. mov Pwm_Limit_By_Rpm, Temp1
  4012. ret
  4013. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  4014. ;
  4015. ; Set pwm limit high rpm
  4016. ;
  4017. ; No assumptions
  4018. ;
  4019. ; Sets power limit for high rpms
  4020. ;
  4021. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  4022. set_pwm_limit_high_rpm:
  4023. IF MCU_48MHZ == 1
  4024. clr C
  4025. mov A, Comm_Period4x_L
  4026. subb A, #0C8h ; Limit Comm_Period to 200, which is 400k erpm
  4027. mov A, Comm_Period4x_H
  4028. subb A, #00h
  4029. ELSE
  4030. clr C
  4031. mov A, Comm_Period4x_L
  4032. subb A, #40h ; Limit Comm_Period to 320, which is 250k erpm
  4033. mov A, Comm_Period4x_H
  4034. subb A, #01h
  4035. ENDIF
  4036. mov A, Pwm_Limit_By_Rpm
  4037. jnc set_pwm_limit_high_rpm_inc_limit
  4038. dec A
  4039. ajmp set_pwm_limit_high_rpm_store
  4040. set_pwm_limit_high_rpm_inc_limit:
  4041. inc A
  4042. set_pwm_limit_high_rpm_store:
  4043. jz ($+4)
  4044. mov Pwm_Limit_By_Rpm, A
  4045. ret
  4046. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  4047. ;
  4048. ; Measure lipo cells
  4049. ;
  4050. ; No assumptions
  4051. ;
  4052. ; Measure voltage and calculate lipo cells
  4053. ;
  4054. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  4055. measure_lipo_cells:
  4056. IF MODE >= 1 ; Tail or multi
  4057. ; If not supported, then exit
  4058. jmp measure_lipo_exit
  4059. ENDIF
  4060. IF MODE == 0 ; Main
  4061. ; Load programmed low voltage limit
  4062. mov Temp1, #Pgm_Low_Voltage_Lim ; Load limit
  4063. mov A, @Temp1
  4064. mov Bit_Access, A ; Store in Bit_Access
  4065. ; Set commutation to BpFET on
  4066. call comm5comm6
  4067. ; Start adc
  4068. Start_Adc
  4069. ; Wait for ADC reference to settle, and then start again
  4070. call wait1ms
  4071. Start_Adc
  4072. ; Wait for ADC conversion to complete
  4073. measure_lipo_wait_adc:
  4074. Get_Adc_Status
  4075. jb AD0BUSY, measure_lipo_wait_adc
  4076. ; Read ADC result
  4077. Read_Adc_Result
  4078. ; Stop ADC
  4079. Stop_Adc
  4080. ; Switch power off
  4081. call switch_power_off
  4082. ; Set limit step
  4083. mov Lipo_Adc_Limit_L, #ADC_LIMIT_L
  4084. mov Lipo_Adc_Limit_H, #ADC_LIMIT_H
  4085. clr C
  4086. mov A, #ADC_LIMIT_H ; Divide 3.0V value by 2
  4087. rrc A
  4088. mov Temp6, A
  4089. mov A, #ADC_LIMIT_L
  4090. jz measure_lipo_exit ; Exit if disabled
  4091. rrc A
  4092. mov Temp5, A
  4093. mov A, #ADC_LIMIT_L ; Calculate 1.5*3.0V=4.5V value
  4094. add A, Temp5
  4095. mov Temp5, A
  4096. mov A, #ADC_LIMIT_H
  4097. addc A, Temp6
  4098. mov Temp6, A
  4099. mov A, Temp5 ; Copy step
  4100. mov Temp3, A
  4101. mov A, Temp6
  4102. mov Temp4, A
  4103. measure_lipo_cell_loop:
  4104. ; Check voltage against xS lower limit
  4105. clr C
  4106. mov A, Temp1
  4107. subb A, Temp3 ; Voltage above limit?
  4108. mov A, Temp2
  4109. subb A, Temp4
  4110. jc measure_lipo_adjust ; No - branch
  4111. ; Set xS voltage limit
  4112. mov A, Lipo_Adc_Limit_L
  4113. add A, #ADC_LIMIT_L
  4114. mov Lipo_Adc_Limit_L, A
  4115. mov A, Lipo_Adc_Limit_H
  4116. addc A, #ADC_LIMIT_H
  4117. mov Lipo_Adc_Limit_H, A
  4118. ; Set (x+1)S lower limit
  4119. mov A, Temp3
  4120. add A, Temp5 ; Add step
  4121. mov Temp3, A
  4122. mov A, Temp4
  4123. addc A, Temp6
  4124. mov Temp4, A
  4125. jmp measure_lipo_cell_loop ; Check for one more battery cell
  4126. measure_lipo_adjust:
  4127. mov Temp7, Lipo_Adc_Limit_L
  4128. mov Temp8, Lipo_Adc_Limit_H
  4129. ; Calculate 3.125%
  4130. clr C
  4131. mov A, Lipo_Adc_Limit_H
  4132. rrc A
  4133. mov Temp2, A
  4134. mov A, Lipo_Adc_Limit_L
  4135. rrc A
  4136. mov Temp1, A ; After this 50%
  4137. clr C
  4138. mov A, Temp2
  4139. rrc A
  4140. mov Temp2, A
  4141. mov A, Temp1
  4142. rrc A
  4143. mov Temp1, A ; After this 25%
  4144. ; Divide three times to get to 3.125%
  4145. mov Temp3, #3
  4146. measure_lipo_divide_loop:
  4147. clr C
  4148. mov A, Temp2
  4149. rrc A
  4150. mov Temp2, A
  4151. mov A, Temp1
  4152. rrc A
  4153. mov Temp1, A
  4154. djnz Temp3, measure_lipo_divide_loop
  4155. ; Add the programmed number of 0.1V (or 3.125% increments)
  4156. mov Temp3, Bit_Access ; Load programmed limit (Bit_Access has Pgm_Low_Voltage_Lim)
  4157. dec Temp3
  4158. jnz measure_lipo_limit_on ; Is low voltage limiting on?
  4159. mov Lipo_Adc_Limit_L, #0 ; No - set limit to zero
  4160. mov Lipo_Adc_Limit_H, #0
  4161. jmp measure_lipo_exit
  4162. measure_lipo_limit_on:
  4163. dec Temp3
  4164. mov A, Temp3
  4165. jz measure_lipo_update
  4166. measure_lipo_add_loop:
  4167. mov A, Temp7 ; Add 3.125%
  4168. add A, Temp1
  4169. mov Temp7, A
  4170. mov A, Temp8
  4171. addc A, Temp2
  4172. mov Temp8, A
  4173. djnz Temp3, measure_lipo_add_loop
  4174. measure_lipo_update:
  4175. ; Set ADC limit
  4176. mov Lipo_Adc_Limit_L, Temp7
  4177. mov Lipo_Adc_Limit_H, Temp8
  4178. ENDIF
  4179. measure_lipo_exit:
  4180. ret
  4181. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  4182. ;
  4183. ; Start ADC conversion
  4184. ;
  4185. ; No assumptions
  4186. ;
  4187. ; Start conversion used for measuring power supply voltage
  4188. ;
  4189. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  4190. start_adc_conversion:
  4191. ; Start adc
  4192. Start_Adc
  4193. ret
  4194. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  4195. ;
  4196. ; Check temperature, power supply voltage and limit power
  4197. ;
  4198. ; No assumptions
  4199. ;
  4200. ; Used to limit main motor power in order to maintain the required voltage
  4201. ;
  4202. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  4203. check_temp_voltage_and_limit_power:
  4204. ; Load programmed low voltage limit
  4205. mov Temp1, #Pgm_Low_Voltage_Lim
  4206. mov A, @Temp1
  4207. mov Temp8, A ; Store in Temp8
  4208. ; Wait for ADC conversion to complete
  4209. Get_Adc_Status
  4210. jb AD0BUSY, check_temp_voltage_and_limit_power
  4211. ; Read ADC result
  4212. Read_Adc_Result
  4213. ; Stop ADC
  4214. Stop_Adc
  4215. inc Adc_Conversion_Cnt ; Increment conversion counter
  4216. clr C
  4217. mov A, Adc_Conversion_Cnt ; Is conversion count equal to temp rate?
  4218. subb A, #TEMP_CHECK_RATE
  4219. jc check_voltage_start ; No - check voltage
  4220. mov Adc_Conversion_Cnt, #0 ; Yes - temperature check. Reset counter
  4221. mov A, Temp2 ; Move ADC MSB to Temp3
  4222. mov Temp3, A
  4223. mov Temp2, #Pgm_Enable_Temp_Prot ; Is temp protection enabled?
  4224. mov A, @Temp2
  4225. jz temp_check_exit ; No - branch
  4226. mov A, Temp3 ; Is temperature reading below 256?
  4227. jnz temp_average_inc_dec ; No - proceed
  4228. mov A, Current_Average_Temp ; Yes - decrement average
  4229. jz temp_average_updated ; Already zero - no change
  4230. jmp temp_average_dec ; Decrement
  4231. temp_average_inc_dec:
  4232. clr C
  4233. mov A, Temp1 ; Check if current temperature is above or below average
  4234. subb A, Current_Average_Temp
  4235. jz temp_average_updated_load_acc ; Equal - no change
  4236. mov A, Current_Average_Temp ; Above - increment average
  4237. jnc temp_average_inc
  4238. jz temp_average_updated ; Below - decrement average if average is not already zero
  4239. temp_average_dec:
  4240. dec A ; Decrement average
  4241. jmp temp_average_updated
  4242. temp_average_inc:
  4243. inc A ; Increment average
  4244. jz temp_average_dec
  4245. jmp temp_average_updated
  4246. temp_average_updated_load_acc:
  4247. mov A, Current_Average_Temp
  4248. temp_average_updated:
  4249. mov Current_Average_Temp, A
  4250. clr C
  4251. subb A, #TEMP_LIMIT ; Is temperature below first limit?
  4252. jc temp_check_exit ; Yes - exit
  4253. mov Pwm_Limit, #192 ; No - limit pwm
  4254. clr C
  4255. subb A, #TEMP_LIMIT_STEP ; Is temperature below second limit
  4256. jc temp_check_exit ; Yes - exit
  4257. mov Pwm_Limit, #128 ; No - limit pwm
  4258. clr C
  4259. subb A, #TEMP_LIMIT_STEP ; Is temperature below third limit
  4260. jc temp_check_exit ; Yes - exit
  4261. mov Pwm_Limit, #64 ; No - limit pwm
  4262. clr C
  4263. subb A, #TEMP_LIMIT_STEP ; Is temperature below final limit
  4264. jc temp_check_exit ; Yes - exit
  4265. mov Pwm_Limit, #0 ; No - limit pwm
  4266. temp_check_exit:
  4267. Set_Adc_Ip_Volt ; Select adc input for next conversion
  4268. ret
  4269. check_voltage_start:
  4270. IF MODE == 0 ; Main
  4271. ; Check if low voltage limiting is enabled
  4272. mov A, Temp8
  4273. clr C
  4274. subb A, #1 ; Is low voltage limit disabled?
  4275. jz check_voltage_good ; Yes - voltage declared good
  4276. mov A, #ADC_LIMIT_L ; Is low voltage limit zero (ESC does not support it)?
  4277. jz check_voltage_good ; Yes - voltage declared good
  4278. ; Check if ADC is saturated
  4279. clr C
  4280. mov A, Temp1
  4281. subb A, #0FFh
  4282. mov A, Temp2
  4283. subb A, #03h
  4284. jnc check_voltage_good ; ADC saturated, can not make judgement
  4285. ; Check voltage against limit
  4286. clr C
  4287. mov A, Temp1
  4288. subb A, Lipo_Adc_Limit_L
  4289. mov A, Temp2
  4290. subb A, Lipo_Adc_Limit_H
  4291. jnc check_voltage_good ; If voltage above limit - branch
  4292. ; Decrease pwm limit
  4293. mov A, Pwm_Limit
  4294. jz check_voltage_lim ; If limit zero - branch
  4295. dec Pwm_Limit ; Decrement limit
  4296. jmp check_voltage_lim
  4297. check_voltage_good:
  4298. ; Increase pwm limit
  4299. mov A, Pwm_Limit
  4300. cpl A
  4301. jz check_voltage_lim ; If limit max - branch
  4302. inc Pwm_Limit ; Increment limit
  4303. check_voltage_lim:
  4304. mov Temp1, Pwm_Limit ; Set limit
  4305. clr C
  4306. mov A, Current_Pwm
  4307. subb A, Temp1
  4308. jnc check_voltage_spoolup_lim ; If current pwm above limit - branch and limit
  4309. mov Temp1, Current_Pwm ; Set current pwm (no limiting)
  4310. check_voltage_spoolup_lim:
  4311. ; Slow spoolup
  4312. clr C
  4313. mov A, Temp1
  4314. subb A, Pwm_Limit_Spoolup
  4315. jc check_voltage_exit ; If current pwm below limit - branch
  4316. mov Temp1, Pwm_Limit_Spoolup
  4317. mov A, Pwm_Limit_Spoolup ; Check if spoolup limit is max
  4318. cpl A
  4319. jz check_voltage_exit ; If max - branch
  4320. mov Pwm_Limit, Pwm_Limit_Spoolup ; Set pwm limit to spoolup limit during ramp (to avoid governor integral buildup)
  4321. check_voltage_exit:
  4322. mov Current_Pwm_Limited, Temp1
  4323. mov Current_Pwm_Lim_Dith, Temp1
  4324. ENDIF
  4325. IF MODE == 1 ; Tail
  4326. ; Increase pwm limit
  4327. mov A, Pwm_Limit
  4328. cpl A
  4329. jz check_voltage_lim ; If limit max - branch
  4330. inc Pwm_Limit ; Increment limit
  4331. check_voltage_lim:
  4332. ENDIF
  4333. IF MODE == 2 ; Multi
  4334. ; Increase pwm limit
  4335. mov A, Pwm_Limit
  4336. add A, #16
  4337. jnc ($+4) ; If not max - branch
  4338. mov A, #255
  4339. mov Pwm_Limit, A ; Increment limit
  4340. ; Set current pwm limited if closed loop mode
  4341. mov Temp2, #Pgm_Gov_Mode ; Governor mode?
  4342. cjne @Temp2, #4, ($+5)
  4343. ajmp check_voltage_pwm_done ; No - branch
  4344. clr C
  4345. mov Temp1, Pwm_Limit ; Set limit
  4346. mov A, Current_Pwm
  4347. subb A, Temp1
  4348. jnc check_voltage_low_rpm ; If current pwm above limit - branch and limit
  4349. mov Temp1, Current_Pwm ; Set current pwm (no limiting)
  4350. check_voltage_low_rpm:
  4351. ; Limit pwm for low rpms
  4352. clr C
  4353. mov A, Temp1 ; Check against limit
  4354. subb A, Pwm_Limit_By_Rpm
  4355. jc ($+4) ; If current pwm below limit - branch
  4356. mov Temp1, Pwm_Limit_By_Rpm ; Limit pwm
  4357. mov Current_Pwm_Limited, Temp1
  4358. mov Current_Pwm_Lim_Dith, Temp1
  4359. check_voltage_pwm_done:
  4360. ENDIF
  4361. ; Set adc mux for next conversion
  4362. mov A, Adc_Conversion_Cnt ; Is next conversion for temperature?
  4363. cjne A, #(TEMP_CHECK_RATE-1), check_voltage_ret
  4364. Set_Adc_Ip_Temp ; Select temp sensor for next conversion
  4365. check_voltage_ret:
  4366. ret
  4367. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  4368. ;
  4369. ; Set startup PWM routine
  4370. ;
  4371. ; Either the SETTLE_PHASE or the STEPPER_PHASE flag must be set
  4372. ;
  4373. ; Used for pwm control during startup
  4374. ;
  4375. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  4376. set_startup_pwm:
  4377. ; Adjust startup power
  4378. mov A, #PWM_START ; Set power
  4379. mov Temp2, #Pgm_Startup_Pwr_Decoded
  4380. mov B, @Temp2
  4381. mul AB
  4382. xch A, B
  4383. mov C, B.7 ; Multiply result by 2 (unity gain is 128)
  4384. rlc A
  4385. mov Temp1, A ; Transfer to Temp1
  4386. clr C
  4387. mov A, Temp1 ; Check against limit
  4388. subb A, Pwm_Limit
  4389. jc startup_pwm_set_pwm ; If pwm below limit - branch
  4390. mov Temp1, Pwm_Limit ; Limit pwm
  4391. startup_pwm_set_pwm:
  4392. ; Set pwm variables
  4393. mov Requested_Pwm, Temp1 ; Update requested pwm
  4394. mov Current_Pwm, Temp1 ; Update current pwm
  4395. mov Current_Pwm_Limited, Temp1 ; Update limited version of current pwm
  4396. mov Current_Pwm_Lim_Dith, Temp1
  4397. mov Pwm_Spoolup_Beg, Temp1 ; Yes - update spoolup beginning pwm (will use PWM_SETTLE or PWM_SETTLE/2)
  4398. ret
  4399. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  4400. ;
  4401. ; Initialize timing routine
  4402. ;
  4403. ; No assumptions
  4404. ;
  4405. ; Part of initialization before motor start
  4406. ;
  4407. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  4408. initialize_timing:
  4409. mov Comm_Period4x_L, #00h ; Set commutation period registers
  4410. mov Comm_Period4x_H, #0F0h
  4411. ret
  4412. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  4413. ;
  4414. ; Calculate next commutation timing routine
  4415. ;
  4416. ; No assumptions
  4417. ;
  4418. ; Called immediately after each commutation
  4419. ; Also sets up timer 3 to wait advance timing
  4420. ; Two entry points are used
  4421. ;
  4422. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  4423. calc_next_comm_timing: ; Entry point for run phase
  4424. ; Read commutation time
  4425. clr EA
  4426. mov TMR2CN, #20h ; Timer2 disabled
  4427. mov Temp1, TMR2L ; Load timer value
  4428. mov Temp2, TMR2H
  4429. mov Temp3, Timer2_X
  4430. jnb TF2H, ($+4) ; Check if interrupt is pending
  4431. inc Temp3 ; If it is pending, then timer has already wrapped
  4432. mov TMR2CN, #24h ; Timer2 enabled
  4433. setb EA
  4434. IF MCU_48MHZ == 1
  4435. clr C
  4436. mov A, Temp3
  4437. rrc A
  4438. mov Temp3, A
  4439. mov A, Temp2
  4440. rrc A
  4441. mov Temp2, A
  4442. mov A, Temp1
  4443. rrc A
  4444. mov Temp1, A
  4445. ENDIF
  4446. ; Calculate this commutation time
  4447. mov Temp4, Prev_Comm_L
  4448. mov Temp5, Prev_Comm_H
  4449. mov Prev_Comm_L, Temp1 ; Store timestamp as previous commutation
  4450. mov Prev_Comm_H, Temp2
  4451. clr C
  4452. mov A, Temp1
  4453. subb A, Temp4 ; Calculate the new commutation time
  4454. mov Temp1, A
  4455. mov A, Temp2
  4456. subb A, Temp5
  4457. jb Flags1.STARTUP_PHASE, calc_next_comm_startup
  4458. IF MCU_48MHZ == 1
  4459. anl A, #7Fh
  4460. ENDIF
  4461. mov Temp2, A
  4462. jnb Flags0.HIGH_RPM, ($+5) ; Branch if high rpm
  4463. ajmp calc_next_comm_timing_fast
  4464. ajmp calc_next_comm_normal
  4465. calc_next_comm_startup:
  4466. mov Temp6, Prev_Comm_X
  4467. mov Prev_Comm_X, Temp3 ; Store extended timestamp as previous commutation
  4468. mov Temp2, A
  4469. mov A, Temp3
  4470. subb A, Temp6 ; Calculate the new extended commutation time
  4471. IF MCU_48MHZ == 1
  4472. anl A, #7Fh
  4473. ENDIF
  4474. mov Temp3, A
  4475. jz ($+6)
  4476. mov Temp1, #0FFh
  4477. mov Temp2, #0FFh
  4478. mov Temp7, Prev_Prev_Comm_L
  4479. mov Temp8, Prev_Prev_Comm_H
  4480. mov Prev_Prev_Comm_L, Temp4
  4481. mov Prev_Prev_Comm_H, Temp5
  4482. clr C
  4483. mov A, Temp5
  4484. subb A, Temp8 ; Calculate previous commutation time (hi byte only)
  4485. mov Temp5, A
  4486. clr C
  4487. mov A, Temp2
  4488. subb A, Temp5 ; Calculate the difference between the two previous commutation times (hi bytes only)
  4489. mov Comm_Diff, A
  4490. mov Temp1, Prev_Comm_L ; Reload this commutation time
  4491. mov Temp2, Prev_Comm_H
  4492. clr C
  4493. mov A, Temp1
  4494. subb A, Temp7 ; Calculate the new commutation time based upon the two last commutations (to reduce sensitivity to offset)
  4495. mov Temp1, A
  4496. mov A, Temp2
  4497. subb A, Temp8
  4498. mov Temp2, A
  4499. clr C
  4500. mov A, Comm_Period4x_H ; Average with previous and save
  4501. rrc A
  4502. mov Temp4, A
  4503. mov A, Comm_Period4x_L
  4504. rrc A
  4505. mov Temp3, A
  4506. mov A, Temp1
  4507. add A, Temp3
  4508. mov Comm_Period4x_L, A
  4509. mov A, Temp2
  4510. addc A, Temp4
  4511. mov Comm_Period4x_H, A
  4512. jnc ($+8)
  4513. mov Comm_Period4x_L, #0FFh
  4514. mov Comm_Period4x_H, #0FFh
  4515. ajmp calc_new_wait_times_setup
  4516. calc_next_comm_normal:
  4517. ; Calculate new commutation time
  4518. mov Temp3, Comm_Period4x_L ; Comm_Period4x(-l-h) holds the time of 4 commutations
  4519. mov Temp4, Comm_Period4x_H
  4520. mov Temp5, Comm_Period4x_L ; Copy variables
  4521. mov Temp6, Comm_Period4x_H
  4522. mov Temp7, #4 ; Divide Comm_Period4x 4 times as default
  4523. mov Temp8, #2 ; Divide new commutation time 2 times as default
  4524. clr C
  4525. mov A, Temp4
  4526. subb A, #04h
  4527. jc ($+4)
  4528. dec Temp7 ; Reduce averaging time constant for low speeds
  4529. dec Temp8
  4530. clr C
  4531. mov A, Temp4
  4532. subb A, #08h
  4533. jc ($+4)
  4534. dec Temp7 ; Reduce averaging time constant more for even lower speeds
  4535. dec Temp8
  4536. calc_next_comm_avg_period_div:
  4537. clr C
  4538. mov A, Temp6
  4539. rrc A ; Divide by 2
  4540. mov Temp6, A
  4541. mov A, Temp5
  4542. rrc A
  4543. mov Temp5, A
  4544. djnz Temp7, calc_next_comm_avg_period_div
  4545. clr C
  4546. mov A, Temp3
  4547. subb A, Temp5 ; Subtract a fraction
  4548. mov Temp3, A
  4549. mov A, Temp4
  4550. subb A, Temp6
  4551. mov Temp4, A
  4552. mov A, Temp8 ; Divide new time
  4553. jz calc_next_comm_new_period_div_done
  4554. calc_next_comm_new_period_div:
  4555. clr C
  4556. mov A, Temp2
  4557. rrc A ; Divide by 2
  4558. mov Temp2, A
  4559. mov A, Temp1
  4560. rrc A
  4561. mov Temp1, A
  4562. djnz Temp8, calc_next_comm_new_period_div
  4563. calc_next_comm_new_period_div_done:
  4564. mov A, Temp3
  4565. add A, Temp1 ; Add the divided new time
  4566. mov Temp3, A
  4567. mov A, Temp4
  4568. addc A, Temp2
  4569. mov Temp4, A
  4570. mov Comm_Period4x_L, Temp3 ; Store Comm_Period4x_X
  4571. mov Comm_Period4x_H, Temp4
  4572. jnc calc_new_wait_times_setup; If period larger than 0xffff - go to slow case
  4573. mov Temp4, #0FFh
  4574. mov Comm_Period4x_L, Temp4 ; Set commutation period registers to very slow timing (0xffff)
  4575. mov Comm_Period4x_H, Temp4
  4576. calc_new_wait_times_setup:
  4577. ; Set high rpm bit (if above 156k erpm)
  4578. clr C
  4579. mov A, Temp4
  4580. subb A, #2
  4581. jnc ($+4)
  4582. setb Flags0.HIGH_RPM ; Set high rpm bit
  4583. ; Load programmed commutation timing
  4584. jnb Flags1.STARTUP_PHASE, calc_new_wait_per_startup_done ; Set dedicated timing during startup
  4585. mov Temp8, #3
  4586. ajmp calc_new_wait_per_demag_done
  4587. calc_new_wait_per_startup_done:
  4588. mov Temp1, #Pgm_Comm_Timing ; Load timing setting
  4589. mov A, @Temp1
  4590. mov Temp8, A ; Store in Temp8
  4591. clr C
  4592. mov A, Demag_Detected_Metric ; Check demag metric
  4593. subb A, #130
  4594. jc calc_new_wait_per_demag_done
  4595. inc Temp8 ; Increase timing
  4596. clr C
  4597. mov A, Demag_Detected_Metric
  4598. subb A, #160
  4599. jc ($+3)
  4600. inc Temp8 ; Increase timing again
  4601. clr C
  4602. mov A, Temp8 ; Limit timing to max
  4603. subb A, #6
  4604. jc ($+4)
  4605. mov Temp8, #5 ; Set timing to max
  4606. calc_new_wait_per_demag_done:
  4607. IF MCU_48MHZ == 0 ; Set timing reduction
  4608. IF (NFETON_DELAY < 128) AND (PFETON_DELAY < 128)
  4609. IF ((NFETON_DELAY + PFETON_DELAY) <= 30)
  4610. mov Temp7, #(4 + ((NFETON_DELAY + PFETON_DELAY)/10)) ; Min to max
  4611. ELSE
  4612. mov Temp7, #7 ; Max
  4613. ENDIF
  4614. ELSE
  4615. mov Temp7, #5 ; Mid
  4616. ENDIF
  4617. ELSE
  4618. IF (NFETON_DELAY < 128) AND (PFETON_DELAY < 128)
  4619. IF ((NFETON_DELAY + PFETON_DELAY) <= 40)
  4620. mov Temp7, #(2 + ((NFETON_DELAY + PFETON_DELAY)/20)) ; Min to max
  4621. ELSE
  4622. mov Temp7, #4 ; Max
  4623. ENDIF
  4624. ELSE
  4625. mov Temp7, #3 ; Mid
  4626. ENDIF
  4627. ENDIF
  4628. ; Load current commutation timing
  4629. mov A, Comm_Period4x_H ; Divide 4 times
  4630. swap A
  4631. anl A, #00Fh
  4632. mov Temp2, A
  4633. mov A, Comm_Period4x_H
  4634. swap A
  4635. anl A, #0F0h
  4636. mov Temp1, A
  4637. mov A, Comm_Period4x_L
  4638. swap A
  4639. anl A, #00Fh
  4640. add A, Temp1
  4641. mov Temp1, A
  4642. clr C
  4643. mov A, Temp1
  4644. subb A, Temp7
  4645. mov Temp3, A
  4646. mov A, Temp2
  4647. subb A, #0
  4648. mov Temp4, A
  4649. jc load_min_time ; Check that result is still positive
  4650. clr C
  4651. mov A, Temp3
  4652. subb A, #(COMM_TIME_MIN SHL 1)
  4653. mov A, Temp4
  4654. subb A, #0
  4655. jnc calc_new_wait_times_exit ; Check that result is still above minumum
  4656. load_min_time:
  4657. mov Temp3, #(COMM_TIME_MIN SHL 1)
  4658. clr A
  4659. mov Temp4, A
  4660. calc_new_wait_times_exit:
  4661. ajmp wait_advance_timing
  4662. ; Fast calculation (Comm_Period4x_H less than 2)
  4663. calc_next_comm_timing_fast:
  4664. ; Calculate new commutation time
  4665. mov Temp3, Comm_Period4x_L ; Comm_Period4x(-l-h) holds the time of 4 commutations
  4666. mov Temp4, Comm_Period4x_H
  4667. mov A, Temp4 ; Divide by 2 4 times
  4668. swap A
  4669. mov Temp7, A
  4670. mov A, Temp3
  4671. swap A
  4672. anl A, #0Fh
  4673. orl A, Temp7
  4674. mov Temp5, A
  4675. clr C
  4676. mov A, Temp3 ; Subtract a fraction
  4677. subb A, Temp5
  4678. mov Temp3, A
  4679. mov A, Temp4
  4680. subb A, #0
  4681. mov Temp4, A
  4682. clr C
  4683. mov A, Temp1
  4684. rrc A ; Divide by 2 2 times
  4685. clr C
  4686. rrc A
  4687. mov Temp1, A
  4688. mov A, Temp3 ; Add the divided new time
  4689. add A, Temp1
  4690. mov Temp3, A
  4691. mov A, Temp4
  4692. addc A, #0
  4693. mov Temp4, A
  4694. mov Comm_Period4x_L, Temp3 ; Store Comm_Period4x_X
  4695. mov Comm_Period4x_H, Temp4
  4696. clr C
  4697. mov A, Temp4 ; If erpm below 156k - go to normal case
  4698. subb A, #2
  4699. jc ($+4)
  4700. clr Flags0.HIGH_RPM ; Clear high rpm bit
  4701. IF MCU_48MHZ == 0 ; Set timing reduction
  4702. IF (NFETON_DELAY < 128) AND (PFETON_DELAY < 128)
  4703. IF ((NFETON_DELAY + PFETON_DELAY) <= 30)
  4704. mov Temp1, #(4 + ((NFETON_DELAY + PFETON_DELAY)/10)) ; Min to max
  4705. ELSE
  4706. mov Temp1, #7 ; Max
  4707. ENDIF
  4708. ELSE
  4709. mov Temp1, #5 ; Mid
  4710. ENDIF
  4711. ELSE
  4712. IF (NFETON_DELAY < 128) AND (PFETON_DELAY < 128)
  4713. IF ((NFETON_DELAY + PFETON_DELAY) <= 40)
  4714. mov Temp1, #(2 + ((NFETON_DELAY + PFETON_DELAY)/20)) ; Min to max
  4715. ELSE
  4716. mov Temp1, #4 ; Max
  4717. ENDIF
  4718. ELSE
  4719. mov Temp1, #3 ; Mid
  4720. ENDIF
  4721. ENDIF
  4722. mov A, Temp4 ; Divide by 2 4 times
  4723. swap A
  4724. mov Temp7, A
  4725. mov Temp4, #0
  4726. mov A, Temp3
  4727. swap A
  4728. anl A, #0Fh
  4729. orl A, Temp7
  4730. mov Temp3, A
  4731. clr C
  4732. mov A, Temp3
  4733. subb A, Temp1
  4734. mov Temp3, A
  4735. jc load_min_time_fast ; Check that result is still positive
  4736. clr C
  4737. subb A, #(COMM_TIME_MIN SHL 1)
  4738. jnc calc_new_wait_times_fast_done ; Check that result is still above minumum
  4739. load_min_time_fast:
  4740. mov Temp3, #(COMM_TIME_MIN SHL 1)
  4741. calc_new_wait_times_fast_done:
  4742. mov Temp1, #Pgm_Comm_Timing ; Load timing setting
  4743. mov A, @Temp1
  4744. mov Temp8, A ; Store in Temp8
  4745. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  4746. ;
  4747. ; Wait advance timing routine
  4748. ;
  4749. ; No assumptions
  4750. ; NOTE: Be VERY careful if using temp registers. They are passed over this routine
  4751. ;
  4752. ; Waits for the advance timing to elapse and sets up the next zero cross wait
  4753. ;
  4754. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  4755. wait_advance_timing:
  4756. jnb Flags0.T3_PENDING, ($+5)
  4757. ajmp wait_advance_timing
  4758. ; Setup next wait time
  4759. mov Next_Wt_Start_L, Wt_ZC_Tout_Start_L
  4760. mov Next_Wt_Start_H, Wt_ZC_Tout_Start_H
  4761. setb Flags0.T3_PENDING
  4762. orl EIE1, #80h ; Enable timer3 interrupts
  4763. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  4764. ;
  4765. ; Calculate new wait times routine
  4766. ;
  4767. ; No assumptions
  4768. ;
  4769. ; Calculates new wait times
  4770. ;
  4771. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  4772. calc_new_wait_times:
  4773. clr C
  4774. clr A
  4775. subb A, Temp3 ; Negate
  4776. mov Temp1, A
  4777. clr A
  4778. subb A, Temp4
  4779. mov Temp2, A
  4780. IF MCU_48MHZ == 1
  4781. clr C
  4782. mov A, Temp1 ; Multiply by 2
  4783. rlc A
  4784. mov Temp1, A
  4785. mov A, Temp2
  4786. rlc A
  4787. mov Temp2, A
  4788. ENDIF
  4789. jnb Flags0.HIGH_RPM, ($+5) ; Branch if high rpm
  4790. ajmp calc_new_wait_times_fast
  4791. mov A, Temp1 ; Copy values
  4792. mov Temp3, A
  4793. mov A, Temp2
  4794. mov Temp4, A
  4795. setb C ; Negative numbers - set carry
  4796. mov A, Temp2
  4797. rrc A ; Divide by 2
  4798. mov Temp6, A
  4799. mov A, Temp1
  4800. rrc A
  4801. mov Temp5, A
  4802. mov Wt_Zc_Tout_Start_L, Temp1; Set 15deg time for zero cross scan timeout
  4803. mov Wt_Zc_Tout_Start_H, Temp2
  4804. clr C
  4805. mov A, Temp8 ; (Temp8 has Pgm_Comm_Timing)
  4806. subb A, #3 ; Is timing normal?
  4807. jz store_times_decrease ; Yes - branch
  4808. mov A, Temp8
  4809. jb ACC.0, adjust_timing_two_steps ; If an odd number - branch
  4810. mov A, Temp1 ; Add 7.5deg and store in Temp1/2
  4811. add A, Temp5
  4812. mov Temp1, A
  4813. mov A, Temp2
  4814. addc A, Temp6
  4815. mov Temp2, A
  4816. mov A, Temp5 ; Store 7.5deg in Temp3/4
  4817. mov Temp3, A
  4818. mov A, Temp6
  4819. mov Temp4, A
  4820. jmp store_times_up_or_down
  4821. adjust_timing_two_steps:
  4822. mov A, Temp1 ; Add 15deg and store in Temp1/2
  4823. add A, Temp1
  4824. mov Temp1, A
  4825. mov A, Temp2
  4826. addc A, Temp2
  4827. mov Temp2, A
  4828. clr C
  4829. mov A, Temp1
  4830. add A, #(COMM_TIME_MIN SHL 1)
  4831. mov Temp1, A
  4832. mov A, Temp2
  4833. addc A, #0
  4834. mov Temp2, A
  4835. mov Temp3, #-(COMM_TIME_MIN SHL 1); Store minimum time in Temp3/4
  4836. mov Temp4, #0FFh
  4837. store_times_up_or_down:
  4838. clr C
  4839. mov A, Temp8
  4840. subb A, #3 ; Is timing higher than normal?
  4841. jc store_times_decrease ; No - branch
  4842. store_times_increase:
  4843. mov Wt_Comm_Start_L, Temp3 ; Now commutation time (~60deg) divided by 4 (~15deg nominal)
  4844. mov Wt_Comm_Start_H, Temp4
  4845. mov Wt_Adv_Start_L, Temp1 ; New commutation advance time (~15deg nominal)
  4846. mov Wt_Adv_Start_H, Temp2
  4847. mov Wt_Zc_Scan_Start_L, Temp5 ; Use this value for zero cross scan delay (7.5deg)
  4848. mov Wt_Zc_Scan_Start_H, Temp6
  4849. ajmp wait_before_zc_scan
  4850. store_times_decrease:
  4851. mov Wt_Comm_Start_L, Temp1 ; Now commutation time (~60deg) divided by 4 (~15deg nominal)
  4852. mov Wt_Comm_Start_H, Temp2
  4853. mov Wt_Adv_Start_L, Temp3 ; New commutation advance time (~15deg nominal)
  4854. mov Wt_Adv_Start_H, Temp4
  4855. mov Wt_Zc_Scan_Start_L, Temp5 ; Use this value for zero cross scan delay (7.5deg)
  4856. mov Wt_Zc_Scan_Start_H, Temp6
  4857. jnb Flags1.STARTUP_PHASE, store_times_exit
  4858. clr C
  4859. mov A, Startup_Cnt
  4860. subb A, #3
  4861. jc store_times_exit
  4862. mov A, Comm_Diff ; Compensate commutation wait for comparator offset
  4863. mov C, ACC.7
  4864. rrc A
  4865. mov Temp1, A
  4866. mov A, Wt_Comm_Start_H
  4867. cpl A
  4868. add A, #1
  4869. addc A, Temp1
  4870. jc store_times_exit
  4871. jb ACC.7, store_times_exit
  4872. mov Wt_Comm_Start_L, #0FFh
  4873. cpl A
  4874. add A, #1
  4875. mov Wt_Comm_Start_H, A
  4876. store_times_exit:
  4877. ajmp wait_before_zc_scan
  4878. calc_new_wait_times_fast:
  4879. mov A, Temp1 ; Copy values
  4880. mov Temp3, A
  4881. setb C ; Negative numbers - set carry
  4882. mov A, Temp1 ; Divide by 2
  4883. rrc A
  4884. mov Temp5, A
  4885. mov Wt_Zc_Tout_Start_L, Temp1; Set 15deg time for zero cross scan timeout
  4886. clr C
  4887. mov A, Temp8 ; (Temp8 has Pgm_Comm_Timing)
  4888. subb A, #3 ; Is timing normal?
  4889. jz store_times_decrease_fast; Yes - branch
  4890. mov A, Temp8
  4891. jb ACC.0, adjust_timing_two_steps_fast ; If an odd number - branch
  4892. mov A, Temp1 ; Add 7.5deg and store in Temp1
  4893. add A, Temp5
  4894. mov Temp1, A
  4895. mov A, Temp5 ; Store 7.5deg in Temp3
  4896. mov Temp3, A
  4897. ajmp store_times_up_or_down_fast
  4898. adjust_timing_two_steps_fast:
  4899. mov A, Temp1 ; Add 15deg and store in Temp1
  4900. add A, Temp1
  4901. add A, #(COMM_TIME_MIN SHL 1)
  4902. mov Temp1, A
  4903. mov Temp3, #-(COMM_TIME_MIN SHL 1) ; Store minimum time in Temp3
  4904. store_times_up_or_down_fast:
  4905. clr C
  4906. mov A, Temp8
  4907. subb A, #3 ; Is timing higher than normal?
  4908. jc store_times_decrease_fast; No - branch
  4909. store_times_increase_fast:
  4910. mov Wt_Comm_Start_L, Temp3 ; Now commutation time (~60deg) divided by 4 (~15deg nominal)
  4911. mov Wt_Adv_Start_L, Temp1 ; New commutation advance time (~15deg nominal)
  4912. mov Wt_Zc_Scan_Start_L, Temp5 ; Use this value for zero cross scan delay (7.5deg)
  4913. ajmp wait_before_zc_scan
  4914. store_times_decrease_fast:
  4915. mov Wt_Comm_Start_L, Temp1 ; Now commutation time (~60deg) divided by 4 (~15deg nominal)
  4916. mov Wt_Adv_Start_L, Temp3 ; New commutation advance time (~15deg nominal)
  4917. mov Wt_Zc_Scan_Start_L, Temp5 ; Use this value for zero cross scan delay (7.5deg)
  4918. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  4919. ;
  4920. ; Wait before zero cross scan routine
  4921. ;
  4922. ; No assumptions
  4923. ;
  4924. ; Waits for the zero cross scan wait time to elapse
  4925. ; Also sets up timer 3 for the zero cross scan timeout time
  4926. ;
  4927. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  4928. wait_before_zc_scan:
  4929. ; Calculate random number
  4930. mov A, Random
  4931. clr C
  4932. rlc A
  4933. jnc wait_before_zc_scan_rand
  4934. xrl A, #06Bh ; Sequence length of 35, when initialized to 1
  4935. wait_before_zc_scan_rand:
  4936. mov Random, A
  4937. wait_before_zc_scan_wait:
  4938. jnb Flags0.T3_PENDING, ($+5)
  4939. ajmp wait_before_zc_scan_wait
  4940. IF MCU_48MHZ == 1
  4941. mov Startup_Zc_Timeout_Cntd, #4
  4942. ELSE
  4943. mov Startup_Zc_Timeout_Cntd, #2
  4944. ENDIF
  4945. setup_zc_scan_timeout:
  4946. setb Flags0.T3_PENDING
  4947. orl EIE1, #80h ; Enable timer3 interrupts
  4948. mov A, Flags1
  4949. anl A, #((1 SHL STARTUP_PHASE)+(1 SHL INITIAL_RUN_PHASE))
  4950. jz wait_before_zc_scan_exit
  4951. mov Temp1, Comm_Period4x_L ; Set long timeout when starting
  4952. mov Temp2, Comm_Period4x_H
  4953. IF MCU_48MHZ == 0
  4954. clr C
  4955. mov A, Temp2
  4956. rrc A
  4957. mov Temp2, A
  4958. mov A, Temp1
  4959. rrc A
  4960. mov Temp1, A
  4961. ENDIF
  4962. clr EA
  4963. anl EIE1, #7Fh ; Disable timer3 interrupts
  4964. mov TMR3CN, #00h ; Timer3 disabled and interrupt flag cleared
  4965. clr C
  4966. clr A
  4967. subb A, Temp1 ; Set timeout
  4968. mov TMR3L, A
  4969. clr A
  4970. subb A, Temp2
  4971. mov TMR3H, A
  4972. mov TMR3CN, #04h ; Timer3 enabled and interrupt flag cleared
  4973. setb Flags0.T3_PENDING
  4974. orl EIE1, #80h ; Enable timer3 interrupts
  4975. setb EA
  4976. wait_before_zc_scan_exit:
  4977. ret
  4978. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  4979. ;
  4980. ; Wait for comparator to go low/high routines
  4981. ;
  4982. ; No assumptions
  4983. ;
  4984. ; Waits for the zero cross scan wait time to elapse
  4985. ; Then scans for comparator going low/high
  4986. ;
  4987. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  4988. wait_for_comp_out_low:
  4989. setb Flags0.DEMAG_DETECTED ; Set demag detected flag as default
  4990. mov Comparator_Read_Cnt, #0 ; Reset number of comparator reads
  4991. mov Bit_Access, #00h ; Desired comparator output
  4992. jnb Flags1.DIR_CHANGE_BRAKE, ($+6)
  4993. mov Bit_Access, #40h
  4994. jmp wait_for_comp_out_start
  4995. wait_for_comp_out_high:
  4996. setb Flags0.DEMAG_DETECTED ; Set demag detected flag as default
  4997. mov Comparator_Read_Cnt, #0 ; Reset number of comparator reads
  4998. mov Bit_Access, #40h ; Desired comparator output
  4999. jnb Flags1.DIR_CHANGE_BRAKE, ($+6)
  5000. mov Bit_Access, #00h
  5001. wait_for_comp_out_start:
  5002. setb EA ; Enable interrupts
  5003. ; Set number of comparator readings
  5004. mov Temp1, #1 ; Number of OK readings required
  5005. jb Flags0.HIGH_RPM, comp_wait_on_comp_able ; Branch if high rpm
  5006. mov A, Flags1 ; Clear demag detected flag if start phases
  5007. anl A, #((1 SHL STARTUP_PHASE)+(1 SHL INITIAL_RUN_PHASE))
  5008. jz ($+4)
  5009. clr Flags0.DEMAG_DETECTED
  5010. clr C ; Set number of readings higher for lower speeds
  5011. mov A, Comm_Period4x_H
  5012. subb A, #05h
  5013. jc comp_wait_on_comp_able
  5014. mov Temp1, #2
  5015. subb A, #05h
  5016. jc comp_wait_no_of_readings
  5017. mov Temp1, #3
  5018. subb A, #05h ; Set number of consecutive readings higher for lower speeds
  5019. jc comp_wait_no_of_readings
  5020. mov Temp1, #6
  5021. comp_wait_no_of_readings:
  5022. jnb Flags1.STARTUP_PHASE, ($+5) ; Set many samples during startup
  5023. mov Temp1, #10
  5024. comp_wait_on_comp_able:
  5025. jb Flags0.T3_PENDING, comp_wait_on_comp_able_not_timed_out ; Has zero cross scan timeout elapsed?
  5026. mov A, Comparator_Read_Cnt ; Check that comparator has been read
  5027. jz comp_wait_on_comp_able_not_timed_out ; If not read - branch
  5028. jnb Flags1.STARTUP_PHASE, comp_wait_on_comp_able_timeout_extended ; Extend timeout during startup
  5029. clr C
  5030. mov A, Startup_Cnt ; Do not extend timeout for the first commutations
  5031. subb A, #3
  5032. jc comp_wait_on_comp_able_timeout_extended
  5033. djnz Startup_Zc_Timeout_Cntd, comp_wait_on_comp_able_extend_timeout
  5034. comp_wait_on_comp_able_timeout_extended:
  5035. setb EA ; Enable interrupts
  5036. setb Flags1.COMP_TIMED_OUT
  5037. ajmp setup_comm_wait
  5038. comp_wait_on_comp_able_extend_timeout:
  5039. call setup_zc_scan_timeout
  5040. comp_wait_on_comp_able_not_timed_out:
  5041. setb EA ; Enable interrupts
  5042. nop ; Allocate only just enough time to capture interrupt
  5043. nop
  5044. clr EA ; Disable interrupts
  5045. jb Flags0.HIGH_RPM, comp_wait_read_comp ; Branch if high rpm
  5046. mov A, Comm_Period4x_H ; Reduce required distance to pwm transition for higher speeds
  5047. clr C
  5048. mov Temp4, A
  5049. subb A, #0Fh
  5050. jc ($+4)
  5051. mov Temp4, #0Fh
  5052. mov A, Temp4
  5053. add A, #5
  5054. jnb Flags2.PGM_PWM_HIGH_FREQ, ($+4) ; More delay for high pwm frequency
  5055. rl A
  5056. jnb Flags1.INITIAL_RUN_PHASE, ($+5)
  5057. mov A, #40
  5058. jb Flags0.PWM_ON, ($+4) ; More delay for pwm off
  5059. rl A
  5060. mov Temp2, A
  5061. jnb Flags1.STARTUP_PHASE, ($+5) ; Set a long delay from pwm on/off events during startup
  5062. mov Temp2, #130
  5063. IF MCU_48MHZ == 0
  5064. mov A, TL1
  5065. ELSE
  5066. mov A, TH1
  5067. rrc A
  5068. mov A, TL1
  5069. rrc A
  5070. ENDIF
  5071. clr C
  5072. subb A, Temp2
  5073. jc comp_wait_on_comp_able ; Re-evaluate pwm cycle
  5074. comp_wait_read_comp:
  5075. inc Comparator_Read_Cnt ; Increment comparator read count
  5076. Read_Comp_Out ; Read comparator output
  5077. anl A, #40h
  5078. cjne A, Bit_Access, comp_read_wrong
  5079. ajmp comp_read_ok
  5080. comp_read_wrong:
  5081. jnb Flags1.STARTUP_PHASE, comp_read_wrong_not_startup
  5082. inc Temp1 ; Increment number of OK readings required
  5083. clr C
  5084. mov A, Temp1
  5085. subb A, #10 ; If above initial requirement - go back and restart
  5086. jc ($+3)
  5087. inc Temp1
  5088. ajmp comp_wait_on_comp_able ; If below initial requirement - continue to look for good ones
  5089. comp_read_wrong_not_startup:
  5090. jb Flags0.DEMAG_DETECTED, ($+5)
  5091. ajmp wait_for_comp_out_start ; If comparator output is not correct, and timeout already extended - go back and restart
  5092. clr Flags0.DEMAG_DETECTED ; Clear demag detected flag
  5093. anl EIE1, #7Fh ; Disable timer3 interrupts
  5094. mov TMR3CN, #00h ; Timer3 disabled and interrupt flag cleared
  5095. jnb Flags0.HIGH_RPM, comp_read_wrong_low_rpm ; Branch if not high rpm
  5096. mov TMR3L, #00h ; Set timeout to 256us
  5097. IF MCU_48MHZ == 1
  5098. mov TMR3H, #0FCh
  5099. ELSE
  5100. mov TMR3H, #0FEh
  5101. ENDIF
  5102. comp_read_wrong_timeout_set:
  5103. mov TMR3CN, #04h ; Timer3 enabled and interrupt flag cleared
  5104. setb Flags0.T3_PENDING
  5105. orl EIE1, #80h ; Enable timer3 interrupts
  5106. ajmp wait_for_comp_out_start ; If comparator output is not correct - go back and restart
  5107. comp_read_wrong_low_rpm:
  5108. mov Temp7, Comm_Period4x_L ; Set timeout to comm period 4x value
  5109. mov Temp8, Comm_Period4x_H
  5110. IF MCU_48MHZ == 1
  5111. clr C
  5112. mov A, Temp7
  5113. rlc A
  5114. mov Temp7, A
  5115. mov A, Temp8
  5116. rlc A
  5117. mov Temp8, A
  5118. jnc ($+6)
  5119. mov Temp7, #0FFh
  5120. mov Temp8, #0FFh
  5121. ENDIF
  5122. clr C
  5123. clr A
  5124. subb A, Temp7
  5125. mov TMR3L, A
  5126. clr A
  5127. subb A, Temp8
  5128. mov TMR3H, A
  5129. ajmp comp_read_wrong_timeout_set
  5130. comp_read_ok:
  5131. clr C
  5132. mov A, Startup_Cnt ; Force a timeout for the first commutations
  5133. subb A, #2
  5134. jnc ($+4)
  5135. ajmp wait_for_comp_out_start
  5136. jnb Flags0.DEMAG_DETECTED, ($+5) ; Do not accept correct comparator output if it is demag
  5137. ajmp wait_for_comp_out_start
  5138. djnz Temp1, comp_read_ok_jmp ; Decrement readings counter - repeat comparator reading if not zero
  5139. ajmp ($+4)
  5140. comp_read_ok_jmp:
  5141. ajmp comp_wait_on_comp_able
  5142. clr Flags1.COMP_TIMED_OUT
  5143. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  5144. ;
  5145. ; Setup commutation timing routine
  5146. ;
  5147. ; No assumptions
  5148. ;
  5149. ; Sets up and starts wait from commutation to zero cross
  5150. ;
  5151. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  5152. setup_comm_wait:
  5153. anl EIE1, #7Fh ; Disable timer3 interrupts
  5154. mov TMR3CN, #00h ; Timer3 disabled and interrupt flag cleared
  5155. mov TMR3L, Wt_Comm_Start_L
  5156. mov TMR3H, Wt_Comm_Start_H
  5157. mov TMR3CN, #04h ; Timer3 enabled and interrupt flag cleared
  5158. ; Setup next wait time
  5159. mov Next_Wt_Start_L, Wt_Adv_Start_L
  5160. mov Next_Wt_Start_H, Wt_Adv_Start_H
  5161. setb Flags0.T3_PENDING
  5162. orl EIE1, #80h ; Enable timer3 interrupts
  5163. setb EA ; Enable interrupts again
  5164. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  5165. ;
  5166. ; Evaluate comparator integrity
  5167. ;
  5168. ; No assumptions
  5169. ;
  5170. ; Checks comparator signal behaviour versus expected behaviour
  5171. ;
  5172. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  5173. evaluate_comparator_integrity:
  5174. mov A, Flags1
  5175. anl A, #((1 SHL STARTUP_PHASE)+(1 SHL INITIAL_RUN_PHASE))
  5176. jz eval_comp_check_timeout
  5177. jb Flags1.INITIAL_RUN_PHASE, ($+5) ; Do not increment beyond startup phase
  5178. inc Startup_Cnt ; Increment counter
  5179. jmp eval_comp_exit
  5180. eval_comp_check_timeout:
  5181. jnb Flags1.COMP_TIMED_OUT, eval_comp_exit ; Has timeout elapsed?
  5182. jb Flags1.DIR_CHANGE_BRAKE, eval_comp_exit ; Do not exit run mode if it is braking
  5183. jb Flags0.DEMAG_DETECTED, eval_comp_exit ; Do not exit run mode if it is a demag situation
  5184. dec SP ; Routine exit without "ret" command
  5185. dec SP
  5186. ljmp run_to_wait_for_power_on_fail ; Yes - exit run mode
  5187. eval_comp_exit:
  5188. ret
  5189. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  5190. ;
  5191. ; Wait for commutation routine
  5192. ;
  5193. ; No assumptions
  5194. ;
  5195. ; Waits from zero cross to commutation
  5196. ;
  5197. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  5198. wait_for_comm:
  5199. ; Update demag metric
  5200. mov Temp1, #0
  5201. jnb Flags0.DEMAG_ENABLED, ($+8); If demag disabled - branch
  5202. jnb Flags0.DEMAG_DETECTED, ($+5)
  5203. mov Temp1, #1
  5204. mov A, Demag_Detected_Metric ; Sliding average of 8, 256 when demag and 0 when not. Limited to minimum 120
  5205. mov B, #7
  5206. mul AB ; Multiply by 7
  5207. mov Temp2, A
  5208. mov A, B ; Add new value for current demag status
  5209. add A, Temp1
  5210. mov B, A
  5211. mov A, Temp2
  5212. mov C, B.0 ; Divide by 8
  5213. rrc A
  5214. mov C, B.1
  5215. rrc A
  5216. mov C, B.2
  5217. rrc A
  5218. mov Demag_Detected_Metric, A
  5219. clr C
  5220. subb A, #120 ; Limit to minimum 120
  5221. jnc ($+5)
  5222. mov Demag_Detected_Metric, #120
  5223. clr C
  5224. mov A, Demag_Detected_Metric ; Check demag metric
  5225. subb A, Demag_Pwr_Off_Thresh
  5226. jc wait_for_comm_wait ; Cut power if many consecutive demags. This will help retain sync during hard accelerations
  5227. setb Flags0.DEMAG_CUT_POWER ; Set demag power cut flag
  5228. All_nFETs_off
  5229. wait_for_comm_wait:
  5230. jnb Flags0.T3_PENDING, ($+5)
  5231. ajmp wait_for_comm_wait
  5232. ; Setup next wait time
  5233. mov Next_Wt_Start_L, Wt_Zc_Scan_Start_L
  5234. mov Next_Wt_Start_H, Wt_Zc_Scan_Start_H
  5235. setb Flags0.T3_PENDING
  5236. orl EIE1, #80h ; Enable timer3 interrupts
  5237. ret
  5238. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  5239. ;
  5240. ; Commutation routines
  5241. ;
  5242. ; No assumptions
  5243. ;
  5244. ; Performs commutation switching
  5245. ; Damped routines uses all pfets on when in pwm off to dampen the motor
  5246. ;
  5247. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  5248. ; Comm phase 1 to comm phase 2
  5249. comm1comm2:
  5250. Set_RPM_Out
  5251. jb Flags3.PGM_DIR_REV, comm12_rev
  5252. clr EA ; Disable all interrupts
  5253. mov Comm_Phase, #2
  5254. BpFET_off ; Turn off pfet
  5255. ApFET_on ; Turn on pfet
  5256. setb EA
  5257. Set_Comp_Phase_B ; Set comparator phase
  5258. jmp comm_exit
  5259. comm12_rev:
  5260. clr EA ; Disable all interrupts
  5261. mov Comm_Phase, #2
  5262. BpFET_off ; Turn off pfet
  5263. CpFET_on ; Turn on pfet (reverse)
  5264. setb EA
  5265. Set_Comp_Phase_B ; Set comparator phase
  5266. jmp comm_exit
  5267. ; Comm phase 2 to comm phase 3
  5268. comm2comm3:
  5269. Clear_RPM_Out
  5270. jnb Flags2.PGM_PWMOFF_DAMPED, comm23_nondamp
  5271. ; Comm2Comm3 Damped
  5272. jb Flags3.PGM_DIR_REV, comm23_damp_rev
  5273. clr EA ; Disable all interrupts
  5274. mov Comm_Phase, #3
  5275. mov DPTR, #pwm_bfet_damped
  5276. mov DampingFET, #(1 SHL BpFET)
  5277. CnFET_off ; Turn off fets
  5278. CpFET_off
  5279. jnb Flags0.PWM_ON, comm23_nfet_off ; Is pwm on?
  5280. BnFET_on ; Pwm on - turn on nfet
  5281. ajmp comm23_fets_done
  5282. comm23_nfet_off:
  5283. BpFET_on ; Pwm off - switch damping fets
  5284. comm23_fets_done:
  5285. setb EA
  5286. Set_Comp_Phase_C ; Set comparator phase
  5287. ljmp comm_exit
  5288. ; Comm2Comm3 Damped reverse
  5289. comm23_damp_rev:
  5290. clr EA ; Disable all interrupts
  5291. mov Comm_Phase, #3
  5292. mov DPTR, #pwm_bfet_damped
  5293. mov DampingFET, #(1 SHL BpFET)
  5294. AnFET_off ; Turn off fets (reverse)
  5295. ApFET_off
  5296. jnb Flags0.PWM_ON, comm23_nfet_off_rev ; Is pwm on?
  5297. BnFET_on ; Pwm on - turn on nfet
  5298. ajmp comm23_fets_done_rev
  5299. comm23_nfet_off_rev:
  5300. BpFET_on ; Pwm off - switch damping fets
  5301. comm23_fets_done_rev:
  5302. setb EA
  5303. Set_Comp_Phase_A ; Set comparator phase (reverse)
  5304. ljmp comm_exit
  5305. ; Comm2Comm3 Non-damped
  5306. comm23_nondamp:
  5307. jb Flags3.PGM_DIR_REV, comm23_nondamp_rev
  5308. clr EA ; Disable all interrupts
  5309. mov Comm_Phase, #3
  5310. mov DPTR, #pwm_bfet
  5311. CnFET_off ; Turn off nfet
  5312. jnb Flags0.PWM_ON, comm23_nfet_done ; Is pwm on?
  5313. BnFET_on ; Yes - turn on nfet
  5314. comm23_nfet_done:
  5315. setb EA
  5316. Set_Comp_Phase_C ; Set comparator phase
  5317. ljmp comm_exit
  5318. ; Comm2Comm3 Non-damped reverse
  5319. comm23_nondamp_rev:
  5320. clr EA ; Disable all interrupts
  5321. mov Comm_Phase, #3
  5322. mov DPTR, #pwm_bfet
  5323. AnFET_off ; Turn off nfet (reverse)
  5324. jnb Flags0.PWM_ON, comm23_nfet_done_rev ; Is pwm on?
  5325. BnFET_on ; Yes - turn on nfet
  5326. comm23_nfet_done_rev:
  5327. setb EA
  5328. Set_Comp_Phase_A ; Set comparator phase (reverse)
  5329. ljmp comm_exit
  5330. ; Comm phase 3 to comm phase 4
  5331. comm3comm4:
  5332. Set_RPM_Out
  5333. jb Flags3.PGM_DIR_REV, comm34_rev
  5334. clr EA ; Disable all interrupts
  5335. mov Comm_Phase, #4
  5336. ApFET_off ; Turn off pfet
  5337. CpFET_on ; Turn on pfet
  5338. setb EA
  5339. Set_Comp_Phase_A ; Set comparator phase
  5340. jmp comm_exit
  5341. comm34_rev:
  5342. clr EA ; Disable all interrupts
  5343. mov Comm_Phase, #4
  5344. CpFET_off ; Turn off pfet (reverse)
  5345. ApFET_on ; Turn on pfet (reverse)
  5346. setb EA
  5347. Set_Comp_Phase_C ; Set comparator phase (reverse)
  5348. jmp comm_exit
  5349. ; Comm phase 4 to comm phase 5
  5350. comm4comm5:
  5351. Clear_RPM_Out
  5352. jnb Flags2.PGM_PWMOFF_DAMPED, comm45_nondamp
  5353. ; Comm4Comm5 Damped
  5354. jb Flags3.PGM_DIR_REV, comm45_damp_rev
  5355. clr EA ; Disable all interrupts
  5356. mov Comm_Phase, #5
  5357. mov DPTR, #pwm_afet_damped
  5358. mov DampingFET, #(1 SHL ApFET)
  5359. BnFET_off ; Turn off fets
  5360. BpFET_off
  5361. jnb Flags0.PWM_ON, comm45_nfet_off ; Is pwm on?
  5362. AnFET_on ; Pwm on - turn on nfet
  5363. ajmp comm45_fets_done
  5364. comm45_nfet_off:
  5365. ApFET_on ; Pwm off - switch damping fets
  5366. comm45_fets_done:
  5367. setb EA
  5368. Set_Comp_Phase_B ; Set comparator phase
  5369. ljmp comm_exit
  5370. ; Comm4Comm5 Damped reverse
  5371. comm45_damp_rev:
  5372. clr EA ; Disable all interrupts
  5373. mov Comm_Phase, #5
  5374. mov DPTR, #pwm_cfet_damped ; (reverse)
  5375. mov DampingFET, #(1 SHL CpFET) ; (reverse)
  5376. BnFET_off ; Turn off fets
  5377. BpFET_off
  5378. jnb Flags0.PWM_ON, comm45_nfet_off_rev ; Is pwm on?
  5379. CnFET_on ; Pwm on - turn on nfet (reverse)
  5380. ajmp comm45_fets_done_rev
  5381. comm45_nfet_off_rev:
  5382. CpFET_on ; Pwm off - switch damping fets (reverse)
  5383. comm45_fets_done_rev:
  5384. setb EA
  5385. Set_Comp_Phase_B ; Set comparator phase
  5386. ljmp comm_exit
  5387. ; Comm4Comm5 Non-damped
  5388. comm45_nondamp:
  5389. jb Flags3.PGM_DIR_REV, comm45_nondamp_rev
  5390. clr EA ; Disable all interrupts
  5391. mov Comm_Phase, #5
  5392. mov DPTR, #pwm_afet
  5393. BnFET_off ; Turn off nfet
  5394. jnb Flags0.PWM_ON, comm45_nfet_done ; Is pwm on?
  5395. AnFET_on ; Yes - turn on nfet
  5396. comm45_nfet_done:
  5397. setb EA
  5398. Set_Comp_Phase_B ; Set comparator phase
  5399. ljmp comm_exit
  5400. ; Comm4Comm5 Non-damped reverse
  5401. comm45_nondamp_rev:
  5402. clr EA ; Disable all interrupts
  5403. mov Comm_Phase, #5
  5404. mov DPTR, #pwm_cfet ; (reverse)
  5405. BnFET_off ; Turn off nfet
  5406. jnb Flags0.PWM_ON, comm45_nfet_done ; Is pwm on?
  5407. CnFET_on ; Yes - turn on nfet (reverse)
  5408. setb EA
  5409. Set_Comp_Phase_B ; Set comparator phase
  5410. ljmp comm_exit
  5411. ; Comm phase 5 to comm phase 6
  5412. comm5comm6:
  5413. Set_RPM_Out
  5414. jb Flags3.PGM_DIR_REV, comm56_rev
  5415. clr EA ; Disable all interrupts
  5416. mov Comm_Phase, #6
  5417. CpFET_off ; Turn off pfet
  5418. BpFET_on ; Turn on pfet
  5419. setb EA
  5420. Set_Comp_Phase_C ; Set comparator phase
  5421. jmp comm_exit
  5422. comm56_rev:
  5423. clr EA ; Disable all interrupts
  5424. mov Comm_Phase, #6
  5425. ApFET_off ; Turn off pfet (reverse)
  5426. BpFET_on ; Turn on pfet
  5427. setb EA
  5428. Set_Comp_Phase_A ; Set comparator phase (reverse)
  5429. jmp comm_exit
  5430. ; Comm phase 6 to comm phase 1
  5431. comm6comm1:
  5432. Clear_RPM_Out
  5433. jnb Flags2.PGM_PWMOFF_DAMPED, comm61_nondamp
  5434. ; Comm6Comm1 Damped
  5435. jb Flags3.PGM_DIR_REV, comm61_damp_rev
  5436. clr EA ; Disable all interrupts
  5437. mov Comm_Phase, #1
  5438. mov DPTR, #pwm_cfet_damped
  5439. mov DampingFET, #(1 SHL CpFET)
  5440. AnFET_off ; Turn off fets
  5441. ApFET_off
  5442. jnb Flags0.PWM_ON, comm61_nfet_off ; Is pwm on?
  5443. CnFET_on ; Pwm on - turn on nfet
  5444. ajmp comm61_fets_done
  5445. comm61_nfet_off:
  5446. CpFET_on ; Pwm off - switch damping fets
  5447. comm61_fets_done:
  5448. setb EA
  5449. Set_Comp_Phase_A ; Set comparator phase
  5450. ljmp comm_exit
  5451. ; Comm6Comm1 Damped reverse
  5452. comm61_damp_rev:
  5453. clr EA ; Disable all interrupts
  5454. mov Comm_Phase, #1
  5455. mov DPTR, #pwm_afet_damped ; (reverse)
  5456. mov DampingFET, #(1 SHL ApFET) ; (reverse)
  5457. CnFET_off ; Turn off fets (reverse)
  5458. CpFET_off
  5459. jnb Flags0.PWM_ON, comm61_nfet_off_rev ; Is pwm on?
  5460. AnFET_on ; Pwm on - turn on nfet
  5461. ajmp comm61_fets_done_rev
  5462. comm61_nfet_off_rev:
  5463. ApFET_on ; Pwm off - switch damping fets (reverse)
  5464. comm61_fets_done_rev:
  5465. setb EA
  5466. Set_Comp_Phase_C ; Set comparator phase (reverse)
  5467. ajmp comm_exit
  5468. ; Comm6Comm1 Non-damped
  5469. comm61_nondamp:
  5470. jb Flags3.PGM_DIR_REV, comm61_nondamp_rev
  5471. clr EA ; Disable all interrupts
  5472. mov Comm_Phase, #1
  5473. mov DPTR, #pwm_cfet
  5474. AnFET_off ; Turn off nfet
  5475. jnb Flags0.PWM_ON, comm61_nfet_done ; Is pwm on?
  5476. CnFET_on ; Yes - turn on nfet
  5477. comm61_nfet_done:
  5478. setb EA
  5479. Set_Comp_Phase_A ; Set comparator phase
  5480. ajmp comm_exit
  5481. ; Comm6Comm1 Non-damped reverse
  5482. comm61_nondamp_rev:
  5483. clr EA ; Disable all interrupts
  5484. mov Comm_Phase, #1
  5485. mov DPTR, #pwm_afet ; (reverse)
  5486. CnFET_off ; Turn off nfet (reverse)
  5487. jnb Flags0.PWM_ON, comm61_nfet_done_rev ; Is pwm on?
  5488. AnFET_on ; Yes - turn on nfet (reverse)
  5489. comm61_nfet_done_rev:
  5490. setb EA
  5491. Set_Comp_Phase_C ; Set comparator phase (reverse)
  5492. comm_exit:
  5493. clr Flags0.DEMAG_CUT_POWER ; Clear demag power cut flag
  5494. ret
  5495. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  5496. ;
  5497. ; Switch power off routine
  5498. ;
  5499. ; No assumptions
  5500. ;
  5501. ; Switches all fets off
  5502. ;
  5503. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  5504. switch_power_off:
  5505. mov DPTR, #pwm_nofet ; Set DPTR register to pwm_nofet
  5506. mov DampingFET, #0
  5507. All_nFETs_Off ; Turn off all nfets
  5508. All_pFETs_Off ; Turn off all pfets
  5509. clr Flags0.PWM_ON ; Set pwm cycle to pwm off
  5510. ret
  5511. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  5512. ;
  5513. ; Set default parameters
  5514. ;
  5515. ; No assumptions
  5516. ;
  5517. ; Sets default programming parameters
  5518. ;
  5519. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  5520. set_default_parameters:
  5521. IF MODE == 0 ; Main
  5522. mov Temp1, #Pgm_Gov_P_Gain
  5523. mov @Temp1, #DEFAULT_PGM_MAIN_P_GAIN
  5524. inc Temp1
  5525. mov @Temp1, #DEFAULT_PGM_MAIN_I_GAIN
  5526. inc Temp1
  5527. mov @Temp1, #DEFAULT_PGM_MAIN_GOVERNOR_MODE
  5528. inc Temp1
  5529. mov @Temp1, #DEFAULT_PGM_MAIN_LOW_VOLTAGE_LIM
  5530. inc Temp1
  5531. mov @Temp1, #0FFh ; Motor gain
  5532. inc Temp1
  5533. mov @Temp1, #0FFh ; Motor idle
  5534. inc Temp1
  5535. mov @Temp1, #DEFAULT_PGM_MAIN_STARTUP_PWR
  5536. inc Temp1
  5537. mov @Temp1, #DEFAULT_PGM_MAIN_PWM_FREQ
  5538. inc Temp1
  5539. mov @Temp1, #DEFAULT_PGM_MAIN_DIRECTION
  5540. inc Temp1
  5541. mov @Temp1, #DEFAULT_PGM_MAIN_RCP_PWM_POL
  5542. mov Temp1, #Pgm_Enable_TX_Program
  5543. mov @Temp1, #DEFAULT_PGM_ENABLE_TX_PROGRAM
  5544. inc Temp1
  5545. mov @Temp1, #DEFAULT_PGM_MAIN_REARM_START
  5546. inc Temp1
  5547. mov @Temp1, #DEFAULT_PGM_MAIN_GOV_SETUP_TARGET
  5548. inc Temp1
  5549. mov @Temp1, #0FFh ; Startup rpm
  5550. inc Temp1
  5551. mov @Temp1, #0FFh ; Startup accel
  5552. inc Temp1
  5553. mov @Temp1, #0FFh ; Voltage comp
  5554. inc Temp1
  5555. mov @Temp1, #DEFAULT_PGM_MAIN_COMM_TIMING
  5556. inc Temp1
  5557. mov @Temp1, #0FFh ; Damping force
  5558. inc Temp1
  5559. mov @Temp1, #DEFAULT_PGM_MAIN_GOVERNOR_RANGE
  5560. inc Temp1
  5561. mov @Temp1, #0FFh ; Startup method
  5562. inc Temp1
  5563. mov @Temp1, #DEFAULT_PGM_PPM_MIN_THROTTLE
  5564. inc Temp1
  5565. mov @Temp1, #DEFAULT_PGM_PPM_MAX_THROTTLE
  5566. inc Temp1
  5567. mov @Temp1, #DEFAULT_PGM_MAIN_BEEP_STRENGTH
  5568. inc Temp1
  5569. mov @Temp1, #DEFAULT_PGM_MAIN_BEACON_STRENGTH
  5570. inc Temp1
  5571. mov @Temp1, #DEFAULT_PGM_MAIN_BEACON_DELAY
  5572. inc Temp1
  5573. mov @Temp1, #0FFh ; Throttle rate
  5574. inc Temp1
  5575. mov @Temp1, #DEFAULT_PGM_MAIN_DEMAG_COMP
  5576. inc Temp1
  5577. mov @Temp1, #DEFAULT_PGM_BEC_VOLTAGE_HIGH
  5578. inc Temp1
  5579. mov @Temp1, #DEFAULT_PGM_PPM_CENTER_THROTTLE
  5580. inc Temp1
  5581. mov @Temp1, #DEFAULT_PGM_MAIN_SPOOLUP_TIME
  5582. inc Temp1
  5583. mov @Temp1, #DEFAULT_PGM_ENABLE_TEMP_PROT
  5584. inc Temp1
  5585. mov @Temp1, #DEFAULT_PGM_ENABLE_POWER_PROT
  5586. inc Temp1
  5587. mov @Temp1, #DEFAULT_PGM_ENABLE_PWM_INPUT
  5588. inc Temp1
  5589. mov @Temp1, #0FFh ; Pwm dither
  5590. ENDIF
  5591. IF MODE == 1 ; Tail
  5592. mov Temp1, #Pgm_Gov_P_Gain
  5593. mov @Temp1, #0FFh
  5594. inc Temp1
  5595. mov @Temp1, #0FFh ; Governor I gain
  5596. inc Temp1
  5597. mov @Temp1, #0FFh ; Governor mode
  5598. inc Temp1
  5599. mov @Temp1, #0FFh ; Low voltage limit
  5600. inc Temp1
  5601. mov @Temp1, #DEFAULT_PGM_TAIL_GAIN
  5602. inc Temp1
  5603. mov @Temp1, #DEFAULT_PGM_TAIL_IDLE_SPEED
  5604. inc Temp1
  5605. mov @Temp1, #DEFAULT_PGM_TAIL_STARTUP_PWR
  5606. inc Temp1
  5607. mov @Temp1, #DEFAULT_PGM_TAIL_PWM_FREQ
  5608. inc Temp1
  5609. mov @Temp1, #DEFAULT_PGM_TAIL_DIRECTION
  5610. inc Temp1
  5611. mov @Temp1, #DEFAULT_PGM_TAIL_RCP_PWM_POL
  5612. mov Temp1, #Pgm_Enable_TX_Program
  5613. mov @Temp1, #DEFAULT_PGM_ENABLE_TX_PROGRAM
  5614. inc Temp1
  5615. mov @Temp1, #0FFh ; Main rearm start
  5616. inc Temp1
  5617. mov @Temp1, #0FFh ; Governor setup target
  5618. inc Temp1
  5619. mov @Temp1, #0FFh ; Startup rpm
  5620. inc Temp1
  5621. mov @Temp1, #0FFh ; Startup accel
  5622. inc Temp1
  5623. mov @Temp1, #0FFh ; Voltage comp
  5624. inc Temp1
  5625. mov @Temp1, #DEFAULT_PGM_TAIL_COMM_TIMING
  5626. inc Temp1
  5627. mov @Temp1, #0FFh ; Damping force
  5628. inc Temp1
  5629. mov @Temp1, #0FFh ; Governor range
  5630. inc Temp1
  5631. mov @Temp1, #0FFh ; Startup method
  5632. inc Temp1
  5633. mov @Temp1, #DEFAULT_PGM_PPM_MIN_THROTTLE
  5634. inc Temp1
  5635. mov @Temp1, #DEFAULT_PGM_PPM_MAX_THROTTLE
  5636. inc Temp1
  5637. mov @Temp1, #DEFAULT_PGM_TAIL_BEEP_STRENGTH
  5638. inc Temp1
  5639. mov @Temp1, #DEFAULT_PGM_TAIL_BEACON_STRENGTH
  5640. inc Temp1
  5641. mov @Temp1, #DEFAULT_PGM_TAIL_BEACON_DELAY
  5642. inc Temp1
  5643. mov @Temp1, #0FFh ; Throttle rate
  5644. inc Temp1
  5645. mov @Temp1, #DEFAULT_PGM_TAIL_DEMAG_COMP
  5646. inc Temp1
  5647. mov @Temp1, #DEFAULT_PGM_BEC_VOLTAGE_HIGH
  5648. inc Temp1
  5649. mov @Temp1, #DEFAULT_PGM_PPM_CENTER_THROTTLE
  5650. inc Temp1
  5651. mov @Temp1, #0FFh
  5652. inc Temp1
  5653. mov @Temp1, #DEFAULT_PGM_ENABLE_TEMP_PROT
  5654. inc Temp1
  5655. mov @Temp1, #DEFAULT_PGM_ENABLE_POWER_PROT
  5656. inc Temp1
  5657. mov @Temp1, #DEFAULT_PGM_ENABLE_PWM_INPUT
  5658. inc Temp1
  5659. mov @Temp1, #DEFAULT_PGM_TAIL_PWM_DITHER
  5660. ENDIF
  5661. IF MODE == 2 ; Multi
  5662. mov Temp1, #Pgm_Gov_P_Gain
  5663. mov @Temp1, #DEFAULT_PGM_MULTI_P_GAIN
  5664. inc Temp1
  5665. mov @Temp1, #DEFAULT_PGM_MULTI_I_GAIN
  5666. inc Temp1
  5667. mov @Temp1, #DEFAULT_PGM_MULTI_GOVERNOR_MODE
  5668. inc Temp1
  5669. mov @Temp1, #0FFh ; Low voltage limit
  5670. inc Temp1
  5671. mov @Temp1, #DEFAULT_PGM_MULTI_GAIN
  5672. inc Temp1
  5673. mov @Temp1, #0FFh
  5674. inc Temp1
  5675. mov @Temp1, #DEFAULT_PGM_MULTI_STARTUP_PWR
  5676. inc Temp1
  5677. mov @Temp1, #DEFAULT_PGM_MULTI_PWM_FREQ
  5678. inc Temp1
  5679. mov @Temp1, #DEFAULT_PGM_MULTI_DIRECTION
  5680. inc Temp1
  5681. mov @Temp1, #DEFAULT_PGM_MULTI_RCP_PWM_POL
  5682. mov Temp1, #Pgm_Enable_TX_Program
  5683. mov @Temp1, #DEFAULT_PGM_ENABLE_TX_PROGRAM
  5684. inc Temp1
  5685. mov @Temp1, #0FFh ; Main rearm start
  5686. inc Temp1
  5687. mov @Temp1, #0FFh ; Governor setup target
  5688. inc Temp1
  5689. mov @Temp1, #0FFh ; Startup rpm
  5690. inc Temp1
  5691. mov @Temp1, #0FFh ; Startup accel
  5692. inc Temp1
  5693. mov @Temp1, #0FFh ; Voltage comp
  5694. inc Temp1
  5695. mov @Temp1, #DEFAULT_PGM_MULTI_COMM_TIMING
  5696. inc Temp1
  5697. mov @Temp1, #0FFh ; Damping force
  5698. inc Temp1
  5699. mov @Temp1, #0FFh ; Governor range
  5700. inc Temp1
  5701. mov @Temp1, #0FFh ; Startup method
  5702. inc Temp1
  5703. mov @Temp1, #DEFAULT_PGM_PPM_MIN_THROTTLE
  5704. inc Temp1
  5705. mov @Temp1, #DEFAULT_PGM_PPM_MAX_THROTTLE
  5706. inc Temp1
  5707. mov @Temp1, #DEFAULT_PGM_MULTI_BEEP_STRENGTH
  5708. inc Temp1
  5709. mov @Temp1, #DEFAULT_PGM_MULTI_BEACON_STRENGTH
  5710. inc Temp1
  5711. mov @Temp1, #DEFAULT_PGM_MULTI_BEACON_DELAY
  5712. inc Temp1
  5713. mov @Temp1, #0FFh ; Throttle rate
  5714. inc Temp1
  5715. mov @Temp1, #DEFAULT_PGM_MULTI_DEMAG_COMP
  5716. inc Temp1
  5717. mov @Temp1, #DEFAULT_PGM_BEC_VOLTAGE_HIGH
  5718. inc Temp1
  5719. mov @Temp1, #DEFAULT_PGM_PPM_CENTER_THROTTLE
  5720. inc Temp1
  5721. mov @Temp1, #0FFh
  5722. inc Temp1
  5723. mov @Temp1, #DEFAULT_PGM_ENABLE_TEMP_PROT
  5724. inc Temp1
  5725. mov @Temp1, #DEFAULT_PGM_ENABLE_POWER_PROT
  5726. inc Temp1
  5727. mov @Temp1, #DEFAULT_PGM_ENABLE_PWM_INPUT
  5728. inc Temp1
  5729. mov @Temp1, #DEFAULT_PGM_MULTI_PWM_DITHER
  5730. ENDIF
  5731. ret
  5732. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  5733. ;
  5734. ; Decode parameters
  5735. ;
  5736. ; No assumptions
  5737. ;
  5738. ; Decodes programming parameters
  5739. ;
  5740. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  5741. decode_parameters:
  5742. ; Load programmed pwm frequency
  5743. mov Temp1, #Pgm_Pwm_Freq ; Load pwm freq
  5744. mov A, @Temp1
  5745. mov Temp8, A ; Store in Temp8
  5746. clr Flags2.PGM_PWMOFF_DAMPED
  5747. IF DAMPED_MODE_ENABLE == 1
  5748. cjne Temp8, #3, ($+5)
  5749. setb Flags2.PGM_PWMOFF_DAMPED
  5750. ENDIF
  5751. ; Load programmed direction
  5752. mov Temp1, #Pgm_Direction
  5753. IF MODE >= 1 ; Tail or multi
  5754. mov A, @Temp1
  5755. clr C
  5756. subb A, #3
  5757. jz decode_params_dir_set
  5758. ENDIF
  5759. clr Flags3.PGM_DIR_REV
  5760. mov A, @Temp1
  5761. jnb ACC.1, ($+5)
  5762. setb Flags3.PGM_DIR_REV
  5763. decode_params_dir_set:
  5764. clr Flags3.PGM_RCP_PWM_POL
  5765. mov Temp1, #Pgm_Input_Pol
  5766. mov A, @Temp1
  5767. jnb ACC.1, ($+5)
  5768. setb Flags3.PGM_RCP_PWM_POL
  5769. clr C
  5770. mov A, Temp8
  5771. subb A, #2
  5772. jz decode_pwm_freq_low
  5773. mov CKCON, #01h ; Timer0 set for clk/4 (22kHz pwm)
  5774. setb Flags2.PGM_PWM_HIGH_FREQ
  5775. jmp decode_pwm_freq_end
  5776. decode_pwm_freq_low:
  5777. mov CKCON, #00h ; Timer0 set for clk/12 (8kHz pwm)
  5778. clr Flags2.PGM_PWM_HIGH_FREQ
  5779. decode_pwm_freq_end:
  5780. ret
  5781. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  5782. ;
  5783. ; Decode settings
  5784. ;
  5785. ; No assumptions
  5786. ;
  5787. ; Decodes various settings
  5788. ;
  5789. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  5790. decode_settings:
  5791. ; Decode governor gains
  5792. mov Temp1, #Pgm_Gov_P_Gain ; Decode governor P gain
  5793. mov A, @Temp1
  5794. dec A
  5795. mov DPTR, #GOV_GAIN_TABLE
  5796. movc A, @A+DPTR
  5797. mov Temp1, #Pgm_Gov_P_Gain_Decoded
  5798. mov @Temp1, A
  5799. mov Temp1, #Pgm_Gov_I_Gain ; Decode governor I gain
  5800. mov A, @Temp1
  5801. dec A
  5802. mov DPTR, #GOV_GAIN_TABLE
  5803. movc A, @A+DPTR
  5804. mov Temp1, #Pgm_Gov_I_Gain_Decoded
  5805. mov @Temp1, A
  5806. ; Decode startup power
  5807. mov Temp1, #Pgm_Startup_Pwr
  5808. mov A, @Temp1
  5809. dec A
  5810. mov DPTR, #STARTUP_POWER_TABLE
  5811. movc A, @A+DPTR
  5812. mov Temp1, #Pgm_Startup_Pwr_Decoded
  5813. mov @Temp1, A
  5814. IF MODE == 0 ; Main
  5815. ; Decode spoolup time
  5816. mov Temp1, #Pgm_Main_Spoolup_Time
  5817. mov A, @Temp1
  5818. mov Temp1, A ; Store
  5819. jnz ($+3) ; If not zero - branch
  5820. inc Temp1
  5821. clr C
  5822. mov A, Temp1
  5823. subb A, #17 ; Limit to 17 max
  5824. jc ($+4)
  5825. mov Temp1, #17
  5826. mov A, Temp1
  5827. add A, Temp1
  5828. add A, Temp1 ; Now 3x
  5829. mov Main_Spoolup_Time_3x, A
  5830. add A, Main_Spoolup_Time_3x
  5831. add A, Main_Spoolup_Time_3x
  5832. add A, Temp1 ; Now 10x
  5833. mov Main_Spoolup_Time_10x, A
  5834. add A, Main_Spoolup_Time_3x
  5835. add A, Temp1
  5836. add A, Temp1 ; Now 15x
  5837. mov Main_Spoolup_Time_15x, A
  5838. ENDIF
  5839. ; Decode demag compensation
  5840. mov Temp1, #Pgm_Demag_Comp
  5841. mov A, @Temp1
  5842. mov Demag_Pwr_Off_Thresh, #255 ; Set default
  5843. mov Low_Rpm_Pwr_Slope, #12 ; Set default
  5844. cjne A, #2, decode_demag_high
  5845. mov Demag_Pwr_Off_Thresh, #160 ; Settings for demag comp low
  5846. mov Low_Rpm_Pwr_Slope, #10
  5847. decode_demag_high:
  5848. cjne A, #3, decode_demag_done
  5849. mov Demag_Pwr_Off_Thresh, #130 ; Settings for demag comp high
  5850. mov Low_Rpm_Pwr_Slope, #5
  5851. decode_demag_done:
  5852. ; Decode pwm dither
  5853. mov Temp1, #Pgm_Pwm_Dither
  5854. mov A, @Temp1
  5855. dec A
  5856. mov DPTR, #PWM_DITHER_TABLE
  5857. movc A, @A+DPTR
  5858. mov Pwm_Dither_Decoded, A
  5859. call switch_power_off ; Reset DPTR
  5860. ret
  5861. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  5862. ;
  5863. ; Set BEC voltage
  5864. ;
  5865. ; No assumptions
  5866. ;
  5867. ; Sets the BEC output voltage low or high
  5868. ;
  5869. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  5870. set_bec_voltage:
  5871. ; Set bec voltage
  5872. IF HIGH_BEC_VOLTAGE == 1
  5873. Set_BEC_Lo ; Set default to low
  5874. mov Temp1, #Pgm_BEC_Voltage_High
  5875. mov A, @Temp1
  5876. jz set_bec_voltage_exit
  5877. Set_BEC_Hi ; Set to high
  5878. set_bec_voltage_exit:
  5879. ENDIF
  5880. IF HIGH_BEC_VOLTAGE == 2
  5881. Set_BEC_0 ; Set default to low
  5882. mov Temp1, #Pgm_BEC_Voltage_High
  5883. mov A, @Temp1
  5884. cjne A, #1, set_bec_voltage_2
  5885. Set_BEC_1 ; Set to level 1
  5886. set_bec_voltage_2:
  5887. cjne A, #2, set_bec_voltage_exit
  5888. Set_BEC_2 ; Set to level 2
  5889. set_bec_voltage_exit:
  5890. ENDIF
  5891. ret
  5892. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  5893. ;
  5894. ; Find throttle gain
  5895. ;
  5896. ; The difference between max and min throttle must be more than 520us (a Pgm_Ppm_xxx_Throttle difference of 130)
  5897. ;
  5898. ; Finds throttle gain from throttle calibration values
  5899. ;
  5900. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  5901. find_throttle_gain:
  5902. ; Load programmed minimum and maximum throttle
  5903. mov Temp1, #Pgm_Ppm_Min_Throttle
  5904. mov A, @Temp1
  5905. mov Temp3, A
  5906. mov Temp1, #Pgm_Ppm_Max_Throttle
  5907. mov A, @Temp1
  5908. mov Temp4, A
  5909. mov Temp1, #Pgm_Direction ; Check if bidirectional operation
  5910. mov A, @Temp1
  5911. cjne A, #3, find_throttle_gain_check_full
  5912. clr C
  5913. mov A, Temp4
  5914. subb A, #14 ; Compensate for higher deadband in bidirectional
  5915. mov Temp4, A
  5916. find_throttle_gain_check_full:
  5917. ; Check if full range is chosen
  5918. jnb Flags3.FULL_THROTTLE_RANGE, find_throttle_gain_calculate
  5919. mov Temp3, #0
  5920. mov Temp4, #255
  5921. find_throttle_gain_calculate:
  5922. ; Calculate difference
  5923. clr C
  5924. mov A, Temp4
  5925. subb A, Temp3
  5926. mov Temp5, A
  5927. ; Check that difference is minimum 130
  5928. clr C
  5929. subb A, #130
  5930. jnc ($+4)
  5931. mov Temp5, #130
  5932. ; Find gain
  5933. mov Ppm_Throttle_Gain, #0
  5934. test_throttle_gain:
  5935. inc Ppm_Throttle_Gain
  5936. mov A, Temp5
  5937. mov B, Ppm_Throttle_Gain ; A has difference, B has gain
  5938. mul AB
  5939. clr C
  5940. mov A, B
  5941. subb A, #125
  5942. jc test_throttle_gain
  5943. ret
  5944. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  5945. ;
  5946. ; Average throttle
  5947. ;
  5948. ; Outputs result in Temp7
  5949. ;
  5950. ; Averages throttle calibration readings
  5951. ;
  5952. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  5953. average_throttle:
  5954. setb Flags3.FULL_THROTTLE_RANGE ; Set range to 1000-2020us
  5955. call find_throttle_gain ; Set throttle gain
  5956. call wait30ms
  5957. mov Temp3, #0
  5958. mov Temp4, #0
  5959. mov Temp5, #16 ; Average 16 measurments
  5960. average_throttle_meas:
  5961. call wait3ms ; Wait for new RC pulse value
  5962. mov A, New_Rcp ; Get new RC pulse value
  5963. add A, Temp3
  5964. mov Temp3, A
  5965. mov A, #0
  5966. addc A, Temp4
  5967. mov Temp4, A
  5968. djnz Temp5, average_throttle_meas
  5969. mov Temp5, #4 ; Shift 4 times
  5970. average_throttle_div:
  5971. clr C
  5972. mov A, Temp4 ; Shift right
  5973. rrc A
  5974. mov Temp4, A
  5975. mov A, Temp3
  5976. rrc A
  5977. mov Temp3, A
  5978. djnz Temp5, average_throttle_div
  5979. mov Temp7, A ; Copy to Temp7
  5980. clr Flags3.FULL_THROTTLE_RANGE
  5981. call find_throttle_gain ; Set throttle gain
  5982. ret
  5983. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  5984. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  5985. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  5986. ;
  5987. ; Main program start
  5988. ;
  5989. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  5990. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  5991. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  5992. pgm_start:
  5993. ; Check flash lock byte
  5994. mov A, RSTSRC
  5995. jb ACC.6, ($+6) ; Check if flash access error was reset source
  5996. mov Bit_Access, #0 ; No - then this is the first try
  5997. inc Bit_Access
  5998. mov DPTR, #LOCK_BYTE_ADDRESS_16K ; First try is for 16k flash size
  5999. mov A, Bit_Access
  6000. dec A
  6001. jz lock_byte_test
  6002. mov DPTR, #LOCK_BYTE_ADDRESS_8K ; Second try is for 8k flash size
  6003. dec A
  6004. jz lock_byte_test
  6005. lock_byte_test:
  6006. movc A, @A+DPTR ; Read lock byte
  6007. inc A
  6008. jz lock_byte_ok ; If lock byte is 0xFF, then start code execution
  6009. IF ONE_S_CAPABLE == 0
  6010. mov RSTSRC, #12h ; Generate hardware reset and set VDD monitor
  6011. ELSE
  6012. mov RSTSRC, #10h ; Generate hardware reset and disable VDD monitor
  6013. ENDIF
  6014. lock_byte_ok:
  6015. ; Disable the WDT.
  6016. IF SIGNATURE_001 == 0f3h
  6017. anl PCA0MD, #NOT(40h) ; Clear watchdog enable bit
  6018. ENDIF
  6019. IF SIGNATURE_001 == 0f8h
  6020. mov WDTCN, #0DEh ; Disable watchdog
  6021. mov WDTCN, #0ADh
  6022. ENDIF
  6023. ; Initialize stack
  6024. mov SP, #0c0h ; Stack = 64 upper bytes of RAM
  6025. ; Initialize VDD monitor
  6026. orl VDM0CN, #080h ; Enable the VDD monitor
  6027. call wait1ms ; Wait at least 100us
  6028. IF ONE_S_CAPABLE == 0
  6029. mov RSTSRC, #02h ; Set VDD monitor as a reset source (PORSF) if not 1S capable
  6030. ELSE
  6031. mov RSTSRC, #00h ; Do not set VDD monitor as a reset source for 1S ESCSs, in order to avoid resets due to it
  6032. ENDIF
  6033. ; Set clock frequency
  6034. IF SIGNATURE_001 == 0f3h
  6035. orl OSCICN, #03h ; Set clock divider to 1 (not supported on 'f850)
  6036. ENDIF
  6037. IF SIGNATURE_001 == 0f8h
  6038. mov CLKSEL, #00h ; Set clock divider to 1 (not supported on 'f3xx)
  6039. ENDIF
  6040. mov A, OSCICL
  6041. add A, #04h ; 24.5MHz to 24MHz (~0.5% per step)
  6042. jb ACC.7, reset_cal_done ; Is carry (7bit) set? - branch
  6043. mov Bit_Access_Int, A
  6044. IF SIGNATURE_002 <> 010h
  6045. mov A, OSCLCN
  6046. ELSE
  6047. mov A, OSCXCN
  6048. ENDIF
  6049. jb ACC.0, reset_cal_done ; Set if cal aleady done
  6050. mov OSCICL, Bit_Access_Int
  6051. IF SIGNATURE_002 <> 010h
  6052. orl OSCLCN, #01h ; Tag that cal is done
  6053. ELSE
  6054. orl OSCXCN, #01h ; Tag that cal is done
  6055. ENDIF
  6056. reset_cal_done:
  6057. ; Switch power off
  6058. call switch_power_off
  6059. ; Ports initialization
  6060. mov P0, #P0_INIT
  6061. mov P0MDOUT, #P0_PUSHPULL
  6062. mov P0MDIN, #P0_DIGITAL
  6063. mov P0SKIP, #P0_SKIP
  6064. mov P1, #P1_INIT
  6065. mov P1MDOUT, #P1_PUSHPULL
  6066. mov P1MDIN, #P1_DIGITAL
  6067. mov P1SKIP, #P1_SKIP
  6068. IF PORT3_EXIST == 1
  6069. mov P2, #P2_INIT
  6070. ENDIF
  6071. mov P2MDOUT, #P2_PUSHPULL
  6072. IF PORT3_EXIST == 1
  6073. mov P2MDIN, #P2_DIGITAL
  6074. mov P2SKIP, #P2_SKIP
  6075. mov P3, #P3_INIT
  6076. mov P3MDOUT, #P3_PUSHPULL
  6077. mov P3MDIN, #P3_DIGITAL
  6078. ENDIF
  6079. ; Initialize the XBAR and related functionality
  6080. Initialize_Xbar
  6081. ; Clear RAM
  6082. clr A ; Clear accumulator
  6083. mov Temp1, A ; Clear Temp1
  6084. clear_ram:
  6085. mov @Temp1, A ; Clear RAM
  6086. djnz Temp1, clear_ram ; Is A not zero? - jump
  6087. ; Initialize LFSR
  6088. mov Random, #1
  6089. ; Set default programmed parameters
  6090. call set_default_parameters
  6091. ; Read all programmed parameters
  6092. call read_all_eeprom_parameters
  6093. ; Set beep strength
  6094. mov Temp1, #Pgm_Beep_Strength
  6095. mov Beep_Strength, @Temp1
  6096. ; Set initial arm variable
  6097. mov Initial_Arm, #1
  6098. ; Initializing beep
  6099. clr EA ; Disable interrupts explicitly
  6100. call wait200ms
  6101. call beep_f1
  6102. call wait30ms
  6103. call beep_f2
  6104. call wait30ms
  6105. call beep_f3
  6106. call wait30ms
  6107. IF MODE <= 1 ; Main or tail
  6108. ; Wait for receiver to initialize
  6109. call wait1s
  6110. call wait200ms
  6111. call wait200ms
  6112. call wait100ms
  6113. ENDIF
  6114. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  6115. ;
  6116. ; No signal entry point
  6117. ;
  6118. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  6119. init_no_signal:
  6120. ; Disable interrupts explicitly
  6121. clr EA
  6122. ; Check if input signal is high for more than 15ms
  6123. mov Temp1, #250
  6124. input_high_check_1:
  6125. mov Temp2, #250
  6126. input_high_check_2:
  6127. jnb RTX_PORT.RTX_PIN, bootloader_done ; Look for low
  6128. djnz Temp2, input_high_check_2
  6129. djnz Temp1, input_high_check_1
  6130. ljmp 1C00h ; Jump to bootloader
  6131. bootloader_done:
  6132. ; Decode parameters
  6133. call decode_parameters
  6134. ; Decode settings
  6135. call decode_settings
  6136. ; Set BEC voltage
  6137. call set_bec_voltage
  6138. ; Find throttle gain from stored min and max settings
  6139. call find_throttle_gain
  6140. ; Set beep strength
  6141. mov Temp1, #Pgm_Beep_Strength
  6142. mov Beep_Strength, @Temp1
  6143. ; Switch power off
  6144. call switch_power_off
  6145. ; Set clock frequency
  6146. IF MCU_48MHZ == 1
  6147. Set_MCU_Clk_24MHz
  6148. ENDIF
  6149. ; Timer control
  6150. mov TCON, #50h ; Timer0 and timer1 enabled
  6151. ; Timer mode
  6152. mov TMOD, #12h ; Timer0 as 8bit, timer1 as 16bit
  6153. ; Timer2: clk/12 for 128us and 32ms interrupts
  6154. mov TMR2CN, #24h ; Timer2 enabled, low counter interrups enabled
  6155. ; Timer3: clk/12 for commutation timing
  6156. mov TMR3CN, #04h ; Timer3 enabled
  6157. ; PCA
  6158. mov PCA0CN, #40h ; PCA enabled
  6159. ; Enable interrupts
  6160. mov IE, #22h ; Enable timer0 and timer2 interrupts
  6161. mov IP, #02h ; High priority to timer0 interrupts
  6162. mov EIE1, #90h ; Enable timer3 and PCA0 interrupts
  6163. ; Initialize comparator
  6164. mov CPT0CN, #80h ; Comparator enabled, no hysteresis
  6165. mov CPT0MD, #00h ; Comparator response time 100ns
  6166. IF COMP1_USED == 1
  6167. mov CPT1CN, #80h ; Comparator enabled, no hysteresis
  6168. mov CPT1MD, #00h ; Comparator response time 100ns
  6169. ENDIF
  6170. ; Initialize ADC
  6171. Initialize_Adc ; Initialize ADC operation
  6172. call wait1ms
  6173. setb EA ; Enable all interrupts
  6174. ; Measure number of lipo cells
  6175. call Measure_Lipo_Cells ; Measure number of lipo cells
  6176. ; Initialize RC pulse
  6177. Rcp_Int_First ; Enable interrupt and set to first edge
  6178. Rcp_Int_Enable ; Enable interrupt
  6179. Rcp_Clear_Int_Flag ; Clear interrupt flag
  6180. clr Flags2.RCP_EDGE_NO ; Set first edge flag
  6181. call wait200ms
  6182. ; Measure PWM frequency
  6183. measure_pwm_freq_init:
  6184. setb Flags0.RCP_MEAS_PWM_FREQ ; Set measure pwm frequency flag
  6185. mov Temp4, #3 ; Number of attempts before going back to detect input signal
  6186. measure_pwm_freq_start:
  6187. mov Temp3, #12 ; Number of pulses to measure
  6188. measure_pwm_freq_loop:
  6189. ; Check if period diff was accepted
  6190. mov A, Rcp_Period_Diff_Accepted
  6191. jnz measure_pwm_freq_wait
  6192. mov Temp3, #12 ; Reset number of pulses to measure
  6193. djnz Temp4, ($+5) ; If it is not zero - proceed
  6194. ljmp init_no_signal ; Go back to detect input signal
  6195. measure_pwm_freq_wait:
  6196. call wait30ms ; Wait 30ms for new pulse
  6197. jb Flags2.RCP_UPDATED, ($+6) ; Is there an updated RC pulse available - proceed
  6198. ljmp init_no_signal ; Go back to detect input signal
  6199. clr Flags2.RCP_UPDATED ; Flag that pulse has been evaluated
  6200. mov A, New_Rcp ; Load value
  6201. clr C
  6202. subb A, #RCP_VALIDATE ; Higher than validate level?
  6203. jc measure_pwm_freq_start ; No - start over
  6204. mov A, Flags3 ; Check pwm frequency flags
  6205. anl A, #((1 SHL RCP_PWM_FREQ_1KHZ)+(1 SHL RCP_PWM_FREQ_2KHZ)+(1 SHL RCP_PWM_FREQ_4KHZ)+(1 SHL RCP_PWM_FREQ_8KHZ)+(1 SHL RCP_PWM_FREQ_12KHZ))
  6206. mov Prev_Rcp_Pwm_Freq, Curr_Rcp_Pwm_Freq ; Store as previous flags for next pulse
  6207. mov Curr_Rcp_Pwm_Freq, A ; Store current flags for next pulse
  6208. cjne A, Prev_Rcp_Pwm_Freq, measure_pwm_freq_start ; Go back if new flags not same as previous
  6209. djnz Temp3, measure_pwm_freq_loop ; Go back if not required number of pulses seen
  6210. ; Clear measure pwm frequency flag
  6211. clr Flags0.RCP_MEAS_PWM_FREQ
  6212. ; Set up RC pulse interrupts after pwm frequency measurement
  6213. Rcp_Int_First ; Enable interrupt and set to first edge
  6214. Rcp_Clear_Int_Flag ; Clear interrupt flag
  6215. clr Flags2.RCP_EDGE_NO ; Set first edge flag
  6216. mov Temp1, #Pgm_Enable_PWM_Input ; Check if PWM input is enabled
  6217. mov A, @Temp1
  6218. jnz test_for_oneshot ; If it is - proceed
  6219. setb Flags2.RCP_PPM ; Set PPM flag
  6220. mov A, Flags3 ; Clear pwm frequency flags
  6221. anl A, #NOT((1 SHL RCP_PWM_FREQ_1KHZ)+(1 SHL RCP_PWM_FREQ_2KHZ)+(1 SHL RCP_PWM_FREQ_4KHZ)+(1 SHL RCP_PWM_FREQ_8KHZ)+(1 SHL RCP_PWM_FREQ_12KHZ))
  6222. mov Flags3, A
  6223. test_for_oneshot:
  6224. ; Test whether signal is OneShot125
  6225. clr Flags2.RCP_PPM_ONESHOT125 ; Clear OneShot125 flag
  6226. mov Rcp_Outside_Range_Cnt, #0 ; Reset out of range counter
  6227. call wait100ms ; Wait for new RC pulse
  6228. jnb Flags2.RCP_PPM, validate_rcp_start ; If flag is not set (PWM) - branch
  6229. clr C
  6230. mov A, Rcp_Outside_Range_Cnt ; Check how many pulses were outside normal PPM range (800-2160us)
  6231. subb A, #10
  6232. jc validate_rcp_start
  6233. setb Flags2.RCP_PPM_ONESHOT125 ; Set OneShot125 flag
  6234. ; Validate RC pulse
  6235. validate_rcp_start:
  6236. call wait3ms ; Wait for next pulse (NB: Uses Temp1/2!)
  6237. mov Temp1, #RCP_VALIDATE ; Set validate level as default
  6238. jnb Flags2.RCP_PPM, ($+5) ; If flag is not set (PWM) - branch
  6239. mov Temp1, #0 ; Set level to zero for PPM (any level will be accepted)
  6240. clr C
  6241. mov A, New_Rcp ; Load value
  6242. subb A, Temp1 ; Higher than validate level?
  6243. jc validate_rcp_start ; No - start over
  6244. ; Beep arm sequence start signal
  6245. clr EA ; Disable all interrupts
  6246. call beep_f1 ; Signal that RC pulse is ready
  6247. call beep_f1
  6248. call beep_f1
  6249. setb EA ; Enable all interrupts
  6250. call wait200ms
  6251. ; Arming sequence start
  6252. mov Gov_Arm_Target, #0 ; Clear governor arm target
  6253. arming_start:
  6254. IF MODE >= 1 ; Tail or multi
  6255. mov Temp1, #Pgm_Direction ; Check if bidirectional operation
  6256. mov A, @Temp1
  6257. cjne A, #3, ($+5)
  6258. ajmp program_by_tx_checked ; Disable tx programming if bidirectional operation
  6259. ENDIF
  6260. call wait3ms
  6261. mov Temp1, #Pgm_Enable_TX_Program; Start programming mode entry if enabled
  6262. mov A, @Temp1
  6263. clr C
  6264. subb A, #1 ; Is TX programming enabled?
  6265. jnc arming_initial_arm_check ; Yes - proceed
  6266. jmp program_by_tx_checked ; No - branch
  6267. arming_initial_arm_check:
  6268. mov A, Initial_Arm ; Yes - check if it is initial arm sequence
  6269. clr C
  6270. subb A, #1 ; Is it the initial arm sequence?
  6271. jnc arming_ppm_check ; Yes - proceed
  6272. jmp program_by_tx_checked ; No - branch
  6273. arming_ppm_check:
  6274. jb Flags2.RCP_PPM, throttle_high_cal_start ; If flag is set (PPM) - branch
  6275. ; PWM tx program entry
  6276. clr C
  6277. mov A, New_Rcp ; Load new RC pulse value
  6278. subb A, #RCP_MAX ; Is RC pulse max?
  6279. jnc program_by_tx_entry_pwm ; Yes - proceed
  6280. jmp program_by_tx_checked ; No - branch
  6281. program_by_tx_entry_pwm:
  6282. clr EA ; Disable all interrupts
  6283. call beep_f4
  6284. setb EA ; Enable all interrupts
  6285. call wait100ms
  6286. clr C
  6287. mov A, New_Rcp ; Load new RC pulse value
  6288. subb A, #RCP_STOP ; Below stop?
  6289. jnc program_by_tx_entry_pwm ; No - start over
  6290. program_by_tx_entry_wait_pwm:
  6291. clr EA ; Disable all interrupts
  6292. call beep_f1
  6293. call wait10ms
  6294. call beep_f1
  6295. setb EA ; Enable all interrupts
  6296. call wait100ms
  6297. clr C
  6298. mov A, New_Rcp ; Load new RC pulse value
  6299. subb A, #RCP_MAX ; At or above max?
  6300. jc program_by_tx_entry_wait_pwm ; No - start over
  6301. jmp program_by_tx ; Yes - enter programming mode
  6302. ; PPM throttle calibration and tx program entry
  6303. throttle_high_cal_start:
  6304. IF MODE <= 1 ; Main or tail
  6305. mov Temp8, #5 ; Set 3 seconds wait time
  6306. ELSE
  6307. mov Temp8, #2 ; Set 1 seconds wait time
  6308. ENDIF
  6309. throttle_high_cal:
  6310. setb Flags3.FULL_THROTTLE_RANGE ; Set range to 1000-2020us
  6311. call find_throttle_gain ; Set throttle gain
  6312. call wait100ms ; Wait for new throttle value
  6313. clr EA ; Disable interrupts (freeze New_Rcp value)
  6314. clr Flags3.FULL_THROTTLE_RANGE ; Set programmed range
  6315. call find_throttle_gain ; Set throttle gain
  6316. mov Temp7, New_Rcp ; Store new RC pulse value
  6317. clr C
  6318. mov A, New_Rcp ; Load new RC pulse value
  6319. subb A, #(RCP_MAX/2) ; Is RC pulse above midstick?
  6320. setb EA ; Enable interrupts
  6321. jc arm_target_updated ; No - branch
  6322. call wait1ms
  6323. clr EA ; Disable all interrupts
  6324. call beep_f4
  6325. setb EA ; Enable all interrupts
  6326. djnz Temp8, throttle_high_cal ; Continue to wait
  6327. call average_throttle
  6328. clr C
  6329. mov A, Temp7 ; Limit to max 250
  6330. subb A, #5 ; Subtract about 2% and ensure that it is 250 or lower
  6331. mov Temp1, #Pgm_Ppm_Max_Throttle ; Store
  6332. mov @Temp1, A
  6333. call wait200ms
  6334. call erase_and_store_all_in_eeprom
  6335. call success_beep
  6336. throttle_low_cal_start:
  6337. mov Temp8, #10 ; Set 3 seconds wait time
  6338. throttle_low_cal:
  6339. setb Flags3.FULL_THROTTLE_RANGE ; Set range to 1000-2020us
  6340. call find_throttle_gain ; Set throttle gain
  6341. call wait100ms
  6342. clr EA ; Disable interrupts (freeze New_Rcp value)
  6343. clr Flags3.FULL_THROTTLE_RANGE ; Set programmed range
  6344. call find_throttle_gain ; Set throttle gain
  6345. mov Temp7, New_Rcp ; Store new RC pulse value
  6346. clr C
  6347. mov A, New_Rcp ; Load new RC pulse value
  6348. subb A, #(RCP_MAX/2) ; Below midstick?
  6349. setb EA ; Enable interrupts
  6350. jnc throttle_low_cal_start ; No - start over
  6351. call wait1ms
  6352. clr EA ; Disable all interrupts
  6353. call beep_f1
  6354. call wait10ms
  6355. call beep_f1
  6356. setb EA ; Enable all interrupts
  6357. djnz Temp8, throttle_low_cal ; Continue to wait
  6358. call average_throttle
  6359. mov A, Temp7
  6360. add A, #5 ; Add about 2%
  6361. mov Temp1, #Pgm_Ppm_Min_Throttle ; Store
  6362. mov @Temp1, A
  6363. call wait200ms
  6364. call erase_and_store_all_in_eeprom
  6365. call success_beep_inverted
  6366. program_by_tx_entry_wait_ppm:
  6367. call wait100ms
  6368. call find_throttle_gain ; Set throttle gain
  6369. clr C
  6370. mov A, New_Rcp ; Load new RC pulse value
  6371. subb A, #RCP_MAX ; At or above max?
  6372. jnc ($+4)
  6373. ajmp arming_ppm_check ; No - go back
  6374. jmp program_by_tx ; Yes - enter programming mode
  6375. program_by_tx_checked:
  6376. clr C
  6377. mov A, New_Rcp ; Load new RC pulse value
  6378. subb A, Gov_Arm_Target ; Is RC pulse larger than arm target?
  6379. jc arm_target_updated ; No - do not update
  6380. mov Gov_Arm_Target, New_Rcp ; Yes - update arm target
  6381. arm_target_updated:
  6382. call wait100ms ; Wait for new throttle value
  6383. mov Temp1, #RCP_STOP ; Default stop value
  6384. mov Temp2, #Pgm_Direction ; Check if bidirectional operation
  6385. mov A, @Temp2
  6386. cjne A, #3, ($+5) ; No - branch
  6387. mov Temp1, #(RCP_STOP+4) ; Higher stop value for bidirectional
  6388. clr C
  6389. mov A, New_Rcp ; Load new RC pulse value
  6390. subb A, Temp1 ; Below stop?
  6391. jc arm_end_beep ; Yes - proceed
  6392. jmp arming_start ; No - start over
  6393. arm_end_beep:
  6394. ; Beep arm sequence end signal
  6395. clr EA ; Disable all interrupts
  6396. call beep_f4 ; Signal that rcpulse is ready
  6397. call beep_f4
  6398. call beep_f4
  6399. setb EA ; Enable all interrupts
  6400. call wait200ms
  6401. ; Clear initial arm variable
  6402. mov Initial_Arm, #0
  6403. ; Armed and waiting for power on
  6404. wait_for_power_on:
  6405. clr A
  6406. mov Power_On_Wait_Cnt_L, A ; Clear wait counter
  6407. mov Power_On_Wait_Cnt_H, A
  6408. wait_for_power_on_loop:
  6409. inc Power_On_Wait_Cnt_L ; Increment low wait counter
  6410. mov A, Power_On_Wait_Cnt_L
  6411. cpl A
  6412. jnz wait_for_power_on_no_beep; Counter wrapping (about 1 sec)?
  6413. inc Power_On_Wait_Cnt_H ; Increment high wait counter
  6414. mov Temp1, #Pgm_Beacon_Delay
  6415. mov A, @Temp1
  6416. mov Temp1, #25 ; Approximately 1 min
  6417. dec A
  6418. jz beep_delay_set
  6419. mov Temp1, #50 ; Approximately 2 min
  6420. dec A
  6421. jz beep_delay_set
  6422. mov Temp1, #125 ; Approximately 5 min
  6423. dec A
  6424. jz beep_delay_set
  6425. mov Temp1, #250 ; Approximately 10 min
  6426. dec A
  6427. jz beep_delay_set
  6428. mov Power_On_Wait_Cnt_H, #0 ; Reset counter for infinite delay
  6429. beep_delay_set:
  6430. clr C
  6431. mov A, Power_On_Wait_Cnt_H
  6432. subb A, Temp1 ; Check against chosen delay
  6433. jc wait_for_power_on_no_beep; Has delay elapsed?
  6434. dec Power_On_Wait_Cnt_H ; Decrement high wait counter
  6435. mov Power_On_Wait_Cnt_L, #180; Set low wait counter
  6436. mov Temp1, #Pgm_Beacon_Strength
  6437. mov Beep_Strength, @Temp1
  6438. clr EA ; Disable all interrupts
  6439. call beep_f4 ; Signal that there is no signal
  6440. setb EA ; Enable all interrupts
  6441. mov Temp1, #Pgm_Beep_Strength
  6442. mov Beep_Strength, @Temp1
  6443. call wait100ms ; Wait for new RC pulse to be measured
  6444. wait_for_power_on_no_beep:
  6445. call wait10ms
  6446. mov A, Rcp_Timeout_Cntd ; Load RC pulse timeout counter value
  6447. jnz wait_for_power_on_ppm_not_missing ; If it is not zero - proceed
  6448. jnb Flags2.RCP_PPM, wait_for_power_on_ppm_not_missing ; If flag is not set (PWM) - branch
  6449. jmp init_no_signal ; If ppm and pulses missing - go back to detect input signal
  6450. wait_for_power_on_ppm_not_missing:
  6451. mov Temp1, #RCP_STOP
  6452. jb Flags2.RCP_PPM, ($+5) ; If flag is set (PPM) - branch
  6453. mov Temp1, #(RCP_STOP+5) ; Higher than stop (for pwm)
  6454. clr C
  6455. mov A, New_Rcp ; Load new RC pulse value
  6456. subb A, Temp1 ; Higher than stop (plus some hysteresis)?
  6457. jc wait_for_power_on_loop ; No - start over
  6458. IF MODE >= 1 ; Tail or multi
  6459. mov Temp1, #Pgm_Direction ; Check if bidirectional operation
  6460. mov A, @Temp1
  6461. clr C
  6462. subb A, #3
  6463. jz wait_for_power_on_check_timeout ; Do not wait if bidirectional operation
  6464. ENDIF
  6465. lcall wait100ms ; Wait to see if start pulse was only a glitch
  6466. wait_for_power_on_check_timeout:
  6467. mov A, Rcp_Timeout_Cntd ; Load RC pulse timeout counter value
  6468. jnz ($+5) ; If it is not zero - proceed
  6469. ljmp init_no_signal ; If it is zero (pulses missing) - go back to detect input signal
  6470. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  6471. ;
  6472. ; Start entry point
  6473. ;
  6474. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  6475. init_start:
  6476. clr EA
  6477. call switch_power_off
  6478. clr A
  6479. mov Requested_Pwm, A ; Set requested pwm to zero
  6480. mov Governor_Req_Pwm, A ; Set governor requested pwm to zero
  6481. mov Current_Pwm, A ; Set current pwm to zero
  6482. mov Current_Pwm_Limited, A ; Set limited current pwm to zero
  6483. mov Current_Pwm_Lim_Dith, A
  6484. mov Pwm_Dither_Excess_Power, A
  6485. setb EA
  6486. mov Temp1, #Pgm_Motor_Idle ; Set idle pwm to programmed value
  6487. mov A, @Temp1
  6488. clr C
  6489. rlc A
  6490. mov Pwm_Motor_Idle, A
  6491. clr A
  6492. mov Gov_Target_L, A ; Set target to zero
  6493. mov Gov_Target_H, A
  6494. mov Gov_Integral_L, A ; Set integral to zero
  6495. mov Gov_Integral_H, A
  6496. mov Gov_Integral_X, A
  6497. mov Adc_Conversion_Cnt, A
  6498. mov Flags0, A ; Clear flags0
  6499. mov Flags1, A ; Clear flags1
  6500. mov Demag_Detected_Metric, A ; Clear demag metric
  6501. ;**** **** **** **** ****
  6502. ; Motor start beginning
  6503. ;**** **** **** **** ****
  6504. mov Adc_Conversion_Cnt, #TEMP_CHECK_RATE ; Make sure a temp reading is done
  6505. Set_Adc_Ip_Temp
  6506. call wait1ms
  6507. call start_adc_conversion
  6508. read_initial_temp:
  6509. Get_Adc_Status
  6510. jb AD0BUSY, read_initial_temp
  6511. Read_Adc_Result ; Read initial temperature
  6512. mov A, Temp2
  6513. jnz ($+3) ; Is reading below 256?
  6514. mov Temp1, A ; Yes - set average temperature value to zero
  6515. mov Current_Average_Temp, Temp1 ; Set initial average temperature
  6516. call check_temp_voltage_and_limit_power
  6517. mov Adc_Conversion_Cnt, #TEMP_CHECK_RATE ; Make sure a temp reading is done next time
  6518. Set_Adc_Ip_Temp
  6519. ; Set up start operating conditions
  6520. mov Temp1, #Pgm_Pwm_Freq
  6521. mov A, @Temp1
  6522. mov Temp7, A ; Store setting in Temp7
  6523. mov @Temp1, #2 ; Set nondamped low frequency pwm mode
  6524. call decode_parameters ; (Decode_parameters uses Temp1 and Temp8)
  6525. mov Temp1, #Pgm_Pwm_Freq
  6526. mov A, Temp7
  6527. mov @Temp1, A ; Restore settings
  6528. ; Set max allowed power
  6529. clr EA ; Disable interrupts to avoid that Requested_Pwm is overwritten
  6530. mov Pwm_Limit, #0FFh ; Set pwm limit to max
  6531. call set_startup_pwm
  6532. mov Pwm_Limit, Requested_Pwm
  6533. mov Pwm_Limit_Spoolup, Requested_Pwm
  6534. mov Pwm_Limit_By_Rpm, Requested_Pwm
  6535. setb EA
  6536. mov Requested_Pwm, #1 ; Set low pwm again after calling set_startup_pwm
  6537. mov Current_Pwm, #1
  6538. mov Current_Pwm_Limited, #1
  6539. mov Current_Pwm_Lim_Dith, #1
  6540. mov Spoolup_Limit_Cnt, Auto_Bailout_Armed
  6541. mov Spoolup_Limit_Skip, #1
  6542. ; Begin startup sequence
  6543. IF MCU_48MHZ == 1
  6544. Set_MCU_Clk_48MHz
  6545. ENDIF
  6546. mov Temp1, #Pgm_Direction ; Check if bidirectional operation
  6547. mov A, @Temp1
  6548. cjne A, #3, init_start_bidir_done
  6549. clr Flags3.PGM_DIR_REV ; Set spinning direction. Default fwd
  6550. jnb Flags2.RCP_DIR_REV, ($+5) ; Check force direction
  6551. setb Flags3.PGM_DIR_REV ; Set spinning direction
  6552. init_start_bidir_done:
  6553. setb Flags1.MOTOR_SPINNING ; Set motor spinning flag
  6554. setb Flags1.STARTUP_PHASE ; Set startup phase flag
  6555. mov Startup_Cnt, #0 ; Reset counter
  6556. call comm5comm6 ; Initialize commutation
  6557. call comm6comm1
  6558. call initialize_timing ; Initialize timing
  6559. call calc_next_comm_timing ; Set virtual commutation point
  6560. call initialize_timing ; Initialize timing
  6561. call calc_next_comm_timing
  6562. call initialize_timing ; Initialize timing
  6563. jmp run1
  6564. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  6565. ;
  6566. ; Run entry point
  6567. ;
  6568. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  6569. damped_transition:
  6570. ; Transition from nondamped to damped if applicable
  6571. clr EA
  6572. call decode_parameters ; Set programmed parameters
  6573. setb EA
  6574. mov Adc_Conversion_Cnt, #0 ; Make sure a voltage reading is done next time
  6575. Set_Adc_Ip_Volt ; Set adc measurement to voltage
  6576. ; Run 1 = B(p-on) + C(n-pwm) - comparator A evaluated
  6577. ; Out_cA changes from low to high
  6578. run1:
  6579. call wait_for_comp_out_high ; Wait zero cross wait and wait for high
  6580. ; setup_comm_wait ; Setup wait time from zero cross to commutation
  6581. ; evaluate_comparator_integrity ; Check whether comparator reading has been normal
  6582. call calc_governor_target ; Calculate governor target
  6583. call wait_for_comm ; Wait from zero cross to commutation
  6584. call comm1comm2 ; Commutate
  6585. call calc_next_comm_timing ; Calculate next timing and start advance timing wait
  6586. ; wait_advance_timing ; Wait advance timing and start zero cross wait
  6587. ; calc_new_wait_times
  6588. ; wait_before_zc_scan ; Wait zero cross wait and start zero cross timeout
  6589. ; Run 2 = A(p-on) + C(n-pwm) - comparator B evaluated
  6590. ; Out_cB changes from high to low
  6591. run2:
  6592. call wait_for_comp_out_low
  6593. ; setup_comm_wait
  6594. ; evaluate_comparator_integrity
  6595. jnb Flags1.GOV_ACTIVE, ($+6)
  6596. lcall calc_governor_prop_error
  6597. jb Flags0.HIGH_RPM, ($+6) ; Skip if high rpm
  6598. lcall set_pwm_limit_low_rpm
  6599. jnb Flags0.HIGH_RPM, ($+6) ; Do if high rpm
  6600. lcall set_pwm_limit_high_rpm
  6601. call wait_for_comm
  6602. call comm2comm3
  6603. call calc_next_comm_timing
  6604. ; wait_advance_timing
  6605. ; calc_new_wait_times
  6606. ; wait_before_zc_scan
  6607. ; Run 3 = A(p-on) + B(n-pwm) - comparator C evaluated
  6608. ; Out_cC changes from low to high
  6609. run3:
  6610. call wait_for_comp_out_high
  6611. ; setup_comm_wait
  6612. ; evaluate_comparator_integrity
  6613. jnb Flags1.GOV_ACTIVE, ($+6)
  6614. lcall calc_governor_int_error
  6615. call wait_for_comm
  6616. call comm3comm4
  6617. call calc_next_comm_timing
  6618. ; wait_advance_timing
  6619. ; calc_new_wait_times
  6620. ; wait_before_zc_scan
  6621. ; Run 4 = C(p-on) + B(n-pwm) - comparator A evaluated
  6622. ; Out_cA changes from high to low
  6623. run4:
  6624. call wait_for_comp_out_low
  6625. ; setup_comm_wait
  6626. ; evaluate_comparator_integrity
  6627. jnb Flags1.GOV_ACTIVE, ($+6)
  6628. lcall calc_governor_prop_correction
  6629. call wait_for_comm
  6630. call comm4comm5
  6631. call calc_next_comm_timing
  6632. ; wait_advance_timing
  6633. ; calc_new_wait_times
  6634. ; wait_before_zc_scan
  6635. ; Run 5 = C(p-on) + A(n-pwm) - comparator B evaluated
  6636. ; Out_cB changes from low to high
  6637. run5:
  6638. call wait_for_comp_out_high
  6639. ; setup_comm_wait
  6640. ; evaluate_comparator_integrity
  6641. jnb Flags1.GOV_ACTIVE, ($+6)
  6642. lcall calc_governor_int_correction
  6643. call wait_for_comm
  6644. call comm5comm6
  6645. call calc_next_comm_timing
  6646. ; wait_advance_timing
  6647. ; calc_new_wait_times
  6648. ; wait_before_zc_scan
  6649. ; Run 6 = B(p-on) + A(n-pwm) - comparator C evaluated
  6650. ; Out_cC changes from high to low
  6651. run6:
  6652. call start_adc_conversion
  6653. call wait_for_comp_out_low
  6654. ; setup_comm_wait
  6655. ; evaluate_comparator_integrity
  6656. call wait_for_comm
  6657. call comm6comm1
  6658. call check_temp_voltage_and_limit_power
  6659. call calc_next_comm_timing
  6660. ; wait_advance_timing
  6661. ; calc_new_wait_times
  6662. ; wait_before_zc_scan
  6663. ; Check if it is direct startup
  6664. jnb Flags1.STARTUP_PHASE, normal_run_checks
  6665. jb Flags1.DIR_CHANGE_BRAKE, normal_run_checks ; If a direction change - branch
  6666. ; Set spoolup power variables
  6667. mov Pwm_Limit, Pwm_Spoolup_Beg ; Set initial max power
  6668. mov Pwm_Limit_Spoolup, Pwm_Spoolup_Beg ; Set initial slow spoolup power
  6669. mov Spoolup_Limit_Cnt, Auto_Bailout_Armed
  6670. mov Spoolup_Limit_Skip, #1
  6671. ; Check startup counter
  6672. mov Temp2, #24 ; Set nominal startup parameters
  6673. mov Temp3, #12
  6674. clr C
  6675. mov A, Startup_Cnt ; Load counter
  6676. subb A, Temp2 ; Is counter above requirement?
  6677. jc direct_start_check_rcp ; No - proceed
  6678. clr Flags1.STARTUP_PHASE ; Clear startup phase flag
  6679. setb Flags1.INITIAL_RUN_PHASE ; Set initial run phase flag
  6680. mov Initial_Run_Rot_Cnt, Temp3 ; Set initial run rotation count
  6681. IF MODE == 1 ; Tail
  6682. mov Pwm_Limit, #0FFh ; Allow full power
  6683. ENDIF
  6684. IF MODE == 2 ; Multi
  6685. mov Pwm_Limit, Pwm_Spoolup_Beg
  6686. mov Pwm_Limit_By_Rpm, Pwm_Spoolup_Beg
  6687. ENDIF
  6688. jmp normal_run_checks
  6689. direct_start_check_rcp:
  6690. clr C
  6691. mov A, New_Rcp ; Load new pulse value
  6692. subb A, #RCP_STOP ; Check if pulse is below stop value
  6693. jc ($+5)
  6694. ljmp run1 ; Continue to run
  6695. jmp run_to_wait_for_power_on
  6696. normal_run_checks:
  6697. ; Check if it is initial run phase
  6698. jnb Flags1.INITIAL_RUN_PHASE, initial_run_phase_done ; If not initial run phase - branch
  6699. jb Flags1.DIR_CHANGE_BRAKE, initial_run_phase_done ; If a direction change - branch
  6700. ; Decrement startup rotaton count
  6701. mov A, Initial_Run_Rot_Cnt
  6702. dec A
  6703. ; Check number of nondamped rotations
  6704. jnz normal_run_check_startup_rot ; Branch if counter is not zero
  6705. clr Flags1.INITIAL_RUN_PHASE ; Clear initial run phase flag
  6706. jmp damped_transition ; Do damped transition if counter is zero
  6707. normal_run_check_startup_rot:
  6708. mov Initial_Run_Rot_Cnt, A ; Not zero - store counter
  6709. clr C
  6710. mov A, New_Rcp ; Load new pulse value
  6711. subb A, #RCP_STOP ; Check if pulse is below stop value
  6712. jc ($+5)
  6713. ljmp run1 ; Continue to run
  6714. jmp run_to_wait_for_power_on
  6715. initial_run_phase_done:
  6716. ; Reset stall count
  6717. mov Stall_Cnt, #0
  6718. IF MODE == 0 ; Main
  6719. ; Check if throttle is zeroed
  6720. clr C
  6721. mov A, Rcp_Stop_Cnt ; Load stop RC pulse counter value
  6722. subb A, #1 ; Is number of stop RC pulses above limit?
  6723. jc run6_check_rcp_stop_count ; If no - branch
  6724. mov Pwm_Limit_Spoolup, Pwm_Spoolup_Beg ; If yes - set initial max powers
  6725. mov Spoolup_Limit_Cnt, Auto_Bailout_Armed ; And set spoolup parameters
  6726. mov Spoolup_Limit_Skip, #1
  6727. run6_check_rcp_stop_count:
  6728. ENDIF
  6729. ; Exit run loop after a given time
  6730. clr C
  6731. mov A, Rcp_Stop_Cnt ; Load stop RC pulse counter low byte value
  6732. mov Temp1, #RCP_STOP_LIMIT
  6733. subb A, Temp1 ; Is number of stop RC pulses above limit?
  6734. jnc run_to_wait_for_power_on ; Yes, go back to wait for poweron
  6735. jnb Flags2.RCP_PPM, run6_check_dir; If flag is not set (PWM) - branch
  6736. mov A, Rcp_Timeout_Cntd ; Load RC pulse timeout counter value
  6737. jz run_to_wait_for_power_on ; If it is zero - go back to wait for poweron
  6738. run6_check_dir:
  6739. IF MODE >= 1 ; Tail or multi
  6740. mov Temp1, #Pgm_Direction ; Check if bidirectional operation
  6741. mov A, @Temp1
  6742. cjne A, #3, run6_check_speed
  6743. jb Flags3.PGM_DIR_REV, run6_check_dir_rev ; Check if actual rotation direction
  6744. jb Flags2.RCP_DIR_REV, run6_check_dir_change ; Matches force direction
  6745. ajmp run6_check_speed
  6746. run6_check_dir_rev:
  6747. jnb Flags2.RCP_DIR_REV, run6_check_dir_change
  6748. ajmp run6_check_speed
  6749. run6_check_dir_change:
  6750. jb Flags1.DIR_CHANGE_BRAKE, run6_check_speed
  6751. setb Flags1.DIR_CHANGE_BRAKE ; Set brake flag
  6752. mov Pwm_Limit, Pwm_Spoolup_Beg ; Set max power while braking
  6753. jmp run4 ; Go back to run 4, thereby changing force direction
  6754. run6_check_speed:
  6755. ENDIF
  6756. mov Temp1, #0F0h ; Default minimum speed
  6757. jnb Flags1.DIR_CHANGE_BRAKE, run6_brake_done; Is it a direction change?
  6758. mov Pwm_Limit, Pwm_Spoolup_Beg ; Set max power while braking
  6759. mov Temp1, #20h ; Bidirectional braking termination speed
  6760. run6_brake_done:
  6761. clr C
  6762. mov A, Comm_Period4x_H ; Is Comm_Period4x more than 32ms (~1220 eRPM)?
  6763. subb A, Temp1
  6764. jnc ($+4) ; Yes - stop or turn direction
  6765. ajmp run1 ; No - go back to run 1
  6766. IF MODE >= 1 ; Tail or multi
  6767. jnb Flags1.DIR_CHANGE_BRAKE, run_to_wait_for_power_on ; If it is not a direction change - stop
  6768. clr Flags1.DIR_CHANGE_BRAKE ; Clear brake flag
  6769. clr Flags3.PGM_DIR_REV ; Set spinning direction. Default fwd
  6770. jnb Flags2.RCP_DIR_REV, ($+5) ; Check force direction
  6771. setb Flags3.PGM_DIR_REV ; Set spinning direction
  6772. setb Flags1.INITIAL_RUN_PHASE
  6773. mov Initial_Run_Rot_Cnt, #18
  6774. mov Pwm_Limit, Pwm_Spoolup_Beg ; Set initial max power
  6775. ajmp run1 ; Go back to run 1
  6776. ENDIF
  6777. run_to_wait_for_power_on_fail:
  6778. inc Stall_Cnt ; Increment stall count
  6779. mov A, New_Rcp ; Check if RCP is zero, then it is a normal stop
  6780. jz run_to_wait_for_power_on
  6781. ajmp run_to_wait_for_power_on_stall_done
  6782. run_to_wait_for_power_on:
  6783. mov Stall_Cnt, #0
  6784. run_to_wait_for_power_on_stall_done:
  6785. clr EA
  6786. call switch_power_off
  6787. mov Temp1, #Pgm_Pwm_Freq
  6788. mov A, @Temp1
  6789. mov Temp7, A ; Store setting in Temp7
  6790. mov @Temp1, #2 ; Set low pwm mode (in order to turn off damping)
  6791. call decode_parameters ; (Decode_parameters uses Temp1 and Temp8)
  6792. mov Temp1, #Pgm_Pwm_Freq
  6793. mov A, Temp7
  6794. mov @Temp1, A ; Restore settings
  6795. clr A
  6796. mov Requested_Pwm, A ; Set requested pwm to zero
  6797. mov Governor_Req_Pwm, A ; Set governor requested pwm to zero
  6798. mov Current_Pwm, A ; Set current pwm to zero
  6799. mov Current_Pwm_Limited, A ; Set limited current pwm to zero
  6800. mov Current_Pwm_Lim_Dith, A
  6801. mov Pwm_Motor_Idle, A ; Set motor idle to zero
  6802. clr Flags1.MOTOR_SPINNING ; Clear motor spinning flag
  6803. IF MCU_48MHZ == 1
  6804. Set_MCU_Clk_24MHz
  6805. ENDIF
  6806. setb EA
  6807. call wait1ms ; Wait for pwm to be stopped
  6808. call switch_power_off
  6809. IF MODE == 0 ; Main
  6810. jnb Flags2.RCP_PPM, run_to_next_state_main ; If flag is not set (PWM) - branch
  6811. mov A, Rcp_Timeout_Cntd ; Load RC pulse timeout counter value
  6812. jnz run_to_next_state_main ; If it is not zero - branch
  6813. jmp init_no_signal ; If it is zero (pulses missing) - go back to detect input signal
  6814. run_to_next_state_main:
  6815. mov Temp1, #Pgm_Main_Rearm_Start
  6816. mov A, @Temp1
  6817. clr C
  6818. subb A, #1 ; Is re-armed start enabled?
  6819. jc jmp_wait_for_power_on ; No - do like tail and start immediately
  6820. jmp validate_rcp_start ; Yes - go back to validate RC pulse
  6821. jmp_wait_for_power_on:
  6822. jmp wait_for_power_on ; Go back to wait for power on
  6823. ENDIF
  6824. IF MODE >= 1 ; Tail or multi
  6825. jnb Flags2.RCP_PPM, jmp_wait_for_power_on ; If flag is not set (PWM) - branch
  6826. clr C
  6827. mov A, Stall_Cnt
  6828. subb A, #5
  6829. jc jmp_wait_for_power_on
  6830. jmp init_no_signal
  6831. jmp_wait_for_power_on:
  6832. jmp wait_for_power_on ; Go back to wait for power on
  6833. ENDIF
  6834. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  6835. $include (BLHeliTxPgm.inc) ; Include source code for programming the ESC with the TX
  6836. $include (BLHeliBootLoad.inc) ; Include source code for bootloader
  6837. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  6838. CSEG AT 19FDh
  6839. reset:
  6840. ljmp pgm_start
  6841. END