📄 bldc_basic.cod
字号:
0000EB F59B MOV CCU6_CC63SRH,A
253: // high for channel 3
254:
255:
256: /// -----------------------------------------------------------------------
257: /// Configuration of Multi-Channel Mode Output Register
258: /// -----------------------------------------------------------------------
259:
260: CCU6_MCMOUTSL = 0x00; // load CCU6 multi channel mode output
0000ED F59E MOV CCU6_MCMOUTSL,A
261: // control register low
262: CCU6_MCMOUTSH = 0x00; // load CCU6 multi channel mode output
0000EF F59F MOV CCU6_MCMOUTSH,A
263: // control register high
264:
265:
266: SFR_PAGE(_cc2, noSST); // switch to page 2
0000F1 75A302 MOV CCU6_PAGE,#02H
267:
268: /// -----------------------------------------------------------------------
269: /// Configuration of Timer Control Register
270: /// -----------------------------------------------------------------------
271:
272: CCU6_TCTR2L = 0x00; // load CCU6 timer control register 2 low
0000F4 F5FA MOV CCU6_TCTR2L,A
273: CCU6_TCTR2H = 0x00; // load CCU6 timer control register 2 high
0000F6 F5FB MOV CCU6_TCTR2H,A
274:
275: /// -----------------------------------------------------------------------
276: /// Configuration of CCU6 trap control:
277: /// -----------------------------------------------------------------------
278: /// - a trap can only be generated by SW by setting the bit TRPF
279: /// - the trap state is left when a zero-match of T12 (while counting up)
280: /// is detected (synchronization to T12)
281: /// - bit TRPF is automatically cleared by HW (according to TRPPEN, TRPM0
282: /// and TRPM1)
283: /// - trap interrupt is disabled
284:
285: CCU6_TRPCTRL = 0x00; // load CCU6 trap control register low
0000F8 F5FE MOV CCU6_TRPCTRL,A
286: CCU6_TRPCTRH = 0x00; // load CCU6 trap control register high
0000FA F5FF MOV CCU6_TRPCTRH,A
287:
288: /// -----------------------------------------------------------------------
289: /// Configuration of Multi Channel Mode:
290: /// -----------------------------------------------------------------------
291: /// - multi channel mode is enabled
292:
293: /// - switching selection:
294: /// - transfer on correct hall event
295:
LX51 LINKER/LOCATER V3.65b 10/12/2005 16:46:10 PAGE 6
296: /// - switching synchronization:
297: /// - direct transfer
298:
299: /// - interrupt on correct hall event is enabled
300: /// - interrupt on wrong hall event is disabled
301: /// - the automatic entering of the idle state is disabled
302:
303: CCU6_MODCTRL = 0x80; // load CCU6 modulation control register low
0000FC 75FC80 MOV CCU6_MODCTRL,#080H
304: CCU6_MODCTRH = 0x00; // load CCU6 modulation control register high
0000FF F5FD MOV CCU6_MODCTRH,A
305:
306: /// -----------------------------------------------------------------------
307: /// Configuration of Multi_Channel Mode Control Register
308: /// -----------------------------------------------------------------------
309:
310: CCU6_MCMCTR = 0x01; // load CCU6 multi channel mode control
000101 75A701 MOV CCU6_MCMCTR,#01H
311: // register
312:
313: /// -----------------------------------------------------------------------
314: /// Configuration of T12 Capture/Compare Mode Select Register
315: /// -----------------------------------------------------------------------
316:
317: CCU6_T12MSELL = 0x88; // load CCU6 T12 campture/compare mode
000104 759A88 MOV CCU6_T12MSELL,#088H
318: // select register low
319:
320: CCU6_T12MSELH = 0x08; // load CCU6 T12 campture/compare mode
000107 759B08 MOV CCU6_T12MSELH,#08H
321: // select register high
322: /// -----------------------------------------------------------------------
323: /// Configuration of Passive State Level Register
324: /// -----------------------------------------------------------------------
325:
326: CCU6_PSLR = 0x00; // load CCU6 passive state level register low
00010A F5A6 MOV CCU6_PSLR,A
327:
328: /// -----------------------------------------------------------------------
329: /// Configuration of CCU6 interrupt control:
330: /// -----------------------------------------------------------------------
331: /// - for channel 0 interrupts is node I3 selected
332: /// - for channel 1 interrupts is node I3 selected
333: /// - for channel 2 interrupts is node I3 selected
334: /// - for correct hall event interrupt is node I3 selected
335: /// - for error interrupts is node I3 selected
336: /// - for T12 interrupts is node I3 selected
337: /// - for T13 interrupts is node I3 selected
338:
339: CCU6_INPL = 0xFF; // load CCU6 capture/compare interrupt node
00010C 759EFF MOV CCU6_INPL,#0FFH
340: // pointer register low
341: CCU6_INPH = 0x3F; // load CCU6 capture/compare interrupt node
00010F 759F3F MOV CCU6_INPH,#03FH
342: // pointer register high
343:
344: CCU6_IENL = 0x00; // load CCU6 capture/compare interrupt
000112 F59C MOV CCU6_IENL,A
345: // enable register low
346: CCU6_IENH = 0x10; // load CCU6 capture/compare interrupt
000114 759D10 MOV CCU6_IENH,#010H
347: // enable register high
348:
349: SFR_PAGE(_cc3, noSST); // switch to page 3
000117 75A303 MOV CCU6_PAGE,#03H
LX51 LINKER/LOCATER V3.65b 10/12/2005 16:46:10 PAGE 7
350:
351: /// -----------------------------------------------------------------------
352: /// Configuration of Compare State Register
353: /// -----------------------------------------------------------------------
354:
355: CCU6_CMPSTATH = 0x00; // load CCU6 compare status register high
00011A F5FF MOV CCU6_CMPSTATH,A
356:
357: /// -----------------------------------------------------------------------
358: /// Configuration of CCU6 module input signals:
359: /// -----------------------------------------------------------------------
360: /// - signal CC60_0 is used as output
361: /// - signal CC61_0 is used as output
362: /// - signal CC62_0 is used as output
363: /// - signal #CTRAP is not used
364:
365: CCU6_PISEL0L = 0x00; // load CCU6 Port Input Select Register 0 Low
00011C F59E MOV CCU6_PISEL0L,A
366:
367: /// - signal CCPOS0_0 is used
368: /// - signal CCPOS1_0 is used
369: /// - signal CCPOS2_0 is used
370: /// - signal T12HR is not used
371:
372: CCU6_PISEL0H = 0x00; // load CCU6 Port Input Select Register 0
00011E F59F MOV CCU6_PISEL0H,A
373: // High
374:
375: /// - signal T13HR is not used
376:
377: CCU6_PISEL2 = 0x00; // load CCU6 Port Input Select Register 2
000120 F5A4 MOV CCU6_PISEL2,A
378:
379: /// Pin P3.0 is used as CC60_0 Output
380: /// Pin P3.1 is used as COUT60_0 Output
381: /// Pin P3.2 is used as CC61_0 Output
382: /// Pin P3.3 is used as COUT61_0 Output
383: /// Pin P3.4 is used as CC62_0 Output
384: /// Pin P3.5 is used as COUT62_0 Output
385:
386: SFR_PAGE(_pp2, noSST); // switch to page 2
000122 75B202 MOV PORT_PAGE,#02H
387: P3_ALTSEL0 |= 0x3F; // set AltSel0
000125 43B03F ORL P3_ALTSEL0,#03FH
388: P3_ALTSEL1 &= ~(ubyte)0x3F; // set AltSel1
000128 53B1C0 ANL P3_ALTSEL1,#0C0H
389:
390: SFR_PAGE(_pp0, noSST); // switch to page 0
00012B F5B2 MOV PORT_PAGE,A
391: P3_DIR |= 0x3F; // set P3.7 OutPut
00012D 43B13F ORL P3_DIR,#03FH
392:
393:
394:
395: /// -----------------------------------------------------------------------
396: /// Configuration of the used CCU6 Channels Interrupts:
397: /// -----------------------------------------------------------------------
398: /// - capture/compare interrupt node 0 is disabled
399: /// - capture/compare interrupt node 1 is disabled
400: /// - capture/compare interrupt node 2 is disabled
401: /// - capture/compare interrupt node 3 is enabled
402:
403: IEN1 |= 0x80; // load interrupt enable register 2
000130 43E880 ORL IEN1,#080H
404:
LX51 LINKER/LOCATER V3.65b 10/12/2005 16:46:10 PAGE 8
405:
406: SFR_PAGE(_cc0, noSST); // switch to page 0
000133 F5A3 MOV CCU6_PAGE,A
407:
408: /// -----------------------------------------------------------------------
409: /// Timer Control Register
410: /// -----------------------------------------------------------------------
411: /// - enable shadow transfer to T12 and T13
412:
413: CCU6_TCTR4L = 0x40; // load CCU6 timer control register 4 low
000135 759C40 MOV CCU6_TCTR4L,#040H
414:
415: CCU6_TCTR4H = 0x40; // load CCU6 timer control register 4 high
000138 759D40 MOV CCU6_TCTR4H,#040H
416:
417: /// Start timer settings
418:
419: CCU6_TCTR4L = 0x02; // start timer 12
00013B 759C02 MOV CCU6_TCTR4L,#02H
420:
421:
422: // USER CODE BEGIN (Init,3)
423:
424: // USER CODE END
425:
426: } // End of function CC6_vInit
00013E 22 RET
----- FUNCTION CC6_vInit (END) -------
----- FUNCTION CC6_viNodeI3 (BEGIN) -----
FILE: 'CC6.C'
456: void CC6_viNodeI3(void) interrupt CCU6_NodeI3_INT
00013F C0E0 PUSH ACC
000141 C083 PUSH DPH
000143 C082 PUSH DPL
000145 C0D0 PUSH PSW
000147 75D000 MOV PSW,#00H
00014A C007 PUSH AR7
457: {
458:
459: // USER CODE BEGIN (NodeI3,2)
460: extern code unsigned char HallPatt[];
461: extern code unsigned char OutputPatt[];
462: unsigned char temp;
463: // USER CODE END
464:
465: SFR_PAGE(_cc3, SST2); // switch to page 3
00014C 75A3A3 MOV CCU6_PAGE,#0A3H
466:
467: if(CCU6_ISH & 0x10) //if ISH_CHE
00014F E59D MOV A,CCU6_ISH
000151 30E418 JNB ACC.4,?C0002?CC6
468: {
469: //correct hall event detection
470:
471: SFR_PAGE(_cc0, noSST); // switch to page 0
000154 75A300 MOV CCU6_PAGE,#00H
472:
473: CCU6_ISRH = 0x10; //clear flag ISH_CHE
000157 75A510 MOV CCU6_ISRH,#010H
474:
475: // USER CODE BEGIN (NodeI3,23)
476: temp = CCU6_MCMOUTSH & 0x07; //get next hall state
00015A E59F MOV A,CCU6_MCMOUTSH
LX51 LINKER/LOCATER V3.65b 10/12/2005 16:46:10 PAGE 9
00015C 5407 ANL A,#07H
00015E FF MOV R7,A
;---- Variable 'temp' assigned to Register 'R7' ----
477: CCU6_MCMOUTSL = OutputPatt[temp]; //program shadow registers with next state values
00015F 900080 MOV DPTR,#OutputPatt
000162 93 MOVC A,@A+DPTR
000163 F59E MOV CCU6_MCMOUTSL,A
478: CCU6_MCMOUTSH = HallPatt[temp]; //the shadow transfer will be automatic
000165 EF MOV A,R7
000166 900079 MOV DPTR,#HallPatt
000169 93 MOVC A,@A+DPTR
00016A F59F MOV CCU6_MCMOUTSH,A
479: // USER CODE END
480:
481: }
00016C ?C0002?CC6:
482:
483: SFR_PAGE(_cc0, RST2); // restore the old CCU page
00016C 75A3E0 MOV CCU6_PAGE,#0E0H
484:
485:
486: } // End of function CC6_viNodeI3
00016F D007 POP AR7
000171 D0D0 POP PSW
000173 D082 POP DPL
000175 D083 POP DPH
000177 D0E0 POP ACC
000179 32 RETI
----- FUNCTION CC6_viNodeI3 (END) -------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -