RENESAS M16C26A-MS

Application Notes
M16C/26A Group
Sample Program (Musical Scale)
1.
Summary
This sample program provides the functionality of musical scale output by using the Renesas Starter Kit for M16C/26A
(R0K33026AS000BE) and an extension board.
Turning the potentiometer
changes the sound and frequency.
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
14 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.)
REJ05B0817-0110 Rev.1.10
2007.12
Page 1 of 17
M16C/26A Group
Sample Program (Musical Scale)
3.
Port Arrangement
The buzzer shown here is the facility mounted on an extension board for the Renesas Starter Kit. To use this facility, connect an extension
board to the Starter Kit.
LCD
VR
P93
10MHz
Xin
SW1
P83
P91
LCD E
P90
LCD_RS
P63
LCD D7
P62
LCD D6
P61
LCD D5
P60
LCD D4
l
e
2 5 9 H z
d
o
P72
M30260F8AGP
REJ05B0817-0110 Rev.1.10
s c a
2007.12
BUZZER
Page 2 of 17
M16C/26A Group
Sample Program (Musical Scale)
4.
Operational Outline
The variable resistor (R9) mounted on the board is used to adjust the musical scale and sound a buzzer. Scales and frequencies are
displayed as adjusted with the variable resistor (R9).
Turning the variable resistor (R9) clockwise lowers the sound, and turning it counterclockwise raises the sound. When SW1 is pressed
while a scale is sounded, the sound stops and a string “mute” is displayed on liquid crystal display.
Liquid crystal display
Scale
259Hz
Do
Liquid crystal display
M16C26A
M16C26A
Buzzer
R9
Liquid crystal display
Scale
259Hz
Do
Scale
292Hz
Re
SW3
SW2
SW1/
BOOT
Buzzer
Outputs the sound do
M16C26A
Buzzer
R9
SW3
SW2
SW1/
BOOT
Outputs the sound re
R9
SW3
SW2
SW1/
BOOT
Outputs the sound do
The operation described above is accomplished using the following microcomputer facilities:
• 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.
• AD24 (single-shot mode, AD value 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 variable resistor (R9) are A/D converted.
• Timer A1 (pulse modulation mode, buzzer output)
This timer outputs a waveform with different high and low pulse widths using the main clock of the microcomputer as the count source.
The high-level width of the output pulse is changed to alter the frequency, by which the buzzer tone is varied.
REJ05B0817-0110 Rev.1.10
2007.12
Page 3 of 17
M16C/26A Group
Sample Program (Musical Scale)
5.
Operational Specification
(1) Immediately after the reset switch is depressed, the scale
corresponding to a variable resistor position is output.
(1) Reset switch depressed
(2) Scale output and display are changed using the variable
resistor (R9).
s
(3) Scale output is turned on or off by pressing SW1.
c a l
e
When scale output is turned off, a string “mute” is
(2) Variable resistor
2 5 9 H z
displayed.
d o
Relationship between VR Input (Input Voltage) and Scale Output
Input voltage
s
Frequency
0 -0.625V
do
259Hz
0.625 -1.25V
re
292Hz
1.25 -1.875V
mi
327Hz
1.875 - 2.5V
fa
347Hz
2.5 - 3.125V
so
393Hz
3.125 - 3.75V
la
441Hz
3.75 - 4.375V
si
498Hz
4.375 - 5V
do
524Hz
c a l
e
2 9 2 H z
r e
(3) SW1 depressed
s
c a l
e
m u t
* The AD values are set by calling the common function “AD
s
average” (RL_AdVeraging). Within the function, a value is
sampled 6 times, and the sampled values except the maximum
c a l
(4) SW1 depressed
e
2 9 2 H z
and minimum values are averaged, the result of which is
e
r e
returned. This average value is acquired 8 times, the average of
which is made a fixed value.
REJ05B0817-0110 Rev.1.10
2007.12
Page 4 of 17
M16C/26A Group
Sample Program (Musical Scale)
6.
Definition of the RSK Functionality and the RSK_LIB APIs and Common Functions Used by
Musical Scale
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
Potentiometer input AD is used
Pushbutton SW1 is used
#if defined _OPTION_USE_SW
#define _OPTION_USE_PUSHSW1
//#define _OPTION_USE_PUSHSW2
//#define _OPTION_USE_PUSHSW3
#endif
REJ05B0817-0110 Rev.1.10
2007.12
Page 5 of 17
M16C/26A Group
Sample Program (Musical Scale)
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_Putc_Lcd( char Ylocation, char outc, int *ERcode );
ApiStatusType RL_Puts_LcdLoc( char Xlocation, char Ylocation, char RvTime, const char far* outc, int
*ERcode );
ApiStatusType RL_Start_Buzzer( char freqNo, int *ERcode );
ApiStatusType RL_Stop_Buzzer( int *ERcode );
ApiStatusType RL_Start_Adc( int AdIdentfier, int *ERcode );
int RL_AdAveraging( int AdLogicalNo, int *AdAverage, int *ERcode );
ApiStatusType RL_GetSwPort( char PortNo, char *Indata, int *ERcode );
void RL_ErrorHook( int FuncNo, int ErrorNo );
For details about the APIs and common functions used by the sample program (musical scale), see the Renesas Starter Kit Library
V.1.00 Reference Manual.
REJ05B0817-0110 Rev.1.10
2007.12
Page 6 of 17
M16C/26A Group
Sample Program (Musical Scale)
7.
Flowchart
Voltmeter
Clear display on LCD
Show the initial screen
Request AD start
Measure potentiometer
Process buzzer
Process measured value
display
NO
SW1 changed?
YES
Process mute display
REJ05B0817-0110 Rev.1.10
2007.12
Page 7 of 17
M16C/26A Group
Sample Program (Musical Scale)
8.
Tutorial
1
Launch the HEW by double-clicking its icon.
2
Change the session name from “default Session” to “SessionM16C_E8_System.”
REJ05B0817-0110 Rev.1.10
2007.12
Page 8 of 17
M16C/26A Group
Sample Program (Musical Scale)
3
Select “M30260F8A” for Device.
Select “Download emulator firmware” for Mode.
REJ05B0817-0110 Rev.1.10
2007.12
Page 9 of 17
M16C/26A Group
Sample Program (Musical Scale)
Check the box labeled “Power supply is carried out. (MAX 300mA)” and then select “5.0V.”
REJ05B0817-0110 Rev.1.10
2007.12
Page 10 of 17
M16C/26A Group
Sample Program (Musical Scale)
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.
REJ05B0817-0110 Rev.1.10
2007.12
Page 11 of 17
M16C/26A Group
Sample Program (Musical Scale)
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.
REJ05B0817-0110 Rev.1.10
2007.12
Page 12 of 17
M16C/26A Group
Sample Program (Musical Scale)
6
7
Click “Start after Reset” to start program execution.
Please do "Cancellation" when "The file is opened" window opens.
REJ05B0817-0110 Rev.1.10
2007.12
Page 13 of 17
M16C/26A Group
Sample Program (Musical Scale)
9.
Example Circuit
10. Part List
Part name
Part No.
Q’ty
Manufacturer
Type number
Value
Remark
Buzzer
BUZZ1
1
CUI inc
CEP-1160
Switching diode
D1
1
ROHM
1SS355TE-17
Chip resistor
R7
1
ROHM
MCR10EZHF103
10k
1/8W, 5%
PCB header
JA1,JA2
2
Molex
10-88-1261
26pin
Male, 2-row, vertical type
REJ05B0817-0110 Rev.1.10
2007.12
No-polarity, separately exited oscillation
Page 14 of 17
M16C/26A Group
Sample Program (Musical Scale)
11.
Web Sitet
Renesas Technology Web site
http://www.renesas.com/
REJ05B0817-0110 Rev.1.10
2007.12
Page 15 of 17
M16C/26A Group
Sample Program (Musical Scale)
Revision History
Content of revision
Rev.
Date of issue
1.00
2006.06.30
-
First revision issued
1.10
2007.12.03
-
Contents of presentation improved
REJ05B0817-0110 Rev.1.10
Page
Points
2007.12
Page 16 of 17
M16C/26A Group
Sample Program (Musical Scale)
REJ05B0817-0110 Rev.1.10
2007.12
Page 17 of 17