Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. ;throttle_momentum_lowpass.asm
  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. .LIST
  28.  
  29. .ifdef   MOMENTUM_LOWPASS_ENABLED
  30.    ;*****************************************************************
  31.    ;* A transversal low pass filter                                  *
  32.    ;*                                                                *
  33.    ;* This is copied from throttle_backemf.asm.                      *
  34.    ;* See the documentation there.                                   *
  35.    ;*****************************************************************
  36.    HILOCAL1    _momentum_lo             ; assign local variables
  37.    HILOCAL2    _momentum_hi
  38.  
  39.    mov   _momentum_lo,momentum_set
  40.    clr   _momentum_hi
  41.  
  42.    ;****
  43.    ;* 1. Add in cumulative previous throttle
  44.    ;****
  45.    add   _momentum_lo,momentum_lo_prev        ; Add in scaled previous samples
  46.    adc   _momentum_hi,momentum_hi_prev        ;
  47.  
  48.    ;****
  49.    ;* 2.
  50.    ;****
  51.    mov   momentum_lo_prev,_momentum_lo        ; Store new value
  52.    mov   momentum_hi_prev,_momentum_hi        ; Store new value
  53.  
  54.    ;****
  55.    ;* 3.
  56.    ;****
  57.  
  58.    B_TEMPLOCAL _lowpass_lo_byte
  59.    ldi   _lowpass_lo_byte, momentum_lowpass_gain
  60.    rcall DIVIDE_16_SIMPLE
  61.  
  62.    ;****
  63.    ;* 4.
  64.    ;****
  65.    sub   momentum_lo_prev,_momentum_lo
  66.    sbc   momentum_hi_prev,_momentum_hi
  67.  
  68.    mov   momentum_set,_momentum_lo
  69. .endif ;MOMENTUM_LOWPASS_ENABLED
  70.