Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. ;throttle_op_set.inc
  2.  
  3. .NOLIST
  4.  
  5. ;  ***************************************************************************************
  6. ;  * PWM MODEL RAILROAD THROTTLE                                                          *
  7. ;  *                                                                                      *
  8. ;  * WRITTEN BY:  PHILIP DEVRIES                                                          *
  9. ;  *                                                                                      *
  10. ;  *  Copyright (C) 2003 Philip DeVries                                                   *
  11. ;  *                                                                                      *
  12. ;  *  This program is free software; you can redistribute it and/or modify                *
  13. ;  *  it under the terms of the GNU General Public License as published by                *
  14. ;  *  the Free Software Foundation; either version 2 of the License, or                   *
  15. ;  *  (at your option) any later version.                                                 *
  16. ;  *                                                                                      *
  17. ;  *  This program is distributed in the hope that it will be useful,                     *
  18. ;  *  but WITHOUT ANY WARRANTY; without even the implied warranty of                      *
  19. ;  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                       *
  20. ;  *  GNU General Public License for more details.                                        *
  21. ;  *                                                                                      *
  22. ;  *  You should have received a copy of the GNU General Public License                   *
  23. ;  *  along with this program; if not, write to the Free Software                         *
  24. ;  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA           *
  25. ;  *                                                                                      *
  26. ;  ***************************************************************************************
  27.  
  28. ;*********************************************************
  29. ;* Operation Settings                                    *
  30. ;*********************************************************
  31.  
  32.  
  33.  
  34. ;*********************************************************
  35. ;* Compile time options
  36. ;*********************************************************
  37. .define TRADITIONAL_ENABLED            ; A traditional throttle.  NOT
  38.                                        ; a dcc decoder
  39.  
  40.    .define WALKAROUND_ENABLED          ; Removable, walkaround throttle
  41.                                        ; (Does nothing unless the
  42.                                        ;  TRADITIONAL_ENABLED is also defined)
  43.  
  44.    .define THROTTLE_LOWPASS_ENABLED    ; Lowpass filter on throttle handle
  45.                                        ; (Does nothing unless the
  46.                                        ;  TRADITIONAL_ENABLED is also defined)
  47.  
  48.    .define MOMENTUM_LOWPASS_ENABLED    ; Lowpass filter on momentum handle
  49.                                        ; (Does nothing unless the
  50.                                        ;  TRADITIONAL_ENABLED and
  51.                                        ;  MOMENTUM_ENABLED are defined)
  52.  
  53.    .define SWITCH_LOWPASS_ENABLED      ; Lowpass filter on direction switches
  54.  
  55.    .define LEDS_ENABLED                ; Acceleration/Deceleration indicators
  56.                                        ; (Does nothing unless the
  57.                                        ;  TRADITIONAL_ENABLED is also defined)
  58.  
  59.    .define LOCO_LIGHT_ENABLED          ; Keep pwm on at low level so light
  60.                                        ; remains on.
  61.                                        ; (Does nothing unless the
  62.                                        ;  TRADITIONAL_ENABLED is also defined)
  63.  
  64. .define BACKEMF_ENABLED                ; If enabled, speed is compensated
  65.                                        ; according to motor back emf
  66.  
  67.    .define BACKEMF_SCALE_ENABLED       ; If enabled, the speed compensation
  68.                                        ; is reduced as the throttle setting
  69.                                        ; is increased.
  70.                                        ; (Does nothing unless the
  71.                                        ;  BACKEMF_ENABLED is also defined)
  72.  
  73.  
  74.    .define LOWPASS_ENABLED             ; Provide a lowpass filter on the
  75.                                        ; the back-emf error amplifier
  76.                                        ; (Does nothing unless the
  77.                                        ;  BACKEMF_ENABLED is also defined)
  78.  
  79. .define OVERLOAD_ENABLED               ; Enable overload protection
  80.  
  81. .define PULSE_ENABLED                  ; Pulse power at low throttle
  82.  
  83.    ;.define PULSE_AMPLITUDE_SCALE      ; Increase pulse size at lowest throttle
  84.                                        ; (Does nothing unless the
  85.                                        ;  PULSE_ENABLED is also defined)
  86.  
  87.    .define PULSE_WIDTH_SCALE           ; Increase pulse width at higher throttle
  88.                                        ; (Does nothing unless the
  89.                                        ;  PULSE_ENABLED is also defined)
  90.  
  91. .define MOMENTUM_ENABLED               ; Simulate momentum
  92.  
  93. .define DIRECTION_ENABLED              ; Direction/brake/STOP input
  94. ;*********************************************************
  95.  
  96. ;*********************************************************
  97. ;* Variables for all compilations
  98. ;*********************************************************
  99.  
  100.    ;*******************
  101.    ;* High frequency pwm settings
  102.    ;*******************
  103. .SET  pwm_period=                0xFF  ; The pwm clock ticks at 156.25nS per tick
  104.                                        ; The pwm runs at pwm_period * 156.25nS
  105.                                        ; The pwm frequency is 1/ (156.25nS * pwm_period)
  106.                                        ; Maximum is 255 (0xFF)
  107.  
  108. .SET  pwm_max=                   0xFF  ; Maximum pwm "duty cycle" is equal to
  109.                                        ; pwm_max / pwm_period
  110.  
  111. .SET  pwm_min=                   0x08  ; Minimum PWM "duty cycle" is equal to
  112.                                        ; pwm_min / pwm_period
  113.  
  114.    
  115.    ;*******************
  116.    ;* Sample rate for throttle/ backemf/ pulses, etc
  117.    ;*******************
  118. .SET  pwm_settle_count=          16    ; settling time for analog measurements
  119.                                        ; (x 40uS)
  120. .SET  pwm_full_count=            250   ; time (x 40uS) between recalculations
  121.                                        ; (255 max)
  122.  
  123. ;*********************************************************
  124. ;* Variables associated with backemf speed control
  125. ;*********************************************************
  126. .ifdef BACKEMF_ENABLED
  127.  
  128.    ;*******************
  129.    ;* General settings
  130.    ;*******************
  131.  
  132.    .SET  error_mult=             2     ; Error Multiplier.  The error between
  133.                                        ; the throttle_set and back_emf is
  134.                                        ; multiplied by 2^error_mult
  135.                                        ; limit -8 < n < 7
  136.                                        ; 1/256 to 128
  137.  
  138.    .ifdef BACKEMF_SCALE_ENABLED
  139.       .SET  err_scale=           5     ; Maximum error gain is as set by error_mult.
  140.                                        ; Error gain decreases exponentially toward
  141.                                        ; zero.  When the throttle is set at 2^err_scale
  142.                                        ; the error be reduced by 2
  143.                                        ; Err scale must not be less than 0.
  144.                                        ; The sum of err_scale and err_mult MUST NOT
  145.                                        ; exceed 7.
  146.    .endif   ;BACKEMF_SCALE_ENABLED
  147.  
  148.    .ifdef LOWPASS_ENABLED
  149.  
  150.       .SET  emf_lowpass_gain=    2     ; tau is about 2^emf_lowpass_gain / 100
  151.                                        ; emf_lowpass_gain 0 to 8 (7?)
  152.    .endif   ;LOWPASS_ENABLED
  153.  
  154. .endif   ;BACKEMF_ENABLED
  155.  
  156. ;*********************************************************
  157. ;* Variables associated with lowspeed pulses
  158. ;*********************************************************
  159. .ifdef PULSE_ENABLED
  160.    .SET  pwm_min=                0x00  ; override previous setting
  161.    .SET  pulse_slope_up=         0x0C
  162.    .SET  pulse_slope_down=       0x08
  163.    .SET  pulse_width_min=        0x08  ; minimum 0x01
  164. .endif ; PULSE_ENABLED
  165.  
  166. ;*********************************************************
  167. ;* Variables associated with momentum
  168. ;*********************************************************
  169. .ifdef MOMENTUM_ENABLED
  170.                                        ; MAY NOT BE MORE THAN 7
  171.  
  172.    .SET  accel_offset=1                ; divide tau_base by 2^accel_offset to give
  173.                                        ; acceleration time constant
  174.    .SET  brake_offset=2                ; divide tau_base by 2^brake_offset to give
  175.                                        ; brake time constant
  176.  
  177.  
  178. .endif MOMENTUM_ENABLED
  179.  
  180.  
  181. ;*********************************************************
  182. ;* Variables associated with direction
  183. ;*********************************************************
  184. .ifdef DIRECTION_ENABLED
  185.  
  186.    .SET  direction_threshold=   16     ; direction relay will switch as long as
  187.                                        ; the throttle (handle and momentum) are
  188.                                        ; less than this value
  189. .endif ;DIRECTION_ENABLED
  190.  
  191. ;*********************************************************
  192. ;* Variables associated with traditional throttle
  193. ;*********************************************************
  194. .ifdef TRADITIONAL_ENABLED
  195.  
  196.  
  197. .ifdef SWITCH_LOWPASS_ENABLED
  198.    .SET  stop_count_max=  10           ; number of identical samples to indicate
  199.    .SET  brake_count_max=  10          ; number of identical samples to indicate
  200.    .SET  reverse_count_max=  10        ; number of identical samples to indicate
  201.    .SET  foreward_count_max=  10       ; number of identical samples to indicate
  202. .endif ;SWITCH_LOWPASS_ENABLED
  203.  
  204. .ifdef THROTTLE_LOWPASS_ENABLED
  205.    .SET  throttle_lowpass_gain=  5     ; tau is about 2^throttle_lowpass_gain / 100
  206.                                        ; throttle_lowpass_gain range 0 to 8 (7?)
  207. .endif ;THROTTLE_LOWPASS_ENABLED
  208.  
  209. .ifdef MOMENTUM_LOWPASS_ENABLED
  210.    .SET  momentum_lowpass_gain=  7     ; tau is about 2^momentum_lowpass_gain / 100
  211.                                        ; momentum_lowpass_gain range 0 to 8 (7?)
  212. .endif ;MOMENTUM_LOWPASS_ENABLED
  213.  
  214. .ifdef LEDS_ENABLED
  215.  
  216.    .SET  accel_led_threshold=2         ; dont light led when acceleration/deceleration
  217.                                        ; is closer than this to the actual speed
  218.    .SET  decel_led_threshold=2         ; dont light led when acceleration/deceleration
  219.                                        ; is closer than this to the actual speed
  220. .endif;LEDS_ENABLED
  221.  
  222. .ifdef LOCO_LIGHT_ENABLED
  223.    .SET  light_pwm=             6      ; run this pwm "duty cycle when throttle is off
  224. .endif ;LOCO_LIGHT_ENABLED             ; to keep loco light on  
  225. .endif ;TRADITIONAL_ENABLED
  226.  
  227. .LIST
  228.