Walk Together
  Mohd Saifulddin
 

1

APPLICATION NOTE

ADC CONVERTER OF HEARTBEATS SOUND

 

ABSTRACT

The Analog-to-digital conversion (ADC) is very useful to convert the analog input to digital output. As an Electrical & Electronic engineer we should had the ability to use this conversion because our world is analog so we must convert it to digital for more convenient and accurate value.

OBJECTIVE

This application note will help users of analog-to-digital converters (ADC) understand how to built, define and write ADC operation using PIC16F88 specifically to convert heartbeats signal into digital signal.

INTRODUCTION

This document describes on how to convert heartbeats sound that already being converted into electrical signal by condenser microphone and also already being amplify by an Op-Amp.This analog input signal will be convert into digital signal using programming and load it into PIC16F88.

IMPORTANT

This application note only explain roughly on how to do ADC converter by programming and to understands the program the user must have the basic knowledge about programming using software MPLAB and pretty much understanding about PIC16F88 that can be read fom the

TARGET DEVICE

  •  
PIC16F88

 

About PIC16F88

Low-Power Features:

• Power

-

-Managed modes:Primary Run: RC oscillator, 76 μA, 1 MHz, 2V

-

RC_RUN: 7 μA, 31.25 kHz, 2V

-

SEC_RUN: 9 μA, 32 kHz, 2V

-

• Timer1 Oscillator: 1.8 μA, 32 kHz, 2V

• Watchdog Timer: 2.2 μA, 2V

• Two

Sleep: 0.1 μA, 2V-Speed Oscillator Start-up

Oscillators:

• Three Crystal modes:

- LP, XT, HS: up to 20 MHz

• Two External RC modes

• One External Clock mode:

- ECIO: up to 20 MHz

• Internal oscillator block:

- 8 user selectable frequencies: 31 kHz,125 kHz, 250 kHz, 500 kHz, 1 MHz, 2 MHz,

4 MHz, 8 MHz

Peripheral Features:

• Capture, Compare, PWM (CCP) module:

- Capture is 16-bit, max. resolution is 12.5 ns

- Compare is 16-bit, max. resolution is 200 ns

- PWM max. resolution is 10-bit

• 10

-bit, 7-channel Analog-to-Digital Converter

• Synchronous Serial Port (SSP) with SPI™ (Master/Slave) and I2C™ (Slave)

• Addressable Universal Synchronous

9-bit address detection:

- RS-232 operation using internal oscillator (no external crystal required)

Asynchronous Receiver Transmitter (AUSART/SCI) with

• Dual Analog Comparator module:

- Programmable on-chip voltage reference

- Programmable input multiplexing from device inputs and internal voltage reference

- Comparator outputs are externally accessible

Special Microcontroller Features

• 100,000 erase/write cycles Enhanced Flash

program memory typical

• 1,000,000 typical erase/write cycles EEPROM

data memory typical

• EEPROM Data Retention: > 40 years

In-Circuit Serial Programming™ (ICSP™) via two pins

• Processor read/write access to program memory

• Low

-Voltage Programming

• In

-Circuit Debugging via two pins

• Extended Watchdog Timer (WDT):

- Programmable period from 1 ms to 268s

• Wide operating volt

The PIC16F88 belongs to the Mid-Range family of the PICmicro® devices.These devices contain features that are new to the PIC16 product line:

age range: 2.0V to 5.5V

• Low

-power modes: RC_RUN allows the core and peripherals to be clocked from the INTRC,while SEC_RUN allows the core and peripherals to be clocked from the low-power Timer1.

• Internal RC oscillator with eight selectable

frequencies, including 31.25 kHz, 125 kHz,250 kHz,500 kHz, 1 MHz, 2 MHz, 4 MHz and 8 MHz. The INTRC can be configured as a primary orsecondary clock source.

• The Timer1 module current consumption has been greatly reduced from 20 μA

• Extended

The WDT has its own 16-bit prescaler.

Watchdog Timer (WDT) that can have a programmable period from 1 ms to 268s.

• Two

-Speed Start-up: When the oscillator is configured for LP, XT or HS Oscillator mode, this feature will clock the device from the INTRC while the oscillator is warming up. This, in turn,will enable almost immediate code execution.

• Fail

-Safe Clock Monitor: This feature will allow the device to continue operation if the primary or secondary clock source fails by switching over to the INTRC.

• The A/D module has a new register for PIC16

devices named ANSEL. This register allows easier configuration of analog or digital I/O pins.

Device Overview

Available Memory In PIC16F88

There are 16 I/O pins that are user configurable on a pin-to-pin basis. Some pins are multiplexed with other device functions. These functions include:

• External Interrupt

• Change on PORTB Interrupt

• Timer0 Clock Input

• Low

-Power Timer1 Clock/Oscillator

• Capture/Compare/PWM

• 10

-bit, 7-channel A/D Converter (PIC16F88 only)

• SPI™/I2C™

• Two Analog Comparators

• AUSART

• MCLR (RA5) can be configured as an input

BLOCK DIAGRAM OF PIC16F88

Note 1:

Higher order bits are from the STATUS register.

2:

The CCP1 pin is determined by the CCPMX bit in Configuration Word 1 register.


Theory of ADC Operation

This is done in multiple steps.

Figure 1 :

Example Analog Signal

First, the analog signal 

          Determining the digital values that represent the analog samples taken at this sampling frequency is called “quantization”. The analog signal is quantized by assigning an analog value to the nearest “allowed” digital value . The number of digital values is called “resolution” and is always limited, for example to 256 values for an 8-bit digital. Therefore quantization of analog signals always results in a loss of information. This “quantization error” is inversely proportional to the resolution of the digital signal. It is also inversely proportional to the signal’s “dynamic range”, the range between minimum and maximum values.

How Pic Works :

  1. Setup Port
  2. Detect Voltage Signal
  3. Detect the High Peak of
  4. Heartbeat Pulse
  5. Detect the Low Peak of Heartbeat
  6. Pulse in interval time 0.2s together with High Peak
  7. Consider as One Heartbeat
  8. Send Information to PIC18F452

 

Total circuit of HEARTBEATS ANALYSER

ADC Circuit Part

The diagram above show the connection of PIC16F88 to our HEARTBEATS ANALYSER circuit.

 

Optimization

The microphone output signal may vary depending on the type of microphone used. Toachieve best results it is important to choose the microphone amplifier gain that delivers a maximum output signal

CONCLUSIONS

Once a user has well understanding on how to define and write the analog-to-digital converters, the user can make your own ADC converter design project. A good understanding of the terms used to specify the converter can help the user sort out the most important design parameters for user system and enable the user to get the best cost and performance for the design.

REFERENCES

1. Website:

www.freescale.com

2. Interfacing PIC Microcontrollers Embedded Design by Interactive Simulation, Martin Bates

(2006) Elsevier.

3. Data sheet of PIC16F88

4. www.atmel.com/literature

 

           On the other hand, the microphone amplifier can be adjusted to cover the ADC’s dynamic range as presented later. This methods reduce the quantization error. In addition, the latter method also increases the signal-to-noise ratio SNR and should therefore be preferred shows the digital values that represent the analog signal. These are the values that are read as ADC conversion results.In this application, the signal has a minimum and a maximum value which are never exceeded. The parts of the signal below the minimum and above the maximum value do not contain any information. They can be removed in order to save memory.This is done by downshifting the whole signal and discarding the part above the “max” value

is converted into a time discrete signal by taking periodic samples.
The time interval
between two samples is called the “sampling period” and its reciprocal the “sampling frequency”. According to the sampling theorem,the sampling frequency has to be at least double the maximum signal frequency. Otherwise the periodic continuation of the signal in the frequency domain would result in spectral overlap, called “aliasing”. Such an aliased signal cannot be uniquely recovered from its samples.


APPENDIX

APPENDIX : Source code to convert the heartbeats signal

;===============================================================

; PROGRAMMER: WALK TOGETHER

; PROJECT: HEARTBEAT ANALYZER

; TITLE: ADCX.asm

; DATE: 28/02/2009

;===============================================================

LIST P=16F877A

ERRORLEVEL -302

ERRORLEVEL -305

#INCLUDE <P16F877A.INC>

__CONFIG 0X3F32 ; HS OSC

; WATCH DOG OFF

; POWER UP TIMER ON

; BROWN OUT OFF

; LVP OFF

; FLASH PROGRAM WRITE OFF

; DATA EE READ PROTECT OFF

; CODE PROTECT OFF

;=============================== DEFINE CONSTANT =====================================

X1 EQU H'20'

X2 EQU H'21'

X3 EQU H'22'

Z1 EQU H'23'

Z2 EQU H'24'

Z3 EQU H'25'

TWOTWO EQU H'26'

;========================================= RESET VECTOR ============================

ORG 0X000

GOTO MAIN

;========================================= INTERRUPT VECTOR ==========================

ORG 0X004

GOTO MAIN ;IF INTERRUPT IS NOT USED, SET TO MAIN

;================================ INITIALIAZATION =====================================

ORG 0X100

MAIN CALL DELAY1

CALL INITIALIZE_IO ;MAKE ALL INPUT OUTPUT

CALL SETUP_ADC ;SETUP FOR ADC

CALL BANK0 ;OPEN BANK0

;================================MAIN PROGRAM ======================================

CALL DELAY1

MOVLW D'2'

MOVWF TWOTWO

ADC0 CLRF Z3

MOVLW D'255'

MOVWF Z1

MOVLW D'50'

MOVWF Z2

ADC

CALL READ_ADC1

SUBLW D'55'

BTFSS STATUS,C

GOTO ADC_ON

BTFSC Z3,0

GOTO ADC

DECFSZ Z1

GOTO ADC

MOVLW D'255'

MOVWF Z1

DECFSZ Z2

GOTO ADC

MOVLW D'1'

MOVWF Z3

GOTO ADC

ADC_ON

BTFSC Z3,0

GOTO TEST_BEATM

DECFSZ TWOTWO

GOTO $+9

MOVLW D'2'

MOVWF TWOTWO

BSF LED7

BTFSS SIGNAL

GOTO $+3

BCF SIGNAL

GOTO $+2

BSF SIGNAL

CALL DELAY_BEAT

BCF LED7

TEST_BEATM

MOVLW D'255'

MOVWF Z1

MOVLW D'5'

MOVWF Z2

TEST_BEATC

DECFSZ Z1,1

GOTO TEST_OFF1

MOVLW D'255'

MOVWF Z1

DECFSZ Z2,1

GOTO TEST_BEATC

GOTO ADC0

TEST_OFF1

CALL READ_ADC1

SUBLW D'55'

BTFSS STATUS,C

GOTO TEST_BEATM

GOTO TEST_BEATC

;============================= SUBROUTINE =========================================

INITIALIZE_IO

CALL BANK1 ;CHANGE TO BANK 1

MOVLW B'11111111'

MOVWF TRISA

MOVLW B'00000000'

MOVWF TRISB

MOVLW B'01001001'

MOVWF TRISC

MOVLW B'00000000'

MOVWF RISD

MOVLW B'00000000'

MOVWF TRISE

CALL BANK0 ;CHANGE TO BANK 0

MOVLW B'00000000'

MOVWF PORTA

MOVLW B'00000000'

MOVWF PORTB

MOVLW B'00110000'

MOVWF PORTC

MOVLW B'00000000'

MOVWF PORTD

MOVLW B'00000000'

MOVWF PORTE

RETURN

SETUP_ADC

MOVLW B'10000000' ;FOSC/32

;CHANNEL 0

;ADC NOT ACTIVE

;ADC OFF

MOVWF ADCON0

CALL BANK1

MOVLW B'01000100' ;LEFT JUSTIFIED

;RA0, RA1, RA3 AS ADC

MOVWF ADCON1

CALL BANK0

RETURN

READ_ADC1

CALL BANK0

MOVLW B'10000001' ;CONFIGURE TO AN0

MOVWF ADCON0

MOVLW D'50'

MOVWF X1

DECFSZ X1

GOTO $-1 ;DELAY A WHILE

BSF ADCON0,2 ;START CONVERSION

BTFSC ADCON0,2 ;WAIT UNTIL ADC COMPLETED

GOTO $-1

MOVF ADRESH,W ;MOVE ADC VALUE TO WORKING REGISTER

BCF ADCON0,ADON ;OFF ADC MODULE

RETURN

READ_ADC2

CALL BANK0

MOVLW B'10001001' ;CONFIGURE TO AN1

MOVWF ADCON0

MOVLW D'50'

MOVWF X1

DECFSZ X1

GOTO $-1 ;DELAY A WHILE

BSF ADCON0,2 ;START CONVERSION

BTFSC ADCON0,2 ;WAIT UNTIL ADC COMPLETED

GOTO $-1

MOVF ADRESH,W ;MOVE ADC VALUE TO WORKING REGISTER

BCF ADCON0,ADON ;OFF ADC MODULE

RETURN

READ_ADC3

CALL BANK0

MOVLW B'10011001' ;CONFIGURE TO AN3

MOVWF ADCON0

MOVLW D'50'

MOVWF X1

DECFSZ X1

GOTO $-1 ;DELAY A WHILE

BSF ADCON0,2 ;START CONVERSION

BTFSC ADCON0,2 ;WAIT UNTIL ADC COMPLETED

GOTO $-1

MOVF ADRESH,W ;MOVE ADC VALUE TO WORKING REGISTER

BCF ADCON0,ADON ;OFF ADC MODULE

RETURN

;============================= CHANGE BANK ROUTINE ==================================

BANK0

BCF STATUS,RP0 ; SELECT BANK 0

BCF STATUS,RP1

RETURN

BANK1

BSF STATUS,RP0 ; SELECT BANK 1

BCF STATUS,RP1

RETURN

BANK2

BSF STATUS,RP1

BCF STATUS,RP0 ; SELECT BANK 2

RETURN

BANK3

BSF STATUS,RP1

BSF STATUS,RP0 ; SELECT BANK 3

RETURN

;============================= DELAY SUBROUTINE ======================================

;============================= DELAY =================================================

DELAY

MOVLW D'5'

MOVWF X3

MOVLW D'60'

MOVWF X2

MOVLW D'255'

MOVWF X1

DECFSZ X1

GOTO $-1

DECFSZ X2

GOTO $-5

DECFSZ X3

GOTO $-9

RETURN

;============================= DELAY 1 ===============================================

DELAY1

MOVLW D'30'

MOVWF X3

MOVLW D'100'

MOVWF X2

MOVLW D'255'

MOVWF X1

DECFSZ X1

GOTO $-1

DECFSZ X2

GOTO $-5

DECFSZ X3

GOTO $-9

RETURN

;============================= DELAY 2 ================================================

DELAY2

MOVLW D'100'

MOVWF X3

MOVLW D'255'

MOVWF X2

MOVLW D'255'

MOVWF X1

DECFSZ X1

GOTO $-1

DECFSZ X2

GOTO $-5

DECFSZ X3

GOTO $-9

RETURN

;============================= DELAY 3 ================================================

DELAY3

MOVWF X3

MOVLW D'50'

MOVWF X2

MOVLW D'100'

MOVWF X1

DECFSZ X1

GOTO $-1

DECFSZ X2

GOTO $-5

DECFSZ X3

GOTO $-9

RETURN

;============================= DELAY_BEAT ===========================================

DELAY_BEAT

MOVLW D'2'

MOVWF X3

MOVLW D'255'

MOVWF X2

MOVLW D'255'

MOVWF X1

DECFSZ X1

GOTO $-1

DECFSZ X2

GOTO $-5

DECFSZ X3

GOTO $-9

RETURN

;============================= DELAY_BEAT_OFF ========================================

DELAY_BEAT_OFF

MOVLW D'2'

MOVWF X3

MOVLW D'255'

MOVWF X2

MOVLW D'255'

MOVWF X1

DECFSZ X1

GOTO $-1

DECFSZ X2

GOTO $-5

DECFSZ X3

GOTO $-9

ETURN

END

 
 
  Today, there have been 3 visitors (4 hits) on this page! Copyright By : Lufias21  
 
This website was created for free with Own-Free-Website.com. Would you also like to have your own website?
Sign up for free