You are on page 1of 29

Micom Car Rally Kit

Operation Test Manual Micom Car Kit, Ver. 5 Version for R8C/38A

This manual describes micom car kit operation test procedures and supports the following boards: Motor drive board, Ver. 4 Sensor board, Ver. 4.1

Version 1.00 March 18, 2011 Renesas Electronics Micom Car Rally Executive Committee

Important Notice (Revision 3.0)


Copyright
Copyright of this manual and its contents belongs to the Renesas Electronics Micom Car Rally Executive Committee. This manual is protected under copyright law and international copyright conventions.

Prohibited Use
The user is prohibited from doing any of the following: Sale of the manual to a third party, or advertisement, use, marketing, or reproduction of the manual for purpose of sale Transfer or reauthorization to a third party of usage rights to the manual Modification or deletion of the contents of the manual, in whole or in part Translation into another language of the contents of the manual Use of the contents of the manual for a purpose that may pose a danger of death or injury to persons

Reprinting and Reproduction


Prior written permission from the Renesas Electronics Micom Car Rally Executive Committee is required in order to reprint or reproduce this manual.

Limitation of Liability
Every effort has been made to ensure the accuracy of the information contained in this manual. However, the Renesas Electronics Micom Car Rally Executive Committee assumes no responsibility for any loss or damage that may arise due to errors this manual may contain.

Other
The information contained in this manual is current as of the date of publication. The Renesas Electronics Micom Car Rally Executive Committee reserves the right to make changes to the information or specifications contained in this manual without prior notice. Please check the information provided on the official micom car Web site (http://www.mcr.gr.jp/) before starting fabrication.

Contact Information
Micom Car Rally Office, Renesas Solutions Corp. MN Building, 2-1 Karuko-saka, Ageba-cho, Shinjuku-ku, Tokyo, Japan Tel. (03) 3266-8510 E-mail: official@mcr.gr.jp

All trademarks and registered trademarks are the property of their respective owners.

Operation Test Manual Micom Car Kit, Ver. 5 Version for R8C/38A

Contents
1. Outline ......................................................................................................................................1 2. Components of Micom Car Kit ................................................................................................2 3. Writing the Operation Test Program to the MCU Board of the Micom Car ............................3
3.1 3.2 Opening the kit07_38a Workspace ............................................................................................................ 3 Writing the Operation Test Program to the MCU Board............................................................................ 4

4. Operation Tests .........................................................................................................................8


4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.9 List of Operation Tests............................................................................................................................... 8 LED Operation Test ................................................................................................................................... 9 Pushbutton Operation Test ....................................................................................................................... 10 Servo Operation Test................................................................................................................................ 11 Right Motor Operation Test ..................................................................................................................... 13 Left Motor Operation Test ....................................................................................................................... 14 Sensor Board Operation Test ................................................................................................................... 15 Straight Forward Test............................................................................................................................... 17 Completion of Operation Tests ................................................................................................................ 18

5. Program Source Code .............................................................................................................19


5.1 Program Code Listing of kit07test_38a.c................................................................................................. 19

Operation Test Manual Micom Car Kit, Ver. 5 Version for R8C/38A

1. Outline
This manual describes operation test procedures for micom cars fabricated and assembled according to the following manuals: Motor Drive Board, Ver. 4, Assembly Manual Sensor Board, Ver. 4.1, Assembly Manual Micom Car Kit, Ver. 5, Body Assembly Manual Operation testing involves the following procedures: 1. Installing the Renesas integrated development environment on a PC Install the Renesas integrated development environment (M16C, R8C version) on the PC to be used for testing. Follow the instructions in Renesas Integrated Development Environment Operation Manual (Version for R8C/38A) to install the software. Note that the sample program will not work with the H8 version of the Renesas integrated development environment. 2. Installing the sample program (operation test program) Install the sample program for the R8C/38A (workspace_r8c38a_100.exe, the 100 portion differs depending on the version) on the PC to be used for testing. Follow the instructions in Renesas Integrated Development Environment Operation Manual (Version for R8C/38A) to install the sample program. 3. Writing the operation test program to the RY_R8C38 board of the micom car This procedure is described later in this manual. 4. Running the operation tests as described in this manual This procedure is described later in this manual. 5. Adjusting the servo center and maximum turn angle Make the necessary adjustments by following the instructions in section 7, Adjusting the Servo Center and Maximum Turn Angle, in Micom Car Kit, Ver. 5, Program Explanation Manualkit07_38a Version (Version for R8C/38A). 6. Writing the running program to the RY_R8C38 board of the micom car Write the kit07_38a.mot file of project kit07_38a to the RY_R8C38 board by following the instructions in Micom Car Kit, Ver. 5, Program Explanation Manualkit07_38a Version (Version for R8C/38A), then try running the micom car on the course.

Operation Test Manual Micom Car Kit, Ver. 5 Version for R8C/38A

2. Components of Micom Car Kit


This manual describes the operation test procedures for a micom car consisting of the components of the micom car kit, Ver. 5. These components are shown below.

0 1 2 P2 RY_R8C38 MCU board Motor drive board, Ver. 4 Left motor 5V Right motor 5V 3 4

P0

5 6 7 Servo

Sensor board, Ver. 4.1

5V

5V Control power supply of MCU, sensor, and motor drive boards 4 AA batteries

5V Drive power supply for right and left motors and servo 4 AA batteries

The same operation test procedures may be used for micom cars with the LM350 add-on set installed on the motor drive board. The configuration with this addition is shown below.

5 V control power supply and 6 V servo power supply generated 0 1 2 P2 RY_R8C38 MCU board 5.0 V Motor drive board, Ver. 4 LM350 add-on set 5 6 7 Servo Sensor board, Ver. 4.1 6V Common power supply 8 batteries 9.6 V Left motor 9.6 V Right motor 9.6 V by 3-pin regulator

3 4

P0

Operation Test Manual Micom Car Kit, Ver. 5 Version for R8C/38A

3. Writing the Operation Test Program to the MCU Board of the Micom Car
3.1 Opening the kit07_38a Workspace
Launch the High-performance Embedded Workshop. 1

Select Browse to another project workspace. 2

Select kit07_38a.hws from the C:\Workspace\kit07_38a folder.

The kit07_38a workspace opens. This workspace contains four projects.


kit07_38a

This is the micom car running program. kit07test_38a In the project described here, this program is used to confirm that the motor drive board and sensor board are operating properly. sioservo1_38a This is a program for adjusting the servo center. sioservo2_38a This is a program for determining the servos maximum turn angle.

Operation Test Manual Micom Car Kit, Ver. 5 Version for R8C/38A

3.2

Writing the Operation Test Program to the MCU Board


Set kit07test_38a as the current project. Right click on kit07test_38a and select Set as Current Project from the menu. The item kit07test_38a is displayed in bold.

Select Build from the Build menu to create a MOT file.

Confirm that kit07test_38a is displayed in bold (indicating current).

RY_WRITER board USB cable 4P cable

Micom Car Kit Ver. 5

Note: Install batteries in the micom car.

Between the PC and the micom car (RY_R8C38 board), an additional board is used to convert the USB signal into a TTL level signal. The figure at left shows the cabling by which the RY_ WRITER board is connected between the PC and the micom car kit, Ver. 5. For details, see Microcontroller Training Manual (Version for R8C/38A).

Operation Test Manual Micom Car Kit, Ver. 5 Version for R8C/38A

Move the two power switches of the micom car to the off position.

Swich off.

Swich off.

As shown in the photo, slide JP1 on the RY_R8C38 board to the right (CN1 side). Note: This setting causes power to be supplied from CN1. When the CN2 position is selected, power is supplied via the USB connection to the PC. Do not use the PCs USB power supply because it could draw excessive current and destroy the MCU. Slide SW2 to the FEW side (near the outer edge of the board). Powering on the RY_R8C38 board with SW2 in the position closest to the outer edge puts it into a state that allows programs to be written to the MCU. Note: Make sure that the RY_R8C38 is powered off before changing the setting of SW2.

Slide JP1 to right (CN1 side).

FEW side (near outer edge)

Operation Test Manual Micom Car Kit, Ver. 5 Version for R8C/38A Move the two power switches of the micom car to the on position.

Swich on.

Swich on.

Select R8C Writer from the Tools menu to launch R8C Writer. Note: If there is no R8C Writer item in the Tools menu, follow the instructions in Renesas Integrated Development Environment Operation Manual (Version for R8C/38A) to register R8C Writer.

Check the check boxes in the R8C Writer dialog box. Make sure that both boxes are checked (). 9

Operation Test Manual Micom Car Kit, Ver. 5 Version for R8C/38A Write kit07test_38a.mot to the MCU. R8C Writer closes automatically when the write operation completes successfully. If an error message is displayed, check for a connection problem with the cable, etc., then retry the write operation. Note: It is not possible to write to the MCU when the Tera Term communication program is running because it makes use of the PCs communication port. Quit Tera Term, then retry the write operation.

10

Move the two power switches of the micom car to the off position.

Swich off.

11

Swich off.

12

Slide SW2 to the position toward the inside of the board. When the RY_R8C38 board is powered on with SW2 in the inside position, the program previously written to the MCU is run. Note: Make sure that the RY_R8C38 is powered off before changing the setting of SW2.

Inner side

Operation Test Manual Micom Car Kit, Ver. 5 Version for R8C/38A

4.
4.1

Operation Tests
List of Operation Tests

You can select and perform tests on different parts of the micom car by changing the settings of the DIP switches on the RY_R8C38 board.

Top

"1" "0" Bottom


P1_3 P1_2 P1_1 P1_0

Description

0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1

0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1

0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1

0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1

Tests the LEDs. The LEDs light alternately at 0.5-second intervals. Tests the pushbutton. LED0 lights when the button is in the off position and LED1 lights when it is in the on position. Performs the servo operation test. The servo cycles through the 0, 30 right, and 30 left positions repeatedly. Does nothing. Performs the right motor operation test. The motor switches between forward and brake operation repeatedly. Performs the right motor operation test. The motor switches between reverse and brake operation repeatedly. Performs the left motor operation test. The motor switches between forward and brake operation repeatedly. Performs the left motor operation test. The motor switches between reverse and brake operation repeatedly. Performs the sensor board bit1 and bit0 operation test. The states of sensor bits 1 and 0 are output to LED1 and LED0. Performs the sensor board bit3 and bit2 operation test. The states of sensor bits 3 and 2 are output to LED1 and LED0. Performs the sensor board bit5 and bit4 operation test. The states of sensor bits 5 and 4 are output to LED1 and LED0. Performs the sensor board bit7 and bit6 operation test. The states of sensor bits 7 and 6 are output to LED1 and LED0. Confirms the micom cars ability to run straight forward. The car advances at PWM 50% and then stops after 2 seconds. Confirms the micom cars ability to run straight forward. The car advances at PWM 50% and then stops after 5 seconds. Confirms the micom cars ability to run straight forward. The car advances at PWM 100% and then stops after 2 seconds. Confirms the micom cars ability to run straight forward. The car advances at PWM 100% and then stops after 5 seconds.

Operation Test Manual Micom Car Kit, Ver. 5 Version for R8C/38A

4.2

LED Operation Test


This test checks the operation of the LEDs on the motor drive board. With the DIP switches set to 0000, move the two power switches of the micom car to the on position.

"1" "0" 0 0 0 0
LED0 and LED1 on the motor drive board light alternately at 0.5-second intervals. After the operation test has finished, slide the two power switches to the off position. If LED0 or LED1 does not light, possible causes include a fault in the flat cable connecting the RY_R8C38 board and motor drive board, solder bridging (shorting), and incorrect LED mounting orientation. Identify the problem visually or using a tester and correct it.

This is the power LED. It lights continuously when the board is powered on.

LED0 LED1

Operation Test Manual Micom Car Kit, Ver. 5 Version for R8C/38A

4.3

Pushbutton Operation Test


This test checks the response of the pushbutton on the motor drive board. With the DIP switches set to 0001, move the two power switches of the micom car to the on position.

"1" "0" 0 0 0 1
LED0 lights when the pushbutton on the motor drive board is not pressed and LED1 lights when it is pressed. After the operation test has finished, slide the two power switches to the off position.

LED0 LED1 Depress the pushbutton.

If only LED0 lights, possible causes include a soldering fault in the circuit leading to the switch. If LED1 is lit constantly, possible causes include solder bridging. Identify the problem visually or using a tester and correct it.

10

Operation Test Manual Micom Car Kit, Ver. 5 Version for R8C/38A

4.4

Servo Operation Test


This test checks the operation of the servo connected to the motor drive board. The area around the micom car should be kept free of obstacles during this test because the front portion of the car moves back and forth. With the DIP switches set to 0010, move the two power switches of the micom car to the on position.

"1" "0" 0 0 1 0
The servo repeatedly cycles through the 0, 30 right, and 30 left positions at one-second intervals. After the operation test has finished, slide the two power switches to the off position.

(1) 0 degree
2

(3) 30 degrees left

(2) 30 degrees right

If the servo does not operate, possible causes include a soldering fault in the circuit leading to the servo and incorrect mounting orientation of the servo connector. Also check whether the power LED on the motor drive board is lit. Identify the problem visually or using a tester and correct it.

If the servo supplied with the kit is replaced with a different servo, and the resulting sequence is 0 30 left 30 right, the servo is a model that reverses the right and left turn operations. If this is the case, change the (minus sign) to a + (plus sign) in line 425 of the handle function in kit07test_ 38a.c. This will reverse right and left, resulting in the correct sequence of 0 30 right 30 left.

11

Operation Test Manual Micom Car Kit, Ver. 5 Version for R8C/38A Note: Servo center adjustment For the micom car to operate properly, the servo angle must be 0 at initial power-on. In most cases, however, the angle is not exactly 0 when power is turned on. Since each servo has its own center value (the value at which the wheels are oriented straight ahead), the value must be adjusted individually for each micom car. To adjust, change the value of SERVO_CENTER in kit07test_38a.c from 3750 as necessary to achieve the true center position. A difference of 26 is equivalent to about one degree of change in the position.

46 : #define

SERVO_CENTER

3750

/* Servo center value

*/

Increasing the value turns the wheels to the left (moving forward), and reducing the value turns the wheels to the right.

Higher value

Lower value

The instructions in section 7, Adjusting the Servo Center and Maximum Turn Angle, in Micom Car Kit, Ver. 5, Program Explanation Manualkit07_38a Version (Version for R8C/38A) are useful when adjusting the servo center value.

12

Operation Test Manual Micom Car Kit, Ver. 5 Version for R8C/38A

4.5

Right Motor Operation Test


This test checks the forward, reverse, and brake operation of the right motor. Since the motor operates (and the wheels move), lift the micom car so that the tires are not making contact with the floor when running this test. With the DIP switches set to 0100, move the two power switches of the micom car to the on position.

"1" "0" 0 1 0 0
The right motor repeatedly switches between forward and brake operation at one-second intervals. After the operation test has finished, slide the two power switches to the off position. If the right motor does not operate in the forward direction, possible causes include a soldering fault in the right motor control circuit. If the right motor turns constantly (does not switch to brake operation), possible causes include solder bridging. Identify the problem visually or using a tester and correct it. If the wheel turns in the wrong direction, the motor cable connection is reversed. If the wheel does not turn, possible causes include solder bridging. Switch the positions of pins 1 and 2 of the connector. With the DIP switches set to 0101, move the two power switches of the micom car to the on position. The right motor repeatedly switches between reverse and brake operation at one-second intervals. After the operation test has finished, slide the two power switches to the off position.

Right motor repeatedly switches between forward and brake operation.

"1" "0" 0 1 0 1

If the right motor does not operate in the reverse direction, possible causes include a soldering fault or a short. Identify the problem visually or using a tester and correct it.

13

Operation Test Manual Micom Car Kit, Ver. 5 Version for R8C/38A

4.6

Left Motor Operation Test


This test checks the forward, reverse, and brake operation of the left motor. Since the motor operates (and the wheels move), lift the micom car so that the tires are not making contact with the floor when running this test. With the DIP switches set to 0110, move the two power switches of the micom car to the on position.

"1" "0" 0 1 1 0
The left motor repeatedly switches between forward and brake operation at one-second intervals. After the operation test has finished, slide the two power switches to the off position. If the left motor does not operate in the forward direction, possible causes include a soldering fault in the left motor control circuit. If the left motor turns constantly (does not switch to brake operation), possible causes include solder bridging. Identify the problem visually or using a tester and correct it. If the wheel turns in the wrong direction, the motor cable connection is reversed. If the wheel does not turn, possible causes include solder bridging. Switch the positions of pins 1 and 2 of the connector. With the DIP switches set to 0111, move the two power switches of the micom car to the on position. The left motor repeatedly switches between reverse and brake operation at one-second intervals. After the operation test has finished, slide the two power switches to the off position.

Right motor repeatedly switches between forward and brake operation.

"1" "0" 0 1 1 1

If the left motor does not operate in the reverse direction, possible causes include a soldering fault or a short. Identify the problem visually or using a tester and correct it.

14

Operation Test Manual Micom Car Kit, Ver. 5 Version for R8C/38A

4.7

Sensor Board Operation Test


With the DIP switches set to 1000, move the two power switches of the micom car to the on position.

"1" "0" 1 0 0 0
7 6 5 4 3 2 1 0
Sensor bit

Variable resistors for adjusting sensitivity

LED0 LED1

The states of sensors 0 and 1 on the sensor board, shown in the photo above, are output to the two LEDs on the motor drive board. The LEDs on the sensor board also light, so this test allows you to confirm that they respond identically. The sensitivity of the sensors can be adjusted by using the variable resistors. If the LEDs on the sensor board do not light, possible causes include faulty soldering on the sensor board, solder bridging, and incorrect part mounting orientation. If the LEDs on the sensor board light but the LEDs on the motor drive board do not, there may be a problem related to the connector. Identify the problem visually or using a tester and correct it.

15

Operation Test Manual Micom Car Kit, Ver. 5 Version for R8C/38A In like manner, you can check the operation of all eight sensors on the sensor board, 7 to 0, by switching the settings of the DIP switches as shown in the table at left.

DIP switches

Sensor number output to LED1 on motor drive board

Sensor number output to LED0 on motor drive board

"1" "0" 1 0 0 0 "1"


3

1 3 5 7

0 2 4
(Start bar detection)

"0" 1 0 0 1 "1" "0" 1 0 1 0 "1" "0" 1 0 1 1

16

Operation Test Manual Micom Car Kit, Ver. 5 Version for R8C/38A

4.8

Straight Forward Test


This test checks whether the micom car can run straight. Place the micom car on a long flat surface, such as the floor of a hallway. (The micom car is not placed on the course for this test.) Set the DIP switches to 1100.

"1" "0" 1 1 0 0
Move the two power switches of the micom car to the off position. Two seconds after power-on, the micom car advances straight forward at a PWM value of 50% for two seconds. By placing the micom car on a long flat surface, such as the floor of a hallway, this test allows you to confirm that that the car can run straight. If it turns to the right or left, adjust the SERVO_CENTER value as described in 4.4, Servo Operation Test, so that the car runs straight. The ability to run in a straight line is extremely important when the micom car is operating at high speed, so make sure to perform this test and adjustment. In the end, you should fine adjust the SERVO_CENTER value down to increments of 1.

17

Operation Test Manual Micom Car Kit, Ver. 5 Version for R8C/38A The straight forward test has four patterns covering different PWM values and running durations until stop. A larger PWM value, or a longer duration until stop, causes the micom car to run a longer distance. Choose the test pattern that best matches the amount of space available, select a long, flat test location such as a hallway, and run the straight forward test to confirm the micom car can run straight. Note: The instructions in section 7, Adjusting the Servo Center and Maximum Turn Angle, in Micom Car Kit, Ver. 5, Program Explanation Manualkit07_38 a Version (Version for R8C/38A) are useful when adjusting the servo center value.

DIP switches

PWM value

Duration until stop

"1" "0" 1 1 0 0 "1"


3

50% 50% 100% 100%

2 seconds 5 seconds 2 seconds 5 seconds

"0" 1 1 0 1 "1" "0" 1 1 1 0 "1" "0" 1 1 1 1

4.9

Completion of Operation Tests

Once all the functions of the micom car are operating correctly, write the running program to the MCU and try it out on the course. Before doing that, however, youll want to make final adjustments. Follow the instructions in section 7, Adjusting the Servo Center and Maximum Turn Angle, in Micom Car Kit, Ver. 5, Program Explanation Manualkit07_38a Version (Version for R8C/38A) to adjust the servo center value. Refer to Micom Car Kit, Ver. 5, Program Explanation Manualkit07_38a Version (Version for R8C/38A) and write the project kit07_38a program in workspace kit07_38a to the RY_R8C38 board. Then try running the micom car on the course.

18

Operation Test Manual Micom Car Kit, Ver. 5 Version for R8C/38A

5. Program Source Code


5.1
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

Program Code Listing of kit07test_38a.c

/**************************************************************************/ /* Target MCU R8C/38A */ /* File description Micom car kit operation test program (for R8C/38A) */ /* Version 1.01 */ /* Date March 14, 2011 */ /* Copyright: Renesas Electronics Micom Car Rally Executive Committee */ /**************************************************************************/ /* Performs operation tests on sensor board, Ver. 4.1, and motor drive board, Ver. 4, of micom car kit. Operation test details are changed by DIP switch settings. DipSW bit 3 2 1 0 0 0 0 0 LED test LEDs light alternately at 0.5-second intervals 0 0 0 1 Pushbutton test OFF: LED0 lit, ON: LED1 lit 0 0 1 0 Servo test Repeated switching from 0 degrees to right 30 degrees to left 30 degrees 0 0 1 1 No operation 0 1 0 0 Right motor test Repeated switching from forward to brake 0 1 0 1 Repeated switching from reverse to brake 0 1 1 0 Left motor test Repeated switching from forward to brake 0 1 1 1 Repeated switching from reverse to brake 1 1 1 1 1 1 1 1 */ /*======================================*/ /* Include */ /*======================================*/ #include "sfr_r838a.h" /* R8C/38A SFR definition file /*======================================*/ /* Symbol definitions */ /*======================================*/ /* Constant settings */ #define PWM_CYCLE 39999 #define SERVO_CENTER 3750 #define HANDLE_STEP 22 0 0 0 0 1 1 1 1 0 0 1 1 0 0 1 1 0 Sensor test 1 0 1 0 1 0 1 Straight Straight Straight Straight forward forward forward forward test test test test
Output Output Output Output of of of of sensor sensor sensor sensor bits bits bits bits 1 3 5 7 and and and and 0 2 4 6 to to to to LEDs LEDs LEDs LEDs 1 1 1 1 and and and and 0 0 0 0

Advance Advance Advance Advance

at at at at

PWM PWM PWM PWM

50%, stop after 2 seconds 50%, stop after 5 seconds 100%, stop after 2 seconds 100%, stop after 5 seconds

*/

/* Motor PWM cycle /* Servo center value /* 1 degree value

*/ */ */

/*======================================*/ /* Prototype declarations */ /*======================================*/ void init( void ); unsigned char sensor_inp_all( unsigned char mask ); unsigned char dipsw_get( void ); unsigned char pushsw_get( void ); 19

Operation Test Manual Micom Car Kit, Ver. 5 Version for R8C/38A
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

void led_out( unsigned char led ); void motor( int accele_l, int accele_r ); void handle( int angle ); /*======================================*/ /* Global variable declarations */ /*======================================*/ unsigned long cnt0; /* Used by timer function unsigned long cnt1; /* Used within main

*/ */

/**************************************************************************/ /* Main program */ /**************************************************************************/ void main( void ) { unsigned char now_sw; /* Remember current DIP switch settings */ unsigned char before_sw; /* Remember previous DIP switch settings */ unsigned char c; /* Used by operation */ int i; /* Used by operation */ /* Initialize MCU functions */ init(); asm(" fset I "); /* Initialize variables */ before_sw = dipsw_get(); cnt1 = 0; /* Initialize micom car state */ handle( 0 ); motor( 0, 0 ); led_out( 0x0 ); while( 1 ) { /* Read DIP switches */ now_sw = dipsw_get(); /* Compare to previous switch value */ if( before_sw != now_sw ) { /* When no match, update previous value and clear timer value */ before_sw = now_sw; cnt1 = 0; } /* Select test mode based on DIP switch value */ switch( now_sw ) { /* LED test: LEDs light alternately at 0.5-second intervals */ case 0: if( cnt1 < 500 ) { led_out( 0x1 ); } else if( cnt1 < 1000 ) { led_out( 0x2 ); } else { cnt1 = 0; } break; /* Pushbutton test: OFF: LED0 lit, ON: LED1 lit */ case 1: 20

/* Initialize /* Enable all interrupts

*/ */

Operation Test Manual Micom Car Kit, Ver. 5 Version for R8C/38A
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

led_out( pushsw_get() + 1 ); break; /* Servo test: Repeated switching from 0 degrees to right 30 degrees to left 30 degrees*/ case 2: if( cnt1 < 1000 ) { handle( 0 ); } else if( cnt1 < 2000 ) { handle( 30 ); } else if( cnt1 < 3000 ) { handle( -30 ); } else { cnt1 = 0; } break; /* No nothing */ case 3: break; /* Right motor test: Repeated switching from forward to brake */ case 4: if( cnt1 < 1000 ) { motor( 0, 100 ); } else if( cnt1 < 2000 ) { motor( 0, 0 ); } else { cnt1 = 0; } break; /* Right motor test: Repeated switching from reverse to brake */ case 5: if( cnt1 < 1000 ) { motor( 0, -100 ); } else if( cnt1 < 2000 ) { motor( 0, 0 ); } else { cnt1 = 0; } break; /* Left motor test: Repeated switching from forward to brake */ case 6: if( cnt1 < 1000 ) { motor( 100, 0 ); } else if( cnt1 < 2000 ) { motor( 0, 0 ); } else { cnt1 = 0; } break; /* Left motor test: Repeated switching from reverse to brake */ case 7: if( cnt1 < 1000 ) { motor( -100, 0 ); } else if( cnt1 < 2000 ) { motor( 0, 0 ); } else { 21

Operation Test Manual Micom Car Kit, Ver. 5 Version for R8C/38A
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235

cnt1 = 0; } break; /* Sensor test: Output of sensor bits 1 and 0 to LEDs 1 and 0 */ case 8: c = sensor_inp_all( 0x03 ); led_out( c ); break; /* Sensor test: Output of sensor bits 3 and 2 to LEDs 1 and 0 */ case 9: c = sensor_inp_all( 0x0c ); c = c >> 2; led_out( c ); break; /* Sensor test: Output of sensor bits 5 and 4 to LEDs 1 and 0 */ case 10: c = sensor_inp_all( 0x30 ); c = c >> 4; led_out( c ); break; /* Sensor test: Output of sensor bits 7 and 6 to LEDs 1 and 0 */ case 11: c = sensor_inp_all( 0xc0 ); c = c >> 6; led_out( c ); break; /* Straight forward test: Advance at PWM 50%, stop after 2 seconds */ case 12: if( cnt1 < 2000 ) { motor( 0, 0 ); } else if( cnt1 < 4000 ) { motor( 50, 50 ); } else { motor( 0, 0 ); } break; /* Straight forward test: Advance at PWM 50%, stop after 5 seconds */ case 13: if( cnt1 < 2000 ) { motor( 0, 0 ); } else if( cnt1 < 7000 ) { motor( 50, 50 ); } else { motor( 0, 0 ); } break; /* Straight forward test: Advance at PWM 100%, stop after 2 seconds */ case 14: if( cnt1 < 2000 ) { motor( 0, 0 ); } else if( cnt1 < 4000 ) { motor( 100, 100 ); } else { 22

Operation Test Manual Micom Car Kit, Ver. 5 Version for R8C/38A
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295

motor( 0, 0 ); } break; /* Straight forward test: Advance at PWM 100%, stop after 5 seconds */ case 15: if( cnt1 < 2000 ) { motor( 0, 0 ); } else if( cnt1 < 7000 ) { motor( 100, 100 ); } else { motor( 0, 0 ); } break; /* Neither applies */ default: break; } } } /************************************************************************/ /* Initialize special function registers (SFRs) of R8C/38A */ /************************************************************************/ void init( void ) { int i; /* Change clock to XIN (20 MHz) */ prc0 = 1; cm13 = 1; cm05 = 0; for(i=0; i<50; i++ ); ocd2 = 0; prc0 = 0; /* Turn on protect */ prc2 = 1; pd0 = 0x00; pd1 = 0xd0; pd2 = 0xfe; pd3 = 0xff; p4 = 0x20; pd4 = 0xb8; pd5 = 0xff; pd6 = 0xff; pd7 = 0xff; pd8 = 0xff; pd9 = 0x3f; pur0 = 0x04; /* Set timer RB */ /* Interrupt frequency

/* /* /* /* /* /*

Clear protect Set P4_6 and P4_7 as XIN-XOUT pins Operate XIN clock Wait until stable (approx. 10 ms) Set system clock to XIN Turn on protect

*/ */ */ */ */ */

/* /* /* /* /* /* /* /* /* /* /* /* /*

Clear PD0 protect 7-0: Sensor board, Ver. 4.1 5:RXD0 4:TXD0 3-0:DIP SW 7-0: Motor drive board, Ver. 4 P4_5 LED: Initially lit 7:XOUT 6:XIN 5:LED 2:VREF

P1_3 to P1_0 pull-up on

*/ */ */ */ */ */ */ */ */ */ */ */ */

= 1 / 20[MHz] * (TRBPRE+1) = 1 / (20*10^6) * 200 = 0.001[s] = 1[ms]

* (TRBPR+1) * 100

*/ trbmr = 0x00; trbpre = 200-1; trbpr = 100-1;

/* Set operation mode, division ratio /* Prescaler register /* Primary register 23

*/ */ */

Operation Test Manual Micom Car Kit, Ver. 5 Version for R8C/38A
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355

trbic trbcr

= 0x07; = 0x01;

/* Set interrupt priority level /* Start count

*/ */

/* Set timer RD reset cycle PWM mode */ /* PWM cycle = 1 / 20[MHz] * count source * (TRDGRA0+1) = 1 / (20*10^6) * 8 * 40000 = 0.016[s] = 16[ms] */ trdpsr0 = 0x08; /* Set TRDIOB0, C0, D0 pins trdpsr1 = 0x05; /* Set TRDIOA1, B1, C1, D1 pins trdmr = 0xf0; /* Set buffer register trdfcr = 0x01; /* Set reset cycle PWM mode trdcr0 = 0x23; /* Select source count: f8 trdgra0 = trdgrc0 = PWM_CYCLE; /* Cycle trdgrb0 = trdgrd0 = 0; /* Set on width of P2_2 pin trdgra1 = trdgrc1 = 0; /* Set on width of P2_4 pin trdgrb1 = trdgrd1 = SERVO_CENTER;/* Set on width of P2_5 pin trdoer1 = 0xcd; /* Select output pin trdstr = 0x0d; /* Start TRD0 count }

*/ */ */ */ */ */ */ */ */ */ */

/**************************************************************************/ /* Timer RB interrupt handler */ /**************************************************************************/ #pragma interrupt intTRB(vect=24) void intTRB( void ) { cnt0++; cnt1++; } /**************************************************************************/ /* Sensor state detection (all sensors including start bar sensor) */ /* Arguments: masked values */ /* Return values: sensor value */ /**************************************************************************/ unsigned char sensor_inp_all( unsigned char mask ) { unsigned char sensor; sensor = ~p0; sensor &= mask; return sensor; } /**************************************************************************/ /* DIP switch value read */ /* Return values: Switch value, 0 to 15 */ /**************************************************************************/ unsigned char dipsw_get( void ) { unsigned char sw; sw = p1 & 0x0f; return } /**************************************************************************/ 24 sw; /* Read in P1_3 to P1_0 */

Operation Test Manual Micom Car Kit, Ver. 5 Version for R8C/38A
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415

/* Pushbutton value read */ /* Return values: Switch value, ON: 1, OFF: 0 */ /**************************************************************************/ unsigned char pushsw_get( void ) { unsigned char sw; sw = ~p2; sw &= 0x01; return } /**************************************************************************/ /* LED control */ /* Arguments: Switch value, LED0: bit 0, LED1: bit 1. 0: dark, 1: lit */ /* Example: 0x3 LED1: ON, LED0: ON, 0x2 LED1: ON, LED0: OFF */ /**************************************************************************/ void led_out( unsigned char led ) { unsigned char data; led = ~led; led <<= 6; data = p2 & 0x3f; p2 = data | led; } /**************************************************************************/ /* Motor Speed control */ /* Arguments: left motor: -100 to 100, right motor: -100 to 100 */ /* 0: stopped, 100: forward 100%, -100: reverse 100% */ /* Return values: None */ /**************************************************************************/ void motor( int data1, int data2 ) { int motor_r, motor_l, sw_data; sw_data = dipsw_get() + 5; motor_l = data1 * sw_data / 20; motor_r = data2 * sw_data / 20; /* Left motor control */ if( motor_l >= 0 ) { p2 &= 0xfd; trdgrd0 = (long)( PWM_CYCLE - 1 ) * motor_l / 100; } else { p2 |= 0x02; trdgrd0 = (long)( PWM_CYCLE - 1 ) * ( -motor_l ) / 100; } /* Right motor control */ if( motor_r >= 0 ) { p2 &= 0xf7; trdgrc1 = (long)( PWM_CYCLE - 1 ) * motor_r / 100; } else { p2 |= 0x08; trdgrc1 = (long)( PWM_CYCLE - 1 ) * ( -motor_r ) / 100; } } 25 sw; /* Read ports with switches */

Operation Test Manual Micom Car Kit, Ver. 5 Version for R8C/38A
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 1

/**************************************************************************/ /* Servo steering operation */ /* Arguments: servo operation angle: - 90 to 90 */ /* -90: 90-degree turn to left, 0: straight, 90: 90-degree turn to right */ /**************************************************************************/ void handle( int angle ) { /* Change - to + to reverse servo left-right. */ trdgrd1 = SERVO_CENTER - angle * HANDLE_STEP; } /**************************************************************************/ /* end of file */ /**************************************************************************/ *****************************************************/

26

You might also like