RENESAS JA1

Application Notes
M16C/26A Group
Sample Program (Lux Meter)
1.
Summary
This sample program provides the functionality of a lux, or illuminance meter by using the Renesas Starter Kit for M16C/26A
(R0K33026AS000BE) and an extension board.
Illuminance meter
The extension board used here is a product
from PI System Co., Ltd.
2.
Introduction
The example described in this document applies to the microcomputers listed below:
Microcomputers: M16C26A
This sample program runs on the Renesas Starter Kit for M16C/26A (R0K33026AS000BE).
Prepare an extension board available for the Renesas Starter Kit or create a circuit similar to the one shown in the example circuit on page
13 and then connect it to the Starter Kit.
This program uses RSK_LIB. For details about RSK_LIB, see the RSK_LIB reference manual. (RSK_LIB is the library software provided
for use with the Renesas Starter Kit for M16C/26A.)
REJ05B0811_0110 Rev.1.10
2007.11
Page 1 of 16
M16C/26A Group
Sample Program (Lux Meter)
3.
Port Arrangement
LCD
P100
Luxmeter
Xin
10MHz
P91
LCD E
P90
LCD RS
P63
LCD D7
P62
LCD D6
P61
LCD D5
P60
LCD D4
L I G H T
L E V E L
0
M30260F8AGP
4.
Operational Outline
Illuminance levels (−4 to 4) are shown on liquid crystal display by using an illuminance sensor.
Determine the criterion for brightness in 5 seconds after the pressing the reset switch.
Then, when light is impinged on the illuminance sensor to increase brightness, the illuminance level displayed on LCD changes from 0 to 1,
2, 3 and 4.
Conversely, when brightness is reduced, the illuminance level displayed on LCD changes from 0 to 1, 2, 3 and 4.
Illuminance sensor
Liquid crystal display
Liquid crystal display
5seconds elapsed
LIGHT
LEVEL 4
M16C26A
M16C26A
Reset switch
depressed
When light is impinged on illuminance
sensor, illuminance level increases.
• Timer A0 (timer mode, main 2 ms cycle)
This timer counts 2 milliseconds using the main clock of the microcomputer as the count source.
It is used as the basic timer of RSK_LIB.
Time management, LCD display management and AD input are performed using this timer.
• AD0 (single-shot mode, illuminance input measurement)
Analog voltages are converted to digital data using the main clock of the microcomputer as a conversion clock.
More specifically, the analog voltages output from the illuminance sensor are A/D converted.
REJ05B0811_0110 Rev.1.10
2007.11
Page 2 of 16
M16C/26A Group
Sample Program (Lux Meter)
5.
Operational Specification
(1)After reset switch depressed
(1) The AD value is read-in for 5 seconds after the reset switch is
depressed, and the values read during that time are averaged to
yield an initial illuminance.
L I G H T
(2) The initial illuminance “0” is displayed.
The initial illuminance and the current illuminance levels are
(4)5 seconds elapsed
A D J U S T
compared in Table 1.
(2)Initial illuminance displayed
* The AD values are set by calling the common function “AD
average” (RL_AdVeraging). Within the function, a value is
sampled 6 times, and the sampled values except the maximum and
minimum values are averaged, the result of which is returned. This
average value is acquired 8 times, the average of which is made a
fixed value.
L I G H T
L E V E L
0
(5) Current illuminance
input level changes
(3) Changed level displayed
L I G H T
L E V E L
-
3
Figure 2. Example of Program Operation
Table 1. Initial Illuminance and Current Illuminance Levels
Initial illuminance level
- 0.70V
- 1.10V
-4
- 0.10V
- 0.40V
-3
- 0.30V
- 0.60V
-2
- 0.50V
- 0.80V
-1
- 0.60V
- 1.00V
Displayed level
0
- 0.80V
- 1.20V
1
- 1.00V
- 1.40V
2
- 1.20V
- 1.60V
3
- 1.40V
- 1.80V
4
1.40 V 1.80V -
REJ05B0811_0110 Rev.1.10
- 1.60V
- 0.90V
- 1.10V
- 1.30V
- 1.50V
- 1.70V
- 1.90V
- 2.10V
- 2.30V
2.30V -
2007.11
1.60V - 1.10V
- 1.40V
- 1.70V
- 2.00V
- 2.10V
- 2.30V
- 2.50V
- 2.60V
2.60V -
Page 3 of 16
M16C/26A Group
Sample Program (Lux Meter)
6.
Definition of the RSK Functionality and the RSK_LIB APIs and Common Functions Used by the
Lux Meter
6.1 Definition of the RSK Functionality
RSKdefine.h file
In this application, the following functionalities (those shown in red) are set.
/*********************************************************
The boot information on CPU is defined
Usually, this mode is used
*********************************************************/
#define _CPU_M16C26A_NORMAL_MOD
/* Use in low power mode can be performed. */
//#define _CPU_M16C26A_32KHZ_MOD
/* Use of access of a flash can be performed. */
//#define _CPU_M16C26A_DATAFLASF_USE
/********************************************************
The hardware function which RSK supports is chosen
/********************************************************/
//#define _USE_KEY
//#define _USE_BUZZER
#define _OPTION_USE_AD
//#define _OPTION_USE_COM_RX
//#define _OPTION_USE_COM_TX
//#define _OPTION_USE_INFRAEDRX
//#define _OPTION_USE_INFRAEDTX
//#define _OPTION_USE_SW
//#define _OPTION_USE_LED
//#define _OPTION_USE_IO
Individual definition of each selected functionality
#if defined _OPTION_USE_AD
/* Define Illumimeter Adc */
#define _OPTION_USE_AD0
/* Define Vr Adc */
//#define _OPTION_USE_AD24
#endif
REJ05B0811_0110 Rev.1.10
Lux meter input AD
2007.11
Page 4 of 16
M16C/26A Group
Sample Program (Lux Meter)
6.2 APIs and Common Functions Used
ApiStatusType RL_SetTimerReq( unsigned int TimerValue, char TimerMode, int *TimerNo, int *ERcode );
ApiStatusType RL_StartTimer( int TimerNo, int *ERcode );
ApiStatusType RL_CheckTimer( int TimerNo, int *ERcode );
ApiStatusType RL_CancelTimer( int TimerNo, int *ERcode );
ApiStatusType RL_Putc_Lcd( char Ylocation, char outc, int *ERcode );
*ERcode );
ApiStatusType RL_Putc_LcdLoc( char Xlocation, char Ylocation, char RvTime, char outc, int *ERcode );
ApiStatusType RL_Puts_LcdLoc( char Xlocation, char Ylocation, char RvTime, const char far* outc, int
*ERcode );
ApiStatusType RL_Start_Adc( int AdIdentfier, int *ERcode );
int RL_AdAveraging( int AdLogicalNo, int *AdAverage, int *ERcode );
void RL_ErrorHook( int FuncNo, int ErrorNo );
For details about the APIs and common functions used by the sample program (lux meter), see the Renesas Starter Kit Library V.1.00
Reference Manual.
REJ05B0811_0110 Rev.1.10
2007.11
Page 5 of 16
M16C/26A Group
Sample Program (Lux Meter)
7.
Flowchart
Lux meter
Clear display on LCD
Show the initial screen
Request AD start
Measure reference
illuminance
Measure illuminance
Process measured value
display
REJ05B0811_0110 Rev.1.10
2007.11
Page 6 of 16
M16C/26A Group
Sample Program (Lux Meter)
8.
Tutorial
1
Launch the HEW by double-clicking its icon.
2
Change the session name from “default Session” to “SessionM16C_E8_System.”
REJ05B0811_0110 Rev.1.10
2007.11
Page 7 of 16
M16C/26A Group
Sample Program (Lux Meter)
3
Select “M30260F8A” for Device.
Select “Download emulator firmware” for Mode.
REJ05B0811_0110 Rev.1.10
2007.11
Page 8 of 16
M16C/26A Group
Sample Program (Lux Meter)
Check the box labeled “Power supply is carried out. (MAX 300mA)” and then select “5.0V.”
REJ05B0811_0110 Rev.1.10
2007.11
Page 9 of 16
M16C/26A Group
Sample Program (Lux Meter)
4
In the program and the work RAM text boxes of Firmware Location Address, enter “FA0” and “0B8” respectively.
Leave the box labeled “Debug a program using the WDT” unchecked.
REJ05B0811_0110 Rev.1.10
2007.11
Page 10 of 16
M16C/26A Group
Sample Program (Lux Meter)
5
Choose Download from the Debug tab and download a module.
The upper-side choices for Download show the location from which a project was downloaded.
REJ05B0811_0110 Rev.1.10
2007.11
Page 11 of 16
M16C/26A Group
Sample Program (Lux Meter)
6
7
Click “Start after Reset” to start program execution.
Please do "Cancellation" when "The file is opened" window opens.
REJ05B0811_0110 Rev.1.10
2007.11
Page 12 of 16
M16C/26A Group
Sample Program (Lux Meter)
9.
Example Circuit
10. Part List
Part name
Part No.
Q’ty
Manufacturer
Type number
Illuminance sensor
U2
1
TOSHIBA
TPS851
Value
Remark
Op-amp
U4
1
TI
LM358PSR
Laminated ceramic
C7 - C8
2
Panasonic
ECJ-1VF1H104
100nF/50V
C9
1
Panasonic
ECE-V1HS010SR
1uF/50V
Chip resistor
R6
1
ROHM
MCR10EZHF102
1k
1/8W,1%(5% also acceptable)
Chip resistor
R8,R10
2
ROHM
MCR10EZHF472
4.7k
1/8W,1%
Chip resistor
R9
1
ROHM
MCR10EZHF103
10k
1/8W,1%(5% also acceptable)
PCB header
JA1,JA2
2
Molex
10-88-1261
26-pin
Male, 2-row, vertical type
capacitor
Electrolytic
capacitor
REJ05B0811_0110 Rev.1.10
2007.11
Page 13 of 16
M16C/26A Group
Sample Program (Lux Meter)
11.
Web Sitet
Renesas Technology Web site
http://www.renesas.com/
REJ05B0811_0110 Rev.1.10
2007.11
Page 14 of 16
M16C/26A Group
Sample Program (Lux Meter)
Revision History
Content of revision
Rev.
Date of issue
1.00
2006.06.30
-
First revision issued
1.10
2007.11.29
-
RSK_LIB APIs supported
REJ05B0811_0110 Rev.1.10
Page
Points
2007.11
Page 15 of 16
M16C/26A Group
Sample Program (Lux Meter)
REJ05B0811_0110 Rev.1.10
2007.11
Page 16 of 16