Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
6400 punk_joker 1
;throttle_pulse.asm
2
 
3
.NOLIST
4
;  ***************************************************************************************
5
;  * PWM MODEL RAILROAD THROTTLE                                                          *
6
;  *                                                                                      *
7
;  * WRITTEN BY:  PHILIP DEVRIES                                                          *
8
;  *                                                                                      *
9
;  *  Copyright (C) 2003 Philip DeVries                                                   *
10
;  *                                                                                      *
11
;  *  This program 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 2 of the License, or                   *
14
;  *  (at your option) any later version.                                                 *
15
;  *                                                                                      *
16
;  *  This program 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 this program; if not, write to the Free Software                         *
23
;  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA           *
24
;  *                                                                                      *
25
;  ***************************************************************************************
26
.LIST
27
 
28
.ifdef PULSE_ENABLED
29
;********************************************************************************
30
;* PULSE_GENERATE                                                                *
31
;* Top level routine                                                             *
32
;*                                                                               *
33
;* Inputs:  throttle_set                                                         *
34
;* Returns: none                                                                 *
35
;* Changed: B_Temp,ramp_target,ramp_target1                                      *
36
;* Calls:   SET_PWM_DUTY                                                         *
37
;*          COUNT_PWM_CYCLES                                                     *
38
;* Goto:    none                                                                 *
39
;********************************************************************************
40
 
41
HILOCAL1 ramp_target
42
HILOCAL2 ramp_target1
43
 
44
   ;*****************************************************************
45
   ;* If throttle_set is less than 128 (0x80)
46
   ;*    Ramp up from wherever the pwm is up to (255 - throttle)
47
   ;* If throttle_set is greater than 127 0x7F)
48
   ;*    Ramp up to throttle_set
49
   ;*****************************************************************
50
 
51
   mov   ramp_target1,throttle_set
52
   sbrs  ramp_target1,7
53
 
54
.ifdef PULSE_AMPLITUDE_SCALE
55
   com   ramp_target1                  ; Ramp up to this value
56
.else
57
   ldi   ramp_target1,0x80
58
.endif
59
 
60
   mov   ramp_target,ramp_target1
61
 
62
   subi  ramp_target,pulse_slope_up    ; Ramp up value - pulse_slope
63
 
64
WAIT_FOR_PWM_1:                        ; Wait for PWM to reset to 0
65
   in    B_Temp,TIFR
66
   sbrs  B_Temp,OCF1A
67
   rjmp  WAIT_FOR_PWM_1
68
 
69
   ldi   B_Temp,0b01000000
70
   out   TIFR,B_Temp
71
 
72
   inc   Cycle_count
73
 
74
   in    B_Temp,OCR1A                  ; Find PWM value
75
   cp    B_Temp,ramp_target            ; Make sure won't go past max.
76
   brsh  DONE_SLOPING_UP
77
 
78
   subi  B_Temp, 0x100-pulse_slope_up  ; OCR1A + pulse_slope_up
79
 
80
   rcall SET_PWM_DUTY
81
   rjmp  WAIT_FOR_PWM_1
82
 
83
DONE_SLOPING_UP:
84
   mov   B_Temp,ramp_target1
85
   rcall SET_PWM_DUTY
86
 
87
   ;*****************************************************************
88
   ;* See if we need to slope down to the throttle setting
89
   ;*****************************************************************
90
   in    B_Temp,OCR1A                  ; Find PWM value
91
   cp    B_Temp,throttle_set
92
   breq  PULSE_GENERATE_RETURN         ; Do nothing if already at final voltage
93
 
94
   ;*****************************************************************
95
   ;* Hang about at the top of the pulse for a while...
96
   ;*****************************************************************
97
 
98
.ifdef PULSE_WIDTH_SCALE
99
   mov   ramp_target1,throttle_set
100
.else
101
   clr   ramp_target1
102
.endif
103
 
104
   add   ramp_target1,Cycle_count
105
 
106
   subi  ramp_target1,0x100-pulse_width_min  ; ramp_target1 + pulse_width_min
107
 
108
   mov   B_Temp1,ramp_target1
109
 
110
   rcall COUNT_PWM_CYCLES
111
 
112
   ;*****************************************************************
113
   ;* Slope down
114
   ;*****************************************************************
115
 
116
   mov   ramp_target,throttle_set      ; Ramp DOWN to this value
117
 
118
   subi  ramp_target,0x100-pulse_slope_down  ;ramp_target + pulse_slope_down
119
 
120
WAIT_FOR_PWM_2:                        ; Wait for PWM to reset to 0
121
   in    B_Temp,TIFR
122
   sbrs  B_Temp,OCF1A
123
   rjmp  WAIT_FOR_PWM_2
124
 
125
   ldi   B_Temp,0b01000000
126
   out   TIFR,B_Temp
127
 
128
   inc   Cycle_count
129
 
130
   in    B_Temp,OCR1A                  ; Find PWM value
131
   cp    ramp_target,B_Temp            ; Make sure won't go past min
132
   brsh  PULSE_GENERATE_RETURN
133
 
134
   subi  B_Temp,pulse_slope_down
135
 
136
   rcall SET_PWM_DUTY
137
   rjmp  WAIT_FOR_PWM_2
138
 
139
PULSE_GENERATE_RETURN:
140
.endif ;PULSE_ENABLED