8
2015 Microchip Technology Inc. DS00001906A-page 1 Studies have shown that proper daily exercise can reduce blood pressure and body mass index. Bracelet- type activity trackers featuring step counting and Bluetooth ® Low Energy (BLE) are now becoming popular as an everyday exercise measurement and motivation tool for people wanting to improve their physical activity and health. OVERVIEW A digital pedometer is a portable electronic device that counts each step a person takes by detecting the motion of the person's body with an accelerometer. This application note demonstrates the implementation of a Bluetooth Low Energy Digital Pedometer using the Microchip PIC16LF1718, a cost effective 8-bit microcontroller with extreme low power (XLP), the Microchip RN4020 Bluetooth 4.1 Low Energy Module, and the Bosch Sensortec BMA250E digital triaxial accelerometer. The Microchip Pedometer Demo can be worn on the wrist like a bracelet/watch. The on-board RN4020 BLE module allows the pedometer demo to communicate with a smartphone or tablet on which the user’s exercise progress can be tracked. The pedometer demo is powered by a single 3V coin lithium battery (CR2032). Figure 1 shows the block diagram of the pedometer demo. FIGURE 1: BLOCK DIAGRAM Author: Zhang Feng Microchip Technology Inc. 8-Bit Microcontroller PIC16LF1718 I2C IOC UART I/Os Accelerometer Bosch BMA250E Push Button RN4020 Bluetooth® 4.1 Low Energy Module Three digits 7-Segment LED Display CR2032 Lithium Battery VDD AN1906 Bluetooth ® Low Energy Digital Pedometer Demo Design

Bluetooth Low Energy Digital Pedometer Demo Design ...ww1.microchip.com/downloads/en/AppNotes/00001906A.pdf · This application note demonstrates the implementation ... In Low Power

Embed Size (px)

Citation preview

AN1906Bluetooth® Low Energy Digital Pedometer Demo Design

Studies have shown that proper daily exercise canreduce blood pressure and body mass index. Bracelet-type activity trackers featuring step counting andBluetooth® Low Energy (BLE) are now becomingpopular as an everyday exercise measurement andmotivation tool for people wanting to improve theirphysical activity and health.

OVERVIEWA digital pedometer is a portable electronic device thatcounts each step a person takes by detecting themotion of the person's body with an accelerometer.This application note demonstrates the implementationof a Bluetooth Low Energy Digital Pedometer using theMicrochip PIC16LF1718, a cost effective 8-bitmicrocontroller with extreme low power (XLP), theMicrochip RN4020 Bluetooth 4.1 Low Energy Module,and the Bosch Sensortec BMA250E digital triaxialaccelerometer.

The Microchip Pedometer Demo can be worn on thewrist like a bracelet/watch. The on-board RN4020 BLEmodule allows the pedometer demo to communicatewith a smartphone or tablet on which the user’sexercise progress can be tracked. The pedometerdemo is powered by a single 3V coin lithium battery(CR2032).

Figure 1 shows the block diagram of the pedometerdemo.

FIGURE 1: BLOCK DIAGRAM

Author: Zhang FengMicrochip Technology Inc.

8-Bit Microcontroller PIC16LF1718

I2C IOC UART I/Os

Accelerometer Bosch BMA250E

Push Button

RN4020 Bluetooth® 4.1 Low Energy Module

Three digits 7-Segment LED Display

CR2032 Lithium Battery

VDD

2015 Microchip Technology Inc. DS00001906A-page 1

BLUETOOTH LOW ENERGY DIGITAL PEDOMETER DEMO DESIGN

THEORY OF OPERATION

Step DetectionThe Microchip pedometer demo uses a Bosch 10-bittriaxial digital accelerometer (BMA250E) to detect themotion of the wearer. The Microchip pedometer demofirmware running in the PIC16LF1718 microcontrollercontains a step detection algorithm library developedby Bosch Sensortec.

A step detection function in this library is calledperiodically by the user application. The microcontrollerwill read the acceleration data of X/Y/Z axes from theaccelerometer via an I2C™ interface when the stepdetection function is called. The step detection functionthen analyzes the accumulated acceleration data anddetermines the number of steps taken by using patternrecognition.

The accumulated number of steps can be shown on thethree digit 7-Segment LED displays or a BLEapplication running in a smartphone/tablet that ispaired with the RN4020 BLE module.

Bluetooth Low Energy (BLE) CommunicationThe RN4020 BLE module complies with BluetoothCore Specification v4.1. The RN4020 supports 13public profiles and 17 public services based on theGeneric Attribute Profile (GATT). Among supportedpublic profiles, four are health-device-related profiles:heart rate monitor, health thermometer, glucose meterand blood pressure monitor.

The RN4020 also supports a user-defined privateprofile/service, which can precisely fit a user'sparticular application. This demo defined a privateservice for the pedometer application. Allconfigurations are saved in the on-board non-volatilememory (NVM) of the RN4020, so users need to set upthe module only once.

The microcontroller activates the RN4020 when theBLE communication is enabled by pressing the on-board push button. The RN4020 then becomespairable with a smartphone or tablet that supports BLE.The microcontroller periodically sends the step numberto the RN4020 via UART interface after successfulpairing. The RN4020 then transmits the step number tothe paired smartphone or tablet, where a compatibleBLE application can be used to display the stepnumber.

Because the Apple® HealthKit, a new feature for iOS 8,adheres to the BLE GATT specifications, medicaldevices like heart rate and blood pressure monitors,thermometers, and glucose meters that are built withRN4020 will be supported natively by HealthKit. Thatmeans device manufacturers could potentially skip theprocess of developing a companion application for theirproduct, and instead, allow HealthKit to automaticallycontrol the device/accessory itself when it has beenpaired with the RN4020 BLE module.

Human InterfaceA single push button provides quick function control tothe pedometer demo via the Interrupt-On-Change(IOC) interface.

To turn on/off the LED display, press the button andquickly release it within 1 second.

To enable/disable BLE communication, press thebutton and hold it down for more than 1 second but lessthan 4 seconds.

To zero the step number, press the button and hold itdown for more than 4 seconds, then release it.

PowerThe pedometer demo is powered by a single 3V coinlithium battery (CR2032). The LED displays areautomatically turned off after 10 seconds to savepower.

The baud rate of the UART communication is set to2400 Kbps so that the RN4020 BLE module can remainin Deep Sleep mode when there is no UART datacommunication.

If there is no motion for 16 seconds, the microcontrollerwill get a no-motion interrupt from the accelerometervia the IOC interface. When the no-motion interruptoccurs, the microcontroller reconfigures theaccelerometer to high-g interrupt and then puts it intoLow Power Mode 1. The microcontroller next goes intoSleep mode as well, putting the overall system into thelowest power consumption mode.

In Low Power Mode 1, the accelerometer is periodicallyswitching between a sleep phase and a wake-upphase. During the sleep phase the whole analog circuitof the accelerometer is powered down. During thewake-up phase, the accelerometer works normally andthe high-g interrupt function is running to determinewhen to wake up from the Low Power Mode.

The accelerometer will generate a high-g interrupt towake up the microcontroller when the wearer's motionis over the preset threshold for a high-accelerationevent, such as walking, picking up the pedometer, orwaving or rotating the pedometer in the air. Thepedometer then resumes normal operation afterwaking up.

DS00001906A-page 2 2015 Microchip Technology Inc.

BLUETOOTH LOW ENERGY DIGITAL PEDOMETER DEMO DESIGN

PROGRAM FLOWCHARTFigure 2 shows the firmware process flow of the pedometer demo.

FIGURE 2: BLOCK DIAGRAM

Start

System Initialization

Step Detection Routine – Read Accelerometer & Calculate Step Number

Display Step Number on Segments LED Display

Display Step Number thru BLE Communication

Main Loop

Sleep Routine

2015 Microchip Technology Inc. DS00001906A-page 3

BLUETOOTH LOW ENERGY DIGITAL PEDOMETER DEMO DESIGN

APPENDIX A: PEDOMETER DEMO BOARDFigure 3 shows the front (top photo) and the back (lower photo) of the pedometer demo board.

FIGURE 3: PEDOMETER DEMO BOARD

DS00001906A-page 4 2015 Microchip Technology Inc.

BLUETOOTH LOW ENERGY DIGITAL PEDOMETER DEMO DESIGN

APPENDIX B: SCHEMATICS

FIGURE 4: PEDOMETER DEMO BOARD SCHEMATICS

330RR12

330RR13

330RR14

BlueLD

3Green

LD1

RedLD

2

GN

D

VDD

GN

DCR2032BT1

MCP1640T-I/CHY

VIN6

S W 1

EN3

G ND2

VFB4

VOU

T5

U2

DNP

10uFC2

R15DNP

DNPR16

R1DNP

R2DNP

GN

DG

ND

GN

DG

ND

GN

D

3V

VDD

L1DNP

MCP1700T-3302E/TT

VIN3

VOU

T2

VSS1

U3

GN

D

VDD

GN

D

10KR10

10KR11

VDD

VDD

GN

D

GN

D

GN

D

GN

D

SDO

1

SDx

2

VDD

IO3

NC

4

IN T 15

IN T 26

VDD

7

GN

DIO

8

GN

D9

CSB10

V DD 11

S C x 12

SDO

SDx

VDD

IO

NC

IN T 1

IN T 2

VDD

GN

DIO

GN

D

CSB

V DD

S C x

BMA250E

U5

GN

DG

ND

GN

DG

ND

VDD

GN

D

K1

SEG F

2

SEG G

3

SEG E

4

SEG D

5K

6SEG

DP

7SEG

C8

SEG B

9SEG

A10

KSEGF

SEGG

SEGE

SEGD

K

SEGD

P

SEGC

SEGB

SEGA

LSHD-7503

D1K

1

SEG F

2

SEG G

3

SEG E

4

SEG D

5K

6SEG

DP

7SEG

C8

SEG B

9SEG

A10

KSEGF

SEGG

SEGE

SEGD

K

SEGD

P

SEGC

SEGB

SEGA

LSHD-7503

D2K

1

SEG F

2

SEG G

3

SEG E

4

SEG D

5K

6SEG

DP

7SEG

C8

SEG B

9SEG

A10

KSEGF

SEGG

SEGE

SEGD

K

SEGD

P

SEGC

SEGB

SEGA

LSHD-7503

D3

CL-SB-12B-01T

13

2

S1

GN

D

470RR3

470RR4

470RR5

470RR6

470RR7

470RR8

470RR9

470RR17

16V0.1μF

C4

VDD

GN

D

GN

D

GN

D

PICkit3

PICkitSe

rial

RE31

RA0

2

RA1

3

RA2

4

RA3

5

RA4

6

RA5

7

GN

D8

RA7

9

RA6

10

RC011

RC112

RC213

RC314

RC415

RC516

RC617

RC718

GN

D19

VDD

20RB0

21RB1

22RB2

23RB3

24RB4

25RB5

26RB6

27RB7

28RE3

RA0

RA1

RA2

RA3

RA4

RA5

GN

D

RA7

RA6

RC0

RC1

RC2

RC3RC4

RC5

RC6

RC7

GN

D

VDD

RB0

RB1

RB2

RB3

RB4

RB5

RB6

RB7

U1

PIC16LF1718-I/SS

ON

OFF

BAT PW

R

GN

D1

AIO2

2

AIO1

3

AIO0

4

UA

RT_TX5

UA

RT_RX6

WA

KE_SW7

CMD

/MLD

P8

G ND9

P IO 1/S C K10

ML DP _E V /PIO 2/CS11

W S /PIO 3/MO S I12

P IO 4/MIS O13

C T S /PIO 514

W AK E _HW15

G ND16

SPI/PIO17

RTS/PIO

618

PIO7

19RSVD

20RSVD

21RSVD

22VD

D23

GN

D24

GN

D

AIO2

AIO1

AIO0

UA

RT_TX

UA

RT_RX

WA

KE_SW

CMD

/MLD

P

G ND

P IO 1/S C KML DP _E V /PIO 2/CSW S /PIO 3/MO S IP IO 4/MIS OC T S /PIO 5W AK E _HW

G ND

SPI/P//IO

RTS/PIO

6

PIO7

RSVD

RSVD

RSVD

VDD

GN

D

RN4020-V/RM

U4

S2

VDD

VDD

VDD

MCP1640_EN

MCP1640_EN

MCLR

MCLR

PIO1

P IO 1P IO 2P IO 3

P IO 1

P IO 2

P IO 3

LDO

_VIN

LDO

_VIN

RN_RX

RN_RX

RN_RX

PIC_TX

PIC_TX

RN_TX

RN_TX

RN_TX

WA

KE_SW

W AK E _HW WA

KE_HW

WA

KE_SW

SDA

SCL

INT1

INT2

DIG

IT_ON

E

DIG

IT_TWO

DIG

IT_THREE

DIG

IT_THREE

DIG

IT_TWO

DIG

IT_ON

E

DIG

IT_ON

E

DIG

IT_TWO

DIG

IT_THREE

IN T 1

IN T 2

SDA

SCL

RN_CTS

ICSPDA

T

ICSPDA

TICSPCLK

ICSPCLK

SEG_A

SEG_A

SEG_A

SEG_A

SEG_B

SEG_B

SEG_B

SEG_B

SEG_C

SEG_C

SEG_C

SEG_C

SEG_D

SEG_D

SEG_D

SEG_D

SEG_E

SEG_E

SEG_E

SEG_E

SEG_F

SEG_F

SEG_F

SEG_F

SEG_G

SEG_G

SEG_G

SEG_G

SEG_D

P

SEG_D

P

SEG_D

P

SEG_D

P

0R R18

CMD

/MLD

P

CMD

/MLD

P

R N_C T S

RN_RTS

RN_RTS

16V0.1μF

C8

GN

D

470R

R20

10KR19

VDD

GN

D

4.7uFC1

4.7uFC7

16V0.1μF

C3

16V0.1μF

C5

16V0.1μF

C6

123

DNPJ2

12

34

56

78

910

1112

J1DN

P

MCU

Bluetooth Module

Power Regulation

Display

Accelerom

eter

GN

D

WR

IST S

TRAP

SC

REW

SC

REW

SC

REW

SC

REW

SC

REW

SC

REW

SC

REW

SC

REW

STA

ND

OFF

STA

ND

OFF

STA

ND

OFF

STA

ND

OFF

Mechanical Assem

bly Parts

WA

TCH

BAS

E

2015 Microchip Technology Inc. DS00001906A-page 5

BLUETOOTH LOW ENERGY DIGITAL PEDOMETER DEMO DESIGN

APPENDIX C: WARNINGS, RESTRICTIONS AND DISCLAIMER

This demo is intended solely for evaluation anddevelopment purposes. It is NOT intended for medical,diagnostic or treatment use. Use of Microchip devicesin life support and/or safety applications is entirely atthe buyer's risk, and the buyer agrees to defend,indemnify and hold harmless Microchip from any andall damages, claims, suits, or expenses resulting fromsuch use.

APPENDIX D: REFERENCESPIC16(L)F1717/8/9 Cost Effective 8-Bit IntelligentAnalog Flash MCU Data Sheet (DS40001740).

RN4020 Bluetooth Low Energy Module Data Sheet(DS50002279).

RN4020 Bluetooth Low Energy Module CommandReference User's Guide (DS70005191).

Data sheet BMA250E Digital, triaxial accelerationsensor (BST-BMA250E-DS004-05).

DS00001906A-page 6 2015 Microchip Technology Inc.

Note the following details of the code protection feature on Microchip devices:• Microchip products meet the specification contained in their particular Microchip Data Sheet.

• Microchip believes that its family of products is one of the most secure families of its kind on the market today, when used in the intended manner and under normal conditions.

• There are dishonest and possibly illegal methods used to breach the code protection feature. All of these methods, to our knowledge, require using the Microchip products in a manner outside the operating specifications contained in Microchip’s Data Sheets. Most likely, the person doing so is engaged in theft of intellectual property.

• Microchip is willing to work with the customer who is concerned about the integrity of their code.

• Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. Code protection does not mean that we are guaranteeing the product as “unbreakable.”

Code protection is constantly evolving. We at Microchip are committed to continuously improving the code protection features of ourproducts. Attempts to break Microchip’s code protection feature may be a violation of the Digital Millennium Copyright Act. If such actsallow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that Act.

Information contained in this publication regarding deviceapplications and the like is provided only for your convenienceand may be superseded by updates. It is your responsibility toensure that your application meets with your specifications.MICROCHIP MAKES NO REPRESENTATIONS ORWARRANTIES OF ANY KIND WHETHER EXPRESS ORIMPLIED, WRITTEN OR ORAL, STATUTORY OROTHERWISE, RELATED TO THE INFORMATION,INCLUDING BUT NOT LIMITED TO ITS CONDITION,QUALITY, PERFORMANCE, MERCHANTABILITY ORFITNESS FOR PURPOSE. Microchip disclaims all liabilityarising from this information and its use. Use of Microchipdevices in life support and/or safety applications is entirely atthe buyer’s risk, and the buyer agrees to defend, indemnify andhold harmless Microchip from any and all damages, claims,suits, or expenses resulting from such use. No licenses areconveyed, implicitly or otherwise, under any Microchipintellectual property rights.

2015 Microchip Technology Inc.

QUALITY MANAGEMENT SYSTEM CERTIFIED BY DNV

== ISO/TS 16949 ==

Trademarks

The Microchip name and logo, the Microchip logo, dsPIC, FlashFlex, flexPWR, JukeBlox, KEELOQ, KEELOQ logo, Kleer, LANCheck, MediaLB, MOST, MOST logo, MPLAB, OptoLyzer, PIC, PICSTART, PIC32 logo, RightTouch, SpyNIC, SST, SST Logo, SuperFlash and UNI/O are registered trademarks of Microchip Technology Incorporated in the U.S.A. and other countries.

The Embedded Control Solutions Company and mTouch are registered trademarks of Microchip Technology Incorporated in the U.S.A.

Analog-for-the-Digital Age, BodyCom, chipKIT, chipKIT logo, CodeGuard, dsPICDEM, dsPICDEM.net, ECAN, In-Circuit Serial Programming, ICSP, Inter-Chip Connectivity, KleerNet, KleerNet logo, MiWi, MPASM, MPF, MPLAB Certified logo, MPLIB, MPLINK, MultiTRAK, NetDetach, Omniscient Code Generation, PICDEM, PICDEM.net, PICkit, PICtail, RightTouch logo, REAL ICE, SQI, Serial Quad I/O, Total Endurance, TSHARC, USBCheck, VariSense, ViewSpan, WiperLock, Wireless DNA, and ZENA are trademarks of Microchip Technology Incorporated in the U.S.A. and other countries.

SQTP is a service mark of Microchip Technology Incorporated in the U.S.A.

Silicon Storage Technology is a registered trademark of Microchip Technology Inc. in other countries.

GestIC is a registered trademarks of Microchip Technology Germany II GmbH & Co. KG, a subsidiary of Microchip Technology Inc., in other countries.

All other trademarks mentioned herein are property of their respective companies.

© 2015, Microchip Technology Incorporated, Printed in the U.S.A., All Rights Reserved.

ISBN: 978-1-63277-172-8

Microchip received ISO/TS-16949:2009 certification for its worldwide

DS00001906A-page 7

headquarters, design and wafer fabrication facilities in Chandler and Tempe, Arizona; Gresham, Oregon and design centers in California and India. The Company’s quality system processes and procedures are for its PIC® MCUs and dsPIC® DSCs, KEELOQ® code hopping devices, Serial EEPROMs, microperipherals, nonvolatile memory and analog products. In addition, Microchip’s quality system for the design and manufacture of development systems is ISO 9001:2000 certified.

DS00001906A-page 8 2015 Microchip Technology Inc.

AMERICASCorporate Office2355 West Chandler Blvd.Chandler, AZ 85224-6199Tel: 480-792-7200 Fax: 480-792-7277Technical Support: http://www.microchip.com/supportWeb Address: www.microchip.comAtlantaDuluth, GA Tel: 678-957-9614 Fax: 678-957-1455Austin, TXTel: 512-257-3370 BostonWestborough, MA Tel: 774-760-0087 Fax: 774-760-0088ChicagoItasca, IL Tel: 630-285-0071 Fax: 630-285-0075ClevelandIndependence, OH Tel: 216-447-0464 Fax: 216-447-0643DallasAddison, TX Tel: 972-818-7423 Fax: 972-818-2924DetroitNovi, MI Tel: 248-848-4000Houston, TX Tel: 281-894-5983IndianapolisNoblesville, IN Tel: 317-773-8323Fax: 317-773-5453Los AngelesMission Viejo, CA Tel: 949-462-9523 Fax: 949-462-9608New York, NY Tel: 631-435-6000San Jose, CA Tel: 408-735-9110Canada - TorontoTel: 905-673-0699 Fax: 905-673-6509

ASIA/PACIFICAsia Pacific OfficeSuites 3707-14, 37th FloorTower 6, The GatewayHarbour City, KowloonHong KongTel: 852-2943-5100Fax: 852-2401-3431Australia - SydneyTel: 61-2-9868-6733Fax: 61-2-9868-6755China - BeijingTel: 86-10-8569-7000 Fax: 86-10-8528-2104China - ChengduTel: 86-28-8665-5511Fax: 86-28-8665-7889China - ChongqingTel: 86-23-8980-9588Fax: 86-23-8980-9500China - DongguanTel: 86-769-8702-9880 China - HangzhouTel: 86-571-8792-8115 Fax: 86-571-8792-8116China - Hong Kong SARTel: 852-2943-5100 Fax: 852-2401-3431China - NanjingTel: 86-25-8473-2460Fax: 86-25-8473-2470China - QingdaoTel: 86-532-8502-7355Fax: 86-532-8502-7205China - ShanghaiTel: 86-21-5407-5533 Fax: 86-21-5407-5066China - ShenyangTel: 86-24-2334-2829Fax: 86-24-2334-2393China - ShenzhenTel: 86-755-8864-2200 Fax: 86-755-8203-1760China - WuhanTel: 86-27-5980-5300Fax: 86-27-5980-5118China - XianTel: 86-29-8833-7252Fax: 86-29-8833-7256

ASIA/PACIFICChina - XiamenTel: 86-592-2388138 Fax: 86-592-2388130China - ZhuhaiTel: 86-756-3210040 Fax: 86-756-3210049India - BangaloreTel: 91-80-3090-4444 Fax: 91-80-3090-4123India - New DelhiTel: 91-11-4160-8631Fax: 91-11-4160-8632India - PuneTel: 91-20-3019-1500Japan - OsakaTel: 81-6-6152-7160 Fax: 81-6-6152-9310Japan - TokyoTel: 81-3-6880- 3770 Fax: 81-3-6880-3771Korea - DaeguTel: 82-53-744-4301Fax: 82-53-744-4302Korea - SeoulTel: 82-2-554-7200Fax: 82-2-558-5932 or 82-2-558-5934Malaysia - Kuala LumpurTel: 60-3-6201-9857Fax: 60-3-6201-9859Malaysia - PenangTel: 60-4-227-8870Fax: 60-4-227-4068Philippines - ManilaTel: 63-2-634-9065Fax: 63-2-634-9069SingaporeTel: 65-6334-8870Fax: 65-6334-8850Taiwan - Hsin ChuTel: 886-3-5778-366Fax: 886-3-5770-955Taiwan - KaohsiungTel: 886-7-213-7828Taiwan - TaipeiTel: 886-2-2508-8600 Fax: 886-2-2508-0102Thailand - BangkokTel: 66-2-694-1351Fax: 66-2-694-1350

EUROPEAustria - WelsTel: 43-7242-2244-39Fax: 43-7242-2244-393Denmark - CopenhagenTel: 45-4450-2828 Fax: 45-4485-2829France - ParisTel: 33-1-69-53-63-20 Fax: 33-1-69-30-90-79Germany - DusseldorfTel: 49-2129-3766400Germany - MunichTel: 49-89-627-144-0 Fax: 49-89-627-144-44Germany - PforzheimTel: 49-7231-424750Italy - Milan Tel: 39-0331-742611 Fax: 39-0331-466781Italy - VeniceTel: 39-049-7625286 Netherlands - DrunenTel: 31-416-690399 Fax: 31-416-690340Poland - WarsawTel: 48-22-3325737 Spain - MadridTel: 34-91-708-08-90Fax: 34-91-708-08-91Sweden - StockholmTel: 46-8-5090-4654UK - WokinghamTel: 44-118-921-5800Fax: 44-118-921-5820

Worldwide Sales and Service

01/27/15