forked from KentuckySolarCar/Drivetek_MPPT
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcan.asm
More file actions
198 lines (160 loc) · 5.52 KB
/
can.asm
File metadata and controls
198 lines (160 loc) · 5.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
;**********************************************************************
; P R O G R A M M MPPTnG *
; *
; Traking program for MPPT new generation *
;**********************************************************************
; *
; Filename: can.asm *
; Date: 15.11.00 *
; Last Update: 18.10.00 *
; File Version: V3.0 *
; *
; Author: Michael Zürcher *
; *
; Company: HTA-Biel/Bienne Indulab *
; *
; Changes: separate CAN handling programm with V3.0 *
; *
;**********************************************************************
; *
; Notes: *
; - Main program : mpptngV4.asm *
; *
;**********************************************************************
InitCAN bsf CAN_CS ; deselect CAN Controller
;**********************************************************************
; INIT CAN MODULE
;**********************************************************************
;read the DIP-switches and attribut IDTracker
clrf IDTrackerTXL
movlw TXBASEADR
movwf IDTrackerTXH
btfsc PORTD,3
incf IDTrackerTXH,F
movlw RXBASEADR
movwf IDTrackerRXH
btfsc PORTD,3
incf IDTrackerRXH,F
movf PORTD,W ; read switches
andlw B'00000111'
bcf _C
movwf IDTrackerTXL
rlf IDTrackerTXL,F ; shift left four positions
rlf IDTrackerTXL,F
rlf IDTrackerTXL,F
rlf IDTrackerTXL,F
rlf IDTrackerTXL,F
movf IDTrackerTXL,W
movwf IDTrackerRXL
call InitSPIPort ; Initialize SPI-Bus
; Wait 40 ms for 2510 to initialize ( there is no significance to 40 ms,
; we just selected a large time since time is not critical)
call wait20ms
call wait20ms
call Init2510 ; Initialize CAN-Controller MCP2510
;*******************************************************************************
; configure and enable RB0/INT
;*******************************************************************************
movf OPTION_REG_P,W ; read Option Register
andlw B'10111111' ; Interupt on falling edge of RB0/INT pin
movwf OPTION_REG_P ;
RETURN
;**********************************************************************
; Update TX0 Buffer
;
; Frame type -> Data Frame
; ID type -> Standart
; Frame Format -> SOF / ID / control / datas / CRC / EOF
; Data Format -> Byte0 : UinH
; Byte1 : UinL
; Byte2 : IinH
; Byte3 : IinL
; Byte4 : UoutH
; Byte5 : UoutL
; Byte6 : TambH
; Byte7 : TambL
;**********************************************************************
UpdateTX0 SPI_WriteL TXB0DLC,0x07 ; 7 bytes to send
movf GenFlags,W ; add GenFlags to UinH Byte
andlw B'00001111'
movwf Temp0
bcf _C
rlf Temp0,F
rlf Temp0,F
rlf Temp0,F
rlf Temp0,F
movfw UIF0H
andlw B'00000011'
movwf UIF0H
movfw Temp0
addwf UIF0H,W
movwf Temp0
SPI_WriteD TXB0D0,Temp0
SPI_WriteD TXB0D1,UIF0L
SPI_WriteD TXB0D2,IIF0H
SPI_WriteD TXB0D3,IIF0L
SPI_WriteD TXB0D4,UOFH
SPI_WriteD TXB0D5,UOFL
call GetTamb
call ConvTempAmb
movwf TAMBL
SPI_WriteD TXB0D6,TAMBL
; call GetTCooler
; call ConvTempCooler
; movwf TCL
; SPI_WriteD TXB0D7,TCL
RETURN
;**********************************************************************
; Send content of TX0 Buffer on CAN Bus
;**********************************************************************
SendCANTX0 clrwdt ; reset watchdog
movlw B'00001000' ; mask bit TXREQ (msg transmit request)
movwf RegMask2510
movlw TXB0CTRL ; transmit buffer1 control register
call Read2510
andwf RegMask2510,W ; test TXREQ bit
btfss STATUS,Z ; wait until TXREQ = 0 (wait for pending msg to be sent)
goto SendCANTX0
movlw RTS0 ; transmit buffer Tx0
call Rts2510
RETURN
;**********************************************************************
; CAN Interrupt Handling routine
;**********************************************************************
IntCAN bsf CANTxRq
bcf INTCON,INTF
bcf INTCON,INTE
goto IntReturn
;**********************************************************************
; Send Data Over CAn if requested
;**********************************************************************
CANRqTest btfss Initialized
RETURN
btfss CAN_PRE ; skip next line if CAN_PRE = 0
RETURN
movf PORTD,W ; read A0-A3
andlw B'00001111' ; mask A0-A3 Bits
btfsc _Z
RETURN
; btfss CANTxRq
; RETURN
movlw CANINTF
call Read2510
movwf Temp4
btfss Temp4,0
RETURN
call GetFilteredIin ; get actual values
call GetFilteredUout
call GetFilteredUin
; call GetTCooler
call GetTamb
call UpdateTX0
call SendCANTX0
SPI_WriteL CANINTF,B'00000000'
movlw CANINTF
call Read2510
nop
bcf INTCON,INTF
bsf INTCON,INTE
bcf CANTxRq
RETURN