Part Number Hot Search : 
6MBP15R C1Z11B RGA37A SRM2A256 NTE76 L7109 HMC463 MPC5603C
Product Description
Full Text Search
 

To Download R8C11 Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
 APPLICATION NOTE
R8C/11 Group
Control of a Brushless DC Motor
1. 0 Abstract
This document describes a control of a brushless DC motor using output compare and external interrupt functions of R8C/11 Group.
2.0 Introduction
The explanation of this document is applied in the following condition. * MCU * Oscillator Frequency * CPU Clock * Compiler Package * Compiler Option :R8C/11 Group :20MHz :10MHz(f(XIN)/2) :NC30WA V.5.20 Release 1 :-OS (A speed is more important than ROM capacity.)
This program can also be used when operating other microcomputers within the M16C family, provided they have the same SFR (Special Function Registers) as the R8C/11 microcomputers. However, some functions may have been modified. Refer to the User's Manual for details. Use functions covered in this Application Note only after careful evaluation.
REJ05B0288-0100Z/Rev.1.00
November 2003
Page 1 of 55
R8C/11 Group Control of a Brushless DC Motor 3. 0 Control of a Brushless DC Motor
3.1 Abstract
1.The R8C/11 group is used to control a brushless DC motor in the way shown in Figure 3.1. 2.The R8C/11 group detects signals that indicate the positions of the rotor's magnetic poles and operates the motor by producing six PWM waveforms that provide control of the rotating magnetic field according to the positional signals from the motor. 3.The R8C/11 group's built-in timer generates a PWM waveform that handles chopping control for the motor.
R8C/11 Group Indicators of rotor position INT1 INT0 KI3 Motor-stop switch INT3 Six-phase output U V W _U _V _W Driver for burshless DC motor DCBLM
CMP00 CMP01 CMP02 P30 P31 P32
[Note] DCBLM U V W _U _V _W INT1/CNTR0 INT0 KI3 INT3 CMP00 CMP01 CMP02 P30 to P32
: Burshless DC motor (120-degree type) : U phase : V phase : W phase : U phase : V phase : W phase : External interrupt input port : External interrupt input port : Key input interrupt port : External interrupt input port : Compare function output port : Compare function output port : Compare function output port : Port P30 to Port P32 output port
Figure 3.1 Set-up for Controlling a Brushless DC Motor
REJ05B0288-0100Z/Rev.1.00
November 2003
Page 2 of 55
R8C/11 Group Control of a Brushless DC Motor 3.2 Specification
1.The PWM waveforms for the motor are generated by the timer and output through CMP and I/O port pins. 2.In the initial stage of the motor's operation, the motor is started by sequential switching of the excited phase on a constant cycle. 3.After switching the excited phase six times (electrical angel 1 rotation*1) and waiting for a certain period, control by the CPU shifts to the procedure where control of the motor is based on the rotor-positional signals from the motor. 4.The positional signals from the motor are taken in through external input port (INT0), external interrupt input port (INT1), key input interrupt port (KI3) and drive the generation of interrups. 5.These interrupts drive switching to produce a rotating magnetic field and control phase excitation through chopping. *1 This application is premised on motor control with four magnetic poles. 1 rotating mechanical angle is 2 rotating electrical angel for motor with four poles
REJ05B0288-0100Z/Rev.1.00
November 2003
Page 3 of 55
R8C/11 Group Control of a Brushless DC Motor 3.3 Descriptions of Function Used
1.As shown in Figure 3.2, timers C (output compare), external interrupt input, key input interrupt, I/O port (Port P1,P3) and timer (timer Y) of the R8C/11 Group are used to implement functions required to control a brushless DC motor.
Timer C ( Output compare) CMP Generation Waveform
Capture, Compare 0 register (16) Comparator 0 Timer C (16) Comparator 1 Compare 1 register (16) Timer
CMP waveform output
Six-phase output
P10 P11 P12 Port P1 P30 P31 P32 I/O port Interrupt request Key input interrupt Edge detection
Port P3
Prescaler Y (8)
Timer Y (8)
Interrupt request
Interrupt request
Interrupt request External interrupt input
Edge detection
Input of motor rotation stop Input of rotor-positional signal
Figure 3.2 Block Diagram of the Configuration for Controlling a Brushless DC Motor * The tasks performed by the R8C/11 Group functional blocks are outlined below. * Timer C (output compare) : generate the waveform for chopping control when the driver transistor turns on; this is output positive three-phase data to the motor driver through CMP00 to CMP02 ports. * External interrupt input (INT3) : stops the motor in response to the driver's rotation-stop signal. * External interrupt input (INT0 to INT1) : generates an interrupt request for the CPU on the rising and falling edges of the rotor positional signal. * Key input interrupt (K13) : generates an interrupt request for the CPU on the rising and falling edges of the rotor positional signal. * I/O port : outputs negative three-phase data to the motor driver * Timer Y : generates an interrupt request for the CPU on a constant cycle.
REJ05B0288-0100Z/Rev.1.00
November 2003
Page 4 of 55
R8C/11 Group Control of a Brushless DC Motor 3.4 Description of Operation
1. Figure 3.3 shows the principle of operation in initial motor control (until the motor has gone through its half rotation, switching of the rotating magnetic-field takes place at a constant period). Initial control of the brushless DC motor is through hardware and software processing by the R8C/11 Group as shown in figure 3.3.
Initial motor control
*1
360 degrees=60ms
60 degrees=10ms CMP00 (U phase) /P10 CMP01 (V phase) /P11 CMP02 (W phase) /P12 P30 (_U phase)
P31 (_V phase) P32 (_W phase)
(1) Hardware processing (a) Timer Y generates an interrupt request (1ms cycle) Software processing (a) Timer Y clears an interrupt request (b) Place the sequential six-phase output data from data table in Port P1, Port P3 every 10ms
(1)
*1
The six-phase initial output pattern for initial motor control is based on the rotor-positional signal. Refer to Table 3.1 for an initial output pattern. [Note] The driver is set to Low Active.
Figure 3.3 Initial Control of the Brushless DC Motor : Principle of Operation Table 3.1 Six-phase initial output pattern for initial motor cotrol
INT1 INT0 KI3 U V W _U _V _W phase phase phase phase phase phase H L H ON OFF OFF OFF ON OFF Rotor-positional signal H L H H L L Six-phase initial output pattern ON OFF OFF OFF ON ON OFF OFF OFF OFF OFF ON OFF OFF OFF ON ON OFF H L L L H H OFF OFF ON ON OFF OFF L L H OFF OFF ON OFF ON OFF
REJ05B0288-0100Z/Rev.1.00
November 2003
Page 5 of 55
R8C/11 Group Control of a Brushless DC Motor
2.Figure 3.4 shows the principle of control to make the magnetic field rotate in response to the rotorpositional signal. Control of the brushless DC motor is through hardware and software processing by the R8C/11 Group, based on the detected rotor-positional signal, as is shown in figure 3.4.
0 INT1 INT0 KI3 60 120 180 240 300 360(0)
CMP00 (U phase) /P10 CMP01 (V phase) /P11 CMP02 (W phase) /P12 P30 (_U phase)
P31 (_V phase) P32 (_W phase)
(1) (3) (2) Hardware processing (a) Generate a key input interrupt Software processing (a)Verify the rotor-positional signal (b)Refer to the data table, place the corresponding six-phase output data in Port P1, Port P3. (c) Switch the KI3input polarity edge (a) Verify the rotor-positional signal (b) Refer to the data table, place the corresponding six-phase output data in Port P1, Port P3. (c)Switch the INT0 interrupt polarity edge (a) Verify the rotor-positional signal (b) Refer to the data table, place the corresponding six-phase output data in Port P1, Port P3. (c) Switch the INT1 interrupt polarity edge
(1)
(2)
(a) Generate INT0 interrupt
(3)
(a) Generate INT1 interrupt
*1 The output pattern on the above is a basic output pattern based on the rotor-positional signal. In this application, it is an output pattern based on 60-degree phase control. Refer to Table 4.3.
[Note]The drive is set to Low Active.
Figure 3.4 Principle of Motor Control Based on the Rotor-Positional Signal
REJ05B0288-0100Z/Rev.1.00
November 2003
Page 6 of 55
R8C/11 Group Control of a Brushless DC Motor
3.In this sample task, chopping control is applied when the driver transistors on the positive-phase side are turned on. A chopping waveform generated by the output compare is output on CMP00 to CMP02. Figure 3.5 shows the principle of operation for output of the chipping waveform. Figure 3.6 shows a relationship between the internal signal and the output waveform.
H'FFFF H'0534 H'04AF H'0429
H'0000 CMP output (internal signal) P1_i bit (i=0 to 2) (CMP output (internal signal)) AND (P1_I bit) AND output (internal signal) Select TCOUT6=1 CMP0i port (i=0 to 2) (1) (2) (3)
Hardware processing Software processing - (a) Match Timer C with Compare 1 register (b) Set Timer C to "H'0000" (c) Set CMP output (internal signal) to "0" (d) Output "H" through CMP0i port (2) (a) Match Timer C with Compare 0 register - (b) Set CMP output (internal signal) to "1" (c) Output "L" through CMP0i port (Duty=at 10%) (3) (a) Match Timer C with Compare 0 register - (b) Set CMP output (internal signal) to "1" (c) Output "L" through CMP0i port (Duty= at 20%) (i=0 to 2) Set value Capture, Compare 0 register : H'04AF (Duty= at 10%), H'0429 (Duty= at 20%) Compare 1 register : H'0534 (1) [Note]The driver is set to Low Active.
Figure 3.5 Output of the Chopping Waveform : Principle of Operation In this application, PWM waveform is output under the setting shown in Table 3.2. Table 3.2 Control procedure and PWM output
Control procedure Initial control of motor Motor control based on the rotorpositional signal PWM cycle 66.67s(15kHz) Low width 6.67s 13.33s Duty 10% 20%
REJ05B0288-0100Z/Rev.1.00
November 2003
Page 7 of 55
R8C/11 Group Control of a Brushless DC Motor
Microcomputer internal signal CMP output (internal signal) P1_0 bit P1_1 bit P1_2 bit
(CMP output (internal signal)) AND (P1_0 to P1_2 bit) Microcomputer internal signal (CMP output)AND (P1_0 bit) (CMP output) AND (P1_1 bit) (CMP output)AND (P1_2 bit) CMP output from CMP0i port is inversed (i=0 to 2). Select TCOUT6=1 Microcomputer output signal CMP00 port CMP01 port CMP02 port
Note: The driver signal is active low.
Figure 3.6 A relationship between the internal signal and the output waveform
REJ05B0288-0100Z/Rev.1.00
November 2003
Page 8 of 55
R8C/11 Group Control of a Brushless DC Motor 4. Description of Software 4.1 Description of Modules
Table 4.1 describes the software used in this sample task.
Table 4.1 Description of Modules
Module Name Function Initialization Set SFR about control. Main Routine Perform motor control in 1ms(Timer Y) cycle. Motor Control Processing Routine Perform initial motor control. Rotor-positional signal (INT1) Interrupt Routine void Sens_In0_int ( void ) void Motor_Cntrl ( void ) void main ( void ) void Init_Motor_sfr ( void ) Label Name
Switch the excited phase by rotor-positional signal output from motor to INT1. Rotor-positional signal (INT0) Interrupt Routine void Sens_In1_int ( void )
Switch the excited phase by rotor-positional signal output from motor to INT0. Rotor-positional signal (KI3) Interrupt Routine void Sens_In2_int ( void )
Switch the excited phase by rotor-positional signal output from motor to K13. Motor-rotation stop signal (INT3) Interrupt Routine void Error_int ( void )
Stop rotating the motor by motor-rotation stop signal from a brush-less DC motor driver. Initial-stage Excited Phase Output Routine Output six phases in the initial motor control. Excited Phase Output Routine void _OutPhase_Active ( u08 ) void _InitOutPhase_Active ( u08 )
Output six phases by rotor-positional signal in the initial motor control. PWM output setup Routine Set PWM waveform output with a pre-set duty. Positional Signal Input Routine Input rotor-positional signal. u08 _Sens_Input ( void ) void _PWM_Set ( void )
* u08 means unsigned char.
REJ05B0288-0100Z/Rev.1.00
November 2003
Page 9 of 55
R8C/11 Group Control of a Brushless DC Motor 4.2 Description of SFR for Internal Use
The figures from 4.2 to 4.30 describes SFR for internal use in this sample task. Figure 4.1 describes what the figures show in detail. Refer to the hardware manual for the further description of the register.
"0" or "1" Blank b7 b6 b5 b4 b3 b2 b1 b0 00 00
:Set for this sample task :Set to "0" or "1"
Timer C control register 0 (009A16 address) TCC0 Bit Symbol TCC00 TCC01 TCC02 TCC03 TCC04 (b6-b5) TCC07 Reserved bit INT3 interrupt, capture select bit (Note1, Note2) INT3 interrupt, polarity select bit (Note1, Note2) capture Bit Name Timer C count start bit Timer C count source select bit (Note 1) 0:Count stop 1:Count start
b2b1
Function
RW RW RW RW RW RW RW RW
00:f1 01:f8 10:f32 11:fRING-fast b4b3 00:rising edge 01:falling edge 10:both edges 11:Nothing is assigned. Set to "0". 0:INT3 1:fRING128
: irrelevant to this sample task, or unused function
Figure 4.1 Description of what SFR shows
REJ05B0288-0100Z/Rev.1.00
November 2003
Page 10 of 55
R8C/11 Group Control of a Brushless DC Motor
b7 b6 b5 b4 b3 b2 b1 b0 00 0 0 1 0 0 0
System clock control register 0 (000616 address) CM0 Bit Symbol (b1-b0) CM02 Bit Name Reserved bit WAIT peripheral clock stop bit function Function Set to"0". 0:Do not stop peripheral function clock in wait mode 1:Stop peripheral function clock in wake mode (Note 6) Set to "1". Set to "0". 0:On 1:Off (Note 3) 0:CM16, CM17 valid 1:divide-by-8 mode Set to "0". RW RW RW RW RW RW RW RW
(b3) (b4) CM05 CM06 (b7)
Reserved bit Reserved bit Main clock (XIN-XOUT) stop bit (Note 2, Note 4) Main clock division select bit 0 (Note 5) Reserved bit
Note1 Set the PRC0 bit of PRCR register to "1" (write enable) before writing to this register. Note2 The CM05 bit is provided to stop the main clock when the ring oscillator mode is selected. This bit cannot be used for detection as to whether the main clock stopped or not. (1) Set the CM06 bit to "1" (divide-by-8 mode) (2) Set the OCD0 and OCD1 register to "002" (disabling oscillation stop detection function) (3) Set the OCD2 bit to "1" (selecting ring oscillator) Note3 During external clock input, only the clock oscillation buffer is turned off and clock input is accepted. Note4 When the CM05 bit is set to "1" (main clock stop), P46 and P47 can be used as input ports. Note5 When entering stop mode from high or middle speed mode, the CM06 bit is set to "1" (divide-by-8 mode) Note6 During ring oscillator mode, this bit must be set to "0" (peripheral clock turned on when in wait mode)
Figure 4.2 System clock control register 0
REJ05B0288-0100Z/Rev.1.00
November 2003
Page 11 of 55
R8C/11 Group Control of a Brushless DC Motor
b7 b6 b5 b4 b3 b2 b1 b0 01 1 1 1 0 0 0
System clock control register 1 (000716 address) CM1 Bit Symbol CM10 (b1) (b2) CM13 CM14 CM15 CM16 CM17 Bit Name All clock stop control bit (Note 4) Reserved bit Reserved bit Port XIN-XOUT Switch bit Low-speed ring oscillation stop bit (Note5, 6) XIN-XOUT drive capability select bit (Note2) Main clock division select bit 1 (Note3) Function 0:Clock on 1:All clocks off (stop mode) Set to "0". Set to "0". 0:Input portP46, P47 1:XIN-XOUT pin 0:Low-speed ring oscillator ring on 1:Low-speed ring oscillator ring off 0:LOW 1:HIGH
b7b6
RW RW RW RW RW RW RW
00:No division mode 01:Division by 2 mode 10:Division by 4 mode 11:Division by 16 mode
RW
Note1 Write to this register after setting the PRC0 bit of PRCR register to "1". Note2 When entering stop mode from high or middle speed mode, the CM15 bit is set to "1" (drive capability high). Note3 Effective when the CM06 bit is "0" (CM16 and CM17 bits enable). Note4 If the CM10 bit is "1" (stop mode), the internal feedback resistor becomes ineffective. Note5 The CM14 bit can be set to "1" (low-speed ring oscillator off) if the OCD2 bit=0 (selecting main clock). When the OCD2 bit is set to "1" (selecting ring oscillator clock), the CM14 bit is set to "0" (low-speed ring oscillator on). This bit remains unchanged when "1" is written. Note6 When using voltage detection interrupt circuit, CM14 bit is set to "0".
Figure 4.3 System clock control register 1
REJ05B0288-0100Z/Rev.1.00
November 2003
Page 12 of 55
R8C/11 Group Control of a Brushless DC Motor
b7 b6 b5 b4 b3 b2 b1 b0 00 0 0 000
Oscillation stop detection register (000C16 address) OCD Bit symbol OCD0 OCD1 OCD2 OCD3 (b7-b4) System clock select bit (Note6) Clock monitor bit (Note3,5) Reserved bit
Bit Name Oscillation stop detection enable bit
b1b0
Function 00:The function is disabled 01:Avoid this setting 10:Avoid this setting 11:The function is enabled (Note4,7) 0:Select main clock (Note7) 1:Select ting oscillator clock (Note2) 0:Main clock on 1:Main clock off Set to "0"
RW
RW
RW RO RW
Note1 Set the PRC0 bit in the PRCR register to "1" (write enable) before rewriting this register. Note2 The OCD2 bit is set to "1"(selecting ring oscillator clock ) automatically if a main clock oscillation stop is detected while the OCD1 to OCD0 bits are set to "112" (oscillation stop detection function enabled). If the OCD3 bit is set to "1"(main clock stop), the OCD2 bit remains unchanged when trying to write "0" (selecting main clock). Note3 The OCD3 bit is enabled when the OCD1 to OCD0 bits are set to "112" (oscillation stop detection function enabled). Read the OCD3 bit several times with the oscillation stop detection interrupt processing program to determine the main clock state. Note4 The OCD1 to OCD0 bits should be set to "002" (oscillation stop detection function disabled) before entering stop mode and ring oscillator (main clock stops). The OCD1 to OCD0 bits should be set to "002" when the HR01 bit in the HR0 register is set to "1" (high-speed ring oscillator selected). Note5 The OCD3 bit remains set to "0" (main clock on) if the OCD1 to OCD0 bits are set to "002". Note6 The CM14 bit goes to "0"(low-speed ring oscillator on) if the OCD2 bit is set to "1" (selecting ring oscillator clock). Note7 Refer to Figure 6.9 "switching clock source from low-speed ring oscillator to main clock" for the switching procedure when the main clock re-oscillates after detecting an oscillation stop.
Figure 4.4 Oscillation stop detection register
REJ05B0288-0100Z/Rev.1.00
November 2003
Page 13 of 55
R8C/11 Group Control of a Brushless DC Motor
b7 b6 b5 b4 b3 b2 b1 b0 00000
Protect register (000A16 address) PRCR
Set Symbol PRC0
Bit Name Protect bit 0
Function Enable write to CM0,CM1,OCD,HR0,HR1 registers 0:Write protected 1:Write enabled Enable write to PM0, PM1 registers 0:Write protected 1:Write enabled Enable write to PD0 register 0:Write protected 1:Write enabled (Note1) Enable write to VCR2, D4INT registers 0:Write protected 1:Write enabled When write, should set to "0". When read, its content is "0".
RW
RW
PRC1
Protect bit 1
RW
PRC2
Protect bit 2
RW
PRC3
Protect bit 3
RW RW RO
(b5-b4) (b7-b6)
Reserved bit Reserved bit
Note1 The PRC2 bit is set to "0" by writing to any address after setting it to "1". Other bits are not set to "0" by writing to any address, and must therefore be set to "0" in a program.
Figure 4.5 Protect register
REJ05B0288-0100Z/Rev.1.00
November 2003
Page 14 of 55
R8C/11 Group Control of a Brushless DC Motor
b7 b6 b5 b4 b3 b2 b1 b0
Interrupt control register KUPIC (004D16 address) INT1IC (005916 address) INT3IC (005A16 address)
Bit Symbol ILVL0
Bit Name Interrupt select bit priority level
b2b1b0
Function 000:Level 0 (interrupt disabled) 001:Level 1 010:Level 2 011:Level 3 100:Level 4 101:Level 5 110:Level 6 111:Level 7
RW RW
ILVL1
RW
ILVL2
RW RW
(Note1)
IR (b7-b4)
Interrupt request bit
0:Interrupt not requested 1:Interrupt requested Nothing is assigned. When write, set to "0". When read, its content is indeterminate.
-
Note1 Only "0" can be written to the IR bit. (Do not write "1"). Note2 To rewrite the interrupt control register, do so at a point that does not generate the interrupt request for that register. Refer to "19.2.6 Changing Interrupt Control Registers" in the Hardware Manual.
Figure 4.6 Interrupt control register
REJ05B0288-0100Z/Rev.1.00
November 2003
Page 15 of 55
R8C/11 Group Control of a Brushless DC Motor
b7 b6 b5 b4 b3 b2 b1 b0 0
Interrupt control register INT0IC (005D16 address) Bit Symbol ILVL0
Bit Name Interrupt select bit priority level
b2b1b0
Function 000:Level 0 (interrupt disabled) 001:Level 1 010:level 2 011:Level 3 100:Level 4 101:Level 5 110:Level 6 111:Level 7
RW RW
ILVL1
RW
ILVL2
RW RW
(Note1)
IR POL (b5) (b7-b6)
0:Interrupt not requested 1:Interrupt requested Polarity select bit 0:Selects falling edge 1:Selects rising edge (Note3) Reserved bit Must always be set to "0" Nothing is assigned. When write, set to "0". When read, its content is indeterminate.
Interrupt request bit
RW RW -
Note1 Only "0" can be written to the IR bit. (Do not write "1"). Note2 To rewrite the interrupt control register, do so at appoint that does not generate the interrupt request for that register. Refer to "19.2.6 Changing Interrupt Control Registers" in the Hardware Manual. Note3 If the INT0PL bit in the INTEN register is set to "1" (both edges), set the POL bit to "0" (selecting falling edge). Note4 The IR bit may be set to "1"(interrupt requested) when the POL bit is rewritten. Refer to "19.2.5 Changing Interrupt source" in the Hardware Manual.
Figure 4.7 Interrupt control register
b7 b6 b5 b4 b3 b2 b1 b0 00 0 0 0 0 0 1
External input enable register (009616 address) INTEN Bit Symbol INT0EN INT0PL (b7-b2) Bit Name INT0 input enable bit (Note1) INT0 input polarity select bit (Note2,3)) Reserved bit Function 0:Disabled 1:Enabled 0:One edge 1:Both edges Must set to "0". RW RW RW RW
Note1 This bit must be set while the INT0STG bit in the PUM register is set to "0" (one-shot trigger disabled) Note2 When setting the INT0PL bit to "1"(selecting both edges), the POL bit in the INT0IC must be set to "0"(selecting falling edge). Note3 The IR bit in the INT01C register may be set to "1"(interrupt requested) when the INT0PL bit is rewritten. Refer to "19.2.5 Changing Interrupts Source" in the Hardware Manual.
Figure 4.8 External input enable register
REJ05B0288-0100Z/Rev.1.00
November 2003
Page 16 of 55
R8C/11 Group Control of a Brushless DC Motor
b7 b6 b5 b4 b3 b2 b1 b0 000
INT0 input filter select register (001E16 address) INT0F Bit Symbol INT0F0 Bit Name INT0 input filter select bit
b1b0
Function 00 : No filter 01 : Filter with f1 sampling 10 : Filter with f8 sampling 11 : Filter with f32 sampling
RW
RW
INT0F1
RW (b2) (b7-b3) Reserved bit Must set to "0". Nothing is assigned. When write, set to "0". If read, its content is indeterminate. RW -
Figure 4.9 INT0 input filter select register
b7 b6 b5 b4 b3 b2 b1 b0 00 0 0 00
Timer X mode register (008B16 address) TXMR Bit Symbol TXMOD0 TXMOD1 R0EDG TXS TXOCNT TXMOD2 TXEDG TXUND Bit Name Operation mode select bit 0,1 INT1/CNTR0 polarity switching bit (Note2,3) Timer X count start flag
b1b0
Function 00 : Timer mode or pulse period measurement mode (Note3) 0 : Rising edge 1 : Falling edge 0 : Stops counting 1 : Starts counting
RW RW RW RW RW RW RW RW RW
Must set to "0" in timer mode Operation mode select bit 2 0 : Other than pulse period measurement mode (Note3) Must set to "0" in timer mode Must set to "0" in timer mode
Note1 The IR bit in the INT1IC may be set to "1" (interrupt requested) when the R0EDG bit is rewritten. Refer to "19.2.5 Changing Interrupt Source" in the Hardware Manual. Note2 This bit is used to select the polarity of INT1 interrupt in timer mode. Note3 When using INT1 interrupts, should select timer mode.
Figure 4.10 Timer X mode register
REJ05B0288-0100Z/Rev.1.00
November 2003
Page 17 of 55
R8C/11 Group Control of a Brushless DC Motor
b7 b6 b5 b4 b3 b2 b1 b0 0 0
Timer Y, Z mode register (008016 address) TYZMR Bit Symbol TYMOD0 R1EDG TYWC
Bit Name Timer Y operation mode bit INT2/CNTR1 polarity switching bit (Note1,2) Timer Y write control bit
Function 0 : Timer mode (Note1) 0 : Rising edge 1 : Falling edge 0 : Write to reload register and counter simultaneously 1 : Write to reload register 0 : Stops counting 1 : Starts counting
RW RW RW RW RW RW RW RW RW
TYS TZMOD0 TZMOD1 TZWC TZS
Timer Y count start flag Timer Z-related bit
Note1 When using INT2 interrupt, must set to timer mode. Note2 The IR bit in the INT2IC may be "1" (interrupt requested) when R1EDG bit is rewritten. Changing Interrupt Source" in the Hardware Manual.
Refer to "19.2.5
Figure 4.11 Timer Y, Z mode register
b7 b6 b5 b4 b3 b2 b1 b0 1 0 0 0
Key input enable register (009816 address) KIEN Bit Symbol KI0EN KI0PL KI1EN KI1PL KI2EN KI2PL KI3EN KI3PL Bit Name KI0 input enable bit KI0 input polarity select bit KI1 input enable bit KI1 input polarity select bit KI2 input enable bit KI2 input polarity select bit KI3 input enable bit KI3 input polarity select bit Function 0 : Disabled 1 : Enabled 0 : Falling edge 1 : Rising edge 0 : Disabled 1 : Enabled 0 : Falling edge 1 : Rising edge 0 : Disabled 1 : Enabled 0 : Falling edge 1 : Rising edge 0 : Disabled 1 : Enabled 0 : Falling edge 1 : Rising edge RW RW RW RW RW RW RW RW RW
Note1 The IR bit in the KUPIC may be set to "1" (interrupt requested) when the KIEN register is written. "19.2.5 Changing Interrupt Source" in the Hardware Manual.
Refer to
Figure 4.12 Key input enable register
REJ05B0288-0100Z/Rev.1.00
November 2003
Page 18 of 55
R8C/11 Group Control of a Brushless DC Motor
b7 b6 b5 b4 b3 b2 b1 b0 00 01
Timer count source setting register (008E16 address) TCSS Bit Symbol TXCK0 TXCK1 TYCK0 TYCK1 TZCK0 TZCK1 Timer Z count source select bit (Note1) Timer Y count source select bit (Note1) Bit Name Timer X count source select bit (Note1)
b1b0
Function 00 : f1 01 : f8 10 : f32 11 : f2
b3b2
RW RW RW RW RW RW RW
00 : f1 01 : f8 10 : fRING 11 : Selects input from CNTR1 pin
b5b4
00 : f1 01 : f8 10 : Selects Timer Y underflow 11 : f2 Must set to be "0"
(b7-b6)
Reserved bit
RW
Note1 Avoid switching a count source while a counter is in progress. Timer counter must be stopped before switching a count source.
Figure 4.13 Timer count source setting register
b7
B0
Prescaler Y register (008116 address) PREY Mode Timer mode Programmable waveform generation mode Function Internal count source or CNTR1 input is counted. Internal count source is counted. Setting range 0016 to FF16 0016 to FF16 RW RW RW
Figure 4.14 Prescaler Y register
b7
b0
Timer Y primary register (008316 address) TYPR Mode Timer mode Function Underflow of Prescaler Y is counted. Setting range 0016 to FF16 RW RW RW
Programmable Underflow of Prescaler is counted. (Note1) 0016 to FF16 waveform generation mode Note1 The values of TYPR register and TYSC register are reloaded to the counter alternately for counting.
Figure 4.15 Timer Y primary register
REJ05B0288-0100Z/Rev.1.00
November 2003
Page 19 of 55
R8C/11 Group Control of a Brushless DC Motor
b7 b6 b5 b4 b3 b2 b1 b0 0001000
Timer C control register 0 (009A16 address) TCC0 Bit Symbol TCC00 TCC01 TCC02 TCC03 TCC04 (b6-b5) TCC07 Reserved bit INT3 interrupt/capture input switching bit (Note1,2) INT3 interrupt and capture polarity select bit (Note1,2)) Bit Name Timer C count start bit Timer C count source select bit (Note1) Function 0 : Stops counting 1 : Starts counting
b2b1
RW RW RW RW RW RW RW RW
00 : f1 01 : f8 10 : f32 11 : fRING-fast
b4b3
00 : Rising edge 01 : Falling edge 10 : Both edges 11 : Avoid this setting Must set to "0" 0 : INT3 1 : fRING128
Note1 Change this bit when TCC00 bit is set to "0" (count stop). Note2 The IR bit in the INT3IC may be set to "1" (interrupt requested) when the TCC03, TCC04, or TCC07 bit is rewritten. Refer to "19.2.5 Changing Interrupt Source" in the Hardware Manual.
Figure 4.16 Timer C control register 0
REJ05B0288-0100Z/Rev.1.00
November 2003
Page 20 of 55
R8C/11 Group Control of a Brushless DC Motor
b7 b6 b5 b4 b3 b2 b1 b0 10 1 1 1 1 0 0 Timer C control register 1 (009B16 address) TCC1 Bit Symbol TCC10 Bit Name INT3 filter select bit (Note1)
b1b0
Function 00 : No filter 01 : Filter with f1 sampling 10 : Filter with f8 sampling 11 : Filter with f32 sampling
RW
RW
TCC11
RW TCC12 Timer C counter select bit (Note2,3) reload 0 : No reload (free-run) 1 : Set TC register to "000016" at compare 1 match 0 : Capture (input capture mode) (Note2) 1 : Compare 0 output (output compare mode)
b5b4
WO
TCC13
Compare 0/Capture select bit
RW
TCC14
Compare 0 output mode select mode (Note3)
TCC15
00 : CMP0 output remains unchanged even when compare 0 signal matched 01 : CMP0 output is reversed when compare 0 signal is matched. 10 : CMP0 output is set to low when compare 0 signal is matched. 11 : CMP0 output is set to high when compare 0 signal is matched.
b7b6
RW
RW
TCC16
Compare 1 output mode select bit (Note3)
TCC17
00 : CMP1 remains unchanged even when compare 1 signal is matched. 01 : CMP1output is reversed when compare 1 signal is matched. 10 : CMP1output is set to low when compare 1 signal is matched. 11 : CMP1output is set to high when compare 1 signal is matched.
RW
RW
Note1 Input is recognized only when the same value from INT3 pin is sampled three times in succession. Note2 The TCC13 bit in the TCC0 register should be "0" (count stop) when rewriting the TCC13 bit. Note3 The TCC12 and TCC14 to TCC17 should be set to "0" when the TCC13 bit is "0" (input capture mode).
Figure 4.17 Timer C control register 1
REJ05B0288-0100Z/Rev.1.00
November 2003
Page 21 of 55
R8C/11 Group Control of a Brushless DC Motor
(b15) b7
(b8) b0 b7
b0
Timer C register (009116-009016 address) TC RW RO
Function Internal count source is counted. "000016" is read out by reading TCC00 bit = 0 (stops counting). Count value is read out by reading when TCC00 bit = 1 (starts counting).
Figure 4.18 Timer C register
(b15) b7
(b8) b0 b7
b0
Capture and compare 0 register (009D16-009C16 address) TM0 Function When active edge of measurement pulse is input, the value in the TC register is stored. The value compared with Timer C is stored. Setting range RW RO 000016 to FFFF16 RW
Mode Input capture mode
Output mode
compare
Figure 4.19 Capture and compare 0 register
(b15) b7
(b8) b0 b7
b0
Compare 1 register (009F16-009E16 address) TM1 Function The value compared with Timer C is stored. Setting range 000016 to FFFF16 RW RW
Mode Output compare mode (Note1)
Note1 Disabled when the TCC13 register is set to "0" (input capture mode).
Figure 4.20 Compare 1 register
REJ05B0288-0100Z/Rev.1.00
November 2003
Page 22 of 55
R8C/11 Group Control of a Brushless DC Motor
b7 b6 b5 b4 b3 b2 b1 b0 01000111
Timer C output control register (00FF16 address) TCOUT Bit Symbol TCOUT0 Bit Name CMP output enable bit 0 Function 0 : Disable CMP output from CMP00 1 : Enable CMP output from CMP00. 0 : Disable CMP output from CMP01. 1 : Enable CMP output from CMP01. 0 : Disable CMP output from CMP02 1 : Enable CMP output from CMP02. 0 : Disable CMP output from CMP10. 1 : Enable CMP output form CMP10. 0 : Disable CMP output from CMP11. 1 : Enable CMP output from CMP11. 0 : Disable CMP output from CMP12. 1 : Enable CMP output from CMP12. 0 : Not reverse CMP output from CMP00 to CMP02 1 : Reverse CMP output from CMP00 to CMP02 0 : Not reverse CMP output from CMP10 to CMP12 1 : Reverse CMP output from CMP10 to CMP12 RW
RW
TCOUT1
CMP output enable bit 1
RW
TCOUT2
CMP output enable bit 2
RW
TCOUT3
CMP output enable bit 3
RW
TCOUT4
CMP output enable bit 4
RW
TCOUT5
CMP output enable bit 5
RW
TCOUT6
CMP output reverse bit 0
RW
TCOUT7
CMP output reverse bit 1
RW
Note1 Invalid when the TCC 13 bit in the TCC1 register is set to "0" (input capture mode).
Figure 4.21 Timer C output control register
REJ05B0288-0100Z/Rev.1.00
November 2003
Page 23 of 55
R8C/11 Group Control of a Brushless DC Motor
b7 b6 b5 b4 b3 b2 b1 b0
Port P1 register (00E116 address) P1 Bit Symbol P1_0 P1_1 P1_2 P1_3 P1_4 P1_5 P1_6 P1_7 Bit Name Port P10 bit Port P11 bit Port P12 bit Port P13 bit Port P14 bit Port P15 bit Port P16 bit Port P17 bit Function The pin level on any I/O port which is set for input mode can be read by reading the corresponding bit in this register. The pin level on any I/O port which is set for output mode can be controlled by writing to the corresponding bit in this register. 0:"L" level 1:"H" level RW RW RW RW RW RW RW RW RW
Figure 4.22 Port P1 register
b7 b6 b5 b4 b3 b2 b1 b0 0 0111
Port P1 direction register (00E316 address) PD1 Bit Symbol PD1_0 PD1_1 PD1_2 PD1_3 PD1_4 PD1_5 PD1_6 PD1_7 Bit Name Port P10 direction bit Port P11 direction bit Port P12 direction bit Port P13 direction bit Port P14 direction bit Port P15 direction bit Port P16 direction bit Port P17 direction bit Function 0 : Input mode (Functions as an input mode) 1 : Output mode (Functions as an output mode) RW RW RW RW RW RW RW RW RW
Figure 4.23 Port P1 register
b7 b6 b5 b4 b3 b2 b1 b0 000
Port P3 register (00E516 address) P3 Bit Symbol P3_0 P3_1 P3_2 P3_3 P3_4 P3_5 P3_6 P3_7 Bit Name Port P30 bit Port P31 bit Port P32 bit Port P33 bit Port P34 bit (Note1) Port P35 bit (Note1) Port P36 bit (Note1) Port P37 bit Function The pin level on any I/O port which is set for input mode can be read by reading the corresponding bit in this register. The pin level on any I/O port which is set for output mode can be controlled by writing to the corresponding bit in this register. 0:"L" level 1:"H" level When read, its content is "0". RW RW RW RW RW RW RW RW RW
Note1 Nothing is assigned.
When writing to this bit, write "1" (low level).
Figure 4.24 Port P3 register
REJ05B0288-0100Z/Rev.1.00
November 2003
Page 24 of 55
R8C/11 Group Control of a Brushless DC Motor
b7 b6 b5 b4 b3 b2 b1 b0 0000111
Port P3 direction register (00E716 address) PD3 Bit Symbol PD3_0 PD3_1 PD3_2 PD3_3 PD3_4 PD3_5 PD3_6 PD3_7 Bit Name Port P30 direction bit Port P31 direction bit Port P32 direction bit Port P33 direction bit Port P34 direction bit (Note1) Port P35 direction bit (Note1) Port P36 direction bit (Note1) Port P37 direction bit Function 0 : Input mode (Function as an input port) 1 : Output mode (Functions as an output mode) RW RW RW RW RW RW RW RW RW
Note1 Nothing is assigned.
When writing to this bit, write "0" (input mode). When reading, its content is "0".
Figure 4.25 Port P3 direction register
b7 b6 b5 b4 b3 b2 b1 b0 00000
Port P4 register (00E816 address) P4 Bit Symbol P4_0 P4_1 P4_2 P4_3 P4_4 P4_5 P4_6 P4_7 Bit Name Port P40 bit (Note1) Port P41bit (Note1) Port P42 bit (Note1) Port P43 bit (Note1) Port P44 bit (Note1) Port P45 bit Port P46 bit Port P47 bit Function The pin level on any I/O port which is set for input mode can be read by reading the corresponding bit in this register. The pin level on any I/O port which is set for output mode can be controlled by writing to the corresponding bit in this register. 0:"L" level 1:"H" level When reading, its content is "0". RW RW RW RW RW RW RW RW RW
Note1 Nothing is assigned.
When writing to this bit, write "0" (low level).
Figure 4.26 Port P4 register
b7 b6 b5 b4 b3 b2 b1 b0 00000000 Port P4 direction register (00EA16 address) PD4 Bit Symbol PD4_0 PD4_1 PD4_2 PD4_3 PD4_4 PD4_5 PD4_6 PD4_7 Note1 Nothing is assigned. Bit Name Port P40 direction bit (Note1) Port P41 direction bit (Note1) Port P42 direction bit (Note1) Port P43 direction bit (Note1) Port P44 direction bit (Note1) Port P45 direction bit Port P46 direction bit (Note1) Port P47 direction bit (Note1) Function 0 : Input mode (Functions as an input port) 1 : Output mode (Functions as an output port) RW RW RW RW RW RW RW RW RW
When writing to this bit, write "0" (input mode). When reading, its content is "0".
Figure 4.27 Port P4 direction register
REJ05B0288-0100Z/Rev.1.00
November 2003
Page 25 of 55
R8C/11 Group Control of a Brushless DC Motor
b7 b6 b5 b4 b3 b2 b1 b0 00 00
Pull-up control register 0 (00FC16 address) PUR0 Bit Symbol PU00 PU01 PU02 PU03 (b5-b4) PU06 PU07 Bit Name Function RW RW RW RW RW RW RW
0 : Not pulled high P00 to P03 pull-up (Note1) 1 : Pulled high P04 to P07 pull-up (Note1) P10 to P13 pull-up (Note1) P14 to P17 pull-up (Note1) Nothing is assigned. When write, set to "0". When read, its content is indeterminate. 0 : Not pulled high P30 to P33 pull-up (Note1) 1 : Pulled high P37 pull-up (Note1)
Note1 The pin for which this bit is "1"(pulled high) and the direction bit is "0" (input mode) is pulled high.
Figure 4.28 Pull-up control register 0
b7 b6 b5 b4 b3 b2 b1 b0 0
Pull-up control register 1 (00FD16 address) PUR1 Bit Symbol (b0) PU11 (b7-b2) Bit Name Function RW RW -
Nothing is assigned. When write, set to "0". When read, its content is indeterminate. P45 pull-up (Note1) 0 : Not pulled high 1 : Pulled high Nothing is assigned. When write, set to "0". When read, its content is indeterminate.
Note1 The P45 pin for which this bit is "1" (pulled high) and the PD4_5 bit is "0" (input mode) is pulled high.
Figure 4.29 Pull-up control register 1
b7 b6 b5 b4 b3 b2 b1 b0 000
Port P1 drive capacity control register (00FE16 address) DRR Bit Symbol DRR0 DRR1 DRR2 DRR3 DRR4 DRR5 DRR6 DRR7 Bit Name P10 drive capacity P11 drive capacity P12 drive capacity P13 drive capacity P14 drive capacity P15 drive capacity P16 drive capacity P17 drive capacity Function Set P1 N-channel output transistor drive capacity 0 : Low 1 : High RW RW RW RW RW RW RW RW RW
Figure 4.30 Port P1 drive capacity control register
REJ05B0288-0100Z/Rev.1.00
November 2003
Page 26 of 55
R8C/11 Group Control of a Brushless DC Motor 4.3 Description of Data Table
In this sample task, six patterns data on the table are output to P1 and P3 at motor control. Table 4.2 shows the description of data table at initial motor control, and Table 4.3 shows the description of data table at motor control based on the rotor-positional signal. Table 4.2 Description of Data Table (_Init_p1Active_Phase_TBL/_Init_p3Active_Phase_TBL)
Table Name _Init_p1Active_Phase_TBL[0] _Init_p3Active_Phase_TBL[0] _Init_p1Active_Phase_TBL[1] _Init_p3Active_Phase_TBL[1] _Init_p1Active_Phase_TBL[2] _Init_p3Active_Phase_TBL[2] _Init_p1Active_Phase_TBL[3] _Init_p3Active_Phase_TBL[3] _Init_p1Active_Phase_TBL[4] _Init_p3Active_Phase_TBL[4] _Init_p1Active_Phase_TBL[5] _Init_p3Active_Phase_TBL[5] Data H'01 H'05 H'01 H'03 H'02 H'03 H'02 H'06 H'04 H'06 H'04 H'05 Output Pattern U=ON, V=OFF, W=OFF _U=OFF, _V=ON, _W=OFF U=ON, V=OFF, W=OFF _U=OFF,_V=OFF, _W=ON U=OFF, V=ON, W=OFF _U=OFF, _V=OFF, _W=ON U=OFF, V=ON, W=OFF _U=ON, _V=OFF, _W=OFF U=OFF, V=OFF, W=ON _U=ON, _V=OFF, _W=OFF U=OFF, V=OFF, W=ON _U=OFF, _V=ON, _W=OFF Size 1Byte 1Byte 1Byte 1Byte 1Byte 1Byte 1Byte 1Byte 1Byte 1Byte 1Byte 1Byte Remarks 0 60 120 180 240 300
Note1 "1" is on, and "0" is off for positive phase. "0" is on , and "1" is off for negative phase. Table 4.3 Description of Data Table (_p1Active_Phase_TBL/_p3Active_Phase_TBL)
Table Name _p1Active_Phase_TBL[0] _p3Active_Phase_TBL[0] _p1Active_Phase_TBL[1] _p3Active_Phase_TBL[1] _p1Active_Phase_TBL[2] _p3Active_Phase_TBL[2] _p1Active_Phase_TBL[3] _p3Active_Phase_TBL[3] _p1Active_Phase_TBL[4] _p3Active_Phase_TBL[4] _p1Active_Phase_TBL[5] _p3Active_Phase_TBL[5] Data H'01 H'03 H'02 H'03 H'02 H'06 H'04 H'06 H'04 H'05 H'01 H'05 Output Pattern U=ON, V=OFF, W=OFF _U=OFF, _V=OFF, _W=ON U=OFF, V=ON, W=OFF _U=OFF, _V=OFF, _W=ON U=OFF, V=ON, W=OFF _U=ON, _V=OFF, _W=OFF U=OFF, V=OFF, W=ON _U=ON, _V=OFF, _W=OFF U=OFF, V=OFF, W=ON _U=OFF, _V=ON, _W=OFF U=ON, V=OFF, W=OFF _U=OFF, _V=ON, _W=OFF Size 1Byte 1Byte 1Byte 1Byte 1Byte 1Byte 1Byte 1Byte 1Byte 1Byte 1Byte 1Byte Remarks 0 60 120 180 240 300
Note1 "1" is on, and "0" is off for positive phase. "0" is on , and "1" is off for negative phase.
REJ05B0288-0100Z/Rev.1.00
November 2003
Page 27 of 55
R8C/11 Group Control of a Brushless DC Motor 4.4 Flowchart
1.Register initialization routine
Initialize prcr = 0x01 cm0 = 0x08 cm1 = 0x78 ocd = 0x00 prcr = 0x00 tcc0 = 0x10 tcc1 = 0xbc tcout = 0x47 p1 = INIT_P1 pd1 = INIT_PD1 p3 = INIT_P3 pd3 = INIT_PD3 p4 = INIT_P4 pd4 = INIT_PD4 pur0 = 0x00 pur1 = 0x00 drr = 0x00 int0f = 0x00 inten = 0x01 txmr = 0x00 txmr = 0x00 tyzmr = 0x00 kien = 0x40 int0ic = 0x00 int1ic = 0x00 int3ic = 0x00 kupic = 0x00 ; cm0,cm1,ocd write enable ; initialize ; initialize ; initialize ; cm0,cm1,ocd write disable ; TC count stop TC source:f1, INT3 both edge, INT3 interrupt ; no filter, TC register reset, output compare mode comp0:"High", comp1:"Low" ; CMP00-CMP02 enable, CMP10-CMP12 disable, CMP00-CMP02 reverse ; CMP00-CMP02 OFF ; P10-P12: output, P13/KI3,P17/INT1: input ; P30-P32 OFF ; P30-P32: output, P33/INT3: input ; initialize ; P45/INT0: input ; initialize ; initialize ; initialize ; INT0 no filter ; INT0 input enable, INT0 one edge ; timer mode ; timer mode tcss = 0x05 ; timer mode prey = 25-1 ; KI3 input enable typr = 100-1 ; initialize tys = 1 ; initialize ; initialize ; initialize ; timerY source:f8 ; 20MHz/8/25=100kHz ; 100kHz/100=1kHz(=1ms) ; timerY count start
return
REJ05B0288-0100Z/Rev.1.00
November 2003
Page 28 of 55
R8C/11 Group Control of a Brushless DC Motor 2.Main routine
Main Initialization Init_Motor_sfr() asm("fset No i")
tyic_ir = 1 Yes tyic_ir = 0 Motor control Motor_Cntrl
; 1ms ?
REJ05B0288-0100Z/Rev.1.00
November 2003
Page 29 of 55
R8C/11 Group Control of a Brushless DC Motor 3.Motor control routine
Motor_Cntrl chage_req=0 No --CD_Motor10ms == 0
Yes cd_motor10ms = PERIOD_10ms ; initialize 10ms counter ; set a change request chage_req = 1
No
motor_sts == MOTOR_OFF
; motor off ?
Yes ; change a motor state motor_sts = MOTOR_START cd_motor10ms = PERIOD_10ms ; initialize 10ms counter ; set a change request chage_req = 1 Positional signal input _Sens_Input() SENSER_DEG0 No Yes out_phase = PHASE_DEG0 r0edg = INT1_FALLING_EDGE pol_int0ic = INT0_RISING_EDGE ki3pl = KI3_FALLING_EDGE Yes out_phase = PHASE_DEG60 r0edg = INT1_FALLING_EDGE pol_int0ic = INT0_RISING_EDGE ki3pl = KI3_RISING_EDGE Yes ; 120deg out_phase = PHASE_DEG120 r0edg = INT1_FALLING_EDGE pol_int0ic = INT0_FALLING_EDGE ki3pl = KI3_RISING_EDGE Yes ; 180deg out_phase = PHASE_DEG180 r0edg = INT1_FALLING_EDGE pol_int0ic = INT0_FALLING_EDGE ki3pl = KI3_RISING_EDGE Yes out_phase = PHASE_DEG240 ; 240deg r0edg = INT1_RISING_EDGE pol_int0ic = INT0_FALLING_EDGE ki3pl = KI3_FALLING_EDGE ; 60deg ; 0deg
SENSER_DEG60 No
SENSER_DEG120 No
SENSER_DEG180 No
SENSER_DEG240 No
out_phase = PHASE_DEG300 r0edg = INT1_RISING_EDGE pol_int0ic = INT0_RISING_EDGE ki3pl = KI3_FALLING_EDGE
; 300deg
A
REJ05B0288-0100Z/Rev.1.00
November 2003
Page 30 of 55
R8C/11 Group Control of a Brushless DC Motor
Motor control routine (continued)
A in_phase = out_phase cu_init_rotate = 0 ir_int3ic = 0 ir_int1ic = 0 ir_int0ic = 0 ir_kupic = 0 int1ic = 0x06 int0ic |= 0x06 kupic = 0x06 int3ic &= 0xf8 motor_sts == MOTOR_START No ; initialize an input angle ; initialize an initial rotation counter ; clear an ERR signal interrupt request ; clear a rotor signal 0 interrupt request ; clear a rotor signal 1 interrupt request ; clear a rotor signal 2 interrupt request ; rotor signal 0 interrupt enable ; rotor signal 1 interrupt enable ; rotor signal 2 interrupt enable ; ERR signal interrupt disable Yes ; motor start pwm_duty = DUTY_10P PWM output setting _PWM_Set() No chage_req == 1 Yes chage_req = 0 No ; output change request ? ; PWM duty initialze
; clear a change request ; Initial rotation end ?
cu_init_rotate >= INIT_ROTATE
Yes motor_sts = MOTOR_START2 ; change a motor state Initial-stage excited phase output _InitOutPhase_Active(motor_sts) int3ic |= 0x06 ; ERR signal interrupt enable
motor_sts == MOTOR_START2 No
Yes
; motor start 2 motor_sts = MOTOR_NOMAL ; change a motor state int3ic |= 0x06 ; ERR signal interrupt enable
motor_sts == MOTOR_NOMAL No Initial-stage excited phase output _OutPhase_Active(motor_sts) PWM output setting _PWM_Set()
Yes
; normal pwm_duty = DUTY_20P PWM output setting _PWM_Set() int3ic |= 0x06 ; ERR signal interrupt enable ; PWM duty :20%
return
REJ05B0288-0100Z/Rev.1.00
November 2003
Page 31 of 55
R8C/11 Group Control of a Brushless DC Motor 4.Rotor-positional signal (INT1) interrupt routine
Sens_In0_int Positional-signal input senser = _Sens_Input() No No ; use a register bank 1
r0edg == INT1_FALLING_EDGE Yes No senser == SENSER_DEG180 Yes No in_phase == _Phase_shift_jdg_TBL[PHASE_DEG180] Yes
senser == SENSER_DEG0 Yes
in_phase == _Phase_shift_jdg_TBL[PHASE_DEG0] Yes in_phase = PHASE_DEG0 ; 0deg r0edg = INT1_FALLING_EDGE ir_int1ic = 0 Excited phase output _OutPhase_Active(motor_sts)
No
in_phase = PHASE_DEG180 ; 180deg r0edg = INT1_RISING_EDGE ir_int1ic = 0 Excited phase output _OutPhase_Active(motor_sts)
reit
REJ05B0288-0100Z/Rev.1.00
November 2003
Page 32 of 55
R8C/11 Group Control of a Brushless DC Motor
5.Rotor positional-signal (INT0) interrupt routine
Sens_In1_int Positional-signal input senser = _Sens_Input()
; use a register bank 1
pol_int0ic == INT0_FALLING_EDGE Yes No senser == SENSER_DEG300 Yes No in_phase == _Phase_shift_jdg_TBL[PHASE_DEG300] Yes
No No
senser == SENSER_DEG120 Yes
in_phase == _Phase_shift_jdg_TBL[PHASE_DEG120] Yes
No
in_phase = PHASE_DEG300 ; 300deg pol_int0ic = INT0_RISING_EDGE ir_int0ic = 0 Excited phase output _OutPhase_Active(motor_sts)
in_phase = PHASE_DEG120 ; 120deg pol_int0ic = INT0_FALLING_EDGE ir_int0ic = 0 Excited phase output _OutPhase_Active(motor_sts)
reit
REJ05B0288-0100Z/Rev.1.00
November 2003
Page 33 of 55
R8C/11 Group Control of a Brushless DC Motor 6.Rotor-positional signal (KI3) interrupt routine
Sens_In2_int Positional-signal input senser = _Sens_Input() No No ; use a register bank 1
ki3pl == KI3_FALLING_EDGE Yes No senser == SENSER_DEG60 Yes No in_phase == _Phase_shift_jdg_TBL[PHASE_DEG60] Yes in_phase = PHASE_DEG60 ki3pl = KI3_RISING_EDGE ir_kupic = 0 Excited phase output _OutPhase_Active(motor_sts)
senser == SENSER_DEG240 Yes
in_phase == _Phase_shift_jdg_TBL[PHASE_DEG240] Yes
No
; 60deg
in_phase = PHASE_DEG240 ; 240deg ki3pl = KI3_FALLING_EDGE ir_kupic = 0 Excited phase output _OutPhase_Active(motor_sts)
reit
REJ05B0288-0100Z/Rev.1.00
November 2003
Page 34 of 55
R8C/11 Group Control of a Brushless DC Motor 7.Motor-rotation stop signal (INT3) interrupt routine
_Error_int motor_sts = MOTOR_ERROR
; use a register bank 1
Excited phase output _OutPhase_Active(motor_sts) PWM output setup _PWM_Set()
reit
REJ05B0288-0100Z/Rev.1.00
November 2003
Page 35 of 55
R8C/11 Group Control of a Brushless DC Motor 8.Initial-stage excited phase output routine
_InitOutPhase_Active Yes p1 &= 0xf8 p3 |= 0x07 p1_data = _Init_p1Active_Phase_TBL[out_phase] p3_data = _Init_p3Active_Phase_TBL[out_phase] p1 = p1_data p3 = p3_data No ; positive phase output off ; negative phase output off ; set the P1 output data ; set the P3 output data
status == MOTOR_START No
++out_phase >= PHASE_DEG360 ; one revolution ? Yes out_phase = PHASE_DEG0 ; initialize the output phase (0deg) ++cu_init_rotate ; count the initial rotation
status == MOTOR_START2 No
Yes p1 &= 0xf8 p3 |= 0x07 ; positive phase output off ; negative phase output off
return
REJ05B0288-0100Z/Rev.1.00
November 2003
Page 36 of 55
R8C/11 Group Control of a Brushless DC Motor 9.Excited phase output routine
_OutPhase_Active Yes p1 &= 0xf8 p3 |= 0x07 p1_data = _p1Active_Phase_TBL[out_phase] p3_data = _p3Active_Phase_TBL[out_phase] p1 = p1_data p3 = p3_data Yes ; positive phase output off ; negative phase output off ; set the P1 output data ; set the P3 output data
status == MOTOR_NOMAL No
status == MOTOR_START No status == MOTOR_START2 No p1 &= 0xf8 p3 |= 0x07 int1ic = 0x00 int0ic = 0x00 kupic = 0x00 int3ic = 0x00 out_phase = PHASE_DEG0 pwm_duty = DUTY_0P
Yes
; positive phase output off ; negative phase output off ; rotor signal 0 interrupt diable ; rotor signal 1 interrupt diable ; rotor signal 2 interrupt diable ; ERR signal interrupt disable ; output phase 0deg ; PWM duty 0%
return
REJ05B0288-0100Z/Rev.1.00
November 2003
Page 37 of 55
R8C/11 Group Control of a Brushless DC Motor 10. PWM output setup output routine
_PWM_Set pwm_period = PWM_15kHz tm1 = pwm_period
; set a tm1 register (PWM period)
pwm_duty == DUTY_10P Yes No pwm_duty == DUTY_20P Yes No tm0 = 0xffff tm0 = DUTY_20P_COMP ; set a tm0 register ; set a tm0 register tm0 = DUTY_10P_COMP ; set a tm0 register
tcout = 0x47 tcc00 = 1
; CMP00-CMP02 enable, CMP10-CMP12 disable, CMP00-CMP02 reverse ; timer C count start
return
11.Positional signal input routine
_Sens_Input work0 = p4 & P4_MASK work1 = p1 & P1_MASK
return (work0 |= work1)
REJ05B0288-0100Z/Rev.1.00
November 2003
Page 38 of 55
R8C/11 Group Control of a Brushless DC Motor
5. Program Listing
/*""FILE COMMENT""*********************************************************** * System Name : DC BrashLess Motor Control * File Name : main.c * Version : Ver 1.00 * Contents : mein processing * CPU : R5F21114FP * Compiler : NC30WA V.5.20 Release 1 * OS : * Programmer : **************************************************************************** * Copyright,2003 RENESAS TECHNOLOGY CORPORATION * AND RENESAS SOLUTIONS CORPORATION * ALL RIGHTS RESERVED **************************************************************************** * History : *""FILE COMMENT END""******************************************************/ #include "sfr_r811.h" #include "motorlib.h" /*""FUNC COMMENT""*********************************************************** * Name : main() *--------------------------------------------------------------------------* Parameters : None * Returns : None * Description : main routine * SubRoutine : Init_Motor_sfr() * : Motor_Cntrl() *--------------------------------------------------------------------------* Note : *--------------------------------------------------------------------------* History : *""FUNC COMMENT END""******************************************************/ void main() { Init_Motor_sfr(); asm("fset i"); while (1) { while (!ir_tyic); ir_tyic = 0; Motor_Cntrl(); } }
/* 1ms ? */ /* Yes clear timerY interrupt req. flag */ /* motor control */
REJ05B0288-0100Z/Rev.1.00
November 2003
Page 39 of 55
R8C/11 Group Control of a Brushless DC Motor
/*""FILE COMMENT""*********************************************************** * System Name : DC BrashLess Motor Control * File Name : motorlib.h * Version : Ver 1.00 * Contents : motor control processing header * CPU : R5F21114FP * Compiler : NC30WA V.5.20 Release 1 * OS : * Programmer : **************************************************************************** * Copyright,2003 RENESAS TECHNOLOGY CORPORATION * AND RENESAS SOLUTIONS CORPORATION * ALL RIGHTS RESERVED **************************************************************************** * History : *""FILE COMMENT END""******************************************************/ #define DEBUG typedef enum { MOTOR_OFF, MOTOR_START, MOTOR_START2, MOTOR_NOMAL, MOTOR_ERROR } MOTOR_STATUS; typedef enum { PHASE_DEG0, PHASE_DEG60, PHASE_DEG120, PHASE_DEG180, PHASE_DEG240, PHASE_DEG300, PHASE_DEG360 } ROTOR_POSITION; #define DUTY_0P #define DUTY_1P #define DUTY_10P 10 #define DUTY_20P 20 #define DUTY_100P 100 #define PERIOD_10ms #define INIT_ROTATE #define PWM_15kHz #define DUTY_10P_COMP #define DUTY_20P_COMP #define SENSER_MASK #define SENSER0_IN #define SENSER1_IN #define SENSER2_IN #define P1_MASK #define P4_MASK #define SENSER_DEG0 #define SENSER_DEG60 #define SENSER_DEG120 #define SENSER_DEG180 #define SENSER_DEG240 #define SENSER_DEG300 #define INIT_P1 #define INIT_PD1 0 1
/* motor stop */ /* motor start */ /* motor start 2 */ /* motor normal */ /* motor error
*/
/* 0deg /* 60deg /* 120deg /* 180deg /* 240deg /* 300deg /* 360deg
*/ */ */ */ */ */ */
/* /* /* 10% */ /* 20% */ /* 100% */
0% */ 1% */
10 6 1333-1 1200-1 1066-1 0xa8 0x80 0x20 0x08 0x88 0x20 0x88 0x80 0xa0 0x20 0x28 0x08 0x00
/* 10ms */ /* one revolution of electrical degree */ /* 15kHz */ /* 10% (at 15kHz) */ /* 20% (at 15kHz) */ /* mask data (bit7=P17,bit5=P45,bit3=P33)=10101000b /* rotor signal 0 (P17/INT1) */ /* rotor signal 1 (P45/INT0) */ /* rotor signal 2 (P13/KI3) */ /* mask data (P17/INT1,P13/KI3) */ /* mask data(P45/INT0) */ /* 0deg */ /* 60deg */ /* 120deg */ /* 180deg */ /* 240deg */ /* 300deg */ /* P10/CMP00 to P12/CMP02: OFF("Low") /* P10/CMP00 to P12/CMP02: output mode, */
*/
0x07
REJ05B0288-0100Z/Rev.1.00
November 2003
Page 40 of 55
R8C/11 Group Control of a Brushless DC Motor
#define INIT_P3 #define INIT_PD3 #define INIT_P4 #define INIT_PD4 0x07 0x07 0x00 0x00 P13/KI3,P17/INT1: input mode */ /* P30 to P32: OFF("High") */ /* P30 to P32: output mode, P33/INT3: input mode /* initialize */ /* P45/INT0: input mode */ /* INT0 Falling edge */ /* INT0 Rising edge */ /* INT1 Rising edge */ /* INT1 Falling edge */ /* KI3 Falling edge */ 1 /* KI3 Rising edge
*/
#define INT0_FALLING_EDGE 0 #define INT0_RISING_EDGE 1 #define INT1_RISING_EDGE 0 #define INT1_FALLING_EDGE 1 #define KI3_FALLING_EDGE 0 #define KI3_RISING_EDGE typedef unsigned char typedef unsigned short void Init_Motor_sfr ( void ); void Motor_Cntrl( void ); void Sens_In0_int ( void ); void Sens_In1_int ( void ); void Sens_In2_int ( void ); void Error_int ( void ); u08; u16;
*/
REJ05B0288-0100Z/Rev.1.00
November 2003
Page 41 of 55
R8C/11 Group Control of a Brushless DC Motor
/*""FILE COMMENT""*********************************************************** * System Name : DC BrashLess Motor Control * File Name : motorlib.c * Version : Ver 1.00 * Contents : motor control processing * CPU : R5F21114FP * Compiler : NC30WA V.5.20 Release 1 * OS : * Programmer : **************************************************************************** * Copyright,2003 RENESAS TECHNOLOGY CORPORATION * AND RENESAS SOLUTIONS CORPORATION * ALL RIGHTS RESERVED **************************************************************************** * History : *""FILE COMMENT END""******************************************************/ #include "sfr_r811.h" #include "motorlib.h" static u08 motor_sts=MOTOR_OFF; static u08 out_phase; static u08 in_phase; static u08 cu_init_rotate; static u16 pwm_period; static u08 pwm_duty; /* motor state */ /* output phase */ /* input angle */ /* initial rotation counter */ /* PWM period */ /* PWM duty */
static void _InitOutPhase_Active ( MOTOR_STATUS ); static void _OutPhase_Active ( MOTOR_STATUS ); static void _PWM_Set ( void ); static u08 _Sens_Input ( void ); static const u08 _Init_p1Active_Phase_TBL[]; static const u08 _Init_p3Active_Phase_TBL[]; static const u08 _p1Active_Phase_TBL[]; static const u08 _p3Active_Phase_TBL[]; static const u08 _Phase_shift_jdg_TBL[]; /*""FUNC COMMENT""*********************************************************** * Name : Init_Motor_sfr() *--------------------------------------------------------------------------* Parameters : None * Returns : None * Description : initialize SFRs for Motor control * SubRoutine : None *--------------------------------------------------------------------------* Note : *--------------------------------------------------------------------------* History : *""FUNC COMMENT END""******************************************************/ void Init_Motor_sfr ( void ) { prcr = 0x01; /* cm0,cm1,ocd write enable */ cm0 = 0x08; /* initialize */ cm1 = 0x78; /* initialize */ ocd = 0x00; /* initialize */ prcr = 0x00; /* cm0,cm1,ocd write disable */ /* TC count stop TC source:f1, INT3 both edge, INT3 interrupt /* no filter, TC register reset, output compare mode */ /* comp0:"High", comp1:"Low" */ tcout = 0x47; /* CMP00-CMP02 enable, CMP10-CMP12 disable */ /* CMP00-CMP02 reverse */ p1 = INIT_P1; /* CMP00-CMP02 OFF */ pd1 = INIT_PD1; /* P10-P12: output, P13/KI3,P17/INT1: input */ p3 = INIT_P3; /* P30-P32 OFF */ pd3 = INIT_PD3; /* P30-P32: output, P33/INT3: input */ p4 = INIT_P4; /* initialize */ tcc0 = 0x10; tcc1 = 0xbc; */
REJ05B0288-0100Z/Rev.1.00
November 2003
Page 42 of 55
R8C/11 Group Control of a Brushless DC Motor
pd4 = INIT_PD4; /* P45/INT0: input */ pur0 = 0x00; /* initialize */ pur1 = 0x00; /* initialize */ drr = 0x00; /* initialize */ int0f = 0x00; inten = 0x01; txmr = 0x00; tyzmr = 0x00; kien = 0x40; int0ic = 0x00; int1ic = 0x00; int3ic = 0x00; kupic = 0x00; tcss = 0x05; prey = 25-1; typr = 100-1; tys = 1; } /* INT0 no filter */ /* INT0 input enable, INT0 one edge */ /* timer mode */ /* timer mode */ /* KI3 input enable */ /* initialize */ /* initialize */ /* initialize */ /* initialize */ /* timerY source:f8 */ /* 20MHz/8/25=100kHz */ /* 100kHz/100=1kHz(=1ms) */ /* timerY count start */
/*""FUNC COMMENT""*********************************************************** * Name : Motor_Cntrl() *--------------------------------------------------------------------------* Parameters : None * Returns : None * Description : Motor control processing routine * SubRoutine : _InitOutPhase_Active() * : _OutPhase_Active() * : _PWM_Set() * : _Sens_Input() *--------------------------------------------------------------------------* Note : Please perform this function in a cycle of 1ms. *--------------------------------------------------------------------------* History : *""FUNC COMMENT END""******************************************************/ void Motor_Cntrl ( void ) { static u08 cd_motor10ms; /* 10ms counter for motor control */ u08 chage_req=0; /* output change request flag if ( --cd_motor10ms == 0 ) { cd_motor10ms = PERIOD_10ms; chage_req = 1; } if ( motor_sts == MOTOR_OFF ) { motor_sts = MOTOR_START; cd_motor10ms = PERIOD_10ms; chage_req = 1; switch (_Sens_Input()) { case SENSER_DEG0: out_phase = PHASE_DEG0;
*/
/* 10ms count */ /* Yes initialize 10ms counter */ /* set a change request */
/* motor off ? { */ /* Yes change a motor state */ /* initialize 10ms counter */ /* set a change request */ /* rotor position signal input */ /* case SENSER_DEG0: */ /* start an output phase from 0deg */ /* Position detection start from 60deg */ r0edg = INT1_FALLING_EDGE; /* INT1 edge set */ pol_int0ic = INT0_RISING_EDGE; /* INT0 edge set */ ki3pl = KI3_FALLING_EDGE; /* KI3 edge set */ break; case SENSER_DEG60: /* case SENSER_DEG60: */ out_phase = PHASE_DEG60; /* start an output phase from 60deg */ /* Position detection start from 120deg */ r0edg = INT1_FALLING_EDGE; /* INT1 edge set */ pol_int0ic = INT0_RISING_EDGE; /* INT0 edge set */ ki3pl = KI3_RISING_EDGE; /* KI3 edge set */ break;
REJ05B0288-0100Z/Rev.1.00
November 2003
Page 43 of 55
R8C/11 Group Control of a Brushless DC Motor
case SENSER_DEG120: out_phase = PHASE_DEG120; r0edg = INT1_FALLING_EDGE; /* pol_int0ic = INT0_FALLING_EDGE; ki3pl = KI3_RISING_EDGE; break; case SENSER_DEG180: out_phase = PHASE_DEG180; r0edg = INT1_FALLING_EDGE; /* pol_int0ic = INT0_FALLING_EDGE; ki3pl = KI3_RISING_EDGE; break; case SENSER_DEG240: out_phase = PHASE_DEG240; r0edg = INT1_RISING_EDGE; pol_int0ic = INT0_FALLING_EDGE; ki3pl = KI3_FALLING_EDGE; break; default: out_phase = PHASE_DEG300; r0edg = INT1_RISING_EDGE; pol_int0ic = INT0_RISING_EDGE; /* ki3pl = KI3_FALLING_EDGE; } in_phase = out_phase; cu_init_rotate = 0; ir_int3ic = 0; ir_int1ic = 0; ir_int0ic = 0; ir_kupic = 0; int1ic = 0x06; int0ic |= 0x06; kupic = 0x06; } int3ic &= 0xf8; /* ERR signal interrupt disable */ switch (motor_sts) { case MOTOR_START: /* case motor start */ pwm_duty = DUTY_10P; /* PWM duty initialze */ _PWM_Set(); /* PWM output */ if ( chage_req == 1 ) { /* output change request ? */ chage_req = 0; /* Yes clear a change request */ if ( cu_init_rotate >= INIT_ROTATE ) /* Initial rotation end ? */ motor_sts = MOTOR_START2; /* Yes change a motor state */ _InitOutPhase_Active(motor_sts); /* output at the start time */ } int3ic |= 0x06; /* ERR signal interrupt enable */ break; case MOTOR_START2: /* case motor start 2 */ motor_sts = MOTOR_NOMAL; /* change a motor state */ int3ic |= 0x06; /* ERR signal interrupt enable */ break; case MOTOR_NOMAL: /* case normal */ pwm_duty = DUTY_20P; /* PWM duty :20% */ _PWM_Set(); /* PWM output */ int3ic |= 0x06; /* ERR signal interrupt enable */ break; default: _OutPhase_Active(motor_sts); /* output */ _PWM_Set(); /* PWM output */ } } /* case SENSER_DEG120: */ /* start an output phase from 120deg */ /* Position detection start from 180deg */ INT1 edge set */ /* INT0 edge set */ /* KI3 edge set */ /* case SENSER_DEG180: */ /* start an output phase from 180deg */ /* Position detection start from 240deg */ INT1 edge set */ /* INT0 edge set */ /* KI3 edge set */ /* case SENSER_DEG240: */ /* start an output phase from 240deg */ /* Position detection start from 300deg */ /* INT1 edge set */ /* INT0 edge set */ /* KI3 edge set */
/* start an output phase from 300deg */ /* Position detection start from 0deg */ /* INT1 edge set */ INT0 edge set */ /* KI3 edge set */
/* initialize an input angle */ /* initialize an initial rotation counter /* clear an ERR signal interrupt request */ /* clear a rotor signal 0 interrupt request */ /* clear a rotor signal 1 interrupt request */ /* clear a rotor signal 2 interrupt request */ /* rotor signal 0 interrupt enable */ /* rotor signal 1 interrupt enable */ /* rotor signal 2 interrupt enable */
*/
REJ05B0288-0100Z/Rev.1.00
November 2003
Page 44 of 55
R8C/11 Group Control of a Brushless DC Motor
REJ05B0288-0100Z/Rev.1.00
November 2003
Page 45 of 55
R8C/11 Group Control of a Brushless DC Motor
/*""FUNC COMMENT""*********************************************************** * Name : Sens_In0_int() *--------------------------------------------------------------------------* Parameters : None * Returns : None * Description : interrupt of Rotor position signal 0 occurs * SubRoutine : _OutPhase_Active() * : _Sens_Input() *--------------------------------------------------------------------------* Note : *--------------------------------------------------------------------------* History : 2003-10-08: processing time * : (except the interrupt sequence, the bank change and return) * : 180deg: about 18.9us / 0deg: about 18.2us *""FUNC COMMENT END""******************************************************/ #pragma INTERRUPT/B Sens_In0_int void Sens_In0_int ( void ) { u08 senser; senser = _Sens_Input(); /* rotor position signal input */ if ( r0edg == INT1_FALLING_EDGE ) { /* INT1 falling endge ? */ if ( senser == SENSER_DEG180 ) { /* Yes rotor position = 180deg ? */ if ( in_phase == _Phase_shift_jdg_TBL[PHASE_DEG180] ) { /* Yes the previous position is right ? */ in_phase = PHASE_DEG180; /* Yes updating of an input angle (180deg) */ r0edg = INT1_RISING_EDGE; /* set the INT1 rising edge */ ir_int1ic = 0; /* clear the interrupt request */ _OutPhase_Active(motor_sts); /* output */ } } }else{ if ( senser == SENSER_DEG0 ) { /* No rotor position = 0deg ? */ if ( in_phase == _Phase_shift_jdg_TBL[PHASE_DEG0] ) { /* Yes the previous position is right ? */ in_phase = PHASE_DEG0; /* Yes updating of an input angle (0deg) r0edg = INT1_FALLING_EDGE; /* set the INT1 falling edge */ ir_int1ic = 0; /* clear the interrupt request */ _OutPhase_Active(motor_sts); /* output */ } } } }
*/
REJ05B0288-0100Z/Rev.1.00
November 2003
Page 46 of 55
R8C/11 Group Control of a Brushless DC Motor
/*""FUNC COMMENT""*********************************************************** * Name : Sens_In1_int() *--------------------------------------------------------------------------* Parameters : None * Returns : None * Description : interrupt of Rotor position signal 1 occurs * SubRoutine : _OutPhase_Active() * : _Sens_Input() *--------------------------------------------------------------------------* Note : use the bank register 1 *--------------------------------------------------------------------------* History : 2003-10-08: processing time * : (except the interrupt sequence, the bank change and return) * : 300deg: about 19.0us / 120deg: about 17.3us *""FUNC COMMENT END""******************************************************/ #pragma INTERRUPT/B Sens_In1_int void Sens_In1_int ( void ) { u08 senser; senser = _Sens_Input(); /* rotor position signal input */ if ( pol_int0ic == INT0_FALLING_EDGE ) { /* INT0 falling endge ? { */ if ( senser == SENSER_DEG300 ) { /* Yes rotor position = 300deg ? */ if ( in_phase == _Phase_shift_jdg_TBL[PHASE_DEG300] ) { /* Yes the previous position is right ? */ in_phase = PHASE_DEG300; /* Yes updating of an input angle (300deg) */ pol_int0ic = INT0_RISING_EDGE; /* set the INT0 rising edge */ ir_int0ic = 0; /* clear the interrupt request */ _OutPhase_Active(motor_sts); /* output */ } } }else{ if ( senser == SENSER_DEG120 ) { /* No rotor position = 120deg ? */ if ( in_phase == _Phase_shift_jdg_TBL[PHASE_DEG120] ) { /* Yes the previous position is right ? */ in_phase = PHASE_DEG120; /* Yes updating of an input angle (120deg) */ pol_int0ic = INT0_FALLING_EDGE;/* set the INT0 falling edge */ ir_int0ic = 0; /* clear the interrupt request */ _OutPhase_Active(motor_sts); /* output */ } } } }
REJ05B0288-0100Z/Rev.1.00
November 2003
Page 47 of 55
R8C/11 Group Control of a Brushless DC Motor
/*""FUNC COMMENT""*********************************************************** * Name : Sens_In2_int() *--------------------------------------------------------------------------* Parameters : None * Returns : None * Description : interrupt of Rotor position signal 2 occurs * SubRoutine : _OutPhase_Active() * : _Sens_Input() *--------------------------------------------------------------------------* Note : use the bank register 1 *--------------------------------------------------------------------------* History : 2003-10-08: processing time * : (except the interrupt sequence, the bank change and return) * : 60deg: about 19.0us / 240deg: about 17.6us *""FUNC COMMENT END""******************************************************/ #pragma INTERRUPT/B Sens_In2_int void Sens_In2_int ( void ) { u08 senser; senser = _Sens_Input(); /* rotor position signal input */ if ( ki3pl == KI3_FALLING_EDGE ) { /* key input falling endge ? { */ if ( senser == SENSER_DEG60 ) { /* Yes rotor position = 60deg ? */ if ( in_phase == _Phase_shift_jdg_TBL[PHASE_DEG60] ) { /* Yes the previous position is right ? */ in_phase = PHASE_DEG60; /* Yes updating of an input angle (60deg) ki3pl = KI3_RISING_EDGE; /* set the KI3 rising edge */ ir_kupic = 0; /* clear the interrupt request */ _OutPhase_Active(motor_sts); /* output */ } } }else{ if ( senser == SENSER_DEG240 ) { /* No rotor position = 240deg ? */ if ( in_phase == _Phase_shift_jdg_TBL[PHASE_DEG240] ) { /* Yes the previous position is right ? */ in_phase = PHASE_DEG240; /* Yes updating of an input angle (240deg) */ ki3pl = KI3_FALLING_EDGE; /* set the KI3 falling edge */ ir_kupic = 0; /* clear the interrupt request */ _OutPhase_Active(motor_sts); /* output */ } } } }
*/
REJ05B0288-0100Z/Rev.1.00
November 2003
Page 48 of 55
R8C/11 Group Control of a Brushless DC Motor
/*""FUNC COMMENT""*********************************************************** * Name : Error_int() *--------------------------------------------------------------------------* Parameters : None * Returns : None * Description : interrupt of motor stop signal occurs * SubRoutine : _OutPhase_Active() * : _PWM_Set() *--------------------------------------------------------------------------* Note : this interrupt is forbidden in the part which performs * : motor control by main processing. *--------------------------------------------------------------------------* History : max : about 15.73us (p3 off) *""FUNC COMMENT END""******************************************************/ #pragma INTERRUPT/B Error_int void Error_int ( void ) { motor_sts = MOTOR_ERROR; _OutPhase_Active(motor_sts); _PWM_Set(); }
/* output */ /* PWM output
*/
/*""FUNC COMMENT""*********************************************************** * Name : _InitOutPhase_Active() *--------------------------------------------------------------------------* Parameters : motor status * Returns : None * Description : change the output phase (at the time of a start processing) * SubRoutine : None *--------------------------------------------------------------------------* Note : *1 short-circuit inhibition: about 2.3us *--------------------------------------------------------------------------* History : *""FUNC COMMENT END""******************************************************/ static void _InitOutPhase_Active ( MOTOR_STATUS status ) { u08 p1_data,p3_data; switch (status) { case MOTOR_START: /* case MOTOR_START: */ p1 &= 0xf8; /* positive phase output off (note *1) */ p3 |= 0x07; /* negative phase output off (note *1) */ p1_data = _Init_p1Active_Phase_TBL[out_phase]; /* set the P1 output data */ p3_data = _Init_p3Active_Phase_TBL[out_phase]; /* set the P3 output data */ // a cycle adjustment is required, if the CPU clock changes. p1 = p1_data; p3 = p3_data; if ( ++out_phase >= PHASE_DEG360 ) /* one revolution ? */ out_phase = PHASE_DEG0; /* Yes initialize the output phase (0deg) */ ++cu_init_rotate; /* count the initial rotation */ break; case MOTOR_START2: /* case MOTOR_START2: */ p1 &= 0xf8; /* positive phase output off */ p3 |= 0x07; /* negative phase output off */ default: break; } }
REJ05B0288-0100Z/Rev.1.00
November 2003
Page 49 of 55
R8C/11 Group Control of a Brushless DC Motor
/*""FUNC COMMENT""*********************************************************** * Name : _OutPhase_Active() *--------------------------------------------------------------------------* Parameters : motor status * Returns : None * Description : change the output phase (at the time of a normal processing) * SubRoutine : None *--------------------------------------------------------------------------* Note : *1 short-circuit inhibition: about 2.3us * : *2 at the time of a start prcessing * : : this is performed by main processing * : at the time of a normal prcessing * : : this is performed by main processing *--------------------------------------------------------------------------* History : *""FUNC COMMENT END""******************************************************/ static void _OutPhase_Active ( MOTOR_STATUS status ) { u08 p1_data,p3_data; switch (status) { case MOTOR_NOMAL: /* case MOTOR_NOMAL: */ p1 &= 0xf8; /* positive phase output off (note *1) */ p3 |= 0x07; /* negative phase output off (note *1) */ p1_data = _p1Active_Phase_TBL[in_phase]; /* set the P1 output data */ p3_data = _p3Active_Phase_TBL[in_phase]; /* set the P3 output data */ // a cycle adjustment is required, if the CPU clock changes. p1 = p1_data; p3 = p3_data; out_phase = in_phase; /* change the output phase */ break; case MOTOR_START: /* case MOTOR_START: */ case MOTOR_START2: /* case MOTOR_START2: */ break; default: p1 &= 0xf8; /* positive phase output off */ p3 |= 0x07; /* negative phase output off */ int1ic = 0x00; /* rotor signal 0 interrupt diable */ int0ic = 0x00; /* rotor signal 1 interrupt diable */ kupic = 0x00; /* rotor signal 2 interrupt diable */ int3ic = 0x00; /* ERR signal interrupt disable */ out_phase = PHASE_DEG0; /* output phase 0deg */ pwm_duty = DUTY_0P; /* PWM duty 0% */ } }
REJ05B0288-0100Z/Rev.1.00
November 2003
Page 50 of 55
R8C/11 Group Control of a Brushless DC Motor
/*""FUNC COMMENT""*********************************************************** * Name : _PWM_Set() *--------------------------------------------------------------------------* Parameters : None * Returns : None * Description : set or change of PWM output * SubRoutine : None *--------------------------------------------------------------------------* Note : This function is performed by the main and INT3 interrupt * : processing. *--------------------------------------------------------------------------* History : *""FUNC COMMENT END""******************************************************/ static void _PWM_Set ( void ) { pwm_period = PWM_15kHz; /* PWM period */ tm1 = pwm_period; /* set a tm1 register (PWM period) */ switch (pwm_duty) { case DUTY_10P: /* case 10%: */ tm0 = DUTY_10P_COMP; /* set a tm0 register */ break; case DUTY_20P: /* case 20%: */ tm0 = DUTY_20P_COMP; /* set a tm0 register */ break; default: tm0 = 0xffff; /* set a tm0 register */ } tcout = 0x47; /* CMP00-CMP02 enable, CMP10-CMP12 disable */ /* CMP00-CMP02 reverse */ tcc00 = 1; /* timer C count start */ }
/*""FUNC COMMENT""*********************************************************** * Name : _Sens_Input() *--------------------------------------------------------------------------* Parameters : None * Returns : data of rotor position signal * Description : rotor position signal input * SubRoutine : None *--------------------------------------------------------------------------* Note : *--------------------------------------------------------------------------* History : *""FUNC COMMENT END""******************************************************/ static u08 _Sens_Input ( void ) { u08 work0,work1; work0 = p4 & P4_MASK; work1 = p1 & P1_MASK; return (work0 |= work1); }
REJ05B0288-0100Z/Rev.1.00
November 2003
Page 51 of 55
R8C/11 Group Control of a Brushless DC Motor
/**** P1 output data table (at the time of a start prcessing) **************/ static const u08 _Init_p1Active_Phase_TBL[] = { INIT_P1 | 0x01, /* 0deg:U phase,(VB phase) ON INIT_P1 | 0x01, /* 60deg:U phase,(WB phase) ON INIT_P1 | 0x02, /* 120deg:V phase,(WB phase) ON INIT_P1 | 0x02, /* 180deg:V phase,(UB phase) ON INIT_P1 | 0x04, /* 240deg:W phase,(UB phase) ON INIT_P1 | 0x04 /* 300deg:W phase,(VB phase) ON }; /**** P3 output data table (at the time of a start prcessing) **************/ static const u08 _Init_p3Active_Phase_TBL[] = { INIT_P3 & 0xfd, /* 0deg:(U phase),VB phase ON INIT_P3 & 0xfb, /* 60deg:(U phase),WB phase ON INIT_P3 & 0xfb, /* 120deg:(V phase),WB phase ON INIT_P3 & 0xfe, /* 180deg:(V phase),UB phase ON INIT_P3 & 0xfe, /* 240deg:(W phase),UB phase ON INIT_P3 & 0xfd /* 300deg:(W phase),VB phase ON }; /**** P1 output data table (at the time of a normal prcessing) *************/ static const u08 _p1Active_Phase_TBL[] = { INIT_P1 | 0x01, /* 60deg:U phase,(WB phase) ON INIT_P1 | 0x02, /* 120deg:V phase,(WB phase) ON INIT_P1 | 0x02, /* 180deg:V phase,(UB phase) ON INIT_P1 | 0x04, /* 240deg:W phase,(UB phase) ON INIT_P1 | 0x04, /* 300deg:W phase,(VB phase) ON INIT_P1 | 0x01 /* 0deg:U phase,(VB phase) ON }; /**** P3 output data table (at the time of a normal prcessing) *************/ static const u08 _p3Active_Phase_TBL[] = { INIT_P3 & 0xfb, /* 60deg:(U phase),WB phase ON INIT_P3 & 0xfb, /* 120deg:(V phase),WB phase ON INIT_P3 & 0xfe, /* 180deg:(V phase),UB phase ON INIT_P3 & 0xfe, /* 240deg:(W phase),UB phase ON INIT_P3 & 0xfd, /* 300deg:(W phase),VB phase ON INIT_P3 & 0xfd /* 0deg:(U phase),VB phase ON }; /**** previous position judge table ****************************************/ static const u08 _Phase_shift_jdg_TBL[] = { PHASE_DEG300, /* 0deg */ PHASE_DEG0, /* 60deg */ PHASE_DEG60, /* 120deg */ PHASE_DEG120, /* 180deg */ PHASE_DEG180, /* 240deg */ PHASE_DEG240, /* 300deg */ 0xff /* void */ };
*/ */ */ */ */ */
*/ */ */ */ */ */
*/ */ */ */ */ */
*/ */ */ */ */ */
REJ05B0288-0100Z/Rev.1.00
November 2003
Page 52 of 55
R8C/11 Group Control of a Brushless DC Motor
6.0 Reference
Hardware Manual R8C/11 Group Hardware Manual (Acquire the most current version from Renesas Technology website)
6.0 Web-site and contact for support
Renesas Web-site http://www.renesas.com
For more information on Renesas technical support about M16C family products Mail to : support_apl@renesas.com
REJ05B0288-0100Z/Rev.1.00
November 2003
Page 53 of 55
R8C/11 Group Control of a Brushless DC Motor
REVISION HISTORY R8C/11 Group Application Note Control of a Brushless DC Motor
Rev. 1.00
Date Page Nov.18, 2003 - First edition issued
Description Summary
REJ05B0288-0100Z/Rev.1.00
November 2003
Page 54 of 55
R8C/11 Group Control of a Brushless DC Motor
Keep safety first in your circuit designs!
1. Renesas Technology Corporation puts the maximum effort into making semiconductor products better and more reliable, but there is always the possibility that trouble may occur with them. Trouble with semiconductors may lead to personal injury, fire or property damage. Remember to give due consideration to safety when making your circuit designs, with appropriate measures such as (i) placement of substitutive, auxiliary circuits, (ii) use of nonflammable material or (iii) prevention against any malfunction or mishap.
Notes regarding these materials
1. These materials are intended as a reference to assist our customers in the selection of the Renesas Technology Corporation product best suited to the customer's application; they do not convey any license under any intellectual property rights, or any other rights, belonging to Renesas Technology Corporation or a third party. 2. Renesas Technology Corporation assumes no responsibility for any damage, or infringement of any third-party's rights, originating in the use of any product data, diagrams, charts, programs, algorithms, or circuit application examples contained in these materials. 3. All information contained in these materials, including product data, diagrams, charts, programs and algorithms represents information on products at the time of publication of these materials, and are subject to change by Renesas Technology Corporation without notice due to product improvements or other reasons. It is therefore recommended that customers contact Renesas Technology Corporation or an authorized Renesas Technology Corporation product distributor for the latest product information before purchasing a product listed herein. The information described here may contain technical inaccuracies or typographical errors. Renesas Technology Corporation assumes no responsibility for any damage, liability, or other loss rising from these inaccuracies or errors. Please also pay attention to information published by Renesas Technology Corporation by various means, including the Renesas Technology Corporation Semiconductor home page (http://www.renesas.com). 4. When using any or all of the information contained in these materials, including product data, diagrams, charts, programs, and algorithms, please be sure to evaluate all information as a total system before making a final decision on the applicability of the information and products. Renesas Technology Corporation assumes no responsibility for any damage, liability or other loss resulting from the information contained herein. 5. Renesas Technology Corporation semiconductors are not designed or manufactured for use in a device or system that is used under circumstances in which human life is potentially at stake. Please contact Renesas Technology Corporation or an authorized Renesas Technology Corporation product distributor when considering the use of a product contained herein for any specific purposes, such as apparatus or systems for transportation, vehicular, medical, aerospace, nuclear, or undersea repeater use. 6. The prior written approval of Renesas Technology Corporation is necessary to reprint or reproduce in whole or in part these materials. 7. If these products or technologies are subject to the Japanese export control restrictions, they must be exported under a license from the Japanese government and cannot be imported into a country other than the approved destination. Any diversion or reexport contrary to the export control laws and regulations of Japan and/or the country of destination is prohibited. 8. Please contact Renesas Technology Corporation for further details on these materials or the products contained therein.
REJ05B0288-0100Z/Rev.1.00
November 2003
Page 55 of 55


▲Up To Search▲   

 
Price & Availability of R8C11

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X