0.4MB

The following document contains information on Cypress products.
AN702-00002-1v0-E
New 8FX Family
8-BIT MICROCONTROLLER
MB95260H series
Distance Module control
Example of connection to GP2Y0A21YK
AN702-00002-1v0-E
All Rights Reserved.
The contents of this document are subject to change without notice. Customers are advised to consult with
FUJITSU sales representatives before ordering.
The information, such as descriptions of function and application circuit examples, in this document are
presented solely for the purpose of reference to show examples of operations and uses of Fujitsu
semiconductor device; Fujitsu does not warrant proper operation of the device with respect to use based on
such information. When you develop equipment incorporating the device based on such information, you
must assume any responsibility arising out of such use of the information. Fujitsu assumes no liability for
any damages whatsoever arising out of the use of the information.
Any information in this document, including descriptions of function and schematic diagrams, shall not be
construed as license of the use or exercise of any intellectual property right, such as patent right or
copyright, or any other right of Fujitsu or any third party or does Fujitsu warrant non-infringement of any
third-party’s intellectual property right or other right by using such information. Fujitsu assumes no liability
for any infringement of the intellectual property rights or other rights of third parties which would result from
the use of information contained herein.
The products described in this document are designed, developed and manufactured as contemplated for
general use, including without limitation, ordinary industrial use, general office use, personal use, and
household use, but are not designed, developed and manufactured as contemplated (1) for use
accompanying fatal risks or dangers that, unless extremely high safety is secured, could have a serious
effect to the public, and could lead directly to death, personal injury, severe physical damage or other loss
(i.e., nuclear reaction control in nuclear facility, aircraft flight control, air traffic control, mass transport
control, medical life support system, missile launch control in weapon system), or (2) for use requiring
extremely high reliability (i.e., submersible repeater and artificial satellite).
Please note that Fujitsu will not be liable against you and/or any third party for any claims or damages
arising in connection with above-mentioned uses of the products.
Any semiconductor devices have an inherent chance of failure. You must protect against injury, damage or
loss from such failures by incorporating safety design measures into your facility and equipment such as
redundancy, fire protection, and prevention of over-current levels and other abnormal operating conditions.
If any products described in this document represent goods or technologies subject to certain restrictions on
export under the Foreign Exchange and Foreign Trade Law of Japan, the prior authorization by Japanese
government will be required for export of those products from Japan.
The company names and brand names herein are the trademarks or registered trademarks of their
respective owners.
Copyright© 2011 FUJITSU SEMICONDUCTOR LIMITED all rights reserved
1
AN702-00002-1v0-E
Revision History
Revision
Date
Description
1.0
Feb 17,2011
Initial release
2
AN702-00002-1v0-E
Subject
Revision History.................................................................................................................... 2
Subject.................................................................................................................................. 3
1
Introduction.................................................................................................................... 4
2
About Distance measurement module of GP2Y0A21YK ............................................... 5
3
2.1
Control signal of GP2Y0A21YK module ............................................................. 6
2.2
Distance censor module GP2Y0A21YK characteristics...................................... 6
2.3
How to get the measurement data from GP2Y0A21YK...................................... 7
2.4
How to connect between GP2Y0A21YK to MB95260H series MCU. ................. 8
Software control by MB95200H series......................................................................... 10
3.1
Main flow .......................................................................................................... 10
3.2
Get a measurement data that used A/D converter of MB95260H series .......... 13
3.3
Initialization of the A/D converter of the MB95260H series............................... 15
3.4
Read out the 10bit A/D conversion result data from MB95260H series. ........... 16
3.5
Voltage conversion result of MB95260H A/D.................................................... 17
3.6
Transform voltage into distance........................................................................ 19
3.7
Display of LCD (Distance data on LCD) ........................................................... 21
3
AN702-00002-1v0-E
1
Introduction
This application note explains the method of controlling the distance measurement module of
GP2Y0A21YK. That module is controlled by “New 8FX” family. MB95260H series is used in the
explanation of control methods.
4
AN702-00002-1v0-E
2
About Distance measurement module of GP2Y0A21YK
The GP2Y0A21YK is popular distance measurement module of offered commercially. The
GP2Y0A21YK has distance measurement controller IC for measurement. These module has LED
and PSD(Position Sensitive Detector) which can detect the distance by noncontact. The type of
output is analog voltage. Figure 2-1 is outline of GP2Y0A21YK. Figure 2-2 is block diagram of
GP2Y0A21YK.
Figure 2-1 GP2Y0A21YK
Figure 2-2 GP2Y0A21YK block diagram
5
AN702-00002-1v0-E
2.1
Control signal of GP2Y0A21YK module
Shown below is the GP2Y0A21YK module signal.
pinNo
Symbol
Function
1
Vo Analog output
Result data
2
GND
GND
3
Vcc
4.5 ~ 5.5V
Chart 2-1 GP2Y0A21YK pin
Vo : Measurement data output voltage.
GND : GND
VCC : Supply Voltage 5V
2.2
Distance censor module GP2Y0A21YK characteristics
The measurement distance of distance censor module GP2Y0A21YK is from 10cm(min) to
80cm(max).
The output voltage of Vo changed by measurement distance.
Figure 2-3 GP2Y0A21YK Charactristics
More detailed information get from data sheet.
http://document.sharpsma.com/files/GP2Y0A21YK-DATA-SHEET.PDF
(Feb 2011)
6
AN702-00002-1v0-E
2.3
How to get the measurement data from GP2Y0A21YK.
The measurement result of distance voltage output from Vo pin which is analog voltage.
Figure 2-3 is the characteristics of censor module of GP2Y0A21YK.
This application note explains how to get measurement data of distance data to use A/D convertor of
the New 8FX series. The New 8FX series have A/D converter which can be selectable to "8 or 10"
bit resolution. This application note used 10bit resolution of A/D conversion.
7
AN702-00002-1v0-E
2.4
How to connect between GP2Y0A21YK to MB95260H series MCU.
Figure 2-5 is the example of MB95260H series and GP2Y0A21YK application. Figure 2-6 is
example schematic. The measurement result display on SC1602BS.
Please see more information about control of the SC1602BS.
That will be able to get it from additional application note of "Example of connection to
SC1602BS".
Distance Sensor:
GP2Y0A21YK
Voltage
LCD:
Distance
SC1602BS
MCU : New 8FX
MB95260 series
Figure 2-4 GP2Y0A21YK application
8
AN702-00002-1v0-E
Figure 2-5 MB95260H with GP2Y0A21YK circuit
Note) When you use MB95200H series. The MB95200H series require to 10V high voltage to flash
programming. That need connect between RSOUT to RST pin.
Please get more information from hardware manual of each micro controller.
9
AN702-00002-1v0-E
3 Software control by MB95200H series
3.1 Main flow
The output voltage of distance measurement result is output from Vo.
Showing below are flowchart of initialization sequence and sample program of display of
measurement data.
main
MCU initialization
LCD initialization
TBT timer use to make a timing
Start the timer
No
of A/D conversion.
End of conversion?
Yes
Calculate of voltage
Display of voltage
GP2Y0A21YK display of voltage
Calculate of distance
GP2Y0A21YK display of distance
Display of distance
10
AN702-00002-1v0-E
Sample code of main flow chart
/* main.c*/
/*********************************************************************
NAME:
main ()
FUNCTION:
*********************************************************************/
void main()
{
unsigned char SenseData;
MCU_initialization();
/*------------------------------------------------------------------*/
//
LCD module initial
/*------------------------------------------------------------------*/
LCD_Initial();
IO_TBTC.byte = 0x1c;
/* TBC3-0 1110b 1.049s@8MHz */
IO_TBTC.bit.TCLR = 1;
/* initial */
IO_TBTC.bit.TBIE = 1;
/* Interruppt enable */
11
AN702-00002-1v0-E
/*------------------------------------------------------------------*/
//
Display of AD Data on SC1602SB_LCD
/*------------------------------------------------------------------*/
while(1) {
if (AD_flag == 1)
{
__DI();
AD_flag = 0;
LCD_Position(0,0);
LCD_Printf(" デンアツ =");
// LCD 文字表示 //
SC1602LCD_Control(LCD_CURSOR_SH_RIGHT);
lcd_voltage();
// caluculate of voltage
lcd_displayf(answer);
// display to LCD
LCD_Printf("V");
// LCD "V" 文字表示 //
LCD_Position(1,0);
LCD_Printf(" キョリ =");
// LCD 文字表示 //
SC1602LCD_Control(LCD_CURSOR_SH_RIGHT);
lcd_distance();
// calculate of distance data
if (answer <= 63){
lcd_displayf(answer);
// display to LCD
LCD_Printf("cm");
// LCD "cm" 文字表示 //
LCD_Printf("overflow");
// LCD 文字表示 //
}
else{
}
AD_flag = 0;
IO_TBTC.bit.TCLR = 1;
/* initial */
__EI();
}
}
}
12
AN702-00002-1v0-E
3.2 Get a measurement data that used A/D converter of MB95260H series
To use the MB95260H A/D converter to get the output voltage Vo of GP2Y0A21YK.
Showing below are flowchart of A/D converter initialize sequence and sample program to get the
measurement data.
Coming from interrupt of the
in
Time Base Timer.
TBT interrupt clear
ADC_start()
No
Start to A/D conversion
A/D Conversion finish?
Check the finish flag of A/D conversion
Yes
ADC_sample()
A/D conversion fag = 1
return
13
Get the A/D conversion data
AN702-00002-1v0-E
Sample code of A/D converter and get a result
/* main.c*/
/*********************************************************************
NAME:
__interrupt void TBT_interrupt ()
FUNCTION: A/D convert and Display function
*********************************************************************/
__interrupt void TBT_interrupt (void)
{
__DI();
IO_TBTC.bit.TBIF = 0;
/* Interruppt clear */
/*------------------------------------------------------------------*/
//
A/D module get GP2Y0A21YK data
/*------------------------------------------------------------------*/
ADC_start();
// A/D start
// A/D converter ready?
while(IO_ADC1.bit.ADMV);
// Check A/D convert finish flag
AD_Sample();
// Measurement data read
AD_flag = 1;
__EI();
}
14
AN702-00002-1v0-E
3.3 Initialization of the A/D converter of the MB95260H series
Showing below are sample program flowchart of A/D conversion initialization.
ADC_start
AN01pin
configuration of analog input
Analog input port use AN01
A/D conversion resolution
= 10bit
Stat the A/D conversion
One time mode
return
Sample code of initialization of the A/D converter.
/*MB95260AD.c*/
/*********************************************************************
NAME:
ADC_start()
FUNCTION:
Initial AD, IO-PORT
*********************************************************************/
void ADC_start(void)
{
IO_ADC1.byte = 0x10;
// AN01 as input
IO_ADC2.byte = 0x01;
// 10-bit resolution, 2/MCLK
IO_ADC1.bit.AD = 1;
// start A/D converter
}
15
AN702-00002-1v0-E
3.4 Read out the 10bit A/D conversion result data from MB95260H series.
Below is sample program flowchart of read out the A/D conversion data from MB95260H series.
ad_data :
ADC_Sample
Memory of A/D conversion result.
ad_data =ADDH upper
ad_data shift the upper data
ad_data =ADDL lower
Start to A/D conversion
return
Read out the10bit A/D conversion result
/*MB95260AD.c*/
unsigned int ad_data;
/*********************************************************************
NAME:
AD_Sample()
FUNCTION:
Use AN00 as the sample voltage channel
*********************************************************************/
void AD_Sample(void)
{
ad_data = IO_ADD.byte.ADDH;
// Read AD Sample value
ad_data = ad_data << 8;
ad_data |= IO_ADD.byte.ADDL;
// Start AD again
IO_ADC1.bit.AD=1;
}
16
AN702-00002-1v0-E
3.5 Voltage conversion result of MB95260H A/D.
Showing below are flowchart of voltage conversion of read out data of A/D conversion data from
MB95260H series.
The 10bit A/D conversion result has upper 2bit + lower 8bit data. The A/D conversion result will
change to analog voltage.
Condition of calculation:
・MCU Voltage = 5.0Vcc
・A/D conversion resolution =10bit
The voltage of 1bit : 5.0V/1023(10bit) = 0.00487585.
Calculated the analog voltage by GP2Y0A21YK output voltage.
calculate_data
upper_voltage =ADDH 上位
A/D data transfer to RAM memory.
lower_voltage =ADDL 下位
Calculate of upper 2bit data.
upperfloat = Upper_voltage *1.25
5.0V / 4(2bit) = 1.25
lowerfloat = lower_voltage *0.004887585
Calculate of lower 8bit data.
5.0V / 1023(8bit) = 0.004887585
calcu_data =
upperfloat + lowerfloat
Answer =
upper 2bit + lower 8bit
return
17
AN702-00002-1v0-E
Sample code of 10bit A/D conversion.
/*Main.c*/
/*********************************************************************
NAME:
caluculate_data()
FUNCTION:
A/D data translate from Hex to Dec
*********************************************************************/
void calculate_data(void)
{
/*
calcu_data =(ad_data * 0.0195);
unsigned int
upper_voltage;
unsigned int
lower_voltage;
float
upperfloat;
float
lowerfloat;
float
ansfloat;
/* 5.0V/10bit Voltage change */
upper_voltage = IO_ADD.byte.ADDH;
// Read AD Sampling H_value
lower_voltage = IO_ADD.byte.ADDL;
// Read AD Sampling L_value
/*------------------------------------------------------------------*/
// Upper 2bit(bit9,bit8) = 5.0V/1023 = 100hex(256) (5.0V/4=1.25)
// Lower 8bit(bit7-0) = 5.0V/1023 = 0.004887585 @1bit*/
// Output = calcudata = 10bit A/D Voltage
/*------------------------------------------------------------------*/
upperfloat = (upper_voltage * 1.25);
/* 上位 2bit */
lowerfloat = (lower_voltage * 0.004887585);
/* 下位 8bit */
ansfloat = (upperfloat + lowerfloat);
calcu_data = ansfloat;
/* 5.0V/10bit Voltage change */
}
18
AN702-00002-1v0-E
3.6
.6
Transform voltage into distance.
Transform the A/D conversion voltage into distance.
This application use formula to transform voltage into distance.
Distance = 27.22 × Voltage (Vo)-1.2027
This formula used approximate value from characteristic chart of the sensor.
Showing below are flowchart of transform the A/D voltage into distance.
calculate_distance
x = calcu_data (A/D Voltage)
Y = -1.2027(approximate value)
Y
ans = X^
Distance = 27.22 * ans
Distance = 27.22×Voltage Vo-1.2027
return
19
AN702-00002-1v0-E
Sample code of transform voltage into distance
/*Main.c*/
/*********************************************************************
NAME:
caluculate_distance()
FUNCTION:
Calculation of measuring distance
in : calucu_data = ad_converter voltage data
out : Y_distance = 27.22 * x^-1.2027
*********************************************************************/
void calculate_distance(float calcu_data)
{
double x;
double y;
double ans;
x = calcu_data;
/* A/D data = Voltage V*/
y = -1.2027;
ans = pow(x, y);
/* ans = x^(-1.2027) */
X_voltage = ans;
//
convert from voltage to distance)
Y_distance = 27.22 * (X_voltage);
}
20
AN702-00002-1v0-E
3.7
Display of LCD (Distance data on LCD)
Calculated measurement distance data display on the LCD. This application use the SC1602BS
which is popular LCD module of offered commercially. The SC1602BS has LCD driver controller
for LCD display. Controlling of the SC1602BS. Please refer to the document of “LCD Module
control Example of connection to SC1602BS”.
Showing below are flowchart of display.
lcd_displayf
Display of the calculated integer data.
Decimal point ( . ) on the display
Display of the second digit decimal
Display of the second digit decimal
Display of the second digit decimal
return
21
AN702-00002-1v0-E
Sample code of calculated data on the display
/*Main.c*/
/*********************************************************************
NAME:
lcd_displayf()
FUNCTION:
Data send to SC1602
*********************************************************************/
void lcd_displayf(float answer)
{
unsigned char save_data;
unsigned char disp_data;
save_data = answer;
/* 1 桁目 float to char 整数変換 */
/*------------------------------------------------------------------*/
//
LCD display of distance upper data 0cm~99cm
/*------------------------------------------------------------------*/
if (flag == 1){
make_distance_data(save_data);
lcd_display_header(henkan);
}
22
/* 整数部 0~99 変換 */
AN702-00002-1v0-E
/*------------------------------------------------------------------*/
//
LCD display of voltage or distance
/*------------------------------------------------------------------*/
else {
lcd_display(save_data);
}
LCD_Printf(".");
// LCD 文字表示 //
/* 少数 1 桁目 (a.bcd - a = 0.bcd)*10 = b.cd */
answer = (answer-save_data)*10;
disp_data = answer;
/* disp_data = b */
lcd_display(disp_data);
/* 少数 2 桁目 (b.cd - b = 0.cd)*10 = c.d */
answer = (answer-disp_data)*10;
disp_data = answer;
/* disp_data = c */
lcd_display(disp_data);
/* 少数 3 桁目 (c.d - c = 0.d)*10 = d */
answer = (answer-disp_data)*10;
disp_data = answer;
lcd_display(disp_data);
}
note:These code are excerpt from sample program.
Please get more detailed information from sample program.
23
AN702-00002-1v0-E
Additional Information
For more information about how to use MB95260H series and “New 8FX family” MCU, BGM
adaptor and SOFTUNE, please visit website
http://jp.fujitsu.com/fsl/
24